Skip to content

Commit 414fef0

Browse files
authored
Use nanmedian3D for TSO data in outlier detection (#8859)
1 parent 3928807 commit 414fef0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

jwst/outlier_detection/tests/test_outlier_detection.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,13 @@ def test_outlier_step_image_weak_cr_coron(exptype, tsovisit, tmp_cwd):
553553

554554

555555
@pytest.mark.parametrize("exptype, tsovisit", exptypes_tso)
556-
def test_outlier_step_weak_cr_tso(exptype, tsovisit):
556+
@pytest.mark.parametrize("rolling_window_width", [7, 0])
557+
def test_outlier_step_weak_cr_tso(exptype, tsovisit, rolling_window_width):
557558
'''Test outlier detection with rolling median on time-varying source
558-
This test fails if rolling_window_width is set to 100, i.e., take simple median
559+
This test fails if rolling_window_width is set to 0, i.e., take simple median
559560
'''
560561
bkg = 1.5
561562
sig = 0.02
562-
rolling_window_width = 7
563563
numsci = 50
564564
signal = 7.0
565565
im = we_many_sci(
@@ -588,8 +588,13 @@ def test_outlier_step_weak_cr_tso(exptype, tsovisit):
588588
assert np.all(np.isnan(result.data[i][dnu]))
589589
assert np.allclose(model.data[~dnu], result.data[i][~dnu])
590590

591-
# Verify source is not flagged
592-
assert np.all(result.dq[:, 7, 7] == datamodels.dqflags.pixel["GOOD"])
591+
# Verify source is not flagged for rolling median
592+
if rolling_window_width == 7:
593+
assert np.all(result.dq[:, 7, 7] == datamodels.dqflags.pixel["GOOD"])
594+
# But this fails for simple median
595+
elif rolling_window_width == 0:
596+
with pytest.raises(AssertionError):
597+
assert np.all(result.dq[:, 7, 7] == datamodels.dqflags.pixel["GOOD"])
593598

594599
# Verify CR is flagged
595600
assert result.dq[cr_timestep, 12, 12] == OUTLIER_DO_NOT_USE

jwst/outlier_detection/tso.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jwst import datamodels as dm
55

66
from stcal.outlier_detection.utils import compute_weight_threshold
7-
from .utils import flag_model_crs
7+
from .utils import flag_model_crs, nanmedian3D
88
from ._fileio import save_median
99

1010
import logging
@@ -41,7 +41,7 @@ def detect_outliers(
4141
medians = compute_rolling_median(weighted_cube, weight_threshold, w=rolling_window_width)
4242

4343
else:
44-
medians = np.nanmedian(weighted_cube.data, axis=0)
44+
medians = nanmedian3D(weighted_cube.data, overwrite_input=False)
4545
# this is a 2-D array, need to repeat it into the time axis
4646
# for consistent shape with rolling median case
4747
medians = np.broadcast_to(medians, weighted_cube.shape)

0 commit comments

Comments
 (0)