24 __all__ = [
"ReadTextCatalogConfig",
"ReadTextCatalogTask"]
33 header_lines = pexConfig.Field(
36 doc=
'Number of lines to skip when reading the text reference file.' 38 colnames = pexConfig.ListField(
41 doc=
"An ordered list of column names to use in ingesting the catalog. " 42 "With an empty list, column names will be discovered from the first line " 43 "after the skipped header lines." 45 delimiter = pexConfig.Field(
48 doc=
'Delimiter to use when reading text reference files. Comma is default.' 60 r"""!Read an object catalog from a text file 62 @anchor ReadTextCatalogTask_ 64 @section meas_algorithms_readTextCatalog_Contents Contents 66 - @ref meas_algorithms_readTextCatalog_Purpose 67 - @ref meas_algorithms_readTextCatalog_Initialize 68 - @ref meas_algorithms_readTextCatalog_Config 69 - @ref meas_algorithms_readTextCatalog_Example 71 @section meas_algorithms_readTextCatalog_Purpose Description 73 Read an object catalog from a text file. Designed to read foreign catalogs 74 so they can be written out in a form suitable for IngestIndexedReferenceTask. 76 @section meas_algorithms_readTextCatalog_Initialize Task initialisation 80 @section meas_algorithms_readTextCatalog_Config Configuration parameters 82 See @ref ReadTextCatalogConfig 84 @section meas_algorithms_readTextCatalog_Example A complete example of using ReadTextCatalogTask 86 Given a file named `table.csv` containing the following: 92 you can read this file with the following code: 94 from lsst.meas.algorithms.readTextCatalogTask import ReadTextCatalogTask 95 task = ReadTextCatalogTask() 96 catalogArray = task.run("table.csv") 98 The resulting `catalogArray` is a numpy structured array containing three fields 99 ("ra", "dec" and "flux") and two rows of data. For more complex cases, 100 config parameters allow you to specify the names of the columns (instead of using automatic discovery) 101 and set the number of rows to skip. 103 _DefaultName =
'readCatalog' 104 ConfigClass = ReadTextCatalogConfig
107 """Read an object catalog from the specified text file 109 @param[in] filename path to text file 110 @return a numpy structured array containing the specified columns 113 if self.config.colnames:
114 names = self.config.colnames
115 arr = np.genfromtxt(filename, dtype=
None, skip_header=self.config.header_lines,
116 delimiter=self.config.delimiter,
121 for name
in arr.dtype.names:
122 value = arr.dtype[name]
123 if value.kind ==
'S':
124 value = np.dtype(
'|U{}'.format(value.itemsize))
125 newDtype.append((name, value))
126 arr = arr.astype(newDtype)
129 return np.atleast_1d(arr)
Read an object catalog from a text file.