From bca42664b4e766327fb26a822fd1e50f9f89cc18 Mon Sep 17 00:00:00 2001 From: John Franklin Crenshaw Date: Sun, 27 Oct 2024 19:42:25 -0700 Subject: [PATCH 1/3] Made more robust to unequal length intra and extra stamp lists. --- python/lsst/ts/wep/task/calcZernikesTask.py | 6 ++++++ python/lsst/ts/wep/task/donutStampSelectorTask.py | 13 +++++++++---- tests/task/test_calcZernikesTieTaskCwfs.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/python/lsst/ts/wep/task/calcZernikesTask.py b/python/lsst/ts/wep/task/calcZernikesTask.py index 9c80be27..e2567610 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..d1715096 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) From 215c1c6c6788ce643620cd54e7d6c49983e3ccdc Mon Sep 17 00:00:00 2001 From: John Franklin Crenshaw Date: Sun, 27 Oct 2024 19:43:54 -0700 Subject: [PATCH 2/3] Bumped version history. --- doc/versionHistory.rst | 8 ++++++++ 1 file changed, 8 insertions(+) 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: ------------- From c0d4ea55f93435b2f8fdb7ffa0591638380e6b43 Mon Sep 17 00:00:00 2001 From: John Franklin Crenshaw Date: Sun, 27 Oct 2024 19:45:37 -0700 Subject: [PATCH 3/3] Linting. --- python/lsst/ts/wep/task/calcZernikesTask.py | 6 +++--- python/lsst/ts/wep/task/donutStampSelectorTask.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/lsst/ts/wep/task/calcZernikesTask.py b/python/lsst/ts/wep/task/calcZernikesTask.py index e2567610..87eeaeba 100644 --- a/python/lsst/ts/wep/task/calcZernikesTask.py +++ b/python/lsst/ts/wep/task/calcZernikesTask.py @@ -238,12 +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 + # 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 d1715096..341979c4 100644 --- a/python/lsst/ts/wep/task/donutStampSelectorTask.py +++ b/python/lsst/ts/wep/task/donutStampSelectorTask.py @@ -175,7 +175,7 @@ def selectStamps(self, donutStamps): entropyValue = np.full(len(donutStamps), np.nan) if "ENTROPY" in list(donutStamps.metadata): fillVals = np.asarray(donutStamps.metadata.getArray("ENTROPY")) - entropyValue[:len(fillVals)] = fillVals + entropyValue[: len(fillVals)] = fillVals if self.config.selectWithEntropy: entropySelect = entropyValue < self.config.maxEntropy else: @@ -189,7 +189,7 @@ def selectStamps(self, donutStamps): snValue = np.full(len(donutStamps), np.nan) if "SN" in list(donutStamps.metadata): fillVals = np.asarray(donutStamps.metadata.getArray("SN")) - snValue[:len(fillVals)] = fillVals + snValue[: len(fillVals)] = fillVals if self.config.selectWithSignalToNoise: # Use user defined SN cutoff or the filter-dependent # defaults, depending on useCustomSnLimit @@ -216,7 +216,7 @@ def selectStamps(self, donutStamps): fracBadPix = np.full(len(donutStamps), np.nan) if "FRAC_BAD_PIX" in list(donutStamps.metadata): fillVals = np.asarray(donutStamps.metadata.getArray("FRAC_BAD_PIX")) - fracBadPix[:len(fillVals)] = fillVals + fracBadPix[: len(fillVals)] = fillVals if self.config.selectWithFracBadPixels: fracBadPixSelect = fracBadPix <= self.config.maxFracBadPixels else: