Skip to content

Commit

Permalink
adding tests for changes in JP-3311 and minor fixes (#8481)
Browse files Browse the repository at this point in the history
Co-authored-by: Howard Bushouse <bushouse@stsci.edu>
  • Loading branch information
penaguerrero and hbushouse committed May 17, 2024
1 parent 3df35ef commit 4d4f935
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ outlier_detection
finished, unless save_intermediate_results is True. This PR also addressed
the _i2d files not being saved in the specified output directory. [#8464]

- Added tests for changes made in #8464. [#8481]

photom
------

Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def detect_outliers(self, blot_models):
def _remove_file(fn):
if isinstance(fn, str) and os.path.isfile(fn):
os.remove(fn)
log.debug(f" {fn}")
log.info(f"Removing file {fn}")


def flag_cr(sci_image, blot_image, snr="5.0 4.0", scale="1.2 0.7", backg=0,
Expand Down
2 changes: 2 additions & 0 deletions jwst/outlier_detection/outlier_detection_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def do_detection(self):
if not pars['in_memory']:
for fn in drizzled_models._models:
_remove_file(fn)
log.info(f"Removing file {fn}")

if pars['resample_data'] is True:
# Blot the median image back to recreate each input image specified
Expand All @@ -130,4 +131,5 @@ def do_detection(self):
if not pars['save_intermediate_results']:
for fn in blot_models._models:
_remove_file(fn)
log.info(f"Removing file {fn}")
del median_model, blot_models
2 changes: 0 additions & 2 deletions jwst/outlier_detection/outlier_detection_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ def process(self, input_data):

state = 'COMPLETE'
if self.input_container:
if not self.save_intermediate_results:
self.log.debug("The following files will be deleted since save_intermediate_results=False:")
for model in self.input_models:
model.meta.cal_step.outlier_detection = state
else:
Expand Down
20 changes: 19 additions & 1 deletion jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import numpy as np
from scipy.ndimage import gaussian_filter
from glob import glob
import os

from stdatamodels.jwst import datamodels

Expand All @@ -15,7 +17,6 @@
)
from jwst.assign_wcs.pointing import create_fitswcs


OUTLIER_DO_NOT_USE = np.bitwise_or(
datamodels.dqflags.pixel["DO_NOT_USE"], datamodels.dqflags.pixel["OUTLIER"]
)
Expand Down Expand Up @@ -184,6 +185,15 @@ def test_outlier_step(we_three_sci, tmp_cwd):
# Drop a CR on the science array
container[0].data[12, 12] += 1

# Verify that intermediary files are removed
OutlierDetectionStep.call(container)
i2d_files = glob(os.path.join(tmp_cwd, '*i2d.fits'))
median_files = glob(os.path.join(tmp_cwd, '*median.fits'))
blot_files = glob(os.path.join(tmp_cwd, '*blot.fits'))
assert len(i2d_files) == 0
assert len(median_files) == 0
assert len(blot_files) == 0

result = OutlierDetectionStep.call(
container, save_results=True, save_intermediate_results=True
)
Expand All @@ -199,6 +209,14 @@ def test_outlier_step(we_three_sci, tmp_cwd):
# Verify CR is flagged
assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE

# Verify that intermediary files are saved at the specified location
i2d_files = glob(os.path.join(tmp_cwd, '*i2d.fits'))
median_files = glob(os.path.join(tmp_cwd, '*median.fits'))
blot_files = glob(os.path.join(tmp_cwd, '*blot.fits'))
assert len(i2d_files) != 0
assert len(median_files) != 0
assert len(blot_files) != 0


def test_outlier_step_on_disk(we_three_sci, tmp_cwd):
"""Test whole step with an outlier including saving intermediate and results files"""
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_slit_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_miri_lrs_slit_spec3(run_pipeline, rtdata_module, fitsdiff_default_kwarg
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
assert diff.identical, diff.report()

if "s2d" in output:
if output == "s2d":
# Compare the calculated wavelengths
tolerance = 1e-03
dmt = datamodels.open(rtdata.truth)
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_nirspec_fs_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_nirspec_fs_spec3(run_pipeline, rtdata_module, fitsdiff_default_kwargs,
diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
assert diff.identical, diff.report()

if "s2d" in output:
if output == "s2d":
# Compare the calculated wavelengths
tolerance = 1e-03
dmt = datamodels.open(rtdata.truth)
Expand Down
2 changes: 1 addition & 1 deletion jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, input_models, output=None, single=False, blendheaders=True,
self.input_models = input_models
self.output_dir = None
self.output_filename = output
if output is not None and '.fits' not in output:
if output is not None and '.fits' not in str(output):
self.output_dir = output
self.output_filename = None

Expand Down
2 changes: 1 addition & 1 deletion jwst/resample/resample_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, input_models, output=None, single=False, blendheaders=False,

self.output_filename = output
self.output_dir = None
if output is not None and '.fits' not in output:
if output is not None and '.fits' not in str(output):
self.output_dir = output
self.output_filename = None
self.pscale_ratio = pscale_ratio
Expand Down

0 comments on commit 4d4f935

Please sign in to comment.