LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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`
    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 1454 of file loadReferenceObjects.py.

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

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

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

◆ 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 771 of file loadReferenceObjects.py.

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

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

◆ hasNanojanskyFluxUnits()

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

Definition at line 54 of file loadReferenceObjects.py.

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

◆ 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 43 of file loadReferenceObjects.py.

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

◆ 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 1393 of file loadReferenceObjects.py.

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