24__all__ = [
"ReadFitsCatalogConfig",
"ReadFitsCatalogTask"]
26from astropy.table
import Table
29import lsst.pipe.base
as pipeBase
33 hdu = pexConfig.Field(
36 doc=
"HDU containing the desired binary table, 0-based but a binary table never occurs in HDU 0",
38 column_map = pexConfig.DictField(
39 doc=
"Mapping of input column name: output column name; each specified column must exist, "
40 "but additional columns in the input data are written using their original name. ",
48 """Read an object catalog from a FITS table
50 The resulting `catalogArray` is a numpy structured array containing fields such
as "name",
"ra" and "dec"
51 and a few rows of data. For more complicated cases config parameters allow you to rename columns
52 and choose which HDU to read.
54 _DefaultName = 'readCatalog'
55 ConfigClass = ReadFitsCatalogConfig
57 def run(self, filename):
58 """Read an object catalog from the specified FITS file
63 Path to specified FITS file
68 a numpy structured array containing the specified columns
71 table = Table.read(filename, hdu=self.config.hdu)
73 raise RuntimeError(
"No data found in %s HDU %s" % (filename, self.config.hdu))
75 if not self.config.column_map:
77 return table.as_array()
79 missingnames = set(self.config.column_map.keys()) - set(table.columns.keys())
81 raise RuntimeError(
"Columns %s in column_map were not found in %s" % (missingnames, filename))
83 for inname, outname
in self.config.column_map.items():
84 table.columns[inname].name = outname
85 return table.as_array()