Skip to content

Commit

Permalink
Allow donut size to be specified via config or run() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisherlevine committed Apr 13, 2021
1 parent 12195ba commit 6fac018
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions python/lsst/pipe/tasks/quickFrameMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class QuickFrameMeasurementTaskConfig(pexConfig.Config):
doc="Minimum number of pixels in a detected source.",
default=10,
)
donutDiameter = pexConfig.Field(
dtype=int,
doc="The expected diameter of donuts in a donut image, in pixels.",
default=400,
)

def setDefaults(self):
super().setDefaults()
Expand Down Expand Up @@ -231,7 +236,7 @@ def _calcMedianXxYy(objData):
return medianXx, medianYy

@staticmethod
def _getCentreOfMass(exp, nominalCentroid, boxSize=500):
def _getCentreOfMass(exp, nominalCentroid, boxSize):
"""Get the centre of mass around a point in the image.
Parameters
Expand Down Expand Up @@ -447,7 +452,7 @@ def _makeEmptyReturnStruct():
result.medianXxYy = (np.nan, np.nan)
return result

def run(self, exp, doDisplay=False):
def run(self, exp, *, donutDiameter=None, doDisplay=False):
"""Calculate position, flux and shape of the brightest star in an image.
Given an an assembled (and at least minimally ISRed exposure),
Expand All @@ -459,6 +464,11 @@ def run(self, exp, doDisplay=False):
exp : lsst.afw.image.Exposure
The exposure in which to find and measure the brightest star.
donutSize : `int`, optional
The expected diameter of donuts in pixels for use in the centre of
mass centroid measurement. If None is provided, the config option
is used.
doDisplay : bool
Display the image and found sources. A diplay object must have
been passed to the task constructor.
Expand Down Expand Up @@ -491,11 +501,14 @@ def run(self, exp, doDisplay=False):
result = self._makeEmptyReturnStruct()
return result

def _run(self, exp, doDisplay=False):
def _run(self, exp, *, donutDiameter=None, doDisplay=False):
"""The actual run method, called by run()
Behaviour is documented in detail in the main run().
"""
if donutDiameter is None:
donutDiameter = self.config.donutDiameter

self.plateScale = exp.getWcs().getPixelScale().asArcseconds()
median = np.nanmedian(exp.image.array)
exp.image -= median # is put back later
Expand Down Expand Up @@ -559,7 +572,8 @@ def _run(self, exp, doDisplay=False):

result.brightestObjCentroidCofM = None
try:
centreOfMass = self._getCentreOfMass(exp, brightestObjCentroid)
boxSize = donutDiameter * 1.3 # allow some slack, as cutting off side of donut is very bad
centreOfMass = self._getCentreOfMass(exp, brightestObjCentroid, boxSize)
result.brightestObjCentroidCofM = centreOfMass
except Exception:
pass
Expand Down

0 comments on commit 6fac018

Please sign in to comment.