Skip to content

Commit

Permalink
Add SED table parser for notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Aug 28, 2024
1 parent 65bab5c commit dad621f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scopesim/source/source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,32 @@ def make_img_wcs_header(
imgwcs.wcs.cunit = [u.deg, u.deg]

return imgwcs.to_header()


def parse_sed_table(filename: Path | str) -> Table:
"""
Parse SED table from example cubes.
Parameters
----------
filename : Path | str
Input file path.
Returns
-------
astropy.table.Table
Parsed table.
"""
tbl = Table.read(filename, format="ascii")
tbl.meta.update(convert_table_comments_to_dict(tbl))
tbl.meta.pop("comments")
new_names = {}
for col in tbl.columns:
cmt = tbl.meta[col.replace("col", "column ")].split("(", maxsplit=1)
tbl[col].unit = cmt[-1].strip(")")
new_names[col] = cmt[0].split(";", maxsplit=1)[0].strip()
# Cannot do a single loop because tbl.columns would get mutated...
for old_name, new_name in new_names.items():
tbl[old_name].name = new_name
return tbl

0 comments on commit dad621f

Please sign in to comment.