24 __all__ = [
"LoadIndexedReferenceObjectsConfig",
"LoadIndexedReferenceObjectsTask"]
26 from .loadReferenceObjects
import hasNanojanskyFluxUnits, convertToNanojansky, getFormatVersionFromRefCat
27 from lsst.meas.algorithms import getRefFluxField, LoadReferenceObjectsTask, LoadReferenceObjectsConfig
30 import lsst.pex.config
as pexConfig
32 from .indexerRegistry
import IndexerRegistry
36 ref_dataset_name = pexConfig.Field(
38 default=
'cal_ref_cat',
39 doc=
'Name of the ingested reference dataset'
44 """Load reference objects from an indexed catalog ingested by
45 IngestIndexReferenceTask.
49 butler : `lsst.daf.persistence.Butler`
50 Data butler for reading catalogs
52 ConfigClass = LoadIndexedReferenceObjectsConfig
53 _DefaultName =
'LoadIndexedReferenceObjectsTask'
56 LoadReferenceObjectsTask.__init__(self, *args, **kwargs)
57 self.
dataset_config = butler.get(
"ref_cat_config", name=self.config.ref_dataset_name, immediate=
True)
65 def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None, centroids=False):
66 shardIdList, isOnBoundaryList = self.
indexer.getShardIds(ctrCoord, radius)
68 refCat = self.
butler.get(
'ref_cat',
73 for shard, isOnBoundary
in zip(shards, isOnBoundaryList):
82 if epoch
is not None and "pm_ra" in refCat.schema:
84 if isinstance(refCat.schema[
"pm_ra"].asKey(), lsst.afw.table.KeyAngle):
87 self.log.
warn(
"Catalog pm_ra field is not an Angle; not applying proper motion")
91 self.log.
warn(
"Found version 0 reference catalog with old style units in schema.")
92 self.log.
warn(
"run `meas_algorithms/bin/convert_refcat_to_nJy.py` to convert fluxes to nJy.")
93 self.log.
warn(
"See RFC-575 for more details.")
100 raise RuntimeError(f
"Format version in reference catalog ({catVersion}) does not match"
101 f
" format_version field in config ({self.dataset_config.format_version})")
104 fluxField =
getRefFluxField(schema=refCat.schema, filterName=filterName)
112 mapper.addMinimalSchema(refCat.schema,
True)
113 mapper.editOutputSchema().addField(
"centroid_x", type=float)
114 mapper.editOutputSchema().addField(
"centroid_y", type=float)
115 mapper.editOutputSchema().addField(
"hasCentroid", type=
"Flag")
117 expandedCat.extend(refCat, mapper=mapper)
121 if not refCat.isContiguous():
122 refCat = refCat.copy(
True)
125 return pipeBase.Struct(
135 shardIdList : `list` of `int`
136 A list of integer shard ids.
140 catalogs : `list` of `lsst.afw.table.SimpleCatalog`
141 A list of reference catalogs, one for each entry in shardIdList.
144 for shardId
in shardIdList:
145 if self.
butler.datasetExists(
'ref_cat',
147 shards.append(self.
butler.get(
'ref_cat',
152 def _trimToCircle(self, refCat, ctrCoord, radius):
153 """Trim a reference catalog to a circular aperture.
157 refCat : `lsst.afw.table.SimpleCatalog`
158 Reference catalog to be trimmed.
159 ctrCoord : `lsst.geom.SpherePoint`
160 ICRS center of search region.
161 radius : `lsst.geom.Angle`
162 Radius of search region.
166 catalog : `lsst.afw.table.SimpleCatalog`
167 Catalog containing objects that fall in the circular aperture.
169 tempCat =
type(refCat)(refCat.schema)
170 for record
in refCat:
171 if record.getCoord().separation(ctrCoord) < radius:
172 tempCat.append(record)