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
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader Class Reference
Inheritance diagram for lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader:
lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoaderBase

Public Member Functions

def __init__ (self, dataIds, refCats, config, log=None)
 
def loadPixelBox (self, bbox, wcs, filterName=None, epoch=None, photoCalib=None, bboxToSpherePadding=100)
 
def loadRegion (self, region, filtFunc=None, filterName=None, epoch=None)
 
def loadSkyCircle (self, ctrCoord, radius, filterName=None, epoch=None)
 
def joinMatchListWithCatalog (self, matchCat, sourceCat)
 
def getMetadataBox (self, bbox, wcs, filterName=None, photoCalib=None, epoch=None, bboxToSpherePadding=100)
 
def applyProperMotions (self, catalog, epoch)
 

Static Public Member Functions

def getMetadataCircle (coord, radius, filterName, photoCalib=None, epoch=None)
 
def addFluxAliases (refCat, defaultFilter, filterReferenceMap)
 
def remapReferenceCatalogSchema (refCat, *filterNameList=None, position=False, photometric=False)
 

Public Attributes

 dataIds
 
 refCats
 
 log
 
 config
 

Detailed Description

This class facilitates loading reference catalogs with gen 3 middleware

The middleware preflight solver will create a list of datarefs that may
possibly overlap a given region. These datarefs are then used to construct
and instance of this class. The class instance should then be passed into
a task which needs reference catalogs. These tasks should then determine
the exact region of the sky reference catalogs will be loaded for, and
call a corresponding method to load the reference objects.

Definition at line 256 of file loadReferenceObjects.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.__init__ (   self,
  dataIds,
  refCats,
  config,
  log = None 
)
 Constructs an instance of ReferenceObjectLoader

Parameters
----------
dataIds : iterable of `lsst.daf.butler.DataIds`
    An iterable object of DataSetRefs which point to reference catalogs
    in a gen 3 repository.
refCats : iterable of `lsst.daf.butler.DeferedDatasetHandle`
    Handles to load refCats on demand
config : `lsst.pex.config.configurableField`
    Configuration for the loader.
log : `lsst.log.Log`, `logging.Logger` or `None`, optional
    Logger object used to write out messages. If `None` a default
    logger will be used.

Definition at line 266 of file loadReferenceObjects.py.

266  def __init__(self, dataIds, refCats, config, log=None):
267  """ Constructs an instance of ReferenceObjectLoader
268 
269  Parameters
270  ----------
271  dataIds : iterable of `lsst.daf.butler.DataIds`
272  An iterable object of DataSetRefs which point to reference catalogs
273  in a gen 3 repository.
274  refCats : iterable of `lsst.daf.butler.DeferedDatasetHandle`
275  Handles to load refCats on demand
276  config : `lsst.pex.config.configurableField`
277  Configuration for the loader.
278  log : `lsst.log.Log`, `logging.Logger` or `None`, optional
279  Logger object used to write out messages. If `None` a default
280  logger will be used.
281  """
282  self.dataIds = dataIds
283  self.refCats = refCats
284  self.log = log or logging.getLogger(__name__).getChild("ReferenceObjectLoader")
285  self.config = config
286 

Member Function Documentation

◆ addFluxAliases()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.addFluxAliases (   refCat,
  defaultFilter,
  filterReferenceMap 
)
static
Add flux columns and aliases for camera to reference mapping.

Creates a new catalog containing the information of the input refCat
as well as added flux columns and aliases between camera and reference
fluxes.

Parameters
----------
refCat : `lsst.afw.table.SimpleCatalog`
    Catalog of reference objects
defaultFilter : `str`
    Name of the default reference filter
filterReferenceMap : `dict` of `str`
    Dictionary with keys corresponding to a filter name and values
    which correspond to the name of the reference filter.

Returns
-------
refCat : `lsst.afw.table.SimpleCatalog`
    Reference catalog with columns added to track reference filters.

Raises
------
`RuntimeError`
    If the specified reference filter name is not specifed as a
    key in the reference filter map.

Definition at line 665 of file loadReferenceObjects.py.

665  def addFluxAliases(refCat, defaultFilter, filterReferenceMap):
666  """Add flux columns and aliases for camera to reference mapping.
667 
668  Creates a new catalog containing the information of the input refCat
669  as well as added flux columns and aliases between camera and reference
670  fluxes.
671 
672  Parameters
673  ----------
674  refCat : `lsst.afw.table.SimpleCatalog`
675  Catalog of reference objects
676  defaultFilter : `str`
677  Name of the default reference filter
678  filterReferenceMap : `dict` of `str`
679  Dictionary with keys corresponding to a filter name and values
680  which correspond to the name of the reference filter.
681 
682  Returns
683  -------
684  refCat : `lsst.afw.table.SimpleCatalog`
685  Reference catalog with columns added to track reference filters.
686 
687  Raises
688  ------
689  `RuntimeError`
690  If the specified reference filter name is not specifed as a
691  key in the reference filter map.
692  """
693  refCat = ReferenceObjectLoader.remapReferenceCatalogSchema(refCat,
694  filterNameList=filterReferenceMap.keys())
695  aliasMap = refCat.schema.getAliasMap()
696  if filterReferenceMap is None:
697  filterReferenceMap = {}
698  for filterName, refFilterName in itertools.chain([(None, defaultFilter)],
699  filterReferenceMap.items()):
700  if refFilterName:
701  camFluxName = filterName + "_camFlux" if filterName is not None else "camFlux"
702  refFluxName = refFilterName + "_flux"
703  if refFluxName not in refCat.schema:
704  raise RuntimeError("Unknown reference filter %s" % (refFluxName,))
705  aliasMap.set(camFluxName, refFluxName)
706 
707  refFluxErrName = refFluxName + "Err"
708  camFluxErrName = camFluxName + "Err"
709  aliasMap.set(camFluxErrName, refFluxErrName)
710 
711  return refCat
712 

◆ applyProperMotions()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoaderBase.applyProperMotions (   self,
  catalog,
  epoch 
)
inherited
Apply proper motion correction to a reference catalog.

Adjust position and position error in the ``catalog``
for proper motion to the specified ``epoch``,
modifying the catalog in place.

Parameters
----------
catalog : `lsst.afw.table.SimpleCatalog`
    Catalog of positions, containing at least these fields:

    - Coordinates, retrieved by the table's coordinate key.
    - ``coord_raErr`` : Error in Right Ascension (rad).
    - ``coord_decErr`` : Error in Declination (rad).
    - ``pm_ra`` : Proper motion in Right Ascension (rad/yr,
        East positive)
    - ``pm_raErr`` : Error in ``pm_ra`` (rad/yr), optional.
    - ``pm_dec`` : Proper motion in Declination (rad/yr,
        North positive)
    - ``pm_decErr`` : Error in ``pm_dec`` (rad/yr), optional.
    - ``epoch`` : Mean epoch of object (an astropy.time.Time)
epoch : `astropy.time.Time`
    Epoch to which to correct proper motion.
    If None, do not apply PM corrections or raise if
    ``config.requireProperMotion`` is True.

Raises
------
RuntimeError
    Raised if ``config.requireProperMotion`` is set but we cannot
    apply the proper motion correction for some reason.

Definition at line 197 of file loadReferenceObjects.py.

197  def applyProperMotions(self, catalog, epoch):
198  """Apply proper motion correction to a reference catalog.
199 
200  Adjust position and position error in the ``catalog``
201  for proper motion to the specified ``epoch``,
202  modifying the catalog in place.
203 
204  Parameters
205  ----------
206  catalog : `lsst.afw.table.SimpleCatalog`
207  Catalog of positions, containing at least these fields:
208 
209  - Coordinates, retrieved by the table's coordinate key.
210  - ``coord_raErr`` : Error in Right Ascension (rad).
211  - ``coord_decErr`` : Error in Declination (rad).
212  - ``pm_ra`` : Proper motion in Right Ascension (rad/yr,
213  East positive)
214  - ``pm_raErr`` : Error in ``pm_ra`` (rad/yr), optional.
215  - ``pm_dec`` : Proper motion in Declination (rad/yr,
216  North positive)
217  - ``pm_decErr`` : Error in ``pm_dec`` (rad/yr), optional.
218  - ``epoch`` : Mean epoch of object (an astropy.time.Time)
219  epoch : `astropy.time.Time`
220  Epoch to which to correct proper motion.
221  If None, do not apply PM corrections or raise if
222  ``config.requireProperMotion`` is True.
223 
224  Raises
225  ------
226  RuntimeError
227  Raised if ``config.requireProperMotion`` is set but we cannot
228  apply the proper motion correction for some reason.
229  """
230  if epoch is None:
231  if self.config.requireProperMotion:
232  raise RuntimeError("requireProperMotion=True but epoch not provided to loader.")
233  else:
234  self.log.debug("No epoch provided: not applying proper motion corrections to refcat.")
235  return
236 
237  # Warn/raise for a catalog in an incorrect format, if epoch was specified.
238  if ("pm_ra" in catalog.schema
239  and not isinstance(catalog.schema["pm_ra"].asKey(), afwTable.KeyAngle)):
240  if self.config.requireProperMotion:
241  raise RuntimeError("requireProperMotion=True but refcat pm_ra field is not an Angle.")
242  else:
243  self.log.warning("Reference catalog pm_ra field is not an Angle; cannot apply proper motion.")
244  return
245 
246  if ("epoch" not in catalog.schema or "pm_ra" not in catalog.schema):
247  if self.config.requireProperMotion:
248  raise RuntimeError("requireProperMotion=True but PM data not available from catalog.")
249  else:
250  self.log.warning("Proper motion correction not available for this reference catalog.")
251  return
252 
253  applyProperMotionsImpl(self.log, catalog, epoch)
254 
255 

◆ getMetadataBox()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.getMetadataBox (   self,
  bbox,
  wcs,
  filterName = None,
  photoCalib = None,
  epoch = None,
  bboxToSpherePadding = 100 
)
Return metadata about the load

This metadata is used for reloading the catalog (e.g., for
reconstituting a normalised match list.)

Parameters
----------
bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
    Bounding box for the pixels.
wcs : `lsst.afw.geom.SkyWcs`
    The WCS object associated with ``bbox``.
filterName : `str` or `None`, optional
    Name of the camera filter, or `None` or blank for the default
    filter.
photoCalib : `None`
    Deprecated, only included for api compatibility.
epoch : `astropy.time.Time` or `None`,  optional
    Epoch to which to correct proper motion and parallax, or `None` to
    not apply such corrections.
bboxToSpherePadding : `int`, optional
    Padding to account for translating a set of corners into a
    spherical (convex) boundary that is certain to encompase the
    enitre area covered by the box.

Returns
-------
md : `lsst.daf.base.PropertyList`
    The metadata detailing the search parameters used for this
    dataset.

Definition at line 581 of file loadReferenceObjects.py.

582  bboxToSpherePadding=100):
583  """Return metadata about the load
584 
585  This metadata is used for reloading the catalog (e.g., for
586  reconstituting a normalised match list.)
587 
588  Parameters
589  ----------
590  bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
591  Bounding box for the pixels.
592  wcs : `lsst.afw.geom.SkyWcs`
593  The WCS object associated with ``bbox``.
594  filterName : `str` or `None`, optional
595  Name of the camera filter, or `None` or blank for the default
596  filter.
597  photoCalib : `None`
598  Deprecated, only included for api compatibility.
599  epoch : `astropy.time.Time` or `None`, optional
600  Epoch to which to correct proper motion and parallax, or `None` to
601  not apply such corrections.
602  bboxToSpherePadding : `int`, optional
603  Padding to account for translating a set of corners into a
604  spherical (convex) boundary that is certain to encompase the
605  enitre area covered by the box.
606 
607  Returns
608  -------
609  md : `lsst.daf.base.PropertyList`
610  The metadata detailing the search parameters used for this
611  dataset.
612  """
613  paddedBbox = geom.Box2D(bbox)
614  paddedBbox.grow(self.config.pixelMargin)
615  _, _, innerCorners, outerCorners = self._makeBoxRegion(paddedBbox, wcs, bboxToSpherePadding)
616  md = PropertyList()
617  for box, corners in zip(("INNER", "OUTER"), (innerCorners, outerCorners)):
618  for (name, corner) in zip(("UPPER_LEFT", "UPPER_RIGHT", "LOWER_LEFT", "LOWER_RIGHT"),
619  corners):
620  md.add(f"{box}_{name}_RA", geom.SpherePoint(corner).getRa().asDegrees(), f"{box}_corner")
621  md.add(f"{box}_{name}_DEC", geom.SpherePoint(corner).getDec().asDegrees(), f"{box}_corner")
622  md.add("SMATCHV", 1, 'SourceMatchVector version number')
623  filterName = "UNKNOWN" if filterName is None else str(filterName)
624  md.add('FILTER', filterName, 'filter name for photometric data')
625  md.add('EPOCH', "NONE" if epoch is None else epoch.mjd, 'Epoch (TAI MJD) for catalog')
626  return md
627 
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57

◆ getMetadataCircle()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.getMetadataCircle (   coord,
  radius,
  filterName,
  photoCalib = None,
  epoch = None 
)
static
Return metadata about the load.

This metadata is used for reloading the catalog (e.g. for
reconstituting a normalized match list.)

Parameters
----------
coord : `lsst.geom.SpherePoint`
    ICRS center of the search region.
radius : `lsst.geom.Angle`
    Radius of the search region.
filterName : `str` or `None`
    Name of the camera filter, or `None` or blank for the default
    filter.
photoCalib : `None`
    Deprecated, only included for api compatibility.
epoch : `astropy.time.Time` or `None`, optional
    Epoch to which to correct proper motion and parallax, or `None` to
    not apply such corrections.

Returns
-------
md : `lsst.daf.base.PropertyList`

Definition at line 629 of file loadReferenceObjects.py.

629  def getMetadataCircle(coord, radius, filterName, photoCalib=None, epoch=None):
630  """Return metadata about the load.
631 
632  This metadata is used for reloading the catalog (e.g. for
633  reconstituting a normalized match list.)
634 
635  Parameters
636  ----------
637  coord : `lsst.geom.SpherePoint`
638  ICRS center of the search region.
639  radius : `lsst.geom.Angle`
640  Radius of the search region.
641  filterName : `str` or `None`
642  Name of the camera filter, or `None` or blank for the default
643  filter.
644  photoCalib : `None`
645  Deprecated, only included for api compatibility.
646  epoch : `astropy.time.Time` or `None`, optional
647  Epoch to which to correct proper motion and parallax, or `None` to
648  not apply such corrections.
649 
650  Returns
651  -------
652  md : `lsst.daf.base.PropertyList`
653  """
654  md = PropertyList()
655  md.add('RA', coord.getRa().asDegrees(), 'field center in degrees')
656  md.add('DEC', coord.getDec().asDegrees(), 'field center in degrees')
657  md.add('RADIUS', radius.asDegrees(), 'field radius in degrees, minimum')
658  md.add('SMATCHV', 1, 'SourceMatchVector version number')
659  filterName = "UNKNOWN" if filterName is None else str(filterName)
660  md.add('FILTER', filterName, 'filter name for photometric data')
661  md.add('EPOCH', "NONE" if epoch is None else epoch.mjd, 'Epoch (TAI MJD) for catalog')
662  return md
663 

◆ joinMatchListWithCatalog()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.joinMatchListWithCatalog (   self,
  matchCat,
  sourceCat 
)
Relink an unpersisted match list to sources and reference objects.

A match list is persisted and unpersisted as a catalog of IDs
produced by afw.table.packMatches(), with match metadata
(as returned by the astrometry tasks) in the catalog's metadata
attribute. This method converts such a match catalog into a match
list, with links to source records and reference object records.

Parameters
----------
matchCat : `lsst.afw.table.BaseCatalog`
    Unpersisted packed match list.
    ``matchCat.table.getMetadata()`` must contain match metadata,
    as returned by the astrometry tasks.
sourceCat : `lsst.afw.table.SourceCatalog`
    Source catalog. As a side effect, the catalog will be sorted
    by ID.

Returns
-------
matchList : `lsst.afw.table.ReferenceMatchVector`
    Match list.

Definition at line 555 of file loadReferenceObjects.py.

555  def joinMatchListWithCatalog(self, matchCat, sourceCat):
556  """Relink an unpersisted match list to sources and reference objects.
557 
558  A match list is persisted and unpersisted as a catalog of IDs
559  produced by afw.table.packMatches(), with match metadata
560  (as returned by the astrometry tasks) in the catalog's metadata
561  attribute. This method converts such a match catalog into a match
562  list, with links to source records and reference object records.
563 
564  Parameters
565  ----------
566  matchCat : `lsst.afw.table.BaseCatalog`
567  Unpersisted packed match list.
568  ``matchCat.table.getMetadata()`` must contain match metadata,
569  as returned by the astrometry tasks.
570  sourceCat : `lsst.afw.table.SourceCatalog`
571  Source catalog. As a side effect, the catalog will be sorted
572  by ID.
573 
574  Returns
575  -------
576  matchList : `lsst.afw.table.ReferenceMatchVector`
577  Match list.
578  """
579  return joinMatchListWithCatalogImpl(self, matchCat, sourceCat)
580 
def joinMatchListWithCatalogImpl(refObjLoader, matchCat, sourceCat)

◆ loadPixelBox()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.loadPixelBox (   self,
  bbox,
  wcs,
  filterName = None,
  epoch = None,
  photoCalib = None,
  bboxToSpherePadding = 100 
)
Load reference objects that are within a pixel-based rectangular
region.

This algorithm works by creating a spherical box whose corners
correspond to the WCS converted corners of the input bounding box
(possibly padded).  It then defines a filtering function which looks at
the pixel position of the reference objects and accepts only those that
lie within the specified bounding box.

The spherical box region and filtering function are passed to the
generic loadRegion method which loads and filters the reference objects
from the datastore and returns a single catalog containing the filtered
set of reference objects.

Parameters
----------
bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
    Box which bounds a region in pixel space.
wcs : `lsst.afw.geom.SkyWcs`
    Wcs object defining the pixel to sky (and inverse) transform for
    the supplied ``bbox``.
filterName : `str` or `None`, optional
    Name of camera filter, or `None` or blank for the default filter.
epoch : `astropy.time.Time` or `None`, optional
    Epoch to which to correct proper motion and parallax, or `None`
    to not apply such corrections.
photoCalib : `None`
    Deprecated and ignored, only included for api compatibility.
bboxToSpherePadding : `int`, optional
    Padding to account for translating a set of corners into a
    spherical (convex) boundary that is certain to encompase the
    enitre area covered by the box.

Returns
-------
referenceCatalog : `lsst.afw.table.SimpleCatalog`
    Catalog containing reference objects inside the specified bounding
    box (padded by self.config.pixelMargin).

Raises
------
RuntimeError
    Raised if no reference catalogs could be found for the specified
    region.
TypeError
    Raised if the loaded reference catalogs do not have matching
    schemas.

Definition at line 324 of file loadReferenceObjects.py.

325  bboxToSpherePadding=100):
326  """Load reference objects that are within a pixel-based rectangular
327  region.
328 
329  This algorithm works by creating a spherical box whose corners
330  correspond to the WCS converted corners of the input bounding box
331  (possibly padded). It then defines a filtering function which looks at
332  the pixel position of the reference objects and accepts only those that
333  lie within the specified bounding box.
334 
335  The spherical box region and filtering function are passed to the
336  generic loadRegion method which loads and filters the reference objects
337  from the datastore and returns a single catalog containing the filtered
338  set of reference objects.
339 
340  Parameters
341  ----------
342  bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
343  Box which bounds a region in pixel space.
344  wcs : `lsst.afw.geom.SkyWcs`
345  Wcs object defining the pixel to sky (and inverse) transform for
346  the supplied ``bbox``.
347  filterName : `str` or `None`, optional
348  Name of camera filter, or `None` or blank for the default filter.
349  epoch : `astropy.time.Time` or `None`, optional
350  Epoch to which to correct proper motion and parallax, or `None`
351  to not apply such corrections.
352  photoCalib : `None`
353  Deprecated and ignored, only included for api compatibility.
354  bboxToSpherePadding : `int`, optional
355  Padding to account for translating a set of corners into a
356  spherical (convex) boundary that is certain to encompase the
357  enitre area covered by the box.
358 
359  Returns
360  -------
361  referenceCatalog : `lsst.afw.table.SimpleCatalog`
362  Catalog containing reference objects inside the specified bounding
363  box (padded by self.config.pixelMargin).
364 
365  Raises
366  ------
367  RuntimeError
368  Raised if no reference catalogs could be found for the specified
369  region.
370  TypeError
371  Raised if the loaded reference catalogs do not have matching
372  schemas.
373  """
374  paddedBbox = geom.Box2D(bbox)
375  paddedBbox.grow(self.config.pixelMargin)
376  innerSkyRegion, outerSkyRegion, _, _ = self._makeBoxRegion(paddedBbox, wcs, bboxToSpherePadding)
377 
378  def _filterFunction(refCat, region):
379  # Perform an initial "pre filter" step based on the refCat coords
380  # and the outerSkyRegion created from the self.config.pixelMargin-
381  # paddedBbox plus an "extra" padding of bboxToSpherePadding and the
382  # raw wcs. This should ensure a large enough projected area on the
383  # sky that accounts for any projection/distortion issues, but small
384  # enough to filter out loaded reference objects that lie well
385  # beyond the projected detector of interest. This step is required
386  # due to the very local nature of the wcs available for the
387  # sky <--> pixel conversions.
388  preFiltFunc = _FilterCatalog(outerSkyRegion)
389  refCat = preFiltFunc(refCat, region)
390 
391  # Add columns to the pre-filtered reference catalog relating their
392  # coordinates to equivalent pixel positions for the wcs provided
393  # and use to populate those columns.
394  refCat = self.remapReferenceCatalogSchema(refCat, position=True)
395  afwTable.updateRefCentroids(wcs, refCat)
396  # No need to filter the catalog if it is entirely contained in the
397  # region defined by the inner sky region.
398  if innerSkyRegion.contains(region):
399  return refCat
400  # Create a new reference catalog, and populate it only with records
401  # that fall inside the padded bbox.
402  filteredRefCat = type(refCat)(refCat.table)
403  centroidKey = afwTable.Point2DKey(refCat.schema['centroid'])
404  for record in refCat:
405  pixCoords = record[centroidKey]
406  if paddedBbox.contains(geom.Point2D(pixCoords)):
407  filteredRefCat.append(record)
408  return filteredRefCat
409  return self.loadRegion(outerSkyRegion, filtFunc=_filterFunction, epoch=epoch, filterName=filterName)
410 
table::Key< int > type
Definition: Detector.cc:163
void updateRefCentroids(geom::SkyWcs const &wcs, ReferenceCollection &refList)
Update centroids in a collection of reference objects.
Definition: wcsUtils.cc:72

◆ loadRegion()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.loadRegion (   self,
  region,
  filtFunc = None,
  filterName = None,
  epoch = None 
)
Load reference objects within a specified region.

This function loads the DataIds used to construct an instance of this
class which intersect or are contained within the specified region. The
reference catalogs which intersect but are not fully contained within
the input region are further filtered by the specified filter function.
This function returns a single source catalog containing all reference
objects inside the specified region.

Parameters
----------
region : `lsst.sphgeom.Region`
    This can be any type that is derived from `lsst.sphgeom.Region` and
    should define the spatial region for which reference objects are to
    be loaded.
filtFunc : callable or `None`, optional
    This optional parameter should be a callable object that takes a
    reference catalog and its corresponding region as parameters,
    filters the catalog by some criteria and returns the filtered
    reference catalog. If `None`, an internal filter function is used
    which filters according to if a reference object falls within the
    input region.
filterName : `str` or `None`, optional
    Name of camera filter, or `None` or blank for the default filter.
epoch : `astropy.time.Time` or `None`, optional
    Epoch to which to correct proper motion and parallax, or `None` to
    not apply such corrections.

Returns
-------
referenceCatalog : `lsst.afw.table.SourceCatalog`
    Catalog containing reference objects which intersect the input region,
    filtered by the specified filter function.

Raises
------
RuntimeError
    Raised if no reference catalogs could be found for the specified
    region.
TypeError
    Raised if the loaded reference catalogs do not have matching
    schemas.

Definition at line 411 of file loadReferenceObjects.py.

411  def loadRegion(self, region, filtFunc=None, filterName=None, epoch=None):
412  """Load reference objects within a specified region.
413 
414  This function loads the DataIds used to construct an instance of this
415  class which intersect or are contained within the specified region. The
416  reference catalogs which intersect but are not fully contained within
417  the input region are further filtered by the specified filter function.
418  This function returns a single source catalog containing all reference
419  objects inside the specified region.
420 
421  Parameters
422  ----------
423  region : `lsst.sphgeom.Region`
424  This can be any type that is derived from `lsst.sphgeom.Region` and
425  should define the spatial region for which reference objects are to
426  be loaded.
427  filtFunc : callable or `None`, optional
428  This optional parameter should be a callable object that takes a
429  reference catalog and its corresponding region as parameters,
430  filters the catalog by some criteria and returns the filtered
431  reference catalog. If `None`, an internal filter function is used
432  which filters according to if a reference object falls within the
433  input region.
434  filterName : `str` or `None`, optional
435  Name of camera filter, or `None` or blank for the default filter.
436  epoch : `astropy.time.Time` or `None`, optional
437  Epoch to which to correct proper motion and parallax, or `None` to
438  not apply such corrections.
439 
440  Returns
441  -------
442  referenceCatalog : `lsst.afw.table.SourceCatalog`
443  Catalog containing reference objects which intersect the input region,
444  filtered by the specified filter function.
445 
446  Raises
447  ------
448  RuntimeError
449  Raised if no reference catalogs could be found for the specified
450  region.
451  TypeError
452  Raised if the loaded reference catalogs do not have matching
453  schemas.
454  """
455  regionLat = region.getBoundingBox().getLat()
456  regionLon = region.getBoundingBox().getLon()
457  self.log.info("Loading reference objects from region bounded by "
458  "[%.8f, %.8f], [%.8f, %.8f] RA Dec",
459  regionLon.getA().asDegrees(), regionLon.getB().asDegrees(),
460  regionLat.getA().asDegrees(), regionLat.getB().asDegrees())
461  if filtFunc is None:
462  filtFunc = _FilterCatalog(region)
463  # filter out all the regions supplied by the constructor that do not overlap
464  overlapList = []
465  for dataId, refCat in zip(self.dataIds, self.refCats):
466  # SphGeom supports some objects intersecting others, but is not symmetric,
467  # try the intersect operation in both directions
468  try:
469  intersects = dataId.region.intersects(region)
470  except TypeError:
471  intersects = region.intersects(dataId.region)
472 
473  if intersects:
474  overlapList.append((dataId, refCat))
475 
476  if len(overlapList) == 0:
477  raise RuntimeError("No reference tables could be found for input region")
478 
479  firstCat = overlapList[0][1].get()
480  refCat = filtFunc(firstCat, overlapList[0][0].region)
481  trimmedAmount = len(firstCat) - len(refCat)
482 
483  # Load in the remaining catalogs
484  for dataId, inputRefCat in overlapList[1:]:
485  tmpCat = inputRefCat.get()
486 
487  if tmpCat.schema != firstCat.schema:
488  raise TypeError("Reference catalogs have mismatching schemas")
489 
490  filteredCat = filtFunc(tmpCat, dataId.region)
491  refCat.extend(filteredCat)
492  trimmedAmount += len(tmpCat) - len(filteredCat)
493 
494  self.log.debug("Trimmed %d refCat objects lying outside padded region, leaving %d",
495  trimmedAmount, len(refCat))
496  self.log.info("Loaded %d reference objects", len(refCat))
497 
498  # Ensure that the loaded reference catalog is continuous in memory
499  if not refCat.isContiguous():
500  refCat = refCat.copy(deep=True)
501 
502  self.applyProperMotions(refCat, epoch)
503 
504  # Verify the schema is in the correct units and has the correct version; automatically convert
505  # it with a warning if this is not the case.
506  if not hasNanojanskyFluxUnits(refCat.schema) or not getFormatVersionFromRefCat(refCat) >= 1:
507  self.log.warning("Found version 0 reference catalog with old style units in schema.")
508  self.log.warning("run `meas_algorithms/bin/convert_refcat_to_nJy.py` to convert fluxes to nJy.")
509  self.log.warning("See RFC-575 for more details.")
510  refCat = convertToNanojansky(refCat, self.log)
511 
512  expandedCat = self.remapReferenceCatalogSchema(refCat, position=True)
513 
514  # Add flux aliases
515  expandedCat = self.addFluxAliases(expandedCat, self.config.defaultFilter, self.config.filterMap)
516 
517  # Ensure that the returned reference catalog is continuous in memory
518  if not expandedCat.isContiguous():
519  expandedCat = expandedCat.copy(deep=True)
520 
521  fluxField = getRefFluxField(schema=expandedCat.schema, filterName=filterName)
522  return pipeBase.Struct(refCat=expandedCat, fluxField=fluxField)
523 
def convertToNanojansky(catalog, log, doConvert=True)

◆ loadSkyCircle()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.loadSkyCircle (   self,
  ctrCoord,
  radius,
  filterName = None,
  epoch = None 
)
Load reference objects that lie within a circular region on the sky.

This method constructs a circular region from an input center and
angular radius, loads reference catalogs which are contained in or
intersect the circle, and filters reference catalogs which intersect
down to objects which lie within the defined circle.

Parameters
----------
ctrCoord : `lsst.geom.SpherePoint`
    Point defining the center of the circular region.
radius : `lsst.geom.Angle`
    Defines the angular radius of the circular region.
filterName : `str` or `None`, optional
    Name of camera filter, or `None` or blank for the default filter.
epoch : `astropy.time.Time` or `None`, optional
    Epoch to which to correct proper motion and parallax, or `None` to
    not apply such corrections.

Returns
-------
referenceCatalog : `lsst.afw.table.SourceCatalog`
    Catalog containing reference objects inside the specified search
    circle.

Definition at line 524 of file loadReferenceObjects.py.

524  def loadSkyCircle(self, ctrCoord, radius, filterName=None, epoch=None):
525  """Load reference objects that lie within a circular region on the sky.
526 
527  This method constructs a circular region from an input center and
528  angular radius, loads reference catalogs which are contained in or
529  intersect the circle, and filters reference catalogs which intersect
530  down to objects which lie within the defined circle.
531 
532  Parameters
533  ----------
534  ctrCoord : `lsst.geom.SpherePoint`
535  Point defining the center of the circular region.
536  radius : `lsst.geom.Angle`
537  Defines the angular radius of the circular region.
538  filterName : `str` or `None`, optional
539  Name of camera filter, or `None` or blank for the default filter.
540  epoch : `astropy.time.Time` or `None`, optional
541  Epoch to which to correct proper motion and parallax, or `None` to
542  not apply such corrections.
543 
544  Returns
545  -------
546  referenceCatalog : `lsst.afw.table.SourceCatalog`
547  Catalog containing reference objects inside the specified search
548  circle.
549  """
550  centerVector = ctrCoord.getVector()
551  sphRadius = sphgeom.Angle(radius.asRadians())
552  circularRegion = sphgeom.Circle(centerVector, sphRadius)
553  return self.loadRegion(circularRegion, filterName=filterName, epoch=epoch)
554 

◆ remapReferenceCatalogSchema()

def lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.remapReferenceCatalogSchema (   refCat,
filterNameList = None,
  position = False,
  photometric = False 
)
static
This function takes in a reference catalog and creates a new catalog with additional
columns defined the remaining function arguments.

Parameters
----------
refCat : `lsst.afw.table.SimpleCatalog`
    Reference catalog to map to new catalog

Returns
-------
expandedCat : `lsst.afw.table.SimpleCatalog`
    Deep copy of input reference catalog with additional columns added

Definition at line 714 of file loadReferenceObjects.py.

714  def remapReferenceCatalogSchema(refCat, *, filterNameList=None, position=False, photometric=False):
715  """This function takes in a reference catalog and creates a new catalog with additional
716  columns defined the remaining function arguments.
717 
718  Parameters
719  ----------
720  refCat : `lsst.afw.table.SimpleCatalog`
721  Reference catalog to map to new catalog
722 
723  Returns
724  -------
725  expandedCat : `lsst.afw.table.SimpleCatalog`
726  Deep copy of input reference catalog with additional columns added
727  """
728  mapper = afwTable.SchemaMapper(refCat.schema, True)
729  mapper.addMinimalSchema(refCat.schema, True)
730  mapper.editOutputSchema().disconnectAliases()
731  if filterNameList:
732  for filterName in filterNameList:
733  mapper.editOutputSchema().addField(f"{filterName}_flux",
734  type=numpy.float64,
735  doc=f"flux in filter {filterName}",
736  units="Jy"
737  )
738  mapper.editOutputSchema().addField(f"{filterName}_fluxErr",
739  type=numpy.float64,
740  doc=f"flux uncertanty in filter {filterName}",
741  units="Jy"
742  )
743 
744  if position:
745  mapper.editOutputSchema().addField("centroid_x", type=float, doReplace=True)
746  mapper.editOutputSchema().addField("centroid_y", type=float, doReplace=True)
747  mapper.editOutputSchema().addField("hasCentroid", type="Flag", doReplace=True)
748  mapper.editOutputSchema().getAliasMap().set("slot_Centroid", "centroid")
749 
750  if photometric:
751  mapper.editOutputSchema().addField("photometric",
752  type="Flag",
753  doc="set if the object can be used for photometric"
754  "calibration",
755  )
756  mapper.editOutputSchema().addField("resolved",
757  type="Flag",
758  doc="set if the object is spatially resolved"
759  )
760  mapper.editOutputSchema().addField("variable",
761  type="Flag",
762  doc="set if the object has variable brightness"
763  )
764 
765  expandedCat = afwTable.SimpleCatalog(mapper.getOutputSchema())
766  expandedCat.setMetadata(refCat.getMetadata())
767  expandedCat.extend(refCat, mapper=mapper)
768 
769  return expandedCat
770 
771 
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
daf::base::PropertySet * set
Definition: fits.cc:912

Member Data Documentation

◆ config

lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.config

Definition at line 285 of file loadReferenceObjects.py.

◆ dataIds

lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.dataIds

Definition at line 282 of file loadReferenceObjects.py.

◆ log

lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.log

Definition at line 284 of file loadReferenceObjects.py.

◆ refCats

lsst.meas.algorithms.loadReferenceObjects.ReferenceObjectLoader.refCats

Definition at line 283 of file loadReferenceObjects.py.


The documentation for this class was generated from the following file: