Skip to content

Commit

Permalink
Add method to get refcat schema from loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jan 15, 2025
1 parent 97b8272 commit 8366484
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
43 changes: 42 additions & 1 deletion python/lsst/meas/algorithms/loadReferenceObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __init__(self, dataIds, refCats, name=None, log=None, config=None):
config = self.ConfigClass()
self.config = config
self.dataIds = dataIds
self.refCats = refCats
self.refCats = list(refCats)
self.name = name
self.log = log or logging.getLogger(__name__).getChild("ReferenceObjectLoader")

Expand Down Expand Up @@ -765,6 +765,47 @@ def loadSkyCircle(self, ctrCoord, radius, filterName, epoch=None):
circularRegion = sphgeom.Circle(centerVector, sphRadius)
return self.loadRegion(circularRegion, filterName, epoch=epoch)

def loadSchema(self, filterName):
"""Load the schema for the reference catalog.
Parameters
----------
filterName : `str`
Name of camera filter.
Returns
-------
output : `lsst.pipe.base.Struct`
Results struct with attributes:
``schema``
Schema of the reference catalogs returned by other 'load'
methods.
``fluxField``
Name of the field containing the flux associated with
``filterName``.
"""
if not self.refCats:
raise RuntimeError("No reference tables could be found.")
cat = self.refCats[0].get()
# Replace the original handle with an in-memory one that caches what
# we've already read, since there's a good chance we'll want to read it
# later.
self.refCats[0] = pipeBase.InMemoryDatasetHandle(cat, dataId=self.refCats[0].dataId, copy=False)
emptyCat = type(cat)(cat.table.clone())
expandedEmptyCat = self._remapReferenceCatalogSchema(
emptyCat,
anyFilterMapsToThis=self.config.anyFilterMapsToThis,
filterMap=self.config.filterMap,
)
fluxField = getRefFluxField(expandedEmptyCat.schema, filterName)
if expandedEmptyCat.schema[fluxField].asField().getUnits() != "nJy":
# if the flux field is not in nJy, check the refcat format version
version = getFormatVersionFromRefCat(emptyCat)
if version > LATEST_FORMAT_VERSION:
raise ValueError(f"Unsupported refcat format version: {version} > {LATEST_FORMAT_VERSION}.")
return pipeBase.Struct(schema=expandedEmptyCat.schema, fluxField=fluxField)


def getRefFluxField(schema, filterName):
"""Get the name of a flux field from a schema.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_referenceObjectLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def testFilterAliasMap(self):
for filterMap in ({}, {"camr": "r"}):
config = ReferenceObjectLoader.ConfigClass()
config.filterMap = filterMap
loader = ReferenceObjectLoader(None, None, name=None, config=config)
loader = ReferenceObjectLoader(None, [], name=None, config=config)
refSchema = _makeSchema(filterNameList="r")
loader._addFluxAliases(refSchema,
anyFilterMapsToThis=config.anyFilterMapsToThis,
Expand Down Expand Up @@ -113,7 +113,7 @@ def testAnyFilterMapsToThisAlias(self):
# test anyFilterMapsToThis
config = ReferenceObjectLoader.ConfigClass()
config.anyFilterMapsToThis = "gg"
loader = ReferenceObjectLoader(None, None, name=None, config=config)
loader = ReferenceObjectLoader(None, [], name=None, config=config)
refSchema = _makeSchema(filterNameList=["gg"])
loader._addFluxAliases(refSchema,
anyFilterMapsToThis=config.anyFilterMapsToThis,
Expand All @@ -129,7 +129,7 @@ def testAnyFilterMapsToThisAlias(self):
def testGetMetadataCircle(self):
center = lsst.geom.SpherePoint(100*lsst.geom.degrees, 45*lsst.geom.degrees)
radius = lsst.geom.Angle(1*lsst.geom.degrees)
loader = ReferenceObjectLoader(None, None, name=None)
loader = ReferenceObjectLoader(None, [], name=None)
metadata = loader.getMetadataCircle(center, radius, "fakeR")
self.assertEqual(metadata['RA'], center.getLongitude().asDegrees())
self.assertEqual(metadata['DEC'], center.getLatitude().asDegrees())
Expand Down

0 comments on commit 8366484

Please sign in to comment.