LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | 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:

Public Member Functions

def __init__
 Create the Task, and add Task-specific fields to the provided measurement table schema. More...
 
def classify
 Create the records needed for dipole classification, and run classifier. More...
 
def run
 Run dipole measurement and classification. More...
 

Public Attributes

 dipoleAnalysis
 

Static Public Attributes

 ConfigClass = DipoleMeasurementConfig
 

Static Private Attributes

string _DefaultName = "dipoleMeasurement"
 
string _ClassificationFlag = "classification_dipole"
 

Detailed Description

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

Contents

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

Description

This class provies a specialized set of Source measurements that 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 centroid.dipole.naive.* and flux.dipole.naive.*.

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 flux.dipole.psf.*.

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

Task initialization

Create the Task, and add Task-specific fields to the provided measurement table schema.

Parameters
[in,out]schemaSchema object for measurement fields; modified in-place.
[in,out]algMetadataPassed to MeasureSources object to be filled with metadata by algorithms (e.g. radii for aperture photometry).
**kwdsPassed to Task.__init__.

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

Invoking the Task

Run dipole measurement and classification.

Parameters
sourcesdiaSources that will be measured using dipole measurement
exposureExposure on which the diaSources were detected
**kwdsSent to SingleFrameMeasurementTask

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

Configuration parameters

See DipoleMeasurementConfig and DipoleClassificationConfig

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

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. These additional fields include:

. classification.dipole : probability of being a dipole

. centroid.dipole.naive.pos : unweighted 3x3 first moment centroid

. centroid.dipole.naive.pos.err : covariance matrix for centroid.dipole.naive.pos

. centroid.dipole.naive.pos.flags : set if the centroid.dipole.naive.pos measurement did not fully succeed

. centroid.dipole.naive.neg : unweighted 3x3 first moment centroid

. centroid.dipole.naive.neg.err : covariance matrix for centroid.dipole.naive.neg

. centroid.dipole.naive.neg.flags : set if the centroid.dipole.naive.neg measurement did not fully succeed

. flux.dipole.naive.pos : raw flux counts

. flux.dipole.naive.pos.err : uncertainty for flux.dipole.naive.pos

. flux.dipole.naive.pos.flags : set if the flux.dipole.naive.pos measurement failed

. flux.dipole.naive.neg : raw flux counts

. flux.dipole.naive.neg.err : uncertainty for flux.dipole.naive.neg

. flux.dipole.naive.neg.flags : set if the flux.dipole.naive.neg measurement failed

. flux.dipole.naive.npos : number of positive pixels

. flux.dipole.naive.nneg : number of negative pixels

. flux.dipole.psf.pos : jointly fitted psf flux counts

. flux.dipole.psf.pos.err : uncertainty for flux.dipole.psf.pos

. flux.dipole.psf.pos.flags : set if the flux.dipole.psf.pos measurement failed

. flux.dipole.psf.neg : jointly fitted psf flux counts

. flux.dipole.psf.neg.err : uncertainty for flux.dipole.psf.neg

. flux.dipole.psf.neg.flags : set if the flux.dipole.psf.neg measurement failed

. flux.dipole.psf.chi2dof : chi2 per degree of freedom of fit

. flux.dipole.psf.centroid : average of the postive and negative lobe positions

. flux.dipole.psf.centroid.err : covariance matrix for flux.dipole.psf.centroid

. flux.dipole.psf.centroid.flags : set if the flux.dipole.psf.centroid measurement did not fully succeed

. flux.dipole.psf.neg.centroid : psf fitted center of negative lobe

. flux.dipole.psf.neg.centroid.err : covariance matrix for flux.dipole.psf.neg.centroid

. flux.dipole.psf.neg.centroid.flags : set if the flux.dipole.psf.neg.centroid measurement did not fully succeed

. flux.dipole.psf.pos.centroid : psf fitted center of positive lobe

. flux.dipole.psf.pos.centroid.err : covariance matrix for flux.dipole.psf.pos.centroid

. flux.dipole.psf.pos.centroid.flags : set if the flux.dipole.psf.pos.centroid measurement did not fully succeed

. flux.dipole.psf.flags.maxpix : set if too large a footprint was sent to the algorithm

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

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 DipoleMeasurement}Task")
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 >> sys.stderr, e
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  algMetadata = dafBase.PropertyList()
11  schema.addField(DipoleMeasurementTask._ClassificationFlag, "F", "probability of being a dipole")
12  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), results.fpSets.numPos, results.fpSets.numNeg)

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

1  measureTask.measure(exposure, diaSources)

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 74 of file dipoleMeasurement.py.

Constructor & Destructor Documentation

def lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask.__init__ (   self,
  schema,
  algMetadata = None,
  kwds 
)

Create the Task, and add Task-specific fields to the provided measurement table schema.

Parameters
[in,out]schemaSchema object for measurement fields; modified in-place.
[in,out]algMetadataPassed to MeasureSources object to be filled with metadata by algorithms (e.g. radii for aperture photometry).
**kwdsPassed to Task.__init__.

Definition at line 277 of file dipoleMeasurement.py.

278  def __init__(self, schema, algMetadata=None, **kwds):
279  """!Create the Task, and add Task-specific fields to the provided measurement table schema.
280 
281  @param[in,out] schema Schema object for measurement fields; modified in-place.
282  @param[in,out] algMetadata Passed to MeasureSources object to be filled with
283  metadata by algorithms (e.g. radii for aperture photometry).
284  @param **kwds Passed to Task.__init__.
285  """
286  SingleFrameMeasurementTask.__init__(self, schema, algMetadata, **kwds)
def __init__
Create the Task, and add Task-specific fields to the provided measurement table schema.
Functor class that provides (S/N, position, orientation) of measured dipoles.

Member Function Documentation

def lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask.classify (   self,
  sources 
)

Create the records needed for dipole classification, and run classifier.

Parameters
[in,out]sourcesThe diaSources to run classification on; modified in in-place

Definition at line 289 of file dipoleMeasurement.py.

290  def classify(self, sources):
291  """!Create the records needed for dipole classification, and run classifier
292 
293  @param[in,out] sources The diaSources to run classification on; modified in in-place
294  """
295 
296  self.log.log(self.log.INFO, "Classifying %d sources" % len(sources))
297  if not sources:
298  return
299 
300  ctrl = self.config.classification
301  try:
302  key = sources[0].getSchema().find(self._ClassificationFlag).getKey()
303  except Exception:
304  self.log.warn("Key %s not found in table" % (self._ClassificationFlag))
305  return
306 
307  for source in sources:
308  passesSn = self.dipoleAnalysis.getSn(source) > ctrl.minSn
309 
310  negFlux = np.abs(source.get("ip_diffim_PsfDipoleFlux_neg_flux"))
311  posFlux = np.abs(source.get("ip_diffim_PsfDipoleFlux_pos_flux"))
312  totalFlux = negFlux + posFlux
313  passesFluxNeg = (negFlux / totalFlux) < ctrl.maxFluxRatio
314  passesFluxPos = (posFlux / totalFlux) < ctrl.maxFluxRatio
315  if (passesSn and passesFluxPos and passesFluxNeg):
316  val = 1.0
317  else:
318  val = 0.0
319 
320  source.set(key, val)
def classify
Create the records needed for dipole classification, and run classifier.
def lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask.run (   self,
  sources,
  exposure,
  kwds 
)

Run dipole measurement and classification.

Parameters
sourcesdiaSources that will be measured using dipole measurement
exposureExposure on which the diaSources were detected
**kwdsSent to SingleFrameMeasurementTask

Definition at line 321 of file dipoleMeasurement.py.

322  def run(self, sources, exposure, **kwds):
323  """!Run dipole measurement and classification
324  @param sources diaSources that will be measured using dipole measurement
325  @param exposure Exposure on which the diaSources were detected
326  @param **kwds Sent to SingleFrameMeasurementTask
327  """
328 
329  SingleFrameMeasurementTask.run(self, sources, exposure, **kwds)
330  self.classify(sources)
def classify
Create the records needed for dipole classification, and run classifier.
def run
Run dipole measurement and classification.

Member Data Documentation

string lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask._ClassificationFlag = "classification_dipole"
staticprivate

Definition at line 275 of file dipoleMeasurement.py.

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

Definition at line 274 of file dipoleMeasurement.py.

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

Definition at line 273 of file dipoleMeasurement.py.

lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask.dipoleAnalysis

Definition at line 286 of file dipoleMeasurement.py.


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