From 7b9eaf11566766ee6ba60160d3467e8f18b35518 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 10 Sep 2024 18:30:38 -0400 Subject: [PATCH 1/7] Drop None default for get method of DataCoordinate in response to the change made in the commit https://github.com/lsst/daf_butler/commit/1c47f99a929882c56c404f3487a014c12fb452ea --- python/lsst/cell_coadds/_identifiers.py | 2 +- tests/test_common.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/lsst/cell_coadds/_identifiers.py b/python/lsst/cell_coadds/_identifiers.py index 2a940dc1..79691300 100644 --- a/python/lsst/cell_coadds/_identifiers.py +++ b/python/lsst/cell_coadds/_identifiers.py @@ -168,7 +168,7 @@ def from_data_id(cls, data_id: DataCoordinate, *, backup_detector: int = -1) -> Struct of identifiers for this observation. """ detector = data_id.get("detector", backup_detector) - day_obs = data_id.get("day_obs", None) + day_obs = data_id.get("day_obs") return cls( instrument=cast(str, data_id["instrument"]), physical_filter=cast(str, data_id["physical_filter"]), diff --git a/tests/test_common.py b/tests/test_common.py index 166ca646..64527d25 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -33,7 +33,7 @@ def setUp(self) -> None: # noqa: D102 self.units = CoaddUnits.nJy quantum_data_id = test_utils.generate_data_id() self.wcs = test_utils.generate_wcs() - self.band = quantum_data_id.get("band", None) + self.band = quantum_data_id.get("band") self.identifiers = PatchIdentifiers.from_data_id(quantum_data_id) self.common = CommonComponents( units=self.units, wcs=self.wcs, band=self.band, identifiers=self.identifiers From 59d3b7c35ff951b565ff2efb4874ad28d72e6dba Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 10 Sep 2024 18:37:17 -0400 Subject: [PATCH 2/7] Avoid unnecessary casting since the get method with a typed default guarantees that detector is int. This change is in response to the commit https://github.com/lsst/daf_butler/commit/1c47f99a929882c56c404f3487a014c12fb452ea --- python/lsst/cell_coadds/_identifiers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/lsst/cell_coadds/_identifiers.py b/python/lsst/cell_coadds/_identifiers.py index 79691300..03cdaf4b 100644 --- a/python/lsst/cell_coadds/_identifiers.py +++ b/python/lsst/cell_coadds/_identifiers.py @@ -174,7 +174,7 @@ def from_data_id(cls, data_id: DataCoordinate, *, backup_detector: int = -1) -> physical_filter=cast(str, data_id["physical_filter"]), visit=cast(int, data_id["visit"]), day_obs=cast(int, day_obs), - detector=cast(int, detector), + detector=detector, ) def __lt__(self, other: Self, /) -> bool: From d5fe1aa240ed6d1dbe8e3bcd49c80e72f5551de0 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 10 Sep 2024 18:38:49 -0400 Subject: [PATCH 3/7] Ignore all errors in _cell_coadd_builder --- mypy.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mypy.ini b/mypy.ini index 1a6b710f..99cfa32d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -37,3 +37,7 @@ ignore_missing_imports = True # mypy does not bode well with monkey patching done here. [mypy-lsst.cell_coadds._GridContainer] ignore_errors = True + +# _cell_coadd_builder.py is not used, and not worth the upkeep. +[mypy-lsst.cell_coadds._cell_coadd_builder] +ignore_errors = True From 929f1395e81fc201d582d81ee7d221446d503835 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Wed, 11 Sep 2024 13:03:36 -0400 Subject: [PATCH 4/7] Modify CoaddUnits to have string values --- python/lsst/cell_coadds/_common_components.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lsst/cell_coadds/_common_components.py b/python/lsst/cell_coadds/_common_components.py index 01908268..b391dcde 100644 --- a/python/lsst/cell_coadds/_common_components.py +++ b/python/lsst/cell_coadds/_common_components.py @@ -44,16 +44,16 @@ class CoaddUnits(enum.Enum): flux unit other than nJy). """ - legacy = enum.auto() + legacy = "legacy" """Pixels in semi-arbitrary unit obtained by scaling the warps to a common zeropoint (typically 27). """ - nJy = enum.auto() + nJy = "nJy" """Pixels represent flux in nanojanskies. """ - chi = enum.auto() + chi = "chi" """Pixels represent a signal-to-noise ratio. """ From 98897cc29cbb1b15ba1eaaf3f8fc2a67229328dc Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Wed, 11 Sep 2024 13:09:50 -0400 Subject: [PATCH 5/7] Add a unit test checking name and value match This consistency is needed to read and write units from/into FITS format. --- tests/test_common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_common.py b/tests/test_common.py index 64527d25..1fa9089e 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -46,6 +46,12 @@ def test_commonComponentsProperties(self): self.assertEqual(self.common.band, self.band) self.assertEqual(self.common.identifiers, self.identifiers) + def test_coaddUnits(self): + """Test that the member name and values are the same.""" + for unit in CoaddUnits: + with self.subTest(unit.name): + self.assertEqual(unit.name, unit.value) + class TestMemory(lsst.utils.tests.MemoryTestCase): """Check for resource/memory leaks.""" From 43254ede5b28aa16ad991fb2675640c2d324ed51 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 10 Sep 2024 17:57:09 -0400 Subject: [PATCH 6/7] Read units from FITS header --- python/lsst/cell_coadds/_fits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/lsst/cell_coadds/_fits.py b/python/lsst/cell_coadds/_fits.py index 6697a7b9..22988ddf 100644 --- a/python/lsst/cell_coadds/_fits.py +++ b/python/lsst/cell_coadds/_fits.py @@ -238,7 +238,7 @@ def readAsMultipleCellCoadd(self) -> MultipleCellCoadd: # Build the quantities needed to construct a MultipleCellCoadd. common = CommonComponents( - units=CoaddUnits(1), # TODO: read from FITS TUNIT1 (DM-40562) + units=CoaddUnits(header["TUNIT1"]), wcs=wcs, band=header["FILTER"], identifiers=PatchIdentifiers( From 15595a1609bf295bac08758688b768539171b79a Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Tue, 10 Sep 2024 17:57:21 -0400 Subject: [PATCH 7/7] Change units to nJy in unit tests --- tests/test_coadds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_coadds.py b/tests/test_coadds.py index 36944a37..c73facdb 100644 --- a/tests/test_coadds.py +++ b/tests/test_coadds.py @@ -66,7 +66,7 @@ def setUpClass(cls) -> None: np.random.seed(42) data_id = test_utils.generate_data_id() common = CommonComponents( - units=CoaddUnits.legacy, # units here are arbitrary. + units=CoaddUnits.nJy, # units here are arbitrary. wcs=test_utils.generate_wcs(), band=data_id["band"], identifiers=PatchIdentifiers.from_data_id(data_id),