Skip to content

Commit

Permalink
Merge branch 'main' into RCAL-950_CRDSKeywordsMisc
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHuwe authored Nov 12, 2024
2 parents 5b27ecd + 11c731a commit fae0ba2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
args: ["--py38-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.7.1'
rev: 'v0.7.3'
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 2 additions & 0 deletions changes/402.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use multiclass of `np.uint32` and `Enum` rather than a subclass of `IntEnum` for
the dqflags as suggested by the numpy devs.
1 change: 1 addition & 0 deletions changes/415.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove units from Guidewindow related data models.
1 change: 1 addition & 0 deletions changes/425.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Enum bug in python < 3.11 for the dqflags.
14 changes: 13 additions & 1 deletion src/roman_datamodels/dqflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
the formula `2**bit_number` where `bit_number` is the 0-index bit of interest.
"""

from enum import IntEnum, unique
import sys
from enum import unique

# Something with pickling of multiclassed enums was changed in 3.11 + allowing
# us to directly us `np.uint32` as the enum object rather than a python `int`.
if sys.version_info < (3, 11):
from enum import IntEnum
else:
from enum import Enum

import numpy as np

class IntEnum(np.uint32, Enum): ...


# fmt: off
Expand Down
11 changes: 3 additions & 8 deletions src/roman_datamodels/maker_utils/_datamodels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import warnings

import numpy as np
from astropy import units as u
from astropy.table import Table

from roman_datamodels import stnode
Expand Down Expand Up @@ -399,13 +398,9 @@ def mk_guidewindow(*, shape=(2, 8, 16, 32, 32), filepath=None, **kwargs):
guidewindow = stnode.Guidewindow()
guidewindow["meta"] = mk_guidewindow_meta(**kwargs.get("meta", {}))

guidewindow["pedestal_frames"] = kwargs.get(
"pedestal_frames", u.Quantity(np.zeros(shape, dtype=np.uint16), u.DN, dtype=np.uint16)
)
guidewindow["signal_frames"] = kwargs.get(
"signal_frames", u.Quantity(np.zeros(shape, dtype=np.uint16), u.DN, dtype=np.uint16)
)
guidewindow["amp33"] = kwargs.get("amp33", u.Quantity(np.zeros(shape, dtype=np.uint16), u.DN, dtype=np.uint16))
guidewindow["pedestal_frames"] = kwargs.get("pedestal_frames", np.zeros(shape, dtype=np.uint16))
guidewindow["signal_frames"] = kwargs.get("signal_frames", np.zeros(shape, dtype=np.uint16))
guidewindow["amp33"] = kwargs.get("amp33", np.zeros(shape, dtype=np.uint16))

return save_node(guidewindow, filepath=filepath)

Expand Down
12 changes: 10 additions & 2 deletions tests/test_dqflags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
from math import log10

import numpy as np
import pytest

from roman_datamodels import datamodels as rdm
Expand Down Expand Up @@ -30,7 +32,10 @@ def test_pixel_flags(flag):
assert isinstance(flag, dqflags.pixel)

# Test that the pixel flags are ints
assert isinstance(flag, int)
if sys.version_info < (3, 11):
assert isinstance(flag, int)
else:
assert isinstance(flag, np.uint32)

# Test that the pixel flags are dict accessible
assert dqflags.pixel[flag.name] is flag
Expand Down Expand Up @@ -78,7 +83,10 @@ def test_group_flags(flag):
assert isinstance(flag, dqflags.group)

# Test that the group flags are ints
assert isinstance(flag, int)
if sys.version_info < (3, 11):
assert isinstance(flag, int)
else:
assert isinstance(flag, np.uint32)

# Test that the group flags are dict accessible
assert dqflags.group[flag.name] is flag
Expand Down
3 changes: 0 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,8 @@ def test_make_guidewindow():

assert guidewindow.meta.exposure.type == "WFI_IMAGE"
assert guidewindow.pedestal_frames.dtype == np.uint16
assert guidewindow.pedestal_frames.unit == u.DN
assert guidewindow.signal_frames.dtype == np.uint16
assert guidewindow.signal_frames.unit == u.DN
assert guidewindow.amp33.dtype == np.uint16
assert guidewindow.amp33.unit == u.DN
assert guidewindow.pedestal_frames.shape == (2, 2, 2, 2, 2)
assert guidewindow.signal_frames.shape == (2, 2, 2, 2, 2)
assert guidewindow.amp33.shape == (2, 2, 2, 2, 2)
Expand Down

0 comments on commit fae0ba2

Please sign in to comment.