LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
lsst.meas.base.tests.BlendContext Class Reference

Public Member Functions

 __init__ (self, owner)
 
 __enter__ (self)
 
 addChild (self, instFlux, centroid, shape=None)
 
 __exit__ (self, type_, value, tb)
 

Public Attributes

 owner
 
 parentRecord
 
 parentImage
 
 children
 

Detailed Description

Context manager which adds multiple overlapping sources and a parent.

Notes
-----
This is used as the return value for `TestDataset.addBlend`, and this is
the only way it should be used.

Definition at line 44 of file tests.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.base.tests.BlendContext.__init__ ( self,
owner )

Definition at line 53 of file tests.py.

53 def __init__(self, owner):
54 self.owner = owner
55 self.parentRecord = self.owner.catalog.addNew()
56 self.parentImage = lsst.afw.image.ImageF(self.owner.exposure.getBBox())
57 self.children = []
58

Member Function Documentation

◆ __enter__()

lsst.meas.base.tests.BlendContext.__enter__ ( self)

Definition at line 59 of file tests.py.

59 def __enter__(self):
60 # BlendContext is its own context manager, so we just return self.
61 return self
62

◆ __exit__()

lsst.meas.base.tests.BlendContext.__exit__ ( self,
type_,
value,
tb )

Definition at line 80 of file tests.py.

80 def __exit__(self, type_, value, tb):
81 # We're not using the context manager for any kind of exception safety
82 # or guarantees; we just want the nice "with" statement syntax.
83
84 if type_ is not None:
85 # exception was raised; just skip all this and let it propagate
86 return
87
88 # On exit, compute and set the truth values for the parent object.
89 self.parentRecord.set(self.owner.keys["nChild"], len(self.children))
90 # Compute instFlux from sum of component fluxes
91 instFlux = 0.0
92 for record, image in self.children:
93 instFlux += record.get(self.owner.keys["instFlux"])
94 self.parentRecord.set(self.owner.keys["instFlux"], instFlux)
95 # Compute centroid from instFlux-weighted mean of component centroids
96 x = 0.0
97 y = 0.0
98 for record, image in self.children:
99 w = record.get(self.owner.keys["instFlux"])/instFlux
100 x += record.get(self.owner.keys["centroid"].getX())*w
101 y += record.get(self.owner.keys["centroid"].getY())*w
102 self.parentRecord.set(self.owner.keys["centroid"], lsst.geom.Point2D(x, y))
103 # Compute shape from instFlux-weighted mean of offset component shapes
104 xx = 0.0
105 yy = 0.0
106 xy = 0.0
107 for record, image in self.children:
108 w = record.get(self.owner.keys["instFlux"])/instFlux
109 dx = record.get(self.owner.keys["centroid"].getX()) - x
110 dy = record.get(self.owner.keys["centroid"].getY()) - y
111 xx += (record.get(self.owner.keys["shape"].getIxx()) + dx**2)*w
112 yy += (record.get(self.owner.keys["shape"].getIyy()) + dy**2)*w
113 xy += (record.get(self.owner.keys["shape"].getIxy()) + dx*dy)*w
114 self.parentRecord.set(self.owner.keys["shape"], lsst.afw.geom.Quadrupole(xx, yy, xy))
115 # Run detection on the parent image to get the parent Footprint.
116 self.owner._installFootprint(self.parentRecord, self.parentImage)
117 # Create perfect HeavyFootprints for all children; these will need to
118 # be modified later to account for the noise we'll add to the image.
119 deblend = lsst.afw.image.MaskedImageF(self.owner.exposure.maskedImage, True)
120 for record, image in self.children:
121 deblend.image.array[:, :] = image.array
122 heavyFootprint = lsst.afw.detection.HeavyFootprintF(self.parentRecord.getFootprint(), deblend)
123 record.setFootprint(heavyFootprint)
124
125
An ellipse core with quadrupole moments as parameters.
Definition Quadrupole.h:47
daf::base::PropertySet * set
Definition fits.cc:931

◆ addChild()

lsst.meas.base.tests.BlendContext.addChild ( self,
instFlux,
centroid,
shape = None )
Add a child to the blend; return corresponding truth catalog record.

instFlux : `float`
    Total instFlux of the source to be added.
centroid : `lsst.geom.Point2D`
    Position of the source to be added.
shape : `lsst.afw.geom.Quadrupole`
    Second moments of the source before PSF convolution.  Note that
    the truth catalog records post-convolution moments)

Definition at line 63 of file tests.py.

63 def addChild(self, instFlux, centroid, shape=None):
64 """Add a child to the blend; return corresponding truth catalog record.
65
66 instFlux : `float`
67 Total instFlux of the source to be added.
68 centroid : `lsst.geom.Point2D`
69 Position of the source to be added.
70 shape : `lsst.afw.geom.Quadrupole`
71 Second moments of the source before PSF convolution. Note that
72 the truth catalog records post-convolution moments)
73 """
74 record, image = self.owner.addSource(instFlux, centroid, shape)
75 record.set(self.owner.keys["parent"], self.parentRecord.getId())
76 self.parentImage += image
77 self.children.append((record, image))
78 return record
79

Member Data Documentation

◆ children

lsst.meas.base.tests.BlendContext.children

Definition at line 57 of file tests.py.

◆ owner

lsst.meas.base.tests.BlendContext.owner

Definition at line 54 of file tests.py.

◆ parentImage

lsst.meas.base.tests.BlendContext.parentImage

Definition at line 56 of file tests.py.

◆ parentRecord

lsst.meas.base.tests.BlendContext.parentRecord

Definition at line 55 of file tests.py.


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