Skip to content

Commit

Permalink
Change the makeDiscreteSkyMap interface to use bbox
Browse files Browse the repository at this point in the history
Both gen2 and gen3 butler can return the bounding box directly
so there is no need to derive it from metadata. In gen3 the
metadata does not include the NAXIS parameters so it is
impossible to calculate the bbox from it.
  • Loading branch information
timj committed Jul 13, 2021
1 parent dac961e commit a290725
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions python/lsst/pipe/tasks/makeDiscreteSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lsst.sphgeom

import lsst.geom as geom
import lsst.afw.image as afwImage
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
from lsst.skymap import DiscreteSkyMap, BaseSkyMap
Expand Down Expand Up @@ -142,47 +141,45 @@ def runDataRef(self, butler, dataRefList):
struct : `lsst.pipe.base.Struct`
The returned struct has one attribute, ``skyMap``, which holds the returned SkyMap
"""
wcs_md_tuple_list = []
wcs_bbox_tuple_list = []
oldSkyMap = None
datasetName = self.config.coaddName + "Coadd_skyMap"
for dataRef in dataRefList:
if not dataRef.datasetExists("calexp"):
self.log.warning("CalExp for %s does not exist: ignoring", dataRef.dataId)
continue
wcs_md_tuple_list.append((dataRef.get("calexp_wcs", immediate=True),
dataRef.get("calexp_md", immediate=True)))
wcs_bbox_tuple_list.append((dataRef.get("calexp_wcs", immediate=True),
dataRef.get("calexp_bbox", immediate=True)))
if self.config.doAppend and butler.datasetExists(datasetName):
oldSkyMap = butler.get(datasetName, immediate=True)
if not isinstance(oldSkyMap.config, DiscreteSkyMap.ConfigClass):
raise TypeError("Cannot append to existing non-discrete skymap")
compareLog = []
if not self.config.skyMap.compare(oldSkyMap.config, output=compareLog.append):
raise ValueError("Cannot append to existing skymap - configurations differ:", *compareLog)
result = self.run(wcs_md_tuple_list, oldSkyMap)
result = self.run(wcs_bbox_tuple_list, oldSkyMap)
if self.config.doWrite:
butler.put(result.skyMap, datasetName)
return result

@pipeBase.timeMethod
def run(self, wcs_md_tuple_list, oldSkyMap=None):
def run(self, wcs_bbox_tuple_list, oldSkyMap=None):
"""Make a SkyMap from the bounds of the given set of calexp metadata.
Parameters
----------
wcs_md_tuple_list : iterable
A list of tuples with each element expected to be a (Wcs, PropertySet) pair
wcs_bbox_tuple_list : iterable
A list of tuples with each element expected to be a (Wcs, Box2I) pair
oldSkyMap : `lsst.skymap.DiscreteSkyMap`, option
The SkyMap to extend if appending
Returns
-------
struct : `lsst.pipe.base.Struct
The returned struct has one attribute, ``skyMap``, which holds the returned SkyMap
"""
self.log.info("Extracting bounding boxes of %d images", len(wcs_md_tuple_list))
self.log.info("Extracting bounding boxes of %d images", len(wcs_bbox_tuple_list))
points = []
for wcs, md in wcs_md_tuple_list:
# nb: don't need to worry about xy0 because Exposure saves Wcs with CRPIX shifted by (-x0, -y0).
boxI = afwImage.bboxFromMetadata(md)
for wcs, boxI in wcs_bbox_tuple_list:
boxD = geom.Box2D(boxI)
points.extend(wcs.pixelToSky(corner).getVector() for corner in boxD.getCorners())
if len(points) == 0:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/tasks/script/makeDiscreteSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def makeDiscreteSkyMap(repo, config_file, collections, instrument,

datasets = butler.registry.queryDatasets('calexp', collections=collections)
wcs_md_tuple_list = [(butler.getDirect(ref.makeComponentRef("wcs")),
butler.getDirect(ref.makeComponentRef("metadata")))
butler.getDirect(ref.makeComponentRef("bbox")))
for ref in datasets]
task = MakeDiscreteSkyMapTask(config=config)
result = task.run(wcs_md_tuple_list, oldSkyMap)
Expand Down

0 comments on commit a290725

Please sign in to comment.