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