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

JP-3768: Fix intermediate issues with non-resampled outlier methods #8853

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 29 additions & 14 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def we_three_sci():
def test_outlier_step_no_outliers(we_three_sci, do_resample, tmp_cwd):
"""Test whole step, no outliers"""
container = ModelContainer(list(we_three_sci))
container[0].var_rnoise[10, 10] = 1E9
pristine = ModelContainer([m.copy() for m in container])
OutlierDetectionStep.call(container, in_memory=True, resample_data=do_resample)

Expand Down Expand Up @@ -261,7 +262,8 @@ def test_outlier_step_base(we_three_sci, tmp_cwd):
assert len(median_files) != 0


def test_outlier_step_spec(tmp_cwd, tmp_path):
@pytest.mark.parametrize('resample', [True, False])
def test_outlier_step_spec(tmp_cwd, tmp_path, resample):
braingram marked this conversation as resolved.
Show resolved Hide resolved
"""Test outlier step for spec data including saving intermediate results."""
output_dir = tmp_path / 'output'
output_dir.mkdir(exist_ok=True)
Expand All @@ -274,18 +276,25 @@ def test_outlier_step_spec(tmp_cwd, tmp_path):
# Make it an exposure type outlier detection expects
miri_cal.meta.exposure.type = "MIR_LRS-FIXEDSLIT"

# Make a couple copies, give them unique exposure numbers and filename
container = ModelContainer([miri_cal, miri_cal.copy(), miri_cal.copy()])
for i, model in enumerate(container):
model.meta.filename = f'test_{i}_cal.fits'
def make_input():
# Make a couple copies, give them unique exposure numbers and filename
container = ModelContainer([miri_cal.copy(), miri_cal.copy(), miri_cal.copy()])
for i, model in enumerate(container):
model.meta.filename = f'test_{i}_cal.fits'

# Drop a CR on the science array in the first image
container[0].data[209, 37] += 1
# Drop a CR on the science array in the first image
container[0].data[209, 37] += 1

return container

# Verify that intermediate files are removed when not saved
# (s2d files are expected, i2d files are not, but we'll check
# for them to make sure the imaging extension didn't creep back in)
OutlierDetectionStep.call(container, output_dir=output_dir, save_results=True)
# If resampling, s2d files are expected, i2d files are not,
# but we'll check for them to make sure the imaging extension
# didn't creep back in.
container = make_input()
OutlierDetectionStep.call(container,
output_dir=output_dir, save_results=True,
resample_data=resample)
for dirname in [output_dir, tmp_cwd]:
result_files = glob(os.path.join(dirname, '*outlierdetectionstep.fits'))
i2d_files = glob(os.path.join(dirname, '*i2d*.fits'))
Expand All @@ -306,9 +315,10 @@ def test_outlier_step_spec(tmp_cwd, tmp_path):
assert len(result_files) == 0

# Call again, but save intermediate to the output path
container = make_input()
result = OutlierDetectionStep.call(
container, save_results=True, save_intermediate_results=True,
output_dir=output_dir
output_dir=output_dir, resample_data=resample
)

# Make sure nothing changed in SCI array
Expand All @@ -331,8 +341,13 @@ def test_outlier_step_spec(tmp_cwd, tmp_path):
assert len(result_files) == len(container)

# s2d, median, and blot files are written to the output directory
assert len(s2d_files) == len(container)
assert len(blot_files) == len(container)
if resample:
assert len(s2d_files) == len(container)
assert len(blot_files) == len(container)
else:
assert len(s2d_files) == 0
assert len(blot_files) == 0

assert len(median_files) == 1

# i2d files not written
Expand Down Expand Up @@ -674,4 +689,4 @@ def make_resamp(input_models):
asn_id="test",
allowed_memory=None,
)
return resamp
return resamp
14 changes: 6 additions & 8 deletions jwst/outlier_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ def median_without_resampling(input_models,
with input_models:
for i in range(len(input_models)):

drizzled_model = input_models.borrow(i)
input_model = input_models.borrow(i)
drizzled_model = copy.deepcopy(input_model)
braingram marked this conversation as resolved.
Show resolved Hide resolved
input_models.shelve(input_model, i, modify=False)

drizzled_model.wht = build_driz_weight(drizzled_model,
weight_type=weight_type,
good_bits=good_bits)
weight_type=weight_type,
good_bits=good_bits)
median_wcs = copy.deepcopy(drizzled_model.meta.wcs)
input_models.shelve(drizzled_model, i, modify=True)

if save_intermediate_results:
# write the drizzled model to file
_fileio.save_drizzled(drizzled_model, make_output_path)

if i == 0:
input_shape = (ngroups,)+drizzled_model.data.shape
Expand Down
Loading