Skip to content

Commit

Permalink
changelog; flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
mcara committed Oct 9, 2024
1 parent 1b103ee commit c07be38
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
14 changes: 12 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
1.16.1 (unreleased)
===================

resample
--------

- Updated resample code to support the new ``drizzle`` API, see
https://github.com/spacetelescope/drizzle/pull/134 for more details. [#8866]


1.16.0 (2024-09-20)
===================

Expand Down Expand Up @@ -43,7 +53,7 @@ associations
- Excluded nearby background candidates from NIRSpec fixed slit associations
for S1600A1 with 5 point dithers, to reduce overlap between background nods
and science exposure. [#8744]

- Added association rule for level 3 image mosaic candidates. [#8798]

badpix_selfcal
Expand Down Expand Up @@ -274,7 +284,7 @@ pipeline
optional `on_disk` parameter to govern whether models in the library should be stored
in memory or on disk. [#8683]

- Updated ``calwebb_spec2`` to run ``nsclean`` on NIRSpec imprint and background
- Updated ``calwebb_spec2`` to run ``nsclean`` on NIRSpec imprint and background
association members. [#8786, #8809]

- Updated `calwebb_spec3` to not save the `pixel_replacement` output by default.[#8765]
Expand Down
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
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 c07be38

Please sign in to comment.