LSSTApplications  20.0.0
LSSTDataManagementBasePackage
mergeOnlyFakes.py
Go to the documentation of this file.
1 import lsst.pex.config as pexConfig
2 import lsst.afw.detection as afwDetect
3 import lsst.pipe.tasks.multiBand as mBand
4 from lsst.pipe.tasks.coaddBase import getSkyInfo
5 
6 # WARNING: if you want to add configuration variables (maybe how close you are
7 # to a fake object), you will need to deal with the fact that the configuration
8 # for a retargeted subtask (like this one) blows away any overrides in setDefault of
9 # the parent task (processCoadd in this case) and, it seems any camera specific
10 # overrides in $OBS_SUBARU/config/hsc/processCcd.py.
11 # See https://dev.lsstcorp.org/trac/ticket/2282 for more details
12 # I think you need something like cmdLineTask.applyOverrides to deal with this
13 
14 # Song Huang
15 
16 
17 class OnlyFakesMergeConfig(mBand.MeasureMergedCoaddSourcesTask.ConfigClass):
18  dummyVar = pexConfig.Field(doc='Dummy config variable, does nothing',
19  dtype=bool, default=True)
20 
21 
22 class OnlyFakesMergeTask(mBand.MeasureMergedCoaddSourcesTask):
23  """This task serves culls the source list to sources which overlap with fakes"""
24 
25  # WARNING: we are using the parent configuration class instead of the
26  # OnlyFakesMergeConfig to avoid having to fix overridden config parameters
27  ConfigClass = mBand.MeasureMergedCoaddSourcesConfig
28 
29  def runDataRef(self, patchRef):
30  """Measure and deblend"""
31 
32  exposure = patchRef.get(self.config.coaddName + "Coadd", immediate=True)
33 
34  """Read in the FAKE mask plane"""
35  mask = exposure.getMaskedImage().getMask()
36  fakebit = mask.getPlaneBitMask('FAKE')
37 
38  sources = self.readSources(patchRef)
39  self.log.info("Found %d sources" % len(sources))
40  """ignore objects whose footprints do NOT overlap with the 'FAKE' mask"""
41  removes = []
42  for i_ss, ss in enumerate(sources):
43  foot = ss.getFootprint()
44  footTmp = afwDetect.Footprint(foot)
45  footTmp.intersectMask(mask, fakebit)
46  if footTmp.getArea() == foot.getArea():
47  removes.append(i_ss)
48  removes = sorted(removes, reverse=True)
49  for r in removes:
50  del sources[r]
51  self.log.info("Found %d sources near fake footprints" % len(sources))
52 
53  if self.config.doDeblend:
54  self.deblend.run(exposure, sources, exposure.getPsf())
55 
56  bigKey = sources.schema["deblend.parent-too-big"].asKey()
57  # catalog is non-contiguous so can't extract column
58  numBig = sum((s.get(bigKey) for s in sources))
59  if numBig > 0:
60  self.log.warn("Patch %s contains %d large footprints that were not deblended" %
61  (patchRef.dataId, numBig))
62  self.measurement.run(exposure, sources)
63  skyInfo = getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
64  self.setPrimaryFlags.run(sources, skyInfo.skyMap, skyInfo.tractInfo, skyInfo.patchInfo,
65  includeDeblend=self.config.doDeblend)
66  self.propagateFlags.run(patchRef.getButler(), sources, self.propagateFlags.getCcdInputs(exposure),
67  exposure.getWcs())
68  if self.config.doMatchSources:
69  self.writeMatches(patchRef, exposure, sources)
70 
71  self.write(patchRef, sources)
lsst::log.log.logContinued.warn
def warn(fmt, *args)
Definition: logContinued.py:202
lsst::log.log.logContinued.info
def info(fmt, *args)
Definition: logContinued.py:198
lsst.synpipe.mergeOnlyFakes.OnlyFakesMergeTask
Definition: mergeOnlyFakes.py:22
lsst.pipe.tasks.coaddBase.getSkyInfo
def getSkyInfo(coaddName, patchRef)
Return the SkyMap, tract and patch information, wcs, and outer bbox of the patch to be coadded.
Definition: coaddBase.py:261
lsst.pipe.tasks.multiBand
Definition: multiBand.py:1
lsst.pipe.tasks.assembleCoadd.run
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)
Definition: assembleCoadd.py:712
lsst.synpipe.mergeOnlyFakes.OnlyFakesMergeConfig
Definition: mergeOnlyFakes.py:17
lsst::afw::detection
Definition: Footprint.h:50
lsst.pipe.tasks.coaddBase
Definition: coaddBase.py:1
lsst::afw::detection::Footprint
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
lsst.synpipe.mergeOnlyFakes.OnlyFakesMergeTask.runDataRef
def runDataRef(self, patchRef)
Definition: mergeOnlyFakes.py:29