24 __all__ = [
"ReadFitsCatalogConfig",
"ReadFitsCatalogTask"]
26 from astropy.io
import fits
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. ",
55 """!Read an object catalog from a FITS table 57 @anchor ReadFitsCatalogTask_ 59 @section meas_algorithms_readFitsCatalog_Contents Contents 61 - @ref meas_algorithms_readFitsCatalog_Purpose 62 - @ref meas_algorithms_readFitsCatalog_Initialize 63 - @ref meas_algorithms_readFitsCatalog_Config 64 - @ref meas_algorithms_readFitsCatalog_Example 66 @section meas_algorithms_readFitsCatalog_Purpose Description 68 Read an object catalog from a FITS table. Designed to read foreign catalogs 69 so they can be written out in a form suitable for IngestIndexedReferenceTask. 71 @section meas_algorithms_readFitsCatalog_Initialize Task initialisation 75 @section meas_algorithms_readFitsCatalog_Config Configuration parameters 77 See @ref ReadFitsCatalogConfig 79 @section meas_algorithms_readFitsCatalog_Example A complete example of using ReadFitsCatalogTask 81 Run the following code from the main directory of meas_algorithms: 83 from lsst.meas.algorithms.readFitsCatalogTask import ReadFitsCatalogTask 84 filePath = "tests/data/testReadFitsCatalog.fits" 85 task = ReadFitsCatalogTask() 86 catalogArray = task.run(filePath) 88 The resulting `catalogArray` is a numpy structured array containing fields such as "name", "ra" and "dec" 89 and a few rows of data. For more complicated cases config parameters allow you to rename columns 90 and choose which HDU to read. 92 _DefaultName =
'readCatalog' 93 ConfigClass = ReadFitsCatalogConfig
95 def run(self, filename):
96 """Read an object catalog from the specified FITS file 98 @param[in] filename path to FITS file 99 @return a numpy structured array containing the specified columns 101 with fits.open(filename)
as f:
102 hdu = f[self.config.hdu]
104 raise RuntimeError(
"No data found in %s HDU %s" % (filename, self.config.hdu))
106 raise RuntimeError(
"%s HDU %s is an image" % (filename, self.config.hdu))
108 if not self.config.column_map:
112 missingnames = set(self.config.column_map.keys()) - set(hdu.columns.names)
114 raise RuntimeError(
"Columns %s in column_map were not found in %s" % (missingnames, filename))
116 for inname, outname
in self.config.column_map.items():
117 hdu.columns[inname].name = outname
Read an object catalog from a FITS table.