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
Classes | Functions
lsst.meas.algorithms.loadReferenceObjects Namespace Reference

Classes

class  _FilterCatalog
 
class  ReferenceObjectLoaderBase
 
class  ReferenceObjectLoader
 
class  LoadReferenceObjectsConfig
 
class  LoadReferenceObjectsTask
 

Functions

def isOldFluxField (name, units)
 
def hasNanojanskyFluxUnits (schema)
 
def getFormatVersionFromRefCat (refCat)
 
def convertToNanojansky (catalog, log, doConvert=True)
 
def getRefFluxField (schema, filterName=None)
 
def getRefFluxKeys (schema, filterName=None)
 
def joinMatchListWithCatalogImpl (refObjLoader, matchCat, sourceCat)
 
def applyProperMotionsImpl (log, catalog, epoch)
 

Function Documentation

◆ applyProperMotionsImpl()

def lsst.meas.algorithms.loadReferenceObjects.applyProperMotionsImpl (   log,
  catalog,
  epoch 
)
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
----------
log : `lsst.log.Log` or `logging.getLogger`
    Log object to write to.
catalog : `lsst.afw.table.SimpleCatalog`
    Catalog of positions, containing:

    - 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.

Definition at line 1455 of file loadReferenceObjects.py.

1455 def applyProperMotionsImpl(log, catalog, epoch):
1456  """Apply proper motion correction to a reference catalog.
1457 
1458  Adjust position and position error in the ``catalog``
1459  for proper motion to the specified ``epoch``,
1460  modifying the catalog in place.
1461 
1462  Parameters
1463  ----------
1464  log : `lsst.log.Log` or `logging.getLogger`
1465  Log object to write to.
1466  catalog : `lsst.afw.table.SimpleCatalog`
1467  Catalog of positions, containing:
1468 
1469  - Coordinates, retrieved by the table's coordinate key.
1470  - ``coord_raErr`` : Error in Right Ascension (rad).
1471  - ``coord_decErr`` : Error in Declination (rad).
1472  - ``pm_ra`` : Proper motion in Right Ascension (rad/yr,
1473  East positive)
1474  - ``pm_raErr`` : Error in ``pm_ra`` (rad/yr), optional.
1475  - ``pm_dec`` : Proper motion in Declination (rad/yr,
1476  North positive)
1477  - ``pm_decErr`` : Error in ``pm_dec`` (rad/yr), optional.
1478  - ``epoch`` : Mean epoch of object (an astropy.time.Time)
1479  epoch : `astropy.time.Time`
1480  Epoch to which to correct proper motion.
1481  """
1482  if "epoch" not in catalog.schema or "pm_ra" not in catalog.schema or "pm_dec" not in catalog.schema:
1483  log.warning("Proper motion correction not available from catalog")
1484  return
1485  if not catalog.isContiguous():
1486  raise RuntimeError("Catalog must be contiguous")
1487  catEpoch = astropy.time.Time(catalog["epoch"], scale="tai", format="mjd")
1488  log.info("Correcting reference catalog for proper motion to %r", epoch)
1489  # Use `epoch.tai` to make sure the time difference is in TAI
1490  timeDiffsYears = (epoch.tai - catEpoch).to(astropy.units.yr).value
1491  coordKey = catalog.table.getCoordKey()
1492  # Compute the offset of each object due to proper motion
1493  # as components of the arc of a great circle along RA and Dec
1494  pmRaRad = catalog["pm_ra"]
1495  pmDecRad = catalog["pm_dec"]
1496  offsetsRaRad = pmRaRad*timeDiffsYears
1497  offsetsDecRad = pmDecRad*timeDiffsYears
1498  # Compute the corresponding bearing and arc length of each offset
1499  # due to proper motion, and apply the offset
1500  # The factor of 1e6 for computing bearing is intended as
1501  # a reasonable scale for typical values of proper motion
1502  # in order to avoid large errors for small values of proper motion;
1503  # using the offsets is another option, but it can give
1504  # needlessly large errors for short duration
1505  offsetBearingsRad = numpy.arctan2(pmDecRad*1e6, pmRaRad*1e6)
1506  offsetAmountsRad = numpy.hypot(offsetsRaRad, offsetsDecRad)
1507  for record, bearingRad, amountRad in zip(catalog, offsetBearingsRad, offsetAmountsRad):
1508  record.set(coordKey,
1509  record.get(coordKey).offset(bearing=bearingRad*geom.radians,
1510  amount=amountRad*geom.radians))
1511  # Increase error in RA and Dec based on error in proper motion
1512  if "coord_raErr" in catalog.schema:
1513  catalog["coord_raErr"] = numpy.hypot(catalog["coord_raErr"],
1514  catalog["pm_raErr"]*timeDiffsYears)
1515  if "coord_decErr" in catalog.schema:
1516  catalog["coord_decErr"] = numpy.hypot(catalog["coord_decErr"],
1517  catalog["pm_decErr"]*timeDiffsYears)
table::Key< int > to

◆ convertToNanojansky()

def lsst.meas.algorithms.loadReferenceObjects.convertToNanojansky (   catalog,
  log,
  doConvert = True 
)
Convert fluxes in a catalog from jansky to nanojansky.

Parameters
----------
catalog : `lsst.afw.table.SimpleCatalog`
    The catalog to convert.
log : `lsst.log.Log` or `logging.Logger`
    Log to send messages to.
doConvert : `bool`, optional
    Return a converted catalog, or just identify the fields that need to be converted?
    This supports the "write=False" mode of `bin/convert_to_nJy.py`.

Returns
-------
catalog : `lsst.afw.table.SimpleCatalog` or None
    The converted catalog, or None if ``doConvert`` is False.

Notes
-----
Support for old units in reference catalogs will be removed after the
release of late calendar year 2019.
Use `meas_algorithms/bin/convert_to_nJy.py` to update your reference catalog.

Definition at line 87 of file loadReferenceObjects.py.

87 def convertToNanojansky(catalog, log, doConvert=True):
88  """Convert fluxes in a catalog from jansky to nanojansky.
89 
90  Parameters
91  ----------
92  catalog : `lsst.afw.table.SimpleCatalog`
93  The catalog to convert.
94  log : `lsst.log.Log` or `logging.Logger`
95  Log to send messages to.
96  doConvert : `bool`, optional
97  Return a converted catalog, or just identify the fields that need to be converted?
98  This supports the "write=False" mode of `bin/convert_to_nJy.py`.
99 
100  Returns
101  -------
102  catalog : `lsst.afw.table.SimpleCatalog` or None
103  The converted catalog, or None if ``doConvert`` is False.
104 
105  Notes
106  -----
107  Support for old units in reference catalogs will be removed after the
108  release of late calendar year 2019.
109  Use `meas_algorithms/bin/convert_to_nJy.py` to update your reference catalog.
110  """
111  # Do not share the AliasMap: for refcats, that gets created when the
112  # catalog is read from disk and should not be propagated.
113  mapper = afwTable.SchemaMapper(catalog.schema, shareAliasMap=False)
114  mapper.addMinimalSchema(afwTable.SimpleTable.makeMinimalSchema())
115  input_fields = []
116  output_fields = []
117  for field in catalog.schema:
118  oldName = field.field.getName()
119  oldUnits = field.field.getUnits()
120  if isOldFluxField(oldName, oldUnits):
121  units = 'nJy'
122  # remap Sigma flux fields to Err, so we can drop the alias
123  if oldName.endswith('_fluxSigma'):
124  name = oldName.replace('_fluxSigma', '_fluxErr')
125  else:
126  name = oldName
127  newField = afwTable.Field[field.dtype](name, field.field.getDoc(), units)
128  mapper.addMapping(field.getKey(), newField)
129  input_fields.append(field.field)
130  output_fields.append(newField)
131  else:
132  mapper.addMapping(field.getKey())
133 
134  fluxFieldsStr = '; '.join("(%s, '%s')" % (field.getName(), field.getUnits()) for field in input_fields)
135 
136  if doConvert:
137  newSchema = mapper.getOutputSchema()
138  output = afwTable.SimpleCatalog(newSchema)
139  output.extend(catalog, mapper=mapper)
140  for field in output_fields:
141  output[field.getName()] *= 1e9
142  log.info("Converted refcat flux fields to nJy (name, units): %s", fluxFieldsStr)
143  return output
144  else:
145  log.info("Found old-style refcat flux fields (name, units): %s", fluxFieldsStr)
146  return None
147 
148 
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 convertToNanojansky(catalog, log, doConvert=True)
A description of a field in a table.
Definition: Field.h:24

◆ getFormatVersionFromRefCat()

def lsst.meas.algorithms.loadReferenceObjects.getFormatVersionFromRefCat (   refCat)
"Return the format version stored in a reference catalog header.

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

Returns
-------
version : `int`
    Format verison integer. Returns `0` if the catalog has no metadata
    or the metadata does not include a "REFCAT_FORMAT_VERSION" key.

Definition at line 64 of file loadReferenceObjects.py.

64 def getFormatVersionFromRefCat(refCat):
65  """"Return the format version stored in a reference catalog header.
66 
67  Parameters
68  ----------
69  refCat : `lsst.afw.table.SimpleCatalog`
70  Reference catalog to inspect.
71 
72  Returns
73  -------
74  version : `int`
75  Format verison integer. Returns `0` if the catalog has no metadata
76  or the metadata does not include a "REFCAT_FORMAT_VERSION" key.
77  """
78  md = refCat.getMetadata()
79  if md is None:
80  return 0
81  try:
82  return md.getScalar("REFCAT_FORMAT_VERSION")
83  except KeyError:
84  return 0
85 
86 

◆ getRefFluxField()

def lsst.meas.algorithms.loadReferenceObjects.getRefFluxField (   schema,
  filterName = None 
)
Get the name of a flux field from a schema.

return the alias of "anyFilterMapsToThis", if present
else if filterName is specified:
    return "*filterName*_camFlux" if present
    else return "*filterName*_flux" if present (camera filter name
        matches reference filter name)
    else throw RuntimeError
else:
    return "camFlux", if present,
    else throw RuntimeError

Parameters
----------
schema : `lsst.afw.table.Schema`
    Reference catalog schema.
filterName : `str`, optional
    Name of camera filter. If not specified, ``defaultFilter`` needs to be
    set in the refcat loader config.

Returns
-------
fluxFieldName : `str`
    Name of flux field.

Raises
------
RuntimeError
    If an appropriate field is not found.

Definition at line 772 of file loadReferenceObjects.py.

772 def getRefFluxField(schema, filterName=None):
773  """Get the name of a flux field from a schema.
774 
775  return the alias of "anyFilterMapsToThis", if present
776  else if filterName is specified:
777  return "*filterName*_camFlux" if present
778  else return "*filterName*_flux" if present (camera filter name
779  matches reference filter name)
780  else throw RuntimeError
781  else:
782  return "camFlux", if present,
783  else throw RuntimeError
784 
785  Parameters
786  ----------
787  schema : `lsst.afw.table.Schema`
788  Reference catalog schema.
789  filterName : `str`, optional
790  Name of camera filter. If not specified, ``defaultFilter`` needs to be
791  set in the refcat loader config.
792 
793  Returns
794  -------
795  fluxFieldName : `str`
796  Name of flux field.
797 
798  Raises
799  ------
800  RuntimeError
801  If an appropriate field is not found.
802  """
803  if not isinstance(schema, afwTable.Schema):
804  raise RuntimeError("schema=%s is not a schema" % (schema,))
805  try:
806  return schema.getAliasMap().get("anyFilterMapsToThis")
807  except LookupError:
808  pass # try the filterMap next
809 
810  if filterName:
811  fluxFieldList = [filterName + "_camFlux", filterName + "_flux"]
812  else:
813  fluxFieldList = ["camFlux"]
814  for fluxField in fluxFieldList:
815  if fluxField in schema:
816  return fluxField
817 
818  raise RuntimeError("Could not find flux field(s) %s" % (", ".join(fluxFieldList)))
819 
820 
Defines the fields and offsets for a table.
Definition: Schema.h:51

◆ getRefFluxKeys()

def lsst.meas.algorithms.loadReferenceObjects.getRefFluxKeys (   schema,
  filterName = None 
)
Return keys for flux and flux error.

Parameters
----------
schema : `lsst.afw.table.Schema`
    Reference catalog schema.
filterName : `str`
    Name of camera filter.

Returns
-------
keys : `tuple` of (`lsst.afw.table.Key`, `lsst.afw.table.Key`)
    Two keys:

    - flux key
    - flux error key, if present, else None

Raises
------
RuntimeError
    If flux field not found.

Definition at line 821 of file loadReferenceObjects.py.

821 def getRefFluxKeys(schema, filterName=None):
822  """Return keys for flux and flux error.
823 
824  Parameters
825  ----------
826  schema : `lsst.afw.table.Schema`
827  Reference catalog schema.
828  filterName : `str`
829  Name of camera filter.
830 
831  Returns
832  -------
833  keys : `tuple` of (`lsst.afw.table.Key`, `lsst.afw.table.Key`)
834  Two keys:
835 
836  - flux key
837  - flux error key, if present, else None
838 
839  Raises
840  ------
841  RuntimeError
842  If flux field not found.
843  """
844  fluxField = getRefFluxField(schema, filterName)
845  fluxErrField = fluxField + "Err"
846  fluxKey = schema[fluxField].asKey()
847  try:
848  fluxErrKey = schema[fluxErrField].asKey()
849  except Exception:
850  fluxErrKey = None
851  return (fluxKey, fluxErrKey)
852 
853 

◆ hasNanojanskyFluxUnits()

def lsst.meas.algorithms.loadReferenceObjects.hasNanojanskyFluxUnits (   schema)
Return True if the units of all flux and fluxErr are correct (nJy).

Definition at line 55 of file loadReferenceObjects.py.

55 def hasNanojanskyFluxUnits(schema):
56  """Return True if the units of all flux and fluxErr are correct (nJy).
57  """
58  for field in schema:
59  if isOldFluxField(field.field.getName(), field.field.getUnits()):
60  return False
61  return True
62 
63 

◆ isOldFluxField()

def lsst.meas.algorithms.loadReferenceObjects.isOldFluxField (   name,
  units 
)
Return True if this name/units combination corresponds to an
"old-style" reference catalog flux field.

Definition at line 44 of file loadReferenceObjects.py.

44 def isOldFluxField(name, units):
45  """Return True if this name/units combination corresponds to an
46  "old-style" reference catalog flux field.
47  """
48  unitsCheck = units != 'nJy' # (units == 'Jy' or units == '' or units == '?')
49  isFlux = name.endswith('_flux')
50  isFluxSigma = name.endswith('_fluxSigma')
51  isFluxErr = name.endswith('_fluxErr')
52  return (isFlux or isFluxSigma or isFluxErr) and unitsCheck
53 
54 

◆ joinMatchListWithCatalogImpl()

def lsst.meas.algorithms.loadReferenceObjects.joinMatchListWithCatalogImpl (   refObjLoader,
  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
----------
refObjLoader
    Reference object loader to use in getting reference objects
matchCat : `lsst.afw.table.BaseCatalog`
    Unperisted 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 1394 of file loadReferenceObjects.py.

1394 def joinMatchListWithCatalogImpl(refObjLoader, matchCat, sourceCat):
1395  """Relink an unpersisted match list to sources and reference
1396  objects.
1397 
1398  A match list is persisted and unpersisted as a catalog of IDs
1399  produced by afw.table.packMatches(), with match metadata
1400  (as returned by the astrometry tasks) in the catalog's metadata
1401  attribute. This method converts such a match catalog into a match
1402  list, with links to source records and reference object records.
1403 
1404  Parameters
1405  ----------
1406  refObjLoader
1407  Reference object loader to use in getting reference objects
1408  matchCat : `lsst.afw.table.BaseCatalog`
1409  Unperisted packed match list.
1410  ``matchCat.table.getMetadata()`` must contain match metadata,
1411  as returned by the astrometry tasks.
1412  sourceCat : `lsst.afw.table.SourceCatalog`
1413  Source catalog. As a side effect, the catalog will be sorted
1414  by ID.
1415 
1416  Returns
1417  -------
1418  matchList : `lsst.afw.table.ReferenceMatchVector`
1419  Match list.
1420  """
1421  matchmeta = matchCat.table.getMetadata()
1422  version = matchmeta.getInt('SMATCHV')
1423  if version != 1:
1424  raise ValueError('SourceMatchVector version number is %i, not 1.' % version)
1425  filterName = matchmeta.getString('FILTER').strip()
1426  try:
1427  epoch = matchmeta.getDouble('EPOCH')
1428  except (LookupError, TypeError):
1429  epoch = None # Not present, or not correct type means it's not set
1430  if 'RADIUS' in matchmeta:
1431  # This is a circle style metadata, call loadSkyCircle
1432  ctrCoord = geom.SpherePoint(matchmeta.getDouble('RA'),
1433  matchmeta.getDouble('DEC'), geom.degrees)
1434  rad = matchmeta.getDouble('RADIUS')*geom.degrees
1435  refCat = refObjLoader.loadSkyCircle(ctrCoord, rad, filterName, epoch=epoch).refCat
1436  elif "INNER_UPPER_LEFT_RA" in matchmeta:
1437  # This is the sky box type (only triggers in the LoadReferenceObject class, not task)
1438  # Only the outer box is required to be loaded to get the maximum region, all filtering
1439  # will be done by the unpackMatches function, and no spatial filtering needs to be done
1440  # by the refObjLoader
1441  box = []
1442  for place in ("UPPER_LEFT", "UPPER_RIGHT", "LOWER_LEFT", "LOWER_RIGHT"):
1443  coord = geom.SpherePoint(matchmeta.getDouble(f"OUTER_{place}_RA"),
1444  matchmeta.getDouble(f"OUTER_{place}_DEC"),
1445  geom.degrees).getVector()
1446  box.append(coord)
1447  outerBox = sphgeom.ConvexPolygon(box)
1448  refCat = refObjLoader.loadRegion(outerBox, filterName=filterName, epoch=epoch).refCat
1449 
1450  refCat.sort()
1451  sourceCat.sort()
1452  return afwTable.unpackMatches(matchCat, refCat, sourceCat)
1453 
1454 
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
bool strip
Definition: fits.cc:911
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > unpackMatches(BaseCatalog const &matches, Cat1 const &cat1, Cat2 const &cat2)
Reconstruct a MatchVector from a BaseCatalog representation of the matches and a pair of catalogs.
Definition: Match.cc:455
def joinMatchListWithCatalogImpl(refObjLoader, matchCat, sourceCat)