Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0d33ba9806+23fb6b1458,g0fba68d861+c03ca182fa,g1e78f5e6d3+6885d38a10,g1ec0fe41b4+f8df4a5e9d,g1fd858c14a+1f896281a9,g35bb328faa+fcb1d3bbc8,g4af146b050+32dc2822d5,g4d2262a081+2d16baa2ff,g53246c7159+fcb1d3bbc8,g5a012ec0e7+6ce3c67fb7,g60b5630c4e+23fb6b1458,g67b6fd64d1+b5a8974b5d,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+4e9c20b633,g8852436030+17127e6d9c,g89139ef638+b5a8974b5d,g9125e01d80+fcb1d3bbc8,g94187f82dc+23fb6b1458,g989de1cb63+b5a8974b5d,g9f33ca652e+b775bc0ddd,g9f7030ddb1+0d26baa418,ga2b97cdc51+23fb6b1458,ga44b1db4f6+f3405f2437,gabe3b4be73+1e0a283bba,gabf8522325+a9d2faf463,gb1101e3267+1c10e8ebae,gb58c049af0+f03b321e39,gb89ab40317+b5a8974b5d,gcf25f946ba+17127e6d9c,gd6cbbdb0b4+ace4583378,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+551b1246a4,ge278dab8ac+fa73091e6d,ge410e46f29+b5a8974b5d,gf67bdafdda+b5a8974b5d,gfe06eef73a+62ba25d42b,v29.0.0.rc5
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 886 of file loadReferenceObjects.py.

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

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

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