Skip to content

Commit

Permalink
RCAL-864: fix numpy 2.0 issues with bitflags in resample (spacetelesc…
Browse files Browse the repository at this point in the history
…ope#1383)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: zacharyburnett <zburnett@stsci.edu>
  • Loading branch information
3 people authored Sep 8, 2024
1 parent 9e2b4d3 commit 908f0f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
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 @@ def build_driz_weight(
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 @@ def build_mask(dqarr, bitvalue):
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(
"'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(
dqarr,
bitvalue,
good_mask_value=1,
dtype=np.uint8,
flag_name_map=pixel,
)
return dqmask


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

0 comments on commit 908f0f9

Please sign in to comment.