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

Switch resample to the new drizzle package API #8866

Merged
merged 19 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changes/8866.resample.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated resample code to support the new ``drizzle`` API, see https://github.com/spacetelescope/drizzle/pull/134 for more details.
28 changes: 20 additions & 8 deletions jwst/outlier_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def median_without_resampling(input_models,
in_memory = not input_models._on_disk
ngroups = len(input_models)

if save_intermediate_results:
# create an empty image model for the median data
median_model = datamodels.ImageModel(None)

with input_models:
for i in range(len(input_models)):

Expand All @@ -128,6 +132,10 @@ def median_without_resampling(input_models,
err_computer = MedianComputer(input_shape, in_memory, buffer_size, dtype)
else:
err_computer = None
if save_intermediate_results:
# update median model's meta with meta from the first model:
median_model.update(drizzled_model)
median_model.meta.wcs = median_wcs

weight_threshold = compute_weight_threshold(weight, maskpt)
drizzled_data[weight < weight_threshold] = np.nan
Expand All @@ -137,6 +145,7 @@ def median_without_resampling(input_models,
err_computer.append(drizzled_err, i)

input_models.shelve(drizzled_model, i, modify=False)
del drizzled_model

# Perform median combination on set of drizzled mosaics
median_data = computer.evaluate()
Expand All @@ -147,13 +156,10 @@ def median_without_resampling(input_models,

if save_intermediate_results:
# Save median model to fits
median_model = datamodels.ImageModel(median_data)
median_model.data = median_data
if return_error:
median_model.err = median_err
median_model.update(drizzled_model)
median_model.meta.wcs = median_wcs
_fileio.save_median(median_model, make_output_path)
del drizzled_model

if return_error:
return median_data, median_wcs, median_err
Expand Down Expand Up @@ -219,6 +225,10 @@ def median_with_resampling(input_models,
indices_by_group = list(input_models.group_indices.values())
ngroups = len(indices_by_group)

if save_intermediate_results:
# create an empty image model for the median data
median_model = datamodels.ImageModel(None)

with input_models:
for i, indices in enumerate(indices_by_group):

Expand All @@ -238,13 +248,18 @@ def median_with_resampling(input_models,
err_computer = MedianComputer(input_shape, in_memory, buffer_size, dtype)
else:
err_computer = None
if save_intermediate_results:
# update median model's meta with meta from the first model:
median_model.update(drizzled_model)
median_model.meta.wcs = median_wcs

weight_threshold = compute_weight_threshold(drizzled_model.wht, maskpt)
drizzled_model.data[drizzled_model.wht < weight_threshold] = np.nan
computer.append(drizzled_model.data, i)
if return_error:
drizzled_model.err[drizzled_model.wht < weight_threshold] = np.nan
err_computer.append(drizzled_model.err, i)
del drizzled_model

# Perform median combination on set of drizzled mosaics
median_data = computer.evaluate()
Expand All @@ -255,15 +270,12 @@ def median_with_resampling(input_models,

if save_intermediate_results:
# Save median model to fits
median_model = datamodels.ImageModel(median_data)
median_model.data = median_data
if return_error:
median_model.err = median_err
median_model.update(drizzled_model)
median_model.meta.wcs = median_wcs
# drizzled model already contains asn_id
make_output_path = partial(make_output_path, asn_id=None)
_fileio.save_median(median_model, make_output_path)
del drizzled_model

if return_error:
return median_data, median_wcs, median_err
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 @@ -36,7 +36,7 @@ def test_nirspec_fs_spec3(run_pipeline, rtdata_module, fitsdiff_default_kwargs,
rtdata = rtdata_module

if suffix == "median":
output = f"jw01309022001_04102_00002_nrs2_{slit_name}_{suffix}.fits"
output = f"jw01309022001_04102_00001_nrs2_{slit_name}_{suffix}.fits"
# also ensure drizzled and blot models were created with the correct names
assert os.path.isfile(output.replace("median", "outlier_s2d"))
assert os.path.isfile(output.replace("median", "blot"))
Expand Down
Loading
Loading