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 | List of all members
lsst.meas.base.tests.BlendContext Class Reference

A Python context manager used to add multiple overlapping sources along with a parent source that represents all of them together. More...

Inheritance diagram for lsst.meas.base.tests.BlendContext:

Public Member Functions

def __init__
 
def __enter__
 
def addChild
 Add a child source to the blend, and return the truth catalog record that corresponds to it. More...
 
def __exit__
 

Public Attributes

 owner
 
 parentRecord
 
 parentImage
 
 children
 

Detailed Description

A Python context manager used to add multiple overlapping sources along with a parent source that represents all of them together.

This is used as the return value for TestDataset.addBlend(), and this is the only way it should be used. The only public method is addChild().

Definition at line 43 of file tests.py.

Constructor & Destructor Documentation

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

Definition at line 52 of file tests.py.

52 
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 = []

Member Function Documentation

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

Definition at line 58 of file tests.py.

58 
59  def __enter__(self):
60  # BlendContext is its own context manager, so we just return self.
61  return self
def lsst.meas.base.tests.BlendContext.__exit__ (   self,
  type_,
  value,
  tb 
)

Definition at line 78 of file tests.py.

78 
79  def __exit__(self, type_, value, tb):
80  # We're not using the context manager for any kind of exception safety or guarantees;
81  # we just want the nice "with" statement syntax.
82  if type_ is not None: # exception was raised; just skip all this and let it propagate
83  return
84  # On exit, we need to compute and set the truth values for the parent object.
85  self.parentRecord.set(self.owner.keys["nChild"], len(self.children))
86  # Compute flux from sum of component fluxes
87  flux = 0.0
88  for record, image in self.children:
89  flux += record.get(self.owner.keys["flux"])
90  self.parentRecord.set(self.owner.keys["flux"], flux)
91  # Compute centroid from flux-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["flux"])/flux
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.afw.geom.Point2D(x, y))
99  # Compute shape from flux-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["flux"])/flux
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.ellipses.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 be modified later to account
114  # 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 
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
def lsst.meas.base.tests.BlendContext.addChild (   self,
  flux,
  centroid,
  shape = None 
)

Add a child source to the blend, and return the truth catalog record that corresponds to it.

Parameters
[in]fluxTotal flux of the source to be added.
[in]centroidPosition of the source to be added (lsst.afw.geom.Point2D).
[in]shape2nd moments of the source before PSF convolution (lsst.afw.geom.ellipses.Quadrupole). Note that the truth catalog records post-convolution moments)

Definition at line 62 of file tests.py.

62 
63  def addChild(self, flux, centroid, shape=None):
64  """!
65  Add a child source to the blend, and return the truth catalog record that corresponds to it.
66 
67  @param[in] flux Total flux of the source to be added.
68  @param[in] centroid Position of the source to be added (lsst.afw.geom.Point2D).
69  @param[in] shape 2nd moments of the source before PSF convolution
70  (lsst.afw.geom.ellipses.Quadrupole). Note that the truth catalog
71  records post-convolution moments)
72  """
73  record, image = self.owner.addSource(flux, centroid, shape)
74  record.set(self.owner.keys["parent"], self.parentRecord.getId())
75  self.parentImage += image
76  self.children.append((record, image))
77  return record
def addChild
Add a child source to the blend, and return the truth catalog record that corresponds to it...
Definition: tests.py:62

Member Data Documentation

lsst.meas.base.tests.BlendContext.children

Definition at line 56 of file tests.py.

lsst.meas.base.tests.BlendContext.owner

Definition at line 53 of file tests.py.

lsst.meas.base.tests.BlendContext.parentImage

Definition at line 55 of file tests.py.

lsst.meas.base.tests.BlendContext.parentRecord

Definition at line 54 of file tests.py.


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