Skip to content

Commit

Permalink
Merge pull request #36 from lsst/tickets/DM-40562
Browse files Browse the repository at this point in the history
DM-40562: Read pixel units from the FITS header
  • Loading branch information
arunkannawadi authored Sep 11, 2024
2 parents c90fb82 + 15595a1 commit 8b199b0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions python/lsst/cell_coadds/_common_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/cell_coadds/_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/cell_coadds/_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ 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"]),
visit=cast(int, data_id["visit"]),
day_obs=cast(int, day_obs),
detector=cast(int, detector),
detector=detector,
)

def __lt__(self, other: Self, /) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_coadds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down

0 comments on commit 8b199b0

Please sign in to comment.