Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-42874 : Tweak PeekExposureTask #80

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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