Skip to content

Commit

Permalink
Address Arun's comments round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
enourbakhsh committed Dec 3, 2023
1 parent be72238 commit 7d0875f
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions python/lsst/meas/extensions/shapeHSM/_hsm_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ def __init__(self, config, name, schema, metadata, logName=None):
# "g": g-type shear, "e": e-type distortion.
self.measTypeSymbol = "g" if config.shearType == "KSB" else "e"

self.e1Key = self._addEllipticityField(name, 1, self.measTypeSymbol, schema, self.doc)
self.e2Key = self._addEllipticityField(name, 2, self.measTypeSymbol, schema, self.doc)
self.sigmaKey = schema.addField(schema.join(name, "sigma"), type=float, doc=f"{self.doc} (width)")
self.e1Key = self._addEllipticityField(name, 1, schema, self.doc)
self.e2Key = self._addEllipticityField(name, 2, schema, self.doc)
self.sigmaKey = schema.addField(
schema.join(name, "sigma"),
type=float,
doc=f"{self.doc} (shape measurement uncertainty per component)",
)
self.resolutionKey = schema.addField(
schema.join(name, "resolution"), type=float, doc="Resolution factor (0=unresolved, 1=resolved)"
)
Expand All @@ -115,34 +119,32 @@ def __init__(self, config, name, schema, metadata, logName=None):
def getExecutionOrder(cls):
return cls.SHAPE_ORDER

def _addEllipticityField(self, name, n, measTypeSymbol, schema, doc):
def _addEllipticityField(self, name, n, schema, doc):
"""
Helper function to add an ellipticity field to a measurement schema.
Parameters
----------
name : str
name : `str`
Base name of the field.
n : int
n : `int`
Specifies whether the field is for the first (1) or second (2)
component.
measTypeSymbol : MeasType
The symbol for measurement type, either 'e' or 'g'.
schema : lsst.afw.table.Schema
schema : `~lsst.afw.table.Schema`
The schema to which the field is added.
doc : str
doc : `str`
The documentation string that needs to be updated to reflect the
type and component of the measurement.
Returns
-------
lsst.afw.table.KeyD
`~lsst.afw.table.KeyD`
The key associated with the added field in the schema.
"""
componentLookup = {1: "+ component", 2: "x component"}
typeLookup = {"e": " of ellipticity", "g": " of estimated shear"}
name = f"{name}_{measTypeSymbol}{n}"
updatedDoc = f"{doc} ({componentLookup[n]}{typeLookup[measTypeSymbol]})"
name = f"{name}_{self.measTypeSymbol}{n}"
updatedDoc = f"{doc} ({componentLookup[n]}{typeLookup[self.measTypeSymbol]})"
return schema.addField(name, type=float, doc=updatedDoc)

def measure(self, record, exposure):
Expand Down Expand Up @@ -221,8 +223,11 @@ def measure(self, record, exposure):
sctrl.setAndMask(bitValue)

# NOTE: Origin defaults to PARENT in all cases accessible from Python.
variance = afwImage.ImageF(exposure.variance[bbox], deep=False)

variance = afwImage.Image(
exposure.variance[bbox],
dtype=exposure.variance.dtype,
deep=False,
)
stat = afwMath.makeStatistics(variance, subMask, afwMath.MEDIAN, sctrl)

skyvar = stat.getValue(afwMath.MEDIAN)
Expand All @@ -249,7 +254,7 @@ def measure(self, record, exposure):
if shape.meas_type != self.measTypeSymbol:
# Give up on the plugin entirely without wasting time measuring
# each source and failing every single time.
raise measBase.FatalAlgorithmError("The plugin config is incompatible with GalSim.")
raise measBase.FatalAlgorithmError("The plugin setup is incompatible with GalSim.")
if shape.meas_type == "e":
record.set(self.e1Key, shape.corrected_e1)
record.set(self.e2Key, shape.corrected_e2)
Expand Down

0 comments on commit 7d0875f

Please sign in to comment.