Skip to content

Commit

Permalink
changelog; flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
mcara committed Oct 12, 2024
1 parent 9267a3a commit d288e1a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
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.
7 changes: 1 addition & 6 deletions jwst/resample/gwcs_drizzle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from drizzle import cdrizzle, utils
from drizzle import cdrizzle
from . import resample_utils

import logging
Expand Down Expand Up @@ -380,13 +380,8 @@ def dodrizzle(insci, input_wcs, inwht, output_wcs, outsci, outwht, outcon,

# Compute the mapping between the input and output pixel coordinates
# for use in drizzle.cdrizzle.tdriz

# pixmap = utils.calc_pixmap(input_wcs, output_wcs)
pixmap = resample_utils.calc_gwcs_pixmap(input_wcs, output_wcs, insci.shape)

# inwht[np.isnan(pixmap[:,:,0])] = 0.

print(f"Pixmap shape: {pixmap.shape}")
log.debug(f"Pixmap shape: {pixmap[:,:,0].shape}")
log.debug(f"Input Sci shape: {insci.shape}")
log.debug(f"Output Sci shape: {outsci.shape}")
Expand Down
35 changes: 20 additions & 15 deletions jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def __init__(self, input_models, output=None, single=False, blendheaders=True,
output_pix_area * np.rad2deg(3600)**2
)


def do_drizzle(self, input_models):
"""Pick the correct drizzling mode based on self.single
"""
Expand Down Expand Up @@ -357,7 +356,7 @@ def resample_many_to_many(self, input_models):
# build ModelLibrary as an association from the output files
# this saves memory if there are multiple groups
asn = asn_from_list(output_models, product_name='outlier_i2d')
asn_dict = json.loads(asn.dump()[1]) # serializes the asn and converts to dict
asn_dict = json.loads(asn.dump()[1]) # serializes the asn and converts to dict

Check warning on line 359 in jwst/resample/resample.py

View check run for this annotation

Codecov / codecov/patch

jwst/resample/resample.py#L359

Added line #L359 was not covered by tests
return ModelLibrary(asn_dict, on_disk=True)
# otherwise just build it as a list of in-memory models
return ModelLibrary(output_models, on_disk=False)
Expand Down Expand Up @@ -397,9 +396,11 @@ def resample_many_to_one(self, input_models):
log.debug(f'Using intensity scale iscale={iscale}')
img.meta.iscale = iscale

inwht = resample_utils.build_driz_weight(img,
weight_type=self.weight_type,
good_bits=self.good_bits)
inwht = resample_utils.build_driz_weight(
img,
weight_type=self.weight_type,
good_bits=self.good_bits,
)
# apply sky subtraction
blevel = img.meta.background.level
if not img.meta.background.subtracted and blevel is not None:
Expand Down Expand Up @@ -446,14 +447,13 @@ def resample_many_to_one(self, input_models):

return ModelLibrary([output_model,], on_disk=False)


def resample_variance_arrays(self, output_model, input_models):
"""Resample variance arrays from input_models to the output_model.
Variance images from each input model are resampled individually and
added to a weighted sum. If weight_type is 'ivm', the inverse of the
added to a weighted sum. If ``weight_type`` is 'ivm', the inverse of the
resampled read noise variance is used as the weight for all the variance
components. If weight_type is 'exptime', the exposure time is used.
components. If ``weight_type`` is 'exptime', the exposure time is used.
The output_model is modified in place.
"""
Expand Down Expand Up @@ -493,8 +493,10 @@ def resample_variance_arrays(self, output_model, input_models):
if rn_var is not None:
mask = (rn_var >= 0) & np.isfinite(rn_var) & (weight > 0)
weighted_rn_var[mask] = np.nansum(
[weighted_rn_var[mask],
rn_var[mask] * weight[mask] * weight[mask]],
[
weighted_rn_var[mask],
rn_var[mask] * weight[mask] * weight[mask]
],
axis=0
)
total_weight_rn_var[mask] += weight[mask]
Expand All @@ -506,8 +508,10 @@ def resample_variance_arrays(self, output_model, input_models):
if pn_var is not None:
mask = (pn_var >= 0) & np.isfinite(pn_var) & (weight > 0)
weighted_pn_var[mask] = np.nansum(
[weighted_pn_var[mask],
pn_var[mask] * weight[mask] * weight[mask]],
[
weighted_pn_var[mask],
pn_var[mask] * weight[mask] * weight[mask]
],
axis=0
)
total_weight_pn_var[mask] += weight[mask]
Expand All @@ -517,8 +521,10 @@ def resample_variance_arrays(self, output_model, input_models):
if flat_var is not None:
mask = (flat_var >= 0) & np.isfinite(flat_var) & (weight > 0)
weighted_flat_var[mask] = np.nansum(
[weighted_flat_var[mask],
flat_var[mask] * weight[mask] * weight[mask]],
[
weighted_flat_var[mask],
flat_var[mask] * weight[mask] * weight[mask]
],
axis=0
)
total_weight_flat_var[mask] += weight[mask]
Expand Down Expand Up @@ -549,7 +555,6 @@ def resample_variance_arrays(self, output_model, input_models):
del weighted_rn_var, weighted_pn_var, weighted_flat_var
del total_weight_rn_var, total_weight_pn_var, total_weight_flat_var


def _resample_one_variance_array(self, name, input_model, output_model):
"""Resample one variance image from an input model.
Expand Down
3 changes: 1 addition & 2 deletions jwst/resample/resample_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
from astropy import units as u
import gwcs
from drizzle.utils import calc_pixmap

from stdatamodels.dqflags import interpret_bit_flags
Expand Down Expand Up @@ -125,7 +124,7 @@ def shape_from_bounding_box(bounding_box):
def calc_gwcs_pixmap(in_wcs, out_wcs, shape=None):
""" Return a pixel grid map from input frame to output frame.
"""
if shape and not np.array_equiv(shape, in_wcs.array_shape):
if shape is not None and not np.array_equiv(shape, in_wcs.array_shape):
in_wcs = deepcopy(in_wcs)
in_wcs.array_shape = shape

Expand Down

0 comments on commit d288e1a

Please sign in to comment.