24__all__ = [
"getRefFluxField",
"getRefFluxKeys",
"LoadReferenceObjectsTask",
"LoadReferenceObjectsConfig",
25 "ReferenceObjectLoader",
"ReferenceObjectLoaderBase"]
30from deprecated.sphinx
import deprecated
40from lsst
import sphgeom
46 """Return True if this name/units combination corresponds to an
47 "old-style" reference catalog flux field.
49 unitsCheck = units != 'nJy'
50 isFlux = name.endswith(
'_flux')
51 isFluxSigma = name.endswith(
'_fluxSigma')
52 isFluxErr = name.endswith(
'_fluxErr')
53 return (isFlux
or isFluxSigma
or isFluxErr)
and unitsCheck
58 """Return True if the units of all flux and fluxErr are correct (nJy).
67 """"Return the format version stored in a reference catalog header.
72 Reference catalog to inspect.
77 Format verison integer. Returns `0` if the catalog has no metadata
78 or the metadata does
not include a
"REFCAT_FORMAT_VERSION" key.
82 deprecation_msg =
"Support for version 0 refcats (pre-nJy fluxes) will be removed after v25."
83 md = refCat.getMetadata()
85 warnings.warn(deprecation_msg)
88 return md.getScalar(
"REFCAT_FORMAT_VERSION")
90 warnings.warn(deprecation_msg)
95@deprecated(reason="Support for version 0 refcats (pre-nJy fluxes) will be removed after v25.
",
96 version="v24.0", category=FutureWarning)
98 """Convert fluxes in a catalog from jansky to nanojansky.
103 The catalog to convert.
105 Log to send messages to.
106 doConvert : `bool`, optional
107 Return a converted catalog,
or just identify the fields that need to be converted?
108 This supports the
"write=False" mode of `bin/convert_to_nJy.py`.
113 The converted catalog,
or None if ``doConvert``
is False.
117 Support
for old units
in reference catalogs will be removed after the
118 release of late calendar year 2019.
119 Use `meas_algorithms/bin/convert_to_nJy.py` to update your reference catalog.
124 mapper.addMinimalSchema(afwTable.SimpleTable.makeMinimalSchema())
127 for field
in catalog.schema:
128 oldName = field.field.getName()
129 oldUnits = field.field.getUnits()
133 if oldName.endswith(
'_fluxSigma'):
134 name = oldName.replace(
'_fluxSigma',
'_fluxErr')
137 newField =
afwTable.Field[field.dtype](name, field.field.getDoc(), units)
138 mapper.addMapping(field.getKey(), newField)
139 input_fields.append(field.field)
140 output_fields.append(newField)
142 mapper.addMapping(field.getKey())
144 fluxFieldsStr =
'; '.join(
"(%s, '%s')" % (field.getName(), field.getUnits())
for field
in input_fields)
147 newSchema = mapper.getOutputSchema()
149 output.reserve(len(catalog))
150 output.extend(catalog, mapper=mapper)
151 for field
in output_fields:
152 output[field.getName()] *= 1e9
153 log.info(
"Converted refcat flux fields to nJy (name, units): %s", fluxFieldsStr)
156 log.info(
"Found old-style refcat flux fields (name, units): %s", fluxFieldsStr)
161 """This is a private helper class which filters catalogs by
162 row based on the row being inside the region used to initialize
168 The spatial region which all objects should lie within
174 """This call method on an instance of this class takes in a reference
175 catalog, and the region
from which the catalog was generated.
177 If the catalog region
is entirely contained within the region used to
178 initialize this
class, then all the entries
in the catalog must be
179 within the region
and so the whole catalog
is returned.
181 If the catalog region
is not entirely contained, then the location
for
182 each record
is tested against the region used to initialize the
class.
183 Records which fall inside this region are added to a new catalog,
and
184 this catalog
is then returned.
189 SourceCatalog to be filtered.
191 Region
in which the catalog was created
193 if catRegion.isWithin(self.
region):
197 filteredRefCat =
type(refCat)(refCat.table)
198 for record
in refCat:
199 if self.
region.contains(record.getCoord().getVector()):
200 filteredRefCat.append(record)
201 return filteredRefCat
205 pixelMargin = pexConfig.RangeField(
206 doc=
"Padding to add to 4 all edges of the bounding box (pixels)",
211 anyFilterMapsToThis = pexConfig.Field(
212 doc=(
"Always use this reference catalog filter, no matter whether or what filter name is "
213 "supplied to the loader. Effectively a trivial filterMap: map all filter names to this filter."
214 " This can be set for purely-astrometric catalogs (e.g. Gaia DR2) where there is only one "
215 "reasonable choice for every camera filter->refcat mapping, but not for refcats used for "
216 "photometry, which need a filterMap and/or colorterms/transmission corrections."),
221 filterMap = pexConfig.DictField(
222 doc=(
"Mapping of camera filter name: reference catalog filter name; "
223 "each reference filter must exist in the refcat."
224 " Note that this does not perform any bandpass corrections: it is just a lookup."),
229 requireProperMotion = pexConfig.Field(
230 doc=
"Require that the fields needed to correct proper motion "
231 "(epoch, pm_ra and pm_dec) are present?",
235 ref_dataset_name = pexConfig.Field(
236 doc=
"Deprecated; do not use. Added for easier transition from LoadIndexedReferenceObjectsConfig to "
237 "LoadReferenceObjectsConfig",
240 deprecated=
'This field is not used. It will be removed after v25.',
246 msg =
"`filterMap` and `anyFilterMapsToThis` are mutually exclusive"
247 raise pexConfig.FieldValidationError(LoadReferenceObjectsConfig.anyFilterMapsToThis,
252 """This class facilitates loading reference catalogs.
254 The QuantumGraph generation will create a list of datasets that may
255 possibly overlap a given region. These datasets are then used to construct
256 an instance of this class. The
class instance should then be passed into
257 a task which needs reference catalogs. These tasks should then determine
258 the exact region of the sky reference catalogs will be loaded
for,
and
259 call a corresponding method to load the reference objects.
263 dataIds : iterable of `lsst.daf.butler.DataCoordinate`
264 An iterable object of data IDs that point to reference catalogs.
265 refCats : iterable of `lsst.daf.butler.DeferredDatasetHandle`
266 Handles to load refCats on demand.
267 name : `str`, optional
268 The name of the refcat that this object will load. This name
is used
269 for applying colorterms,
for example.
270 config : `LoadReferenceObjectsConfig`
271 Configuration of this reference loader.
272 log : `
lsst.log.Log`, `logging.Logger`
or `
None`, optional
273 Logger object used to write out messages. If `
None` a default
276 ConfigClass = LoadReferenceObjectsConfig
278 def __init__(self, dataIds, refCats, name=None, log=None, config=None, **kwargs):
280 warnings.warn(
"Instantiating ReferenceObjectLoader with additional kwargs is deprecated "
281 "and will be removed after v25.0", FutureWarning, stacklevel=2)
289 self.
log = log
or logging.getLogger(__name__).getChild(
"ReferenceObjectLoader")
292 """Apply proper motion correction to a reference catalog.
294 Adjust position and position error
in the ``catalog``
295 for proper motion to the specified ``epoch``,
296 modifying the catalog
in place.
301 Catalog of positions, containing at least these fields:
303 - Coordinates, retrieved by the table
's coordinate key.
304 - ``coord_raErr`` : Error in Right Ascension (rad).
305 - ``coord_decErr`` : Error
in Declination (rad).
306 - ``pm_ra`` : Proper motion
in Right Ascension (rad/yr,
308 - ``pm_raErr`` : Error
in ``pm_ra`` (rad/yr), optional.
309 - ``pm_dec`` : Proper motion
in Declination (rad/yr,
311 - ``pm_decErr`` : Error
in ``pm_dec`` (rad/yr), optional.
312 - ``epoch`` : Mean epoch of object (an astropy.time.Time)
313 epoch : `astropy.time.Time`
314 Epoch to which to correct proper motion.
315 If
None, do
not apply PM corrections
or raise if
316 ``config.requireProperMotion``
is True.
321 Raised
if ``config.requireProperMotion``
is set but we cannot
322 apply the proper motion correction
for some reason.
325 if self.
config.requireProperMotion:
326 raise RuntimeError(
"requireProperMotion=True but epoch not provided to loader.")
328 self.
log.debug(
"No epoch provided: not applying proper motion corrections to refcat.")
332 if (
"pm_ra" in catalog.schema
333 and not isinstance(catalog.schema[
"pm_ra"].asKey(), afwTable.KeyAngle)):
334 if self.
config.requireProperMotion:
335 raise RuntimeError(
"requireProperMotion=True but refcat pm_ra field is not an Angle.")
337 self.
log.warning(
"Reference catalog pm_ra field is not an Angle; cannot apply proper motion.")
340 if (
"epoch" not in catalog.schema
or "pm_ra" not in catalog.schema):
341 if self.
config.requireProperMotion:
342 raise RuntimeError(
"requireProperMotion=True but PM data not available from catalog.")
344 self.
log.warning(
"Proper motion correction not available for this reference catalog.")
351 addIsPhotometric=False, addIsResolved=False,
352 addIsVariable=False, coordErrDim=2,
353 addProperMotion=False, properMotionErrDim=2,
355 """Make a standard schema for reference object catalogs.
359 filterNameList : `list` of `str`
360 List of filter names. Used to create <filterName>_flux fields.
361 addIsPhotometric : `bool`
362 If True then add field
"photometric".
363 addIsResolved : `bool`
364 If
True then add field
"resolved".
365 addIsVariable : `bool`
366 If
True then add field
"variable".
368 Number of coord error fields; must be one of 0, 2, 3:
370 - If 2
or 3: add fields
"coord_raErr" and "coord_decErr".
371 - If 3: also add field
"coord_radecErr".
372 addProperMotion : `bool`
373 If
True add fields
"epoch",
"pm_ra",
"pm_dec" and "pm_flag".
374 properMotionErrDim : `int`
375 Number of proper motion error fields; must be one of 0, 2, 3;
376 ignored
if addProperMotion false:
377 - If 2
or 3: add fields
"pm_raErr" and "pm_decErr".
378 - If 3: also add field
"pm_radecErr".
380 If
True add fields
"epoch",
"parallax",
"parallaxErr"
386 Schema
for reference catalog, an
391 Reference catalogs support additional covariances, such
as
392 covariance between RA
and proper motion
in declination,
393 that are
not supported by this method, but can be added after
396 schema = afwTable.SimpleTable.makeMinimalSchema()
398 afwTable.Point2DKey.addFields(
401 "centroid on an exposure, if relevant",
407 doc=
"is position known?",
409 for filterName
in filterNameList:
411 field=
"%s_flux" % (filterName,),
413 doc=
"flux in filter %s" % (filterName,),
416 for filterName
in filterNameList:
418 field=
"%s_fluxErr" % (filterName,),
420 doc=
"flux uncertainty in filter %s" % (filterName,),
427 doc=
"set if the object can be used for photometric calibration",
433 doc=
"set if the object is spatially resolved",
439 doc=
"set if the object has variable brightness",
441 if coordErrDim
not in (0, 2, 3):
442 raise ValueError(
"coordErrDim={}; must be (0, 2, 3)".format(coordErrDim))
444 afwTable.CovarianceMatrix2fKey.addFields(
448 units=[
"rad",
"rad"],
449 diagonalOnly=(coordErrDim == 2),
452 if addProperMotion
or addParallax:
456 doc=
"date of observation (TAI, MJD)",
464 doc=
"proper motion in the right ascension direction = dra/dt * cos(dec)",
470 doc=
"proper motion in the declination direction",
473 if properMotionErrDim
not in (0, 2, 3):
474 raise ValueError(
"properMotionErrDim={}; must be (0, 2, 3)".format(properMotionErrDim))
475 if properMotionErrDim > 0:
476 afwTable.CovarianceMatrix2fKey.addFields(
480 units=[
"rad/year",
"rad/year"],
481 diagonalOnly=(properMotionErrDim == 2),
486 doc=
"Set if proper motion or proper motion error is bad",
499 doc=
"uncertainty in parallax",
503 field=
"parallax_flag",
505 doc=
"Set if parallax or parallax error is bad",
510 def _remapReferenceCatalogSchema(refCat, *, anyFilterMapsToThis=None,
511 filterMap=None, centroids=False):
512 """This function takes in a reference catalog and returns a new catalog
513 with additional columns defined
from the remaining function arguments.
518 Reference catalog to map to new catalog
519 anyFilterMapsToThis : `str`, optional
520 Always use this reference catalog filter.
521 Mutually exclusive
with `filterMap`
522 filterMap : `dict` [`str`,`str`], optional
523 Mapping of camera filter name: reference catalog filter name.
524 centroids : `bool`, optional
525 Add centroid fields to the loaded Schema. ``loadPixelBox`` expects
526 these fields to exist.
531 Deep copy of input reference catalog
with additional columns added
533 if anyFilterMapsToThis
or filterMap:
534 ReferenceObjectLoader._addFluxAliases(refCat.schema, anyFilterMapsToThis, filterMap)
537 mapper.addMinimalSchema(refCat.schema,
True)
538 mapper.editOutputSchema().disconnectAliases()
545 mapper.editOutputSchema().addField(
"centroid_x", type=float, doReplace=
True)
546 mapper.editOutputSchema().addField(
"centroid_y", type=float, doReplace=
True)
547 mapper.editOutputSchema().addField(
"hasCentroid", type=
"Flag", doReplace=
True)
548 mapper.editOutputSchema().getAliasMap().
set(
"slot_Centroid",
"centroid")
551 expandedCat.setMetadata(refCat.getMetadata())
552 expandedCat.extend(refCat, mapper=mapper)
557 def _addFluxAliases(schema, anyFilterMapsToThis=None, filterMap=None):
558 """Add aliases for camera filter fluxes to the schema.
560 For each camFilter: refFilter in filterMap, adds these aliases:
561 <camFilter>_camFlux: <refFilter>_flux
562 <camFilter>_camFluxErr: <refFilter>_fluxErr,
if the latter exists
563 or sets `anyFilterMapsToThis`
in the schema.
568 Schema
for reference catalog.
569 anyFilterMapsToThis : `str`, optional
570 Always use this reference catalog filter.
571 Mutually exclusive
with `filterMap`.
572 filterMap : `dict` [`str`,`str`], optional
573 Mapping of camera filter name: reference catalog filter name.
574 Mutually exclusive
with `anyFilterMapsToThis`.
579 Raised
if any required reference flux field
is missing
from the
583 if anyFilterMapsToThis
and filterMap:
584 raise ValueError(
"anyFilterMapsToThis and filterMap are mutually exclusive!")
586 aliasMap = schema.getAliasMap()
588 if anyFilterMapsToThis
is not None:
589 refFluxName = anyFilterMapsToThis +
"_flux"
590 if refFluxName
not in schema:
591 msg = f
"Unknown reference filter for anyFilterMapsToThis='{refFluxName}'"
592 raise RuntimeError(msg)
593 aliasMap.set(
"anyFilterMapsToThis", refFluxName)
596 def addAliasesForOneFilter(filterName, refFilterName):
597 """Add aliases for a single filter
601 filterName : `str` (optional)
602 Camera filter name. The resulting alias name is
604 refFilterName : `str`
605 Reference catalog filter name; the field
606 <refFilterName>_flux must exist.
608 camFluxName = filterName + "_camFlux"
609 refFluxName = refFilterName +
"_flux"
610 if refFluxName
not in schema:
611 raise RuntimeError(
"Unknown reference filter %s" % (refFluxName,))
612 aliasMap.set(camFluxName, refFluxName)
613 refFluxErrName = refFluxName +
"Err"
614 if refFluxErrName
in schema:
615 camFluxErrName = camFluxName +
"Err"
616 aliasMap.set(camFluxErrName, refFluxErrName)
618 if filterMap
is not None:
619 for filterName, refFilterName
in filterMap.items():
620 addAliasesForOneFilter(filterName, refFilterName)
623 def _makeBoxRegion(BBox, wcs, BBoxPadding):
636 outerLocalBBox.grow(BBoxPadding)
637 innerLocalBBox.grow(-1*BBoxPadding)
649 innerBoxCorners = innerLocalBBox.getCorners()
650 innerSphCorners = [wcs.pixelToSky(corner).getVector()
for corner
in innerBoxCorners]
653 outerBoxCorners = outerLocalBBox.getCorners()
654 outerSphCorners = [wcs.pixelToSky(corner).getVector()
for corner
in outerBoxCorners]
657 return innerSkyRegion, outerSkyRegion, innerSphCorners, outerSphCorners
660 def _calculateCircle(bbox, wcs, pixelMargin):
661 """Compute on-sky center and radius of search region.
668 WCS; used to convert pixel positions to sky coordinates.
670 Padding to add to 4 all edges of the bounding box (pixels).
674 results : `lsst.pipe.base.Struct`
678 ICRS center of the search region.
680 Radius of the search region.
682 Bounding box used to compute the circle.
685 bbox.grow(pixelMargin)
686 coord = wcs.pixelToSky(bbox.getCenter())
687 radius =
max(coord.separation(wcs.pixelToSky(pp))
for pp
in bbox.getCorners())
688 return pipeBase.Struct(coord=coord, radius=radius, bbox=bbox)
692 """Return metadata about the loaded reference catalog, in an on-sky
695 This metadata is used
for reloading the catalog (e.g.
for
696 reconstituting a normalized match list).
701 ICRS center of the search region.
703 Radius of the search region.
705 Name of the camera filter.
706 epoch : `astropy.time.Time`
or `
None`, optional
707 Epoch that proper motion
and parallax were corrected to,
or `
None`
708 if no such corrections were applied.
713 Metadata about the catalog.
716 md.add('RA', coord.getRa().asDegrees(),
'field center in degrees')
717 md.add(
'DEC', coord.getDec().asDegrees(),
'field center in degrees')
718 md.add(
'RADIUS', radius.asDegrees(),
'field radius in degrees, minimum')
721 md.add(
'SMATCHV', 2,
'SourceMatchVector version number')
722 md.add(
'FILTER', filterName,
'camera filter name for photometric data')
723 md.add(
'TIMESYS',
"TAI",
"time scale of time keywords")
724 md.add(
'JEPOCH',
None if epoch
is None else epoch.tai.jyear,
725 'Julian epoch (TAI Julian Epoch year) for catalog')
729 bboxToSpherePadding=100):
730 """Return metadata about the loaded reference catalog, in an
733 This metadata is used
for reloading the catalog (e.g.,
for
734 reconstituting a normalised match list).
739 Bounding box
for the pixels.
741 The WCS object associated
with ``bbox``.
743 Name of the camera filter.
744 epoch : `astropy.time.Time`
or `
None`, optional
745 Epoch that proper motion
and parallax were corrected to,
or `
None`
746 if no such corrections were applied.
747 bboxToSpherePadding : `int`, optional
748 Padding
in pixels to account
for translating a set of corners into
749 a spherical (convex) boundary that
is certain to encompass the
750 enitre area covered by the box.
755 The metadata detailing the search parameters used
for this
759 md = self.getMetadataCircle(circle.coord, circle.radius, filterName, epoch=epoch)
761 paddedBbox = circle.bbox
762 _, _, innerCorners, outerCorners = self._makeBoxRegion(paddedBbox, wcs, bboxToSpherePadding)
763 for box, corners
in zip((
"INNER",
"OUTER"), (innerCorners, outerCorners)):
764 for (name, corner)
in zip((
"UPPER_LEFT",
"UPPER_RIGHT",
"LOWER_LEFT",
"LOWER_RIGHT"),
766 md.add(f
"{box}_{name}_RA",
geom.SpherePoint(corner).getRa().asDegrees(), f
"{box}_corner")
767 md.add(f
"{box}_{name}_DEC",
geom.SpherePoint(corner).getDec().asDegrees(), f
"{box}_corner")
771 bboxToSpherePadding=100):
772 """Load reference objects that are within a pixel-based rectangular
775 This algorithm works by creating a spherical box whose corners
776 correspond to the WCS converted corners of the input bounding box
777 (possibly padded). It then defines a filtering function which looks at
778 the pixel position of the reference objects and accepts only those that
779 lie within the specified bounding box.
781 The spherical box region
and filtering function are passed to the
782 generic loadRegion method which loads
and filters the reference objects
783 from the datastore
and returns a single catalog containing the filtered
784 set of reference objects.
789 Box which bounds a region
in pixel space.
791 Wcs object defining the pixel to sky (
and inverse) transform
for
792 the supplied ``bbox``.
794 Name of camera filter.
795 epoch : `astropy.time.Time`
or `
None`, optional
796 Epoch to which to correct proper motion
and parallax,
or `
None`
797 to
not apply such corrections.
798 bboxToSpherePadding : `int`, optional
799 Padding to account
for translating a set of corners into a
800 spherical (convex) boundary that
is certain to encompase the
801 enitre area covered by the box.
805 output : `lsst.pipe.base.Struct`
806 Results struct
with attributes:
809 Catalog containing reference objects inside the specified
810 bounding box (padded by self.
config.pixelMargin).
812 Name of the field containing the flux associated
with
818 Raised
if no reference catalogs could be found
for the specified
821 Raised
if the loaded reference catalogs do
not have matching
825 paddedBbox.grow(self.config.pixelMargin)
826 innerSkyRegion, outerSkyRegion, _, _ = self._makeBoxRegion(paddedBbox, wcs, bboxToSpherePadding)
828 def _filterFunction(refCat, region):
839 refCat = preFiltFunc(refCat, region)
848 if innerSkyRegion.contains(region):
852 filteredRefCat =
type(refCat)(refCat.table)
854 for record
in refCat:
855 pixCoords = record[centroidKey]
857 filteredRefCat.append(record)
858 return filteredRefCat
859 return self.
loadRegion(outerSkyRegion, filterName, filtFunc=_filterFunction, epoch=epoch)
861 def loadRegion(self, region, filterName, filtFunc=None, epoch=None):
862 """Load reference objects within a specified region.
864 This function loads the DataIds used to construct an instance of this
865 class which intersect or are contained within the specified region. The
866 reference catalogs which intersect but are
not fully contained within
867 the input region are further filtered by the specified filter function.
868 This function returns a single source catalog containing all reference
869 objects inside the specified region.
875 should define the spatial region
for which reference objects are to
877 filtFunc : callable
or `
None`, optional
878 This optional parameter should be a callable object that takes a
879 reference catalog
and its corresponding region
as parameters,
880 filters the catalog by some criteria
and returns the filtered
881 reference catalog. If `
None`, an internal filter function
is used
882 which filters according to
if a reference object falls within the
885 Name of camera filter.
886 epoch : `astropy.time.Time`
or `
None`, optional
887 Epoch to which to correct proper motion
and parallax,
or `
None` to
888 not apply such corrections.
892 output : `lsst.pipe.base.Struct`
893 Results struct
with attributes:
896 Catalog containing reference objects which intersect the
897 input region, filtered by the specified filter function.
899 Name of the field containing the flux associated
with
905 Raised
if no reference catalogs could be found
for the specified
908 Raised
if the loaded reference catalogs do
not have matching
911 regionLat = region.getBoundingBox().getLat()
912 regionLon = region.getBoundingBox().getLon()
913 self.log.info("Loading reference objects from %s in region bounded by "
914 "[%.8f, %.8f], [%.8f, %.8f] RA Dec",
916 regionLon.getA().asDegrees(), regionLon.getB().asDegrees(),
917 regionLat.getA().asDegrees(), regionLat.getB().asDegrees())
926 intersects = dataId.region.intersects(region)
928 intersects = region.intersects(dataId.region)
931 overlapList.append((dataId, refCat))
933 if len(overlapList) == 0:
934 raise RuntimeError(
"No reference tables could be found for input region")
936 firstCat = overlapList[0][1].get()
937 refCat = filtFunc(firstCat, overlapList[0][0].region)
938 trimmedAmount = len(firstCat) - len(refCat)
941 for dataId, inputRefCat
in overlapList[1:]:
942 tmpCat = inputRefCat.get()
944 if tmpCat.schema != firstCat.schema:
945 raise TypeError(
"Reference catalogs have mismatching schemas")
947 filteredCat = filtFunc(tmpCat, dataId.region)
948 refCat.extend(filteredCat)
949 trimmedAmount += len(tmpCat) - len(filteredCat)
951 self.
log.debug(
"Trimmed %d refCat objects lying outside padded region, leaving %d",
952 trimmedAmount, len(refCat))
953 self.
log.info(
"Loaded %d reference objects", len(refCat))
956 if not refCat.isContiguous():
957 refCat = refCat.copy(deep=
True)
965 self.
log.warning(
"Found version 0 reference catalog with old style units in schema.")
966 self.
log.warning(
"run `meas_algorithms/bin/convert_refcat_to_nJy.py` to convert fluxes to nJy.")
967 self.
log.warning(
"See RFC-575 for more details.")
971 anyFilterMapsToThis=self.
config.anyFilterMapsToThis,
972 filterMap=self.
config.filterMap)
975 if not expandedCat.isContiguous():
976 expandedCat = expandedCat.copy(deep=
True)
978 fluxField = getRefFluxField(expandedCat.schema, filterName)
979 return pipeBase.Struct(refCat=expandedCat, fluxField=fluxField)
982 """Load reference objects that lie within a circular region on the sky.
984 This method constructs a circular region from an input center
and
985 angular radius, loads reference catalogs which are contained
in or
986 intersect the circle,
and filters reference catalogs which intersect
987 down to objects which lie within the defined circle.
992 Point defining the center of the circular region.
994 Defines the angular radius of the circular region.
996 Name of camera filter.
997 epoch : `astropy.time.Time`
or `
None`, optional
998 Epoch to which to correct proper motion
and parallax,
or `
None` to
999 not apply such corrections.
1003 output : `lsst.pipe.base.Struct`
1004 Results struct
with attributes:
1007 Catalog containing reference objects inside the specified
1010 Name of the field containing the flux associated
with
1013 centerVector = ctrCoord.getVector()
1016 return self.
loadRegion(circularRegion, filterName, epoch=epoch)
1019def getRefFluxField(schema, filterName):
1020 """Get the name of a flux field from a schema.
1025 Reference catalog schema.
1027 Name of camera filter.
1031 fluxFieldName : `str`
1036 Return the alias of ``anyFilterMapsToThis``, if present
1037 else,
return ``*filterName*_camFlux``
if present,
1038 else,
return ``*filterName*_flux``
if present (camera filter name
1039 matches reference filter name),
else raise an exception.
1044 Raised
if an appropriate field
is not found.
1047 raise RuntimeError(
"schema=%s is not a schema" % (schema,))
1049 return schema.getAliasMap().get(
"anyFilterMapsToThis")
1053 fluxFieldList = [filterName +
"_camFlux", filterName +
"_flux"]
1054 for fluxField
in fluxFieldList:
1055 if fluxField
in schema:
1058 raise RuntimeError(
"Could not find flux field(s) %s" % (
", ".join(fluxFieldList)))
1062 """Return keys for flux and flux error.
1067 Reference catalog schema.
1069 Name of camera filter.
1077 - flux error key, if present,
else None
1082 If flux field
not found.
1084 fluxField = getRefFluxField(schema, filterName)
1085 fluxErrField = fluxField + "Err"
1086 fluxKey = schema[fluxField].asKey()
1088 fluxErrKey = schema[fluxErrField].asKey()
1091 return (fluxKey, fluxErrKey)
1094@deprecated(reason=(
"This task is used in gen2 only; it will be removed after v25. "
1095 "See DM-35671 for details on updating code to avoid this warning."),
1096 version=
"v25.0", category=FutureWarning)
1098 """Abstract gen2 base class to load objects from reference catalogs.
1100 _DefaultName = "LoadReferenceObjects"
1103 def loadSkyCircle(self, ctrCoord, radius, filterName, epoch=None, centroids=False):
1104 """Load reference objects that overlap a circular sky region.
1109 ICRS center of search region.
1111 Radius of search region.
1113 Name of filter. This can be used for flux limit comparisons.
1114 epoch : `astropy.time.Time`
or `
None`, optional
1115 Epoch to which to correct proper motion
and parallax,
or `
None` to
1116 not apply such corrections.
1117 centroids : `bool`, optional
1118 Add centroid fields to the loaded Schema. ``loadPixelBox`` expects
1119 these fields to exist.
1123 results : `lsst.pipe.base.Struct`
1124 A `~lsst.pipe.base.Struct` containing the following fields:
1127 A catalog of reference objects
with the standard
1128 schema,
as documented
in the main doc string
for
1129 `LoadReferenceObjects`.
1130 The catalog
is guaranteed to be contiguous.
1131 (`lsst.afw.catalog.SimpleCatalog`)
1133 Name of flux field
for specified `filterName`. (`str`)
1137 Note that subclasses are responsible
for performing the proper motion
1138 correction, since this
is the lowest-level interface
for retrieving
1144@deprecated(reason=
"Base class only used for gen2 interface, and will be removed after v25.0. "
1145 "Please use ReferenceObjectLoader directly.",
1146 version=
"v25.0", category=FutureWarning)
1148 """Stub of a deprecated class.
1153 Configuration for the loader.
1160 """Apply proper motion correction to a reference catalog.
1162 Adjust position and position error
in the ``catalog``
1163 for proper motion to the specified ``epoch``,
1164 modifying the catalog
in place.
1169 Log object to write to.
1171 Catalog of positions, containing:
1173 - Coordinates, retrieved by the table
's coordinate key.
1174 - ``coord_raErr`` : Error in Right Ascension (rad).
1175 - ``coord_decErr`` : Error
in Declination (rad).
1176 - ``pm_ra`` : Proper motion
in Right Ascension (rad/yr,
1178 - ``pm_raErr`` : Error
in ``pm_ra`` (rad/yr), optional.
1179 - ``pm_dec`` : Proper motion
in Declination (rad/yr,
1181 - ``pm_decErr`` : Error
in ``pm_dec`` (rad/yr), optional.
1182 - ``epoch`` : Mean epoch of object (an astropy.time.Time)
1183 epoch : `astropy.time.Time`
1184 Epoch to which to correct proper motion.
1186 if "epoch" not in catalog.schema
or "pm_ra" not in catalog.schema
or "pm_dec" not in catalog.schema:
1187 log.warning(
"Proper motion correction not available from catalog")
1189 if not catalog.isContiguous():
1190 raise RuntimeError(
"Catalog must be contiguous")
1191 catEpoch = astropy.time.Time(catalog[
"epoch"], scale=
"tai", format=
"mjd")
1192 log.info(
"Correcting reference catalog for proper motion to %r", epoch)
1194 timeDiffsYears = (epoch.tai - catEpoch).
to(astropy.units.yr).value
1195 coordKey = catalog.table.getCoordKey()
1198 pmRaRad = catalog[
"pm_ra"]
1199 pmDecRad = catalog[
"pm_dec"]
1200 offsetsRaRad = pmRaRad*timeDiffsYears
1201 offsetsDecRad = pmDecRad*timeDiffsYears
1209 offsetBearingsRad = numpy.arctan2(pmDecRad*1e6, pmRaRad*1e6)
1210 offsetAmountsRad = numpy.hypot(offsetsRaRad, offsetsDecRad)
1211 for record, bearingRad, amountRad
in zip(catalog, offsetBearingsRad, offsetAmountsRad):
1212 record.set(coordKey,
1213 record.get(coordKey).offset(bearing=bearingRad*geom.radians,
1214 amount=amountRad*geom.radians))
1216 if "coord_raErr" in catalog.schema:
1217 catalog[
"coord_raErr"] = numpy.hypot(catalog[
"coord_raErr"],
1218 catalog[
"pm_raErr"]*timeDiffsYears)
1219 if "coord_decErr" in catalog.schema:
1220 catalog[
"coord_decErr"] = numpy.hypot(catalog[
"coord_decErr"],
1221 catalog[
"pm_decErr"]*timeDiffsYears)
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
A mapping between the keys of two Schemas, used to copy data between them.
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Class for storing ordered metadata with comments.
A class representing an angle.
A floating-point coordinate rectangle geometry.
An integer coordinate rectangle.
Point in an unspecified spherical coordinate system.
This static class includes a variety of methods for interacting with the the logging module.
def __call__(self, refCat, catRegion)
def __init__(self, region)
def loadSkyCircle(self, ctrCoord, radius, filterName, epoch=None, centroids=False)
def __init__(self, config=None, *args, **kwargs)
def _calculateCircle(bbox, wcs, pixelMargin)
def __init__(self, dataIds, refCats, name=None, log=None, config=None, **kwargs)
def _makeBoxRegion(BBox, wcs, BBoxPadding)
def applyProperMotions(self, catalog, epoch)
def loadSkyCircle(self, ctrCoord, radius, filterName, epoch=None)
def _remapReferenceCatalogSchema(refCat, *anyFilterMapsToThis=None, filterMap=None, centroids=False)
def loadRegion(self, region, filterName, filtFunc=None, epoch=None)
def getMetadataBox(self, bbox, wcs, filterName, epoch=None, bboxToSpherePadding=100)
def loadPixelBox(self, bbox, wcs, filterName, epoch=None, bboxToSpherePadding=100)
def makeMinimalSchema(filterNameList, *addCentroid=False, addIsPhotometric=False, addIsResolved=False, addIsVariable=False, coordErrDim=2, addProperMotion=False, properMotionErrDim=2, addParallax=False)
def getMetadataCircle(coord, radius, filterName, epoch=None)
Angle represents an angle in radians.
Circle is a circular region on the unit sphere that contains its boundary.
ConvexPolygon is a closed convex polygon on the unit sphere.
Region is a minimal interface for 2-dimensional regions on the unit sphere.
daf::base::PropertySet * set
void updateRefCentroids(geom::SkyWcs const &wcs, ReferenceCollection &refList)
Update centroids in a collection of reference objects.
def hasNanojanskyFluxUnits(schema)
def getRefFluxKeys(schema, filterName)
def convertToNanojansky(catalog, log, doConvert=True)
def isOldFluxField(name, units)
def getFormatVersionFromRefCat(refCat)
def applyProperMotionsImpl(log, catalog, epoch)
A description of a field in a table.