LSSTApplications  20.0.0
LSSTDataManagementBasePackage
detectOnlyFakes.py
Go to the documentation of this file.
1 from deprecated.sphinx import deprecated
2 
3 import lsst.pex.config as pexConfig
4 import lsst.pipe.base as pipeBase
5 import lsst.afw.table as afwTable
6 import lsst.meas.algorithms as measAlg
7 import lsst.afw.detection as afwDetect
8 
9 # WARNING: if you want to add configuration variables (maybe how close you are
10 # to a fake object), you will need to deal with the fact that the configuration
11 # for a retargeted subtask (like this one) blows away any overrides in setDefault of
12 # the parent task (processCoadd in this case) and, it seems any camera specific
13 # overrides in $OBS_SUBARU/config/hsc/processCcd.py.
14 # See https://dev.lsstcorp.org/trac/ticket/2282 for more details
15 # I think you need something like cmdLineTask.applyOverrides to deal with this
16 
17 
18 class OnlyFakesDetectionConfig(measAlg.SourceDetectionTask.ConfigClass):
19  dummyVar = pexConfig.Field(doc='Dummy config variable, does nothing',
20  dtype=bool, default=True)
21 
22 
23 class OnlyFakesDetectionTask(measAlg.SourceDetectionTask):
24  """This task serves culls the source list to sources which overlap with fakes"""
25 
26  # WARNING: we are using the parent configuration class instead of the
27  # OnlyFakesDetectionConfig to avoid having to fix overridden config parameters
28  # from processCoaddConfig.setDefaults and from the camera-specific $OBS_SUBARU/config
29  ConfigClass = measAlg.SourceDetectionConfig
30 
31  def run(self, table, exposure, doSmooth=True, sigma=None, clearMask=True):
32  if self.negativeFlagKey is not None and self.negativeFlagKey not in table.getSchema():
33  raise ValueError("Table has incorrect Schema")
34 
35  # detect the footprints as usual
36  fpSets = self.detectFootprints(exposure=exposure, doSmooth=doSmooth, sigma=sigma,
37  clearMask=clearMask)
38 
39  # ignore objects whose footprints do NOT overlap with the 'FAKE' mask
40  mask = exposure.getMaskedImage().getMask()
41  fakebit = mask.getPlaneBitMask('FAKE')
42  fpPos = fpSets.positive.getFootprints()
43  removes = []
44  for i_foot, foot in enumerate(fpPos):
45  footTmp = afwDetect.Footprint(foot)
46  footTmp.intersectMask(mask, fakebit)
47  if footTmp.getArea() == foot.getArea():
48  removes.append(i_foot)
49  removes = sorted(removes, reverse=True)
50  for r in removes:
51  del fpPos[r]
52 
53  self.log.info("Found %d sources near fake footprints" % len(fpPos))
54 
55  fpSets.numPos = len(fpPos)
56  if fpSets.negative:
57  del fpSets.negative.getFootprints()[0:]
58  fpSets.negative = None
59 
60  # make sources
61  sources = afwTable.SourceCatalog(table)
62  table.preallocate(fpSets.numPos)
63  if fpSets.positive:
64  fpSets.positive.makeSources(sources)
65 
66  return pipeBase.Struct(sources=sources, fpSets=fpSets)
67 
68  @deprecated(reason="Replaced by OnlyFakesDetectionTask.run(). Will be removed after v20.",
69  category=FutureWarning)
70  def makeSourceCatalog(self, *args, **kwargs):
71  return self.run(*args, **kwargs)
lsst.synpipe.detectOnlyFakes.OnlyFakesDetectionConfig
Definition: detectOnlyFakes.py:18
lsst::log.log.logContinued.info
def info(fmt, *args)
Definition: logContinued.py:198
lsst.synpipe.detectOnlyFakes.OnlyFakesDetectionTask
Definition: detectOnlyFakes.py:23
lsst::afw::table._source.SourceCatalog
Definition: _source.py:33
lsst::afw::table
Definition: table.dox:3
lsst.synpipe.detectOnlyFakes.OnlyFakesDetectionTask.run
def run(self, table, exposure, doSmooth=True, sigma=None, clearMask=True)
Definition: detectOnlyFakes.py:31
lsst::afw::detection
Definition: Footprint.h:50
lsst::afw::detection::Footprint
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
lsst.pipe.base
Definition: __init__.py:1
lsst::meas::algorithms
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.
Definition: CoaddBoundedField.h:34
lsst.synpipe.detectOnlyFakes.OnlyFakesDetectionTask.makeSourceCatalog
def makeSourceCatalog(self, *args, **kwargs)
Definition: detectOnlyFakes.py:70