Skip to content

Commit

Permalink
Merge pull request #550 from lsst/tickets/DM-30995
Browse files Browse the repository at this point in the history
DM-30995: Fix butler make-discrete-skymap
  • Loading branch information
timj committed Jul 14, 2021
2 parents ecf9ee7 + b1787b1 commit bd923b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 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
9 changes: 4 additions & 5 deletions python/lsst/pipe/tasks/script/makeDiscreteSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ def makeDiscreteSkyMap(repo, config_file, collections, instrument,
raise LookupError(msg, *e.args[1:])

datasets = butler.registry.queryDatasets('calexp', collections=collections)
wcs_md_tuple_list = [(butler.getDirect('calexp.metadata', ref), butler.getDirect('calexp.wcs', ref))
for ref in datasets]
wcs_bbox_tuple_list = [(butler.getDirect(ref.makeComponentRef("wcs")),
butler.getDirect(ref.makeComponentRef("bbox")))
for ref in datasets]
task = MakeDiscreteSkyMapTask(config=config)
result = task.run(wcs_md_tuple_list, oldSkyMap)
result = task.run(wcs_bbox_tuple_list, oldSkyMap)
result.skyMap.register(skymap_id, butler)
butler.put(result.skyMap, BaseSkyMap.SKYMAP_DATASET_TYPE_NAME, dataId={'skymap': skymap_id},
run=BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME)

0 comments on commit bd923b4

Please sign in to comment.