diff --git a/doc/versionHistory.rst b/doc/versionHistory.rst index 2e440874..8f20728d 100644 --- a/doc/versionHistory.rst +++ b/doc/versionHistory.rst @@ -6,6 +6,14 @@ Version History ################## +.. _lsst.ts.wep-12.4.1: + +------------- +12.4.1 +------------- + +* Fixed bug where CalcZernikesTask fails when the number of intra/extra stamps is not equal + .. _lsst.ts.wep-12.4.0: ------------- diff --git a/python/lsst/ts/wep/task/calcZernikesTask.py b/python/lsst/ts/wep/task/calcZernikesTask.py index 9c80be27..87eeaeba 100644 --- a/python/lsst/ts/wep/task/calcZernikesTask.py +++ b/python/lsst/ts/wep/task/calcZernikesTask.py @@ -238,6 +238,12 @@ def createZkTable( zkCoeffCombined.flags, ) ): + # If zk is None, we need to stop. This can happen when running + # paired Zernike estimation and the number of intra/extra stamps + # is not the same + if zk is None: + break + row = dict() row["label"] = f"pair{i+1}" row["used"] = not flag diff --git a/python/lsst/ts/wep/task/donutStampSelectorTask.py b/python/lsst/ts/wep/task/donutStampSelectorTask.py index 89bfdea2..341979c4 100644 --- a/python/lsst/ts/wep/task/donutStampSelectorTask.py +++ b/python/lsst/ts/wep/task/donutStampSelectorTask.py @@ -172,8 +172,10 @@ def selectStamps(self, donutStamps): entropySelect = np.ones(len(donutStamps), dtype="bool") # Collect the entropy information if available + entropyValue = np.full(len(donutStamps), np.nan) if "ENTROPY" in list(donutStamps.metadata): - entropyValue = np.asarray(donutStamps.metadata.getArray("ENTROPY")) + fillVals = np.asarray(donutStamps.metadata.getArray("ENTROPY")) + entropyValue[: len(fillVals)] = fillVals if self.config.selectWithEntropy: entropySelect = entropyValue < self.config.maxEntropy else: @@ -184,9 +186,10 @@ def selectStamps(self, donutStamps): snSelect = np.ones(len(donutStamps), dtype="bool") # collect the SN information if available + snValue = np.full(len(donutStamps), np.nan) if "SN" in list(donutStamps.metadata): - snValue = np.asarray(donutStamps.metadata.getArray("SN")) - + fillVals = np.asarray(donutStamps.metadata.getArray("SN")) + snValue[: len(fillVals)] = fillVals if self.config.selectWithSignalToNoise: # Use user defined SN cutoff or the filter-dependent # defaults, depending on useCustomSnLimit @@ -210,8 +213,10 @@ def selectStamps(self, donutStamps): fracBadPixSelect = np.ones(len(donutStamps), dtype="bool") # collect fraction-of-bad-pixels information if available + fracBadPix = np.full(len(donutStamps), np.nan) if "FRAC_BAD_PIX" in list(donutStamps.metadata): - fracBadPix = np.asarray(donutStamps.metadata.getArray("FRAC_BAD_PIX")) + fillVals = np.asarray(donutStamps.metadata.getArray("FRAC_BAD_PIX")) + fracBadPix[: len(fillVals)] = fillVals if self.config.selectWithFracBadPixels: fracBadPixSelect = fracBadPix <= self.config.maxFracBadPixels else: diff --git a/tests/task/test_calcZernikesTieTaskCwfs.py b/tests/task/test_calcZernikesTieTaskCwfs.py index 2c46ae82..3005f82b 100644 --- a/tests/task/test_calcZernikesTieTaskCwfs.py +++ b/tests/task/test_calcZernikesTieTaskCwfs.py @@ -269,3 +269,15 @@ def testWithAndWithoutPairs(self): # Check that the averages are similar zkAvgUnpaired = np.mean([zkAvgExtra, zkAvgIntra], axis=0) self.assertLess(np.sqrt(np.sum(np.square(zkAvgPairs - zkAvgUnpaired))), 0.30) + + def testUnevenPairs(self): + # Test for when you have more of either extra or intra + # Load the test data + stampsExtra = self.donutStampsExtra + stampsIntra = self.donutStampsIntra + + # Increase length of extra list + stampsExtra.extend([stampsExtra[0]]) + + # Now estimate Zernikes + self.task.run(stampsExtra, stampsIntra)