LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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