Skip to content

Commit

Permalink
Merge pull request #80 from lsst-sitcom/tickets/DM-42874
Browse files Browse the repository at this point in the history
DM-42874 : Tweak PeekExposureTask
  • Loading branch information
jmeyers314 committed Feb 13, 2024
2 parents 96a40da + 103b541 commit e223147
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions python/lsst/summit/utils/peekExposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,44 @@ def run(
- pixelMode : `float`
Mode estimate of entire image.
"""
# Make a copy so the original image is unmodified.
exposure = exposure.clone()
try:
result = self._run(
exposure, doDisplay, doDisplayIndices, mode, binSize, donutDiameter
)
except Exception as e:
self.log.warning(f"Peek failed: {e}")
result = pipeBase.Struct(
mode="failed",
binSize=0,
binnedSourceCat=None,
table=None,
brightestIdx=0,
brightestCentroid=Point2D(np.nan, np.nan),
brightestPixelShape=Quadrupole(np.nan, np.nan, np.nan),
brightestEquatorialShape=Quadrupole(np.nan, np.nan, np.nan),
brightestAltAzShape=Quadrupole(np.nan, np.nan, np.nan),
psfPixelShape=Quadrupole(np.nan, np.nan, np.nan),
psfEquatorialShape=Quadrupole(np.nan, np.nan, np.nan),
psfAltAzShape=Quadrupole(np.nan, np.nan, np.nan),
pixelMedian=np.nan,
pixelMode=np.nan,
)
return result

def _run(self, exposure, doDisplay, doDisplayIndices, mode, binSize, donutDiameter):
""" The actual run method, called by run().
"""
# If image is ~large, then use a subsampling of the image for
# speedy median/mode estimates.
arr = exposure.getMaskedImage().getImage().array
sampling = 1
if arr.size > 250_000:
sampling = int(np.floor(np.sqrt(arr.size / 250_000)))
pixelMedian = np.nanmedian(arr[::sampling, ::sampling])
pixelMode = _estimateMode(arr[::sampling, ::sampling])

if donutDiameter is None:
donutDiameter = self.getDonutDiameter(exposure)

Expand Down Expand Up @@ -873,13 +911,6 @@ def run(
exposure, binSize, binnedSourceCat, maxFluxIdx, doDisplayIndices
)

# If image is still ~large, then use a subsampling of the image for
# speedy median/mode estimates.
arr = exposure.getMaskedImage().getImage().array
sampling = 1
if arr.size > 250_000:
sampling = int(np.floor(np.sqrt(arr.size / 250_000)))

return pipeBase.Struct(
mode=mode,
binSize=binSize,
Expand All @@ -893,8 +924,8 @@ def run(
psfPixelShape=psfShape,
psfEquatorialShape=equatorialShapes[1],
psfAltAzShape=altAzShapes[1],
pixelMedian=np.nanmedian(arr[::sampling, ::sampling]),
pixelMode=_estimateMode(arr[::sampling, ::sampling]),
pixelMedian=pixelMedian,
pixelMode=pixelMode,
)

def runPeek(self, exposure, mode, donutDiameter, binSize=None):
Expand Down

0 comments on commit e223147

Please sign in to comment.