LSST Applications g063fba187b+fee0456c91,g0f08755f38+ea96e5a5a3,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+90257ff92a,g20f6ffc8e0+ea96e5a5a3,g217e2c1bcf+937a289c59,g28da252d5a+daa7da44eb,g2bbee38e9b+253935c60e,g2bc492864f+253935c60e,g3156d2b45e+6e55a43351,g32e5bea42b+31359a2a7a,g347aa1857d+253935c60e,g35bb328faa+a8ce1bb630,g3a166c0a6a+253935c60e,g3b1af351f3+a8ce1bb630,g3e281a1b8c+c5dd892a6c,g414038480c+416496e02f,g41af890bb2+afe91b1188,g599934f4f4+0db33f7991,g7af13505b9+e36de7bce6,g80478fca09+da231ba887,g82479be7b0+a4516e59e3,g858d7b2824+ea96e5a5a3,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+bc6ab8dfbd,gb58c049af0+d64f4d3760,gc28159a63d+253935c60e,gcab2d0539d+3f2b72788c,gcf0d15dbbd+4ea9c45075,gda6a2b7d83+4ea9c45075,gdaeeff99f8+1711a396fd,ge79ae78c31+253935c60e,gef2f8181fd+3031e3cf99,gf0baf85859+c1f95f4921,gfa517265be+ea96e5a5a3,gfa999e8aa5+17cd334064,w.2024.50
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst.meas.algorithms.loadReferenceObjects Namespace Reference

Classes

class  _FilterCatalog
 
class  LoadReferenceObjectsConfig
 
class  ReferenceObjectLoader
 

Functions

 getFormatVersionFromRefCat (refCat)
 
 getRefFluxField (schema, filterName)
 
 getRefFluxKeys (schema, filterName)
 
 applyProperMotionsImpl (log, catalog, epoch)
 

Function Documentation

◆ applyProperMotionsImpl()

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.Logger`
    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 844 of file loadReferenceObjects.py.

844def applyProperMotionsImpl(log, catalog, epoch):
845 """Apply proper motion correction to a reference catalog.
846
847 Adjust position and position error in the ``catalog``
848 for proper motion to the specified ``epoch``,
849 modifying the catalog in place.
850
851 Parameters
852 ----------
853 log : `lsst.log.Log` or `logging.Logger`
854 Log object to write to.
855 catalog : `lsst.afw.table.SimpleCatalog`
856 Catalog of positions, containing:
857
858 - Coordinates, retrieved by the table's coordinate key.
859 - ``coord_raErr`` : Error in Right Ascension (rad).
860 - ``coord_decErr`` : Error in Declination (rad).
861 - ``pm_ra`` : Proper motion in Right Ascension (rad/yr,
862 East positive)
863 - ``pm_raErr`` : Error in ``pm_ra`` (rad/yr), optional.
864 - ``pm_dec`` : Proper motion in Declination (rad/yr,
865 North positive)
866 - ``pm_decErr`` : Error in ``pm_dec`` (rad/yr), optional.
867 - ``epoch`` : Mean epoch of object (an astropy.time.Time)
868 epoch : `astropy.time.Time`
869 Epoch to which to correct proper motion.
870 """
871 if "epoch" not in catalog.schema or "pm_ra" not in catalog.schema or "pm_dec" not in catalog.schema:
872 log.warning("Proper motion correction not available from catalog")
873 return
874 if not catalog.isContiguous():
875 raise RuntimeError("Catalog must be contiguous")
876 catEpoch = astropy.time.Time(catalog["epoch"], scale="tai", format="mjd")
877 log.info("Correcting reference catalog for proper motion to %r", epoch)
878 # Use `epoch.tai` to make sure the time difference is in TAI
879 timeDiffsYears = (epoch.tai - catEpoch).to(astropy.units.yr).value
880 coordKey = catalog.table.getCoordKey()
881 # Compute the offset of each object due to proper motion
882 # as components of the arc of a great circle along RA and Dec
883 pmRaRad = catalog["pm_ra"]
884 pmDecRad = catalog["pm_dec"]
885 offsetsRaRad = pmRaRad*timeDiffsYears
886 offsetsDecRad = pmDecRad*timeDiffsYears
887 # Compute the corresponding bearing and arc length of each offset
888 # due to proper motion, and apply the offset.
889 # The factor of 1e6 for computing bearing is intended as
890 # a reasonable scale for typical values of proper motion
891 # in order to avoid large errors for small values of proper motion;
892 # using the offsets is another option, but it can give
893 # needlessly large errors for short duration.
894 offsetBearingsRad = numpy.arctan2(offsetsDecRad*1e6, offsetsRaRad*1e6)
895 offsetAmountsRad = numpy.hypot(offsetsRaRad, offsetsDecRad)
896 for record, bearingRad, amountRad in zip(catalog, offsetBearingsRad, offsetAmountsRad):
897 record.set(coordKey,
898 record.get(coordKey).offset(bearing=bearingRad*geom.radians,
899 amount=amountRad*geom.radians))
900 # TODO DM-36979: this needs to incorporate the full covariance!
901 # Increase error in RA and Dec based on error in proper motion
902 if "coord_raErr" in catalog.schema:
903 catalog["coord_raErr"] = numpy.hypot(catalog["coord_raErr"],
904 catalog["pm_raErr"]*timeDiffsYears)
905 if "coord_decErr" in catalog.schema:
906 catalog["coord_decErr"] = numpy.hypot(catalog["coord_decErr"],
907 catalog["pm_decErr"]*timeDiffsYears)

◆ getFormatVersionFromRefCat()

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

Raises
------
ValueError
    Raised if the catalog is version 0, has no metadata, or does not
    include a "REFCAT_FORMAT_VERSION" key.

Definition at line 41 of file loadReferenceObjects.py.

41def getFormatVersionFromRefCat(refCat):
42 """"Return the format version stored in a reference catalog header.
43
44 Parameters
45 ----------
46 refCat : `lsst.afw.table.SimpleCatalog`
47 Reference catalog to inspect.
48
49 Returns
50 -------
51 version : `int`
52 Format version integer.
53
54 Raises
55 ------
56 ValueError
57 Raised if the catalog is version 0, has no metadata, or does not
58 include a "REFCAT_FORMAT_VERSION" key.
59 """
60 errMsg = "Version 0 refcats are no longer supported: refcat fluxes must have nJy units."
61 md = refCat.getMetadata()
62 if md is None:
63 raise ValueError(f"No metadata found in refcat header. {errMsg}")
64
65 try:
66 version = md.getScalar("REFCAT_FORMAT_VERSION")
67 if version == 0:
68 raise ValueError(errMsg)
69 else:
70 return version
71 except KeyError:
72 raise ValueError(f"No version number found in refcat header metadata. {errMsg}")
73
74

◆ getRefFluxField()

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

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

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

Notes
-----
Return the alias of ``anyFilterMapsToThis``, if present
else, return ``*filterName*_camFlux`` if present,
else, return ``*filterName*_flux`` if present (camera filter name
matches reference filter name), else raise an exception.

Raises
------
RuntimeError
    Raised if an appropriate field is not found.

Definition at line 769 of file loadReferenceObjects.py.

769def getRefFluxField(schema, filterName):
770 """Get the name of a flux field from a schema.
771
772 Parameters
773 ----------
774 schema : `lsst.afw.table.Schema`
775 Reference catalog schema.
776 filterName : `str`
777 Name of camera filter.
778
779 Returns
780 -------
781 fluxFieldName : `str`
782 Name of flux field.
783
784 Notes
785 -----
786 Return the alias of ``anyFilterMapsToThis``, if present
787 else, return ``*filterName*_camFlux`` if present,
788 else, return ``*filterName*_flux`` if present (camera filter name
789 matches reference filter name), else raise an exception.
790
791 Raises
792 ------
793 RuntimeError
794 Raised if an appropriate field is not found.
795 """
796 if not isinstance(schema, afwTable.Schema):
797 raise RuntimeError("schema=%s is not a schema" % (schema,))
798 try:
799 return schema.getAliasMap().get("anyFilterMapsToThis")
800 except LookupError:
801 pass # try the filterMap next
802
803 fluxFieldList = [filterName + "_camFlux", filterName + "_flux"]
804 for fluxField in fluxFieldList:
805 if fluxField in schema:
806 return fluxField
807
808 raise RuntimeError("Could not find flux field(s) %s" % (", ".join(fluxFieldList)))
809
810
Defines the fields and offsets for a table.
Definition Schema.h:51

◆ getRefFluxKeys()

lsst.meas.algorithms.loadReferenceObjects.getRefFluxKeys ( schema,
filterName )
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 811 of file loadReferenceObjects.py.

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