Skip to content

Instantly share code, notes, and snippets.

@ctslater
Last active January 25, 2018 17:26
Show Gist options
  • Save ctslater/7fa5e621e27c963f7b3dc27078600e14 to your computer and use it in GitHub Desktop.
Save ctslater/7fa5e621e27c963f7b3dc27078600e14 to your computer and use it in GitHub Desktop.
ImageDifferenceDriver
#!/usr/bin/env python
from lsst.pipe.drivers.imageDifferenceDriver import ImageDifferenceDriverTask
ImageDifferenceDriverTask.parseAndSubmit()
from lsst.pipe.base import ArgumentParser, ButlerInitializedTaskRunner, ConfigDatasetType
from lsst.pipe.tasks.imageDifference import ImageDifferenceTask
from lsst.pex.config import Config, Field, ConfigurableField, ListField
from lsst.ctrl.pool.parallel import BatchParallelTask, BatchTaskRunner
class ImageDifferenceDriverConfig(Config):
imageDifference = ConfigurableField(target=ImageDifferenceTask, doc="CCD processing task")
ignoreCcdList = ListField(dtype=int, default=[], doc="List of CCDs to ignore when processing")
ccdKey = Field(dtype=str, default="ccd", doc="DataId key corresponding to a single sensor")
class ImageDifferenceTaskRunner(BatchTaskRunner, ButlerInitializedTaskRunner):
"""Run batches, and initialize Task using a butler"""
pass
class ImageDifferenceDriverTask(BatchParallelTask):
"""Process CCDs in parallel
"""
ConfigClass = ImageDifferenceDriverConfig
_DefaultName = "imageDifferenceDriver"
RunnerClass = ImageDifferenceTaskRunner
def __init__(self, butler=None, refObjLoader=None, *args, **kwargs):
"""!
@param[in] butler The butler is passed to the refObjLoader constructor in case it is
needed. Ignored if the refObjLoader argument provides a loader directly.
@param[in] refObjLoader An instance of LoadReferenceObjectsTasks that supplies an
external reference catalog. May be None if the butler argument is provided or
all steps requiring a reference catalog are disabled.
@param[in,out] kwargs other keyword arguments for lsst.ctrl.pool.BatchParallelTask
"""
BatchParallelTask.__init__(self, *args, **kwargs)
self.ignoreCcds = set(self.config.ignoreCcdList)
self.makeSubtask("imageDifference", butler=butler)
#self.makeSubtask("processCcd", butler=butler, refObjLoader=refObjLoader)
@classmethod
def _makeArgumentParser(cls, *args, **kwargs):
kwargs.pop("doBatch", False)
parser = ArgumentParser(name="imageDifferenceDriver", *args, **kwargs)
parser.add_id_argument("--id",
datasetType="calexp",
level="sensor",
help="data ID, e.g. --id visit=12345 ccd=67")
return parser
def run(self, sensorRef):
"""Process a single CCD, with scatter-gather-scatter using MPI.
"""
if sensorRef.dataId[self.config.ccdKey] in self.ignoreCcds:
self.log.warn("Ignoring %s: CCD in ignoreCcdList" % (sensorRef.dataId))
return None
with self.logOperation("processing %s" % (sensorRef.dataId,)):
return self.imageDifference.run(sensorRef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment