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-36201: Add force remake option to bestEffortIsr #24

Merged
merged 2 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
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
28 changes: 20 additions & 8 deletions python/lsst/summit/utils/bestEffort.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ def clearCache(self):
"""
self._cache = {}

def getExposure(self, expIdOrDataId, extraIsrOptions={}, skipCosmics=False, **kwargs):
def getExposure(self, expIdOrDataId, extraIsrOptions={}, skipCosmics=False, forceRemake=False,
**kwargs):
"""Get the postIsr and cosmic-repaired image for this dataId.

Note that when using the forceRemake option the image will not be
written to the repo for reuse.

Parameters
----------
expIdOrDataId : `dict`
Expand All @@ -170,6 +174,13 @@ def getExposure(self, expIdOrDataId, extraIsrOptions={}, skipCosmics=False, **kw
image only.
skipCosmics : `bool`, optional # XXX THIS CURRENTLY DOESN'T WORK!
Skip doing cosmic ray repair for this image?
forceRemake : `bool`
Remake the exposure even if there is a pre-existing one in the
repo. Images that are force-remade are never written, as this is
assumed to be used for testing/debug purposes, as opposed to normal
operation. For updating individual images, removal from the
registry can be used, and for bulk-updates the overall run number
can be incremented.

Returns
-------
Expand All @@ -178,12 +189,13 @@ def getExposure(self, expIdOrDataId, extraIsrOptions={}, skipCosmics=False, **kw
"""
dataId = self._parseExpIdOrDataId(expIdOrDataId, **kwargs)

try:
exp = self.butler.get(self._datasetName, dataId=dataId)
self.log.info("Found a ready-made quickLookExp in the repo. Returning that.")
return exp
except LookupError:
pass
if not forceRemake:
try:
exp = self.butler.get(self._datasetName, dataId=dataId)
self.log.info("Found a ready-made quickLookExp in the repo. Returning that.")
return exp
except LookupError:
pass

try:
raw = self.butler.get('raw', dataId=dataId)
Expand Down Expand Up @@ -227,7 +239,7 @@ def getExposure(self, expIdOrDataId, extraIsrOptions={}, skipCosmics=False, **kw

quickLookExp = self.quickLookIsrTask.run(raw, **isrDict, isrBaseConfig=isrConfig).outputExposure

if self.doWrite:
if self.doWrite and not forceRemake:
try:
self.butler.put(quickLookExp, self._datasetName, dataId)
self.log.info(f'Put {self._datasetName} for {dataId}')
Expand Down
5 changes: 5 additions & 0 deletions tests/test_bestEffortIsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ def setUpClass(cls):
cls.dataId = {'day_obs': 20210121, 'seq_num': 743, 'detector': 0}

def test_getExposure(self):
# in most locations this will load a pre-made image
exp = self.bestEffortIsr.getExposure(self.dataId)
self.assertIsInstance(exp, afwImage.Exposure)

# this will always actually run isr with whatever calibs are available
exp = self.bestEffortIsr.getExposure(self.dataId, forceRemake=True)
self.assertIsInstance(exp, afwImage.Exposure)


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand Down