Skip to content

Commit e089fba

Browse files
committed
Only delete images if we are finished with them
Work around segfault when doing afwImage.MaskedImageF(None)
1 parent 0c025fa commit e089fba

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

python/lsst/rubintv/production/slac/botTesting.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def plotNoises(self, expRecord, timeout):
639639

640640
return saveFile
641641

642-
def plotFocalPlane(self, expRecord, timeout):
642+
def plotFocalPlane(self, expRecord, timeout, doNotDelete=False):
643643
"""Create a binned mosaic of the full focal plane as a png.
644644
645645
The binning factor is controlled via the locationConfig.binning
@@ -651,6 +651,8 @@ def plotFocalPlane(self, expRecord, timeout):
651651
The exposure record.
652652
timeout : `int`
653653
The timeout for waiting for the data to be complete.
654+
doNotDelete : `bool`, optional
655+
If True, do not delete the input data, even if it is complete.
654656
655657
Returns
656658
-------
@@ -675,6 +677,7 @@ def plotFocalPlane(self, expRecord, timeout):
675677
dataPath=self.locationConfig.calculatedDataPath,
676678
savePlotAs=saveFile,
677679
nExpected=nExpected,
680+
doNotDelete=doNotDelete,
678681
timeout=timeout,
679682
logger=self.log)
680683
self.log.info(f'Wrote focal plane plot for {expRecord.dataId} to {saveFile}')
@@ -766,6 +769,10 @@ def runCcobAnalysis(self, expRecord, timeout):
766769
deleteIfComplete=False,
767770
deleteRegardless=False,
768771
)
772+
if image is None:
773+
self.log.warning(f'No mosaic found for {expRecord.dataId}')
774+
return None
775+
769776
spotInfo = analyzeCcobSpotImage(image, binning=binning)
770777

771778
dayObs = expRecord.day_obs
@@ -842,18 +849,23 @@ def callback(self, expRecord, doPlotMosaic=False, doPlotNoises=False, doCcobAnal
842849
# TODO: Need some kind of wait mechanism for each of these
843850
if doPlotNoises:
844851
noiseMapFile = self.plotNoises(expRecord, timeout=timeout)
845-
channel = f'{instPrefix}_noise_map'
846-
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, noiseMapFile)
852+
if noiseMapFile:
853+
channel = f'{instPrefix}_noise_map'
854+
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, noiseMapFile)
847855

848856
if doPlotMosaic:
849-
focalPlaneFile = self.plotFocalPlane(expRecord, timeout=timeout)
850-
channel = f'{instPrefix}_focal_plane_mosaic'
851-
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, focalPlaneFile)
857+
focalPlaneFile = self.plotFocalPlane(expRecord,
858+
timeout=timeout,
859+
doNotDelete=doCcobAnalysis)
860+
if focalPlaneFile:
861+
channel = f'{instPrefix}_focal_plane_mosaic'
862+
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, focalPlaneFile)
852863

853864
if doCcobAnalysis:
854865
ccobAnalsisPlot = self.runCcobAnalysis(expRecord, timeout=timeout)
855-
channel = f'{instPrefix}_ccob_analysis'
856-
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, ccobAnalsisPlot, isLiveFile=True)
866+
if ccobAnalsisPlot:
867+
channel = f'{instPrefix}_ccob_analysis'
868+
self.uploader.uploadPerSeqNumPlot(channel, dayObs, seqNum, ccobAnalsisPlot, isLiveFile=True)
857869

858870
def run(self):
859871
"""Run continuously, calling the callback method with the latest

python/lsst/rubintv/production/slac/mosaicing.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def makeMosaic(deferredDatasetRefs,
272272
nExpected,
273273
deleteIfComplete,
274274
deleteRegardless,
275+
doNotDelete,
275276
logger=None):
276277
"""Make a binned mosaic image from a list of deferredDatasetRefs.
277278
@@ -297,6 +298,8 @@ def makeMosaic(deferredDatasetRefs,
297298
is the number which was found.
298299
deleteRegardless : `bool`, optional
299300
If True, delete the binned images regardless of how many are found.
301+
doNotDelete : `bool`, optional
302+
If True, do not delete the binned images after reading them.
300303
logger : `logging.Logger`, optional
301304
The logger, created if not provided.
302305
deleteAfterReading : `bool`
@@ -321,6 +324,11 @@ def makeMosaic(deferredDatasetRefs,
321324
if logger is None:
322325
logger = logging.getLogger(__name__)
323326

327+
if doNotDelete:
328+
if deleteRegardless:
329+
raise ValueError("doNotDelete and deleteRegardless are mutually exclusive")
330+
deleteIfComplete = False
331+
324332
instrument = camera.getName()
325333

326334
detectorNameList = []
@@ -437,6 +445,7 @@ def plotFocalPlaneMosaic(butler,
437445
timeout,
438446
deleteIfComplete=True,
439447
deleteRegardless=False,
448+
doNotDelete=False,
440449
logger=None):
441450
"""Save a full focal plane binned mosaic image for a given expId.
442451
@@ -468,6 +477,10 @@ def plotFocalPlaneMosaic(butler,
468477
is the number which was found.
469478
deleteRegardless : `bool`, optional
470479
If True, delete the binned images regardless of how many are found.
480+
`doNotDelete` trumps `deleteIfComplete`, but raises a ValueError if
481+
used with `deleteRegardless`.
482+
doNotDelete : `bool`, optional
483+
If True, do not delete the binned images after reading them.
471484
logger : `logging.Logger`, optional
472485
The logger, created if not provided.
473486
@@ -488,6 +501,7 @@ def plotFocalPlaneMosaic(butler,
488501
timeout=timeout,
489502
deleteIfComplete=deleteIfComplete,
490503
deleteRegardless=deleteRegardless,
504+
doNotDelete=doNotDelete,
491505
logger=logger)
492506

493507
if mosaic is None:
@@ -507,6 +521,7 @@ def getMosaicImage(butler,
507521
timeout,
508522
deleteIfComplete=True,
509523
deleteRegardless=False,
524+
doNotDelete=False,
510525
logger=None):
511526
"""Save a full focal plane binned mosaic image for a given expId.
512527
@@ -534,6 +549,8 @@ def getMosaicImage(butler,
534549
is the number which was found.
535550
deleteRegardless : `bool`, optional
536551
If True, delete the binned images regardless of how many are found.
552+
doNotDelete : `bool`, optional
553+
If True, do not delete the binned images after reading them.
537554
logger : `logging.Logger`, optional
538555
The logger, created if not provided.
539556
@@ -567,6 +584,7 @@ def getMosaicImage(butler,
567584
nExpected=nExpected,
568585
deleteIfComplete=deleteIfComplete,
569586
deleteRegardless=deleteRegardless,
587+
doNotDelete=doNotDelete,
570588
logger=logger
571589
).output_mosaic
572590
if mosaic is None:

0 commit comments

Comments
 (0)