LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
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