aerosoltools.loaders.support.reading¶
Shared file-reading helpers for the instrument loaders.
Every loader used to hand-roll the same “detect encoding/delimiter, then read”
dance — often calling _detect_delimiter()
several times and re-parsing the file with numpy.genfromtxt()/
pandas.read_csv() more than once. These helpers give one place to sniff a
file and read its data table, so a loader detects once and reads once.
Module Contents¶
- aerosoltools.loaders.support.reading.sniff(file, encoding=None, delimiter=None, **detect_kwargs)[source]¶
Return
(encoding, delimiter)forfile, detecting what is missing.Pass a value you already know to skip detecting it; pass neither to detect both.
detect_kwargs(e.g.sample_lines=30) are forwarded to_detect_delimiter()so loaders that need a larger sample keep their exact detection behaviour.
- aerosoltools.loaders.support.reading.read_table(file, *, encoding=None, delimiter=None, **read_csv_kwargs)[source]¶
Read
fileas a delimited table withpandas.read_csv().Detects the encoding and delimiter (via
sniff()) when they are not supplied, then forwardsread_csv_kwargs(header,usecols,skipfooter,engine,nrows, …) unchanged topandas.read_csv().- Parameters:
- Return type:
- aerosoltools.loaders.support.reading.read_cells(file, *, skip_header, max_rows=1, encoding=None, delimiter=None, **genfromtxt_kwargs)[source]¶
Read a small block of header cells as strings via
numpy.genfromtxt().A thin wrapper for the
genfromtxt(..., skip_header=N, max_rows=1, dtype=str)metadata pluck the loaders repeat, with encoding/delimiter detection folded in. Keeps genfromtxt’s exact tokenising, so results are identical to the previous inline calls.