Skip to content

Commit

Permalink
Use multiclass of uint32 and Enum rather than IntEnum (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Nov 11, 2024
1 parent 3ed89f4 commit b374e0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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.
8 changes: 5 additions & 3 deletions src/roman_datamodels/dqflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
the formula `2**bit_number` where `bit_number` is the 0-index bit of interest.
"""

from enum import IntEnum, unique
from enum import Enum, unique

import numpy as np


# fmt: off
@unique
class pixel(IntEnum):
class pixel(np.uint32, Enum):
"""Pixel-specific data quality flags"""

GOOD = 0 # No bits set, all is good
Expand Down Expand Up @@ -62,7 +64,7 @@ class pixel(IntEnum):


@unique
class group(IntEnum):
class group(np.uint32, Enum):
"""Group-specific data quality flags
Once groups are combined, these flags are equivalent to the pixel-specific flags.
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dqflags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import log10

import numpy as np
import pytest

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

# Test that the pixel flags are ints
assert isinstance(flag, int)
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 +79,7 @@ def test_group_flags(flag):
assert isinstance(flag, dqflags.group)

# Test that the group flags are ints
assert isinstance(flag, int)
assert isinstance(flag, np.uint32)

# Test that the group flags are dict accessible
assert dqflags.group[flag.name] is flag
Expand Down

0 comments on commit b374e0e

Please sign in to comment.