def runDataRef(self, expRef): """Perform sky correction on an exposure We restore the original sky, and remove it again using multiple algorithms. We optionally apply: 1. A large-scale background model. This step removes very-large-scale sky such as moonlight. 2. A sky frame. 3. A medium-scale background model. This step removes residual sky (This is smooth on the focal plane). Only the master node executes this method. The data is held on the slave nodes, which do all the hard work. Parameters ---------- expRef : `lsst.daf.persistence.ButlerDataRef` Data reference for exposure. See Also -------- ~lsst.pipe.drivers.SkyCorrectionTask.run """ if DEBUG: extension = "-%(visit)d.fits" % expRef.dataId with self.logOperation("processing %s" % (expRef.dataId,)): pool = Pool() pool.cacheClear() pool.storeSet(butler=expRef.getButler()) camera = expRef.get("camera") dataIdList = [ccdRef.dataId for ccdRef in expRef.subItems("ccd") if ccdRef.datasetExists(self.config.calexpType)] exposures = pool.map(self.loadImage, dataIdList) if DEBUG: makeCameraImage(camera, exposures, "restored" + extension) exposures = pool.mapToPrevious(self.collectOriginal, dataIdList) makeCameraImage(camera, exposures, "original" + extension) exposures = pool.mapToPrevious(self.collectMask, dataIdList) makeCameraImage(camera, exposures, "mask" + extension) if self.config.doBgModel: exposures = self.focalPlaneBackground(camera, pool, dataIdList, self.config.bgModel) if self.config.doSky: measScales = pool.mapToPrevious(self.measureSkyFrame, dataIdList) scale = self.sky.solveScales(measScales) self.log.info("Sky frame scale: %s" % (scale,)) exposures = pool.mapToPrevious(self.subtractSkyFrame, dataIdList, scale) if DEBUG: makeCameraImage(camera, exposures, "skysub" + extension) calibs = pool.mapToPrevious(self.collectSky, dataIdList) makeCameraImage(camera, calibs, "sky" + extension) if self.config.doBgModel2: exposures = self.focalPlaneBackground(camera, pool, dataIdList, self.config.bgModel2) # Persist camera-level image of calexp image = makeCameraImage(camera, exposures) expRef.put(image, "calexp_camera") pool.mapToPrevious(self.write, dataIdList)
def run(self, expRef): """Perform sky correction on an exposure We restore the original sky, and remove it again using multiple algorithms. We optionally apply: 1. A large-scale background model. 2. A sky frame. Only the master node executes this method. The data is held on the slave nodes, which do all the hard work. Parameters ---------- expRef : `lsst.daf.persistence.ButlerDataRef` Data reference for exposure. """ if DEBUG: extension = "-%(visit)d.fits" % expRef.dataId with self.logOperation("processing %s" % (expRef.dataId, )): pool = Pool() pool.cacheClear() pool.storeSet(butler=expRef.getButler()) camera = expRef.get("camera") dataIdList = [ ccdRef.dataId for ccdRef in expRef.subItems("ccd") if ccdRef.datasetExists("calexp") ] exposures = pool.map(self.loadImage, dataIdList) if DEBUG: makeCameraImage(camera, exposures, "restored" + extension) exposures = pool.mapToPrevious(self.collectOriginal, dataIdList) makeCameraImage(camera, exposures, "original" + extension) exposures = pool.mapToPrevious(self.collectMask, dataIdList) makeCameraImage(camera, exposures, "mask" + extension) if self.config.doBgModel: bgModel = FocalPlaneBackground.fromCamera( self.config.bgModel, camera) data = [ Struct(dataId=dataId, bgModel=bgModel.clone()) for dataId in dataIdList ] bgModelList = pool.mapToPrevious(self.accumulateModel, data) for ii, bg in enumerate(bgModelList): self.log.info("Background %d: %d pixels", ii, bg._numbers.getArray().sum()) bgModel.merge(bg) if DEBUG: bgModel.getStatsImage().writeFits("bgModel" + extension) bgImages = pool.mapToPrevious(self.realiseModel, dataIdList, bgModel) makeCameraImage(camera, bgImages, "bgModelCamera" + extension) exposures = pool.mapToPrevious(self.subtractModel, dataIdList, bgModel) if DEBUG: makeCameraImage(camera, exposures, "modelsub" + extension) if self.config.doSky: measScales = pool.mapToPrevious(self.measureSkyFrame, dataIdList) scale = self.sky.solveScales(measScales) self.log.info("Sky frame scale: %s" % (scale, )) exposures = pool.mapToPrevious(self.subtractSkyFrame, dataIdList, scale) if DEBUG: makeCameraImage(camera, exposures, "skysub" + extension) calibs = pool.mapToPrevious(self.collectSky, dataIdList) makeCameraImage(camera, calibs, "sky" + extension) # Persist camera-level image of calexp image = makeCameraImage(camera, exposures) expRef.put(image, "calexp_camera") pool.mapToPrevious(self.write, dataIdList)