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

RCAL-900: fix numpy 2.0 issues with bitflags in resample #1383

Merged
merged 5 commits into from
Sep 8, 2024
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
1 change: 1 addition & 0 deletions changes/1383.resample.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an incompatibility with ``numpy 2.0`` in ``resample.resample_utils.build_mask()``. Switched code in ``build_driz_weight()`` to use ``astropy`` equivalent of ``build_mask()``. Deprecated ``resample.resample_utils.build_mask()``.
29 changes: 21 additions & 8 deletions romancal/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from astropy import wcs as fitswcs
from astropy.modeling import Model
from astropy.nddata.bitmask import interpret_bit_flags
from astropy.nddata.bitmask import bitfield_to_boolean_mask
from roman_datamodels.dqflags import pixel
from stcal.alignment.util import wcs_from_footprints

Expand Down Expand Up @@ -136,7 +136,13 @@
print(weight_map)
"""

dqmask = build_mask(model.dq, good_bits)
dqmask = bitfield_to_boolean_mask(
model.dq,
good_bits,
good_mask_value=1,
dtype=np.uint8,
flag_name_map=pixel,
)

if weight_type == "ivm":
if (
Expand Down Expand Up @@ -195,13 +201,20 @@
obtain the bit mask.
- The resulting bit mask is returned as a `numpy.ndarray` of dtype `numpy.uint8`.
"""
bitvalue = interpret_bit_flags(
bitvalue, flag_name_map={dq.name: dq.value for dq in pixel}
warnings.warn(

Check warning on line 204 in romancal/resample/resample_utils.py

View check run for this annotation

Codecov / codecov/patch

romancal/resample/resample_utils.py#L204

Added line #L204 was not covered by tests
"'build_mask' has been deprecated since release 0.16.3. "
"Use functions from astropy.nddata.bitmask module instead such as "
"bitfield_to_boolean_mask().",
DeprecationWarning,
)

if bitvalue is None:
return np.ones(dqarr.shape, dtype=np.uint8)
return np.logical_not(np.bitwise_and(dqarr, ~bitvalue)).astype(np.uint8)
dqmask = bitfield_to_boolean_mask(

Check warning on line 210 in romancal/resample/resample_utils.py

View check run for this annotation

Codecov / codecov/patch

romancal/resample/resample_utils.py#L210

Added line #L210 was not covered by tests
dqarr,
bitvalue,
good_mask_value=1,
dtype=np.uint8,
flag_name_map=pixel,
)
return dqmask

Check warning on line 217 in romancal/resample/resample_utils.py

View check run for this annotation

Codecov / codecov/patch

romancal/resample/resample_utils.py#L217

Added line #L217 was not covered by tests


def calc_gwcs_pixmap(in_wcs, out_wcs, shape=None):
Expand Down