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 The file is assumed to be encoded as UTF-8 (which is compatible with ASCII). 78 @section meas_algorithms_readTextCatalog_Initialize Task initialisation 82 @section meas_algorithms_readTextCatalog_Config Configuration parameters 84 See @ref ReadTextCatalogConfig 86 @section meas_algorithms_readTextCatalog_Example A complete example of using ReadTextCatalogTask 88 Given a file named `table.csv` containing the following: 94 you can read this file with the following code: 96 from lsst.meas.algorithms.readTextCatalogTask import ReadTextCatalogTask 97 task = ReadTextCatalogTask() 98 catalogArray = task.run("table.csv") 100 The resulting `catalogArray` is a numpy structured array containing three fields 101 ("ra", "dec" and "flux") and two rows of data. For more complex cases, 102 config parameters allow you to specify the names of the columns (instead of using automatic discovery) 103 and set the number of rows to skip. 105 _DefaultName =
'readCatalog' 106 ConfigClass = ReadTextCatalogConfig
109 """Read an object catalog from the specified text file 111 @param[in] filename path to text file 112 @return a numpy structured array containing the specified columns 115 if self.config.colnames:
116 names = self.config.colnames
117 arr = np.genfromtxt(filename, dtype=
None, encoding=
"utf-8",
118 skip_header=self.config.header_lines,
119 delimiter=self.config.delimiter,
123 return np.atleast_1d(arr)
Read an object catalog from a text file.