From b94a02ebd398781b6fa4249bbf4d346aab304285 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 10 Oct 2024 10:03:27 -0400 Subject: [PATCH 1/3] Fix for roman numpy 2 issue --- src/stcal/saturation/saturation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stcal/saturation/saturation.py b/src/stcal/saturation/saturation.py index a2797470a..c607c64a5 100644 --- a/src/stcal/saturation/saturation.py +++ b/src/stcal/saturation/saturation.py @@ -63,10 +63,10 @@ def flag_saturated_pixels( updated pixel dq array """ nints, ngroups, nrows, ncols = data.shape - dnu = dqflags["DO_NOT_USE"] - saturated = dqflags["SATURATED"] - ad_floor = dqflags["AD_FLOOR"] - no_sat_check = dqflags["NO_SAT_CHECK"] + dnu = int(dqflags["DO_NOT_USE"]) + saturated = int(dqflags["SATURATED"]) + ad_floor = int(dqflags["AD_FLOOR"]) + no_sat_check = int(dqflags["NO_SAT_CHECK"]) # Identify pixels flagged in reference file as NO_SAT_CHECK, no_sat_check_mask = np.bitwise_and(sat_dq, no_sat_check) == no_sat_check From 12f1f79c5fd220ae73ae25a2a36665880feda55f Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 10 Oct 2024 10:29:04 -0400 Subject: [PATCH 2/3] Add tests --- tests/test_saturation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_saturation.py b/tests/test_saturation.py index fb207f776..cc1465a39 100644 --- a/tests/test_saturation.py +++ b/tests/test_saturation.py @@ -3,6 +3,7 @@ Unit tests for saturation flagging """ +from enum import IntEnum import numpy as np @@ -227,3 +228,27 @@ def test_zero_frame(): # Check ZEROFRAME flagged elements are zeroed out. assert zframe[0, 0, 0] == 0.0 assert zframe[1, 0, 1] == 0.0 + + +def test_intenum_flags(): + """ + In numpy 2.0 IntEnums induce a failure in bitwise_or. Romancal uses IntEnums + for clarity rather than raw dictionaries of integers + """ + + class DqFlags(IntEnum): + GOOD = 0 + DO_NOT_USE = 1 + SATURATED = 2 + AD_FLOOR = 64 + NO_SAT_CHECK = 2**21 + + # Create inputs, data, and saturation maps + data = np.zeros((1, 5, 20, 20), dtype=np.float32) + gdq = np.zeros((1, 5, 20, 20), dtype=np.uint32) + pdq = np.zeros((20, 20), dtype=np.uint32) + sat_thresh = np.ones((20, 20)) * 100000.0 + sat_dq = np.zeros((20, 20), dtype=np.uint32) + + # Simple test to check no errors are raised + _ = flag_saturated_pixels(data, gdq, pdq, sat_thresh, sat_dq, ATOD_LIMIT, DqFlags) From c9b926c58a656ef5c93d26bc987b107b7465101a Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 10 Oct 2024 10:36:50 -0400 Subject: [PATCH 3/3] Add changelog --- changes/305.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/305.bugfix.rst diff --git a/changes/305.bugfix.rst b/changes/305.bugfix.rst new file mode 100644 index 000000000..6f8471937 --- /dev/null +++ b/changes/305.bugfix.rst @@ -0,0 +1 @@ +Fix `IntEnum` saturation flag issue with numpy 2+ for romancal.