LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.meas.base.tests.BlendContext Class Reference

Public Member Functions

def __init__ (self, owner)
 
def __enter__ (self)
 
def addChild (self, instFlux, centroid, shape=None)
 
def __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 40 of file tests.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 49 of file tests.py.

49  def __init__(self, owner):
50  self.owner = owner
51  self.parentRecord = self.owner.catalog.addNew()
52  self.parentImage = lsst.afw.image.ImageF(self.owner.exposure.getBBox())
53  self.children = []
54 

Member Function Documentation

◆ __enter__()

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

Definition at line 55 of file tests.py.

55  def __enter__(self):
56  # BlendContext is its own context manager, so we just return self.
57  return self
58 

◆ __exit__()

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

Definition at line 76 of file tests.py.

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

◆ addChild()

def 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 59 of file tests.py.

59  def addChild(self, instFlux, centroid, shape=None):
60  """Add a child to the blend; return corresponding truth catalog record.
61 
62  instFlux : `float`
63  Total instFlux of the source to be added.
64  centroid : `lsst.geom.Point2D`
65  Position of the source to be added.
66  shape : `lsst.afw.geom.Quadrupole`
67  Second moments of the source before PSF convolution. Note that
68  the truth catalog records post-convolution moments)
69  """
70  record, image = self.owner.addSource(instFlux, centroid, shape)
71  record.set(self.owner.keys["parent"], self.parentRecord.getId())
72  self.parentImage += image
73  self.children.append((record, image))
74  return record
75 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

Member Data Documentation

◆ children

lsst.meas.base.tests.BlendContext.children

Definition at line 53 of file tests.py.

◆ owner

lsst.meas.base.tests.BlendContext.owner

Definition at line 50 of file tests.py.

◆ parentImage

lsst.meas.base.tests.BlendContext.parentImage

Definition at line 52 of file tests.py.

◆ parentRecord

lsst.meas.base.tests.BlendContext.parentRecord

Definition at line 51 of file tests.py.


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