Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multiclass of uint32 and Enum rather than IntEnum #402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 3 in tests/test_dqflags.py

View check run for this annotation

Codecov / codecov/patch

tests/test_dqflags.py#L3

Added line #L3 was not covered by tests
import pytest

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

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

Check warning on line 34 in tests/test_dqflags.py

View check run for this annotation

Codecov / codecov/patch

tests/test_dqflags.py#L34

Added line #L34 was not covered by tests

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

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

Check warning on line 82 in tests/test_dqflags.py

View check run for this annotation

Codecov / codecov/patch

tests/test_dqflags.py#L82

Added line #L82 was not covered by tests

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