lsst.ip.diffim  13.0-26-g703d095+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Static Public Attributes | Static Private Attributes | List of all members
lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask Class Reference

Measurement of Sources, specifically ones from difference images, for characterization as dipoles. More...

Inheritance diagram for lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask:

Static Public Attributes

 ConfigClass = DipoleMeasurementConfig
 

Static Private Attributes

string _DefaultName = "dipoleMeasurement"
 

Detailed Description

Measurement of Sources, specifically ones from difference images, for characterization as dipoles.

Contents

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Description

This class provides a default configuration for running Source measurement on image differences.

These default plugins include:

1 class DipoleMeasurementConfig(SingleFrameMeasurementConfig):
2  """!Measurement of detected diaSources as dipoles"""
3 
4  def setDefaults(self):
5  SingleFrameMeasurementConfig.setDefaults(self)
6  self.plugins = ["base_CircularApertureFlux",
7  "base_PixelFlags",
8  "base_SkyCoord",
9  "base_PsfFlux",
10  "ip_diffim_NaiveDipoleCentroid",
11  "ip_diffim_NaiveDipoleFlux",
12  "ip_diffim_PsfDipoleFlux",
13  "ip_diffim_ClassificationDipole",
14  ]
15 
16  self.slots.calibFlux = None
17  self.slots.modelFlux = None
18  self.slots.instFlux = None
19  self.slots.shape = None
20  self.slots.centroid = "ip_diffim_NaiveDipoleCentroid"
21  self.doReplaceWithNoise = False

These plugins enabled by default allow the user to test the hypothesis that the Source is a dipole. This includes a set of measurements derived from intermediate base classes DipoleCentroidAlgorithm and DipoleFluxAlgorithm. Their respective algorithm control classes are defined in DipoleCentroidControl and DipoleFluxControl. Each centroid and flux measurement will have _neg (negative) and _pos (positive lobe) fields.

The first set of measurements uses a "naive" alrogithm for centroid and flux measurements, implemented in NaiveDipoleCentroidControl and NaiveDipoleFluxControl. The algorithm uses a naive 3x3 weighted moment around the nominal centroids of each peak in the Source Footprint. These algorithms fill the table fields ip_diffim_NaiveDipoleCentroid* and ip_diffim_NaiveDipoleFlux*

The second set of measurements undertakes a joint-Psf model on the negative and positive lobe simultaneously. This fit simultaneously solves for the negative and positive lobe centroids and fluxes using non-linear least squares minimization. The fields are stored in table elements ip_diffim_PsfDipoleFlux*.

Because this Task is just a config for SourceMeasurementTask, the same result may be acheived by manually editing the config and running SourceMeasurementTask. For example:

1 config = SingleFrameMeasurementConfig()
2 config.plugins.names = ["base_PsfFlux",
3  "ip_diffim_PsfDipoleFlux",
4  "ip_diffim_NaiveDipoleFlux",
5  "ip_diffim_NaiveDipoleCentroid",
6  "ip_diffim_ClassificationDipole",
7  "base_CircularApertureFlux",
8  "base_SkyCoord"]
9 
10 config.slots.calibFlux = None
11 config.slots.modelFlux = None
12 config.slots.instFlux = None
13 config.slots.shape = None
14 config.slots.centroid = "ip_diffim_NaiveDipoleCentroid"
15 config.doReplaceWithNoise = False
16 
17 schema = afwTable.SourceTable.makeMinimalSchema()
18 task = SingleFrameMeasurementTask(schema, config=config)
19 
20 task.run(sources, exposure)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Task initialization

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Invoking the Task

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Configuration parameters

See DipoleMeasurementConfig

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Quantities set in Metadata

No specific values are set in the Task metadata. However, the Source schema are modified to store the results of the dipole-specific measurements.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Debug variables

The command line task interface supports a flag -d/–debug to import debug.py from your PYTHONPATH. The relevant contents of debug.py for this Task include:

1 import sys
2 import lsstDebug
3 def DebugInfo(name):
4  di = lsstDebug.getInfo(name)
5  if name == "lsst.ip.diffim.dipoleMeasurement":
6  di.display = True # enable debug output
7  di.maskTransparency = 90 # ds9 mask transparency
8  di.displayDiaSources = True # show exposure with dipole results
9  return di
10 lsstDebug.Info = DebugInfo
11 lsstDebug.frame = 1

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

A complete example of using DipoleMeasurementTask

This code is dipoleMeasTask.py in the examples directory, and can be run as e.g.

1 examples/dipoleMeasTask.py
2 examples/dipoleMeasTask.py --debug
3 examples/dipoleMeasTask.py --debug --image /path/to/image.fits
Start the processing by parsing the command line, where the user has the option of enabling debugging output and/or sending their own image for demonstration (in case they have not downloaded the afwdata package).
1 if __name__ == "__main__":
2  import argparse
3  parser = argparse.ArgumentParser(
4  description="Demonstrate the use of SourceDetectionTask and DipoleMeasurementTask")
5 
6  parser.add_argument('--debug', '-d', action="store_true", help="Load debug.py?", default=False)
7  parser.add_argument("--image", "-i", help="User defined image", default=None)
8 
9  args = parser.parse_args()
10 
11  if args.debug:
12  try:
13  import debug
14  debug.lsstDebug.frame = 2
15  except ImportError as e:
16  print(e, file=sys.stderr)
17 
18  run(args)

The processing occurs in the run function. We first extract an exposure from disk or afwdata, displaying it if requested:
1 def run(args):
2  exposure = loadData(args.image)
3  if args.debug:
4  ds9.mtv(exposure, frame=1)

Create a default source schema that we will append fields to as we add more algorithms:

1  schema = afwTable.SourceTable.makeMinimalSchema()

Create the detection and measurement Tasks, with some minor tweaking of their configs:

1  # Create the detection task
2  config = SourceDetectionTask.ConfigClass()
3  config.thresholdPolarity = "both"
4  config.background.isNanSafe = True
5  config.thresholdValue = 3
6  detectionTask = SourceDetectionTask(config=config, schema=schema)
7 
8  # And the measurement Task
9  config = DipoleMeasurementTask.ConfigClass()
10  config.plugins.names.remove('base_SkyCoord')
11 
12  algMetadata = dafBase.PropertyList()
13  measureTask = DipoleMeasurementTask(schema, algMetadata, config=config)

Having fully initialied the schema, we create a Source table from it:

1  # Create the output table
2  tab = afwTable.SourceTable.make(schema)

Run detection:

1  # Process the data
2  results = detectionTask.run(tab, exposure)

Because we are looking for dipoles, we need to merge the positive and negative detections:

1  # Merge the positve and negative sources
2  fpSet = results.fpSets.positive
3  growFootprint = 2
4  fpSet.merge(results.fpSets.negative, growFootprint, growFootprint, False)
5  diaSources = afwTable.SourceCatalog(tab)
6  fpSet.makeSources(diaSources)
7 
8  print("Merged %s Sources into %d diaSources (from %d +ve, %d -ve)" % (len(results.sources),
9  len(diaSources),
10  results.fpSets.numPos,
11  results.fpSets.numNeg))

Finally, perform measurement (both standard and dipole-specialized) on the merged sources:

1  measureTask.run(diaSources, exposure)

Optionally display debugging information:

1  # Display dipoles if debug enabled
2  if args.debug:
3  dpa = DipoleAnalysis()
4  dpa.displayDipoles(exposure, diaSources)
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Definition at line 130 of file dipoleMeasurement.py.

Member Data Documentation

string lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask._DefaultName = "dipoleMeasurement"
staticprivate

Definition at line 301 of file dipoleMeasurement.py.

lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask.ConfigClass = DipoleMeasurementConfig
static

Definition at line 300 of file dipoleMeasurement.py.


The documentation for this class was generated from the following file: