LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
loadIndexedReferenceObjects.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 #
4 # Copyright 2008-2017 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <https://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 __all__ = ["LoadIndexedReferenceObjectsConfig", "LoadIndexedReferenceObjectsTask"]
25 
26 from .loadReferenceObjects import hasNanojanskyFluxUnits, convertToNanojansky, getFormatVersionFromRefCat
27 from lsst.meas.algorithms import getRefFluxField, LoadReferenceObjectsTask, LoadReferenceObjectsConfig
28 import lsst.afw.table as afwTable
29 import lsst.pex.config as pexConfig
30 import lsst.pipe.base as pipeBase
31 from lsst.utils.timer import timeMethod
32 from .indexerRegistry import IndexerRegistry
33 
34 
36  ref_dataset_name = pexConfig.Field(
37  dtype=str,
38  default='cal_ref_cat',
39  doc='Name of the ingested reference dataset'
40  )
41 
42 
44  """Load reference objects from an indexed catalog ingested by
45  IngestIndexReferenceTask.
46 
47  Parameters
48  ----------
49  butler : `lsst.daf.persistence.Butler`
50  Data butler for reading catalogs
51  """
52  ConfigClass = LoadIndexedReferenceObjectsConfig
53  _DefaultName = 'LoadIndexedReferenceObjectsTask'
54 
55  def __init__(self, butler, *args, **kwargs):
56  LoadReferenceObjectsTask.__init__(self, *args, **kwargs)
57  self.dataset_configdataset_config = butler.get("ref_cat_config", name=self.config.ref_dataset_name, immediate=True)
58  self.indexerindexer = IndexerRegistry[self.dataset_configdataset_config.indexer.name](self.dataset_configdataset_config.indexer.active)
59  # This needs to come from the loader config, not the dataset_config since directory aliases can
60  # change the path where the shards are found.
61  self.ref_dataset_nameref_dataset_name = self.config.ref_dataset_name
62  self.butlerbutlerbutler = butler
63 
64  @timeMethod
65  def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None, centroids=False):
66  shardIdList, isOnBoundaryList = self.indexerindexer.getShardIds(ctrCoord, radius)
67  shards = self.getShardsgetShards(shardIdList)
68  refCat = self.butlerbutlerbutler.get('ref_cat',
69  dataId=self.indexerindexer.makeDataId('master_schema', self.ref_dataset_nameref_dataset_name),
70  immediate=True)
71 
72  # load the catalog, one shard at a time
73  for shard, isOnBoundary in zip(shards, isOnBoundaryList):
74  if shard is None:
75  continue
76  if isOnBoundary:
77  refCat.extend(self._trimToCircle_trimToCircle(shard, ctrCoord, radius))
78  else:
79  refCat.extend(shard)
80 
81  # make sure catalog is contiguous: must do this before PM calculations
82  if not refCat.isContiguous():
83  refCat = refCat.copy(True)
84 
85  # apply proper motion corrections
86  self.applyProperMotionsapplyProperMotions(refCat, epoch)
87 
88  # update version=0 style refcats to have nJy fluxes
89  if self.dataset_configdataset_config.format_version == 0 or not hasNanojanskyFluxUnits(refCat.schema):
90  self.log.warning("Found version 0 reference catalog with old style units in schema.")
91  self.log.warning("run `meas_algorithms/bin/convert_refcat_to_nJy.py` to convert fluxes to nJy.")
92  self.log.warning("See RFC-575 for more details.")
93  refCat = convertToNanojansky(refCat, self.log)
94  else:
95  # For version >= 1, the version should be in the catalog header,
96  # too, and should be consistent with the version in the config.
97  catVersion = getFormatVersionFromRefCat(refCat)
98  if catVersion != self.dataset_configdataset_config.format_version:
99  raise RuntimeError(f"Format version in reference catalog ({catVersion}) does not match"
100  f" format_version field in config ({self.dataset_config.format_version})")
101 
102  self._addFluxAliases_addFluxAliases(refCat.schema)
103  fluxField = getRefFluxField(schema=refCat.schema, filterName=filterName)
104 
105  if centroids:
106  # add and initialize centroid and hasCentroid fields (these are
107  # added after loading to avoid wasting space in the saved catalogs)
108  # the new fields are automatically initialized to (nan, nan) and
109  # False so no need to set them explicitly
110  mapper = afwTable.SchemaMapper(refCat.schema, True)
111  mapper.addMinimalSchema(refCat.schema, True)
112  mapper.editOutputSchema().addField("centroid_x", type=float)
113  mapper.editOutputSchema().addField("centroid_y", type=float)
114  mapper.editOutputSchema().addField("hasCentroid", type="Flag")
115  expandedCat = afwTable.SimpleCatalog(mapper.getOutputSchema())
116  expandedCat.extend(refCat, mapper=mapper)
117  refCat = expandedCat
118 
119  # return reference catalog
120  return pipeBase.Struct(
121  refCat=refCat,
122  fluxField=fluxField,
123  )
124 
125  def getShards(self, shardIdList):
126  """Get shards by ID.
127 
128  Parameters
129  ----------
130  shardIdList : `list` of `int`
131  A list of integer shard ids.
132 
133  Returns
134  -------
135  catalogs : `list` of `lsst.afw.table.SimpleCatalog`
136  A list of reference catalogs, one for each entry in shardIdList.
137  """
138  shards = []
139  for shardId in shardIdList:
140  if self.butlerbutlerbutler.datasetExists('ref_cat',
141  dataId=self.indexerindexer.makeDataId(shardId, self.ref_dataset_nameref_dataset_name)):
142  shards.append(self.butlerbutlerbutler.get('ref_cat',
143  dataId=self.indexerindexer.makeDataId(shardId, self.ref_dataset_nameref_dataset_name),
144  immediate=True))
145  return shards
146 
147  def _trimToCircle(self, refCat, ctrCoord, radius):
148  """Trim a reference catalog to a circular aperture.
149 
150  Parameters
151  ----------
152  refCat : `lsst.afw.table.SimpleCatalog`
153  Reference catalog to be trimmed.
154  ctrCoord : `lsst.geom.SpherePoint`
155  ICRS center of search region.
156  radius : `lsst.geom.Angle`
157  Radius of search region.
158 
159  Returns
160  -------
161  catalog : `lsst.afw.table.SimpleCatalog`
162  Catalog containing objects that fall in the circular aperture.
163  """
164  tempCat = type(refCat)(refCat.schema)
165  for record in refCat:
166  if record.getCoord().separation(ctrCoord) < radius:
167  tempCat.append(record)
168  return tempCat
table::Key< int > type
Definition: Detector.cc:163
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None, centroids=False)
def convertToNanojansky(catalog, log, doConvert=True)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.