LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
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.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 833 of file loadReferenceObjects.py.

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

758def getRefFluxField(schema, filterName):
759 """Get the name of a flux field from a schema.
760
761 Parameters
762 ----------
763 schema : `lsst.afw.table.Schema`
764 Reference catalog schema.
765 filterName : `str`
766 Name of camera filter.
767
768 Returns
769 -------
770 fluxFieldName : `str`
771 Name of flux field.
772
773 Notes
774 -----
775 Return the alias of ``anyFilterMapsToThis``, if present
776 else, return ``*filterName*_camFlux`` if present,
777 else, return ``*filterName*_flux`` if present (camera filter name
778 matches reference filter name), else raise an exception.
779
780 Raises
781 ------
782 RuntimeError
783 Raised if an appropriate field is not found.
784 """
785 if not isinstance(schema, afwTable.Schema):
786 raise RuntimeError("schema=%s is not a schema" % (schema,))
787 try:
788 return schema.getAliasMap().get("anyFilterMapsToThis")
789 except LookupError:
790 pass # try the filterMap next
791
792 fluxFieldList = [filterName + "_camFlux", filterName + "_flux"]
793 for fluxField in fluxFieldList:
794 if fluxField in schema:
795 return fluxField
796
797 raise RuntimeError("Could not find flux field(s) %s" % (", ".join(fluxFieldList)))
798
799
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 800 of file loadReferenceObjects.py.

800def getRefFluxKeys(schema, filterName):
801 """Return keys for flux and flux error.
802
803 Parameters
804 ----------
805 schema : `lsst.afw.table.Schema`
806 Reference catalog schema.
807 filterName : `str`
808 Name of camera filter.
809
810 Returns
811 -------
812 keys : `tuple` of (`lsst.afw.table.Key`, `lsst.afw.table.Key`)
813 Two keys:
814
815 - flux key
816 - flux error key, if present, else None
817
818 Raises
819 ------
820 RuntimeError
821 If flux field not found.
822 """
823 fluxField = getRefFluxField(schema, filterName)
824 fluxErrField = fluxField + "Err"
825 fluxKey = schema[fluxField].asKey()
826 try:
827 fluxErrKey = schema[fluxErrField].asKey()
828 except Exception:
829 fluxErrKey = None
830 return (fluxKey, fluxErrKey)
831
832