LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.base.plugins.VariancePlugin Class Reference
Inheritance diagram for lsst.meas.base.plugins.VariancePlugin:
lsst.meas.base.wrappers.GenericPlugin lsst.meas.base.pluginsBase.BasePlugin

Public Member Functions

 getExecutionOrder (cls)
 
 __init__ (self, config, name, schema, metadata)
 
 measure (self, measRecord, exposure, center)
 
 fail (self, measRecord, error=None)
 

Public Attributes

 varValue
 
 emptyFootprintFlag
 
 FAILURE_BAD_CENTROID
 
 FAILURE_EMPTY_FOOTPRINT
 

Static Public Attributes

 ConfigClass = VarianceConfig
 
int FAILURE_BAD_CENTROID = 1
 
int FAILURE_EMPTY_FOOTPRINT = 2
 

Detailed Description

Compute the median variance corresponding to a footprint.

The aim here is to measure the background variance, rather than that of
the object itself. In order to achieve this, the variance is calculated
over an area scaled up from the shape of the input footprint.

Parameters
----------
config : `VarianceConfig`
    Plugin configuraion.
name : `str`
    Plugin name.
schema : `lsst.afw.table.Schema`
    The schema for the measurement output catalog. New fields will be
    added to hold measurements produced by this plugin.
metadata : `lsst.daf.base.PropertySet`
    Plugin metadata that will be attached to the output catalog

Definition at line 234 of file plugins.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.base.plugins.VariancePlugin.__init__ ( self,
config,
name,
schema,
metadata )

Reimplemented from lsst.meas.base.wrappers.GenericPlugin.

Definition at line 268 of file plugins.py.

268 def __init__(self, config, name, schema, metadata):
269 GenericPlugin.__init__(self, config, name, schema, metadata)
270 self.varValue = schema.addField(name + '_value', type="D", doc="Variance at object position")
271 self.emptyFootprintFlag = schema.addField(name + '_flag_emptyFootprint', type="Flag",
272 doc="Set to True when the footprint has no usable pixels")
273
274 # Alias the badCentroid flag to that which is defined for the target
275 # of the centroid slot. We do not simply rely on the alias because
276 # that could be changed post-measurement.
277 schema.getAliasMap().set(name + '_flag_badCentroid', schema.getAliasMap().apply("slot_Centroid_flag"))
278
daf::base::PropertySet * set
Definition fits.cc:931

Member Function Documentation

◆ fail()

lsst.meas.base.plugins.VariancePlugin.fail ( self,
measRecord,
error = None )
Record a measurement failure.

This default implementation simply records the failure in the source
record.

Parameters
----------
measRecord : `lsst.afw.table.SourceRecord`
    Catalog record for the source being measured.
error : `Exception`
    Error causing failure, or `None`.

Reimplemented from lsst.meas.base.wrappers.GenericPlugin.

Definition at line 307 of file plugins.py.

307 def fail(self, measRecord, error=None):
308 # Check that we have an error object and that it is of type
309 # MeasurementError
310 if isinstance(error, MeasurementError):
311 assert error.getFlagBit() in (self.FAILURE_BAD_CENTROID, self.FAILURE_EMPTY_FOOTPRINT)
312 # FAILURE_BAD_CENTROID handled by alias to centroid record.
313 if error.getFlagBit() == self.FAILURE_EMPTY_FOOTPRINT:
314 measRecord.set(self.emptyFootprintFlag, True)
315 measRecord.set(self.varValue, np.nan)
316 GenericPlugin.fail(self, measRecord, error)
317
318

◆ getExecutionOrder()

lsst.meas.base.plugins.VariancePlugin.getExecutionOrder ( cls)
Get the relative execution order of this plugin.

Must be reimplemented as a class method by concrete derived classes.

Reimplemented from lsst.meas.base.wrappers.GenericPlugin.

Definition at line 265 of file plugins.py.

265 def getExecutionOrder(cls):
266 return BasePlugin.FLUX_ORDER
267

◆ measure()

lsst.meas.base.plugins.VariancePlugin.measure ( self,
measRecord,
exposure,
center )
Measure a single source.

It is the responsibility of this method to perform the desired
measurement and record the result in the `measRecord`.

Parameters
----------
measRecord : `lsst.afw.table.SourceRecord`
    Catalog record for the source being measured.
exposure : `lsst.afw.image.Exposure`
    Exposure on which the source is being measured.
center : `lsst.geom.Point2D`
    Pixel coordinates of the object.

Raises
------
MeasurementError
    Raised if the measurement fails for a known/justifiable reason.

Reimplemented from lsst.meas.base.wrappers.GenericPlugin.

Definition at line 279 of file plugins.py.

279 def measure(self, measRecord, exposure, center):
280 # Create an aperture and grow it by scale value defined in config to
281 # ensure there are enough pixels around the object to get decent
282 # statistics
283 if not np.all(np.isfinite(measRecord.getCentroid())):
284 raise MeasurementError("Bad centroid and/or shape", self.FAILURE_BAD_CENTROID)
285 aperture = lsst.afw.geom.Ellipse(measRecord.getShape(), measRecord.getCentroid())
286 aperture.scale(self.config.scale)
287 ellipse = lsst.afw.geom.SpanSet.fromShape(aperture)
288 foot = lsst.afw.detection.Footprint(ellipse)
289 foot.clipTo(exposure.getBBox(lsst.afw.image.PARENT))
290 # Filter out any pixels which have mask bits set corresponding to the
291 # planes to be excluded (defined in config.mask)
292 maskedImage = exposure.getMaskedImage()
293 pixels = lsst.afw.detection.makeHeavyFootprint(foot, maskedImage)
294 maskBits = maskedImage.getMask().getPlaneBitMask(self.config.mask)
295 logicalMask = np.logical_not(pixels.getMaskArray() & maskBits)
296 # Compute the median variance value for each pixel not excluded by the
297 # mask and write the record. Numpy median is used here instead of
298 # afw.math makeStatistics because of an issue with data types being
299 # passed into the C++ layer (DM-2379).
300 if np.any(logicalMask):
301 medVar = np.median(pixels.getVarianceArray()[logicalMask])
302 measRecord.set(self.varValue, medVar)
303 else:
304 raise MeasurementError("Footprint empty, or all pixels are masked, can't compute median",
305 self.FAILURE_EMPTY_FOOTPRINT)
306
Class to describe the properties of a detected object from an image.
Definition Footprint.h:63
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, lsst::geom::Point2I offset=lsst::geom::Point2I())
Factory function for creating SpanSets from a Stencil.
Definition SpanSet.cc:688
An ellipse defined by an arbitrary BaseCore and a center point.
Definition Ellipse.h:51
HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > makeHeavyFootprint(Footprint const &foot, lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > const &img, HeavyFootprintCtrl const *ctrl=nullptr)
Create a HeavyFootprint with footprint defined by the given Footprint and pixel values from the given...

Member Data Documentation

◆ ConfigClass

lsst.meas.base.plugins.VariancePlugin.ConfigClass = VarianceConfig
static

Definition at line 254 of file plugins.py.

◆ emptyFootprintFlag

lsst.meas.base.plugins.VariancePlugin.emptyFootprintFlag

Definition at line 271 of file plugins.py.

◆ FAILURE_BAD_CENTROID [1/2]

int lsst.meas.base.plugins.VariancePlugin.FAILURE_BAD_CENTROID = 1
static

Definition at line 256 of file plugins.py.

◆ FAILURE_BAD_CENTROID [2/2]

lsst.meas.base.plugins.VariancePlugin.FAILURE_BAD_CENTROID

Definition at line 284 of file plugins.py.

◆ FAILURE_EMPTY_FOOTPRINT [1/2]

int lsst.meas.base.plugins.VariancePlugin.FAILURE_EMPTY_FOOTPRINT = 2
static

Definition at line 260 of file plugins.py.

◆ FAILURE_EMPTY_FOOTPRINT [2/2]

lsst.meas.base.plugins.VariancePlugin.FAILURE_EMPTY_FOOTPRINT

Definition at line 305 of file plugins.py.

◆ varValue

lsst.meas.base.plugins.VariancePlugin.varValue

Definition at line 270 of file plugins.py.


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