LSST Applications g013ef56533+63812263fb,g083dd6704c+a047e97985,g199a45376c+0ba108daf9,g1fd858c14a+fde7a7a78c,g210f2d0738+db0c280453,g262e1987ae+abed931625,g29ae962dfc+058d1915d8,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+64337f1634,g47891489e3+f459a6810c,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5a60e81ecd+d9e514a434,g64539dfbff+db0c280453,g67b6fd64d1+f459a6810c,g6ebf1fc0d4+8c5ae1fdc5,g7382096ae9+36d16ea71a,g74acd417e5+c70e70fbf6,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+f459a6810c,g8d7436a09f+1b779678e3,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g97be763408+9583a964dd,g98a1a72a9c+028271c396,g98df359435+530b675b85,gb8cb2b794d+4e54f68785,gbf99507273+8c5ae1fdc5,gc2a301910b+db0c280453,gca7fc764a6+f459a6810c,gd7ef33dd92+f459a6810c,gdab6d2f7ff+c70e70fbf6,ge410e46f29+f459a6810c,ge41e95a9f2+db0c280453,geaed405ab2+e3b4b2a692,gf9a733ac38+8c5ae1fdc5,w.2025.43
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 882 of file loadReferenceObjects.py.

882def applyProperMotionsImpl(log, catalog, epoch):
883 """Apply proper motion correction to a reference catalog.
884
885 Adjust position and position error in the ``catalog``
886 for proper motion to the specified ``epoch``,
887 modifying the catalog in place.
888
889 Parameters
890 ----------
891 log : `lsst.log.Log` or `logging.Logger`
892 Log object to write to.
893 catalog : `lsst.afw.table.SimpleCatalog`
894 Catalog of positions, containing:
895
896 - Coordinates, retrieved by the table's coordinate key.
897 - ``coord_raErr`` : Error in Right Ascension (rad).
898 - ``coord_decErr`` : Error in Declination (rad).
899 - ``pm_ra`` : Proper motion in Right Ascension (rad/yr,
900 East positive)
901 - ``pm_raErr`` : Error in ``pm_ra`` (rad/yr), optional.
902 - ``pm_dec`` : Proper motion in Declination (rad/yr,
903 North positive)
904 - ``pm_decErr`` : Error in ``pm_dec`` (rad/yr), optional.
905 - ``epoch`` : Mean epoch of object (an astropy.time.Time)
906 epoch : `astropy.time.Time`
907 Epoch to which to correct proper motion.
908 """
909 if "epoch" not in catalog.schema or "pm_ra" not in catalog.schema or "pm_dec" not in catalog.schema:
910 log.warning("Proper motion correction not available from catalog")
911 return
912 if not catalog.isContiguous():
913 raise RuntimeError("Catalog must be contiguous")
914 catEpoch = astropy.time.Time(catalog["epoch"], scale="tai", format="mjd")
915 log.info("Correcting reference catalog for proper motion to %r", epoch)
916 # Use `epoch.tai` to make sure the time difference is in TAI
917 timeDiffsYears = (epoch.tai - catEpoch).to(astropy.units.yr).value
918 coordKey = catalog.table.getCoordKey()
919 # Compute the offset of each object due to proper motion
920 # as components of the arc of a great circle along RA and Dec
921 pmRaRad = catalog["pm_ra"]
922 pmDecRad = catalog["pm_dec"]
923 offsetsRaRad = pmRaRad*timeDiffsYears
924 offsetsDecRad = pmDecRad*timeDiffsYears
925 # Compute the corresponding bearing and arc length of each offset
926 # due to proper motion, and apply the offset.
927 # The factor of 1e6 for computing bearing is intended as
928 # a reasonable scale for typical values of proper motion
929 # in order to avoid large errors for small values of proper motion;
930 # using the offsets is another option, but it can give
931 # needlessly large errors for short duration.
932 offsetBearingsRad = numpy.arctan2(offsetsDecRad*1e6, offsetsRaRad*1e6)
933 offsetAmountsRad = numpy.hypot(offsetsRaRad, offsetsDecRad)
934 for record, bearingRad, amountRad in zip(catalog, offsetBearingsRad, offsetAmountsRad):
935 record.set(coordKey,
936 record.get(coordKey).offset(bearing=bearingRad*geom.radians,
937 amount=amountRad*geom.radians))
938 # TODO DM-36979: this needs to incorporate the full covariance!
939 # Increase error in RA and Dec based on error in proper motion
940 if "coord_raErr" in catalog.schema:
941 catalog["coord_raErr"] = numpy.hypot(catalog["coord_raErr"],
942 catalog["pm_raErr"]*timeDiffsYears)
943 if "coord_decErr" in catalog.schema:
944 catalog["coord_decErr"] = numpy.hypot(catalog["coord_decErr"],
945 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 807 of file loadReferenceObjects.py.

807def getRefFluxField(schema, filterName):
808 """Get the name of a flux field from a schema.
809
810 Parameters
811 ----------
812 schema : `lsst.afw.table.Schema`
813 Reference catalog schema.
814 filterName : `str`
815 Name of camera filter.
816
817 Returns
818 -------
819 fluxFieldName : `str`
820 Name of flux field.
821
822 Notes
823 -----
824 Return the alias of ``anyFilterMapsToThis``, if present
825 else, return ``*filterName*_camFlux`` if present,
826 else, return ``*filterName*_flux`` if present (camera filter name
827 matches reference filter name), else raise an exception.
828
829 Raises
830 ------
831 RuntimeError
832 Raised if an appropriate field is not found.
833 """
834 if not isinstance(schema, afwTable.Schema):
835 raise RuntimeError("schema=%s is not a schema" % (schema,))
836 try:
837 return schema.getAliasMap().get("anyFilterMapsToThis")
838 except LookupError:
839 pass # try the filterMap next
840
841 fluxFieldList = [filterName + "_camFlux", filterName + "_flux"]
842 for fluxField in fluxFieldList:
843 if fluxField in schema:
844 return fluxField
845
846 raise RuntimeError("Could not find flux field(s) %s" % (", ".join(fluxFieldList)))
847
848
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 849 of file loadReferenceObjects.py.

849def getRefFluxKeys(schema, filterName):
850 """Return keys for flux and flux error.
851
852 Parameters
853 ----------
854 schema : `lsst.afw.table.Schema`
855 Reference catalog schema.
856 filterName : `str`
857 Name of camera filter.
858
859 Returns
860 -------
861 keys : `tuple` of (`lsst.afw.table.Key`, `lsst.afw.table.Key`)
862 Two keys:
863
864 - flux key
865 - flux error key, if present, else None
866
867 Raises
868 ------
869 RuntimeError
870 If flux field not found.
871 """
872 fluxField = getRefFluxField(schema, filterName)
873 fluxErrField = fluxField + "Err"
874 fluxKey = schema[fluxField].asKey()
875 try:
876 fluxErrKey = schema[fluxErrField].asKey()
877 except Exception:
878 fluxErrKey = None
879 return (fluxKey, fluxErrKey)
880
881