Parse a File#
Parse irregular data tables into .csv files or astropy.Table objects using the parse_file method.
- astroparse.parse_file(fname_in: str, sep_reg: str = '(?<=\\S)( |\\t)+(?!\\s)', nan_reg: str = 'nan', hdr: int = -1, lo: int = 1, hi: int = -1, fname_out: str = None) Table#
Translates the contents of a file into string interpretable by the astropy readers.
The parsed contents are returned as an astropy Table and can be optionally be saved to an output file. Empty or NaN data can be replaced according to a specified pattern.
- Parameters:
fname_in (str) – Name of the input file.
sep_reg (str) – Regex pattern matching column separators in the input file.
nan_reg (str) – Regex pattern matching empty or NaN data in the input file.
hdr (int, default = -1) – Line number in the input file where the header is found. Only one line can be read as the ‘header’ and it must have the same column format as the data. A value of -1 means no header will be prepended to the data.
lo (int, default = 1) – First line number in the input file where the data appear.
hi (int, default = -1) – Last line number in the input file where the data appear.
fname_out (str, default = None) – Name of the output file. A value of None indicates that data should not be saved to any external file. If a file name is specified, the contents of any file at that existing path will be overwritten.
- Returns:
tbl – The parsed contents of the input file as an astropy Table.
- Return type:
astropy.table.Table