Commit fb155307 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

add table utils

parent 86a46ad6
Pipeline #4374 passed with stage
in 0 seconds
...@@ -12,6 +12,4 @@ Modified-History: ...@@ -12,6 +12,4 @@ Modified-History:
from ._module_docstr import ModuleHeader from ._module_docstr import ModuleHeader
from ._retry import retry from ._retry import retry
from .tempfile import randfile from .tempfile import randfile
from .table_utils import table_to_hdu, hdu_to_table
"""
Identifier: csst_dadel/csst_dadel/utils.py
Name: utils.py
Description: Table utils.
Author: Bo Zhang
Created: 2024-02-18
Modified-History:
2024-02-18, Bo Zhang, implement utils for conversion between Table and BinTableHDU
"""
from astropy import table
from astropy.io import fits
def table_to_hdu(tbl: table.Table, name: str = "") -> fits.BinTableHDU:
"""Convert a table to a BinTableHDU."""
# encode meta
encoded_tbl = fits.connect._encode_mixins(tbl)
# convert to HDU
hdu = fits.table_to_hdu(encoded_tbl)
# add HDU name
hdu.name = name
return hdu
def hdu_to_table(hdu: fits.BinTableHDU) -> table.Table:
"""Convert a BinTableHDU to a table."""
return table.Table.read(hdu)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment