Skip to content

Commit

Permalink
JP-1657: Make ivm default weight_type for resample (#5738)
Browse files Browse the repository at this point in the history
* Make ivm default weight_type for resample

* Remove CRDS printing from Jenkinsfiles

* Make outlier_detection use ivm

* Handle the case where there's no var_rnoise

* Add tests for build_driz_weight

* Issue warning when var_rnoise doesn't exist
  • Loading branch information
jdavies-st authored Feb 25, 2021
1 parent e9eb1d4 commit 3057780
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 107 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ associations

- Constraint added to Asn_Lv3Coron to remove background exposures [#5781]

resample
--------

- Make inverse variance ``weight_type="ivm"`` the default weighting scheme for
multiple exposures resampled into a single output. [#5738]


1.0.0 (2021-02-22)
==================
Expand Down
1 change: 0 additions & 1 deletion JenkinsfileRT
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ bc0.build_cmds = [
"pip install -e .[test,ephem]",
"pip install pytest-xdist pytest-sugar",
"pip freeze",
'echo "CRDS_CONTEXT = $(crds list --contexts $CRDS_CONTEXT --mappings | grep pmap)"',
]
bc0.build_cmds = PipInject(env.OVERRIDE_REQUIREMENTS) + bc0.build_cmds
bc0.test_cmds = [
Expand Down
1 change: 0 additions & 1 deletion JenkinsfileRT_dev
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ bc0.build_cmds = [
"pip install -e .[test,ephem]",
"pip install pytest-xdist pytest-sugar",
"pip freeze",
'echo "CRDS_CONTEXT = $(crds list --contexts $CRDS_CONTEXT --mappings | grep pmap)"',
]
bc0.build_cmds = PipInject(env.OVERRIDE_REQUIREMENTS) + bc0.build_cmds
bc0.test_cmds = [
Expand Down
2 changes: 1 addition & 1 deletion jwst/datamodels/schemas/core.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ properties:
weight_type:
title: Type of drizzle weighting to use in resampling input
type: string
enum: [exptime, error]
enum: [exptime, ivm]
fits_keyword: RESWHT
background:
title: Background information
Expand Down
4 changes: 2 additions & 2 deletions jwst/outlier_detection/outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _convert_inputs(self):
dq=self.inputs.dq[i])
image.meta = self.inputs.meta
image.wht = build_driz_weight(image,
weight_type='exptime',
weight_type='ivm',
good_bits=bits)
self.input_models.append(image)
self.converted = True
Expand Down Expand Up @@ -202,7 +202,7 @@ def do_detection(self):
for i in range(len(self.input_models)):
drizzled_models[i].wht = build_driz_weight(
self.input_models[i],
weight_type='exptime',
weight_type='ivm',
good_bits=pars['good_bits'])

# Initialize intermediate products used in the outlier detection
Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection_scaled.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def do_detection(self):
for image in self.input_models:
image.wht = resample_utils.build_driz_weight(
image,
weight_type='exptime',
weight_type='ivm',
good_bits=pars['good_bits']
)

Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection_scaled_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OutlierDetectionScaledStep(Step):
"""

spec = """
weight_type = option('exptime','error',None,default='exptime')
weight_type = option('ivm','exptime',default='ivm')
pixfrac = float(default=1.0)
kernel = string(default='square') # drizzle kernel
fillval = string(default='INDEF')
Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def do_detection(self):
for i in range(len(self.input_models)):
drizzled_models[i].wht = resample_utils.build_driz_weight(
self.input_models[i],
weight_type='exptime',
weight_type='ivm',
good_bits=pars['good_bits'])

# Initialize intermediate products used in the outlier detection
Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection_stack_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OutlierDetectionStackStep(Step):
"""

spec = """
weight_type = option('exptime','error',None,default='exptime')
weight_type = option('ivm','exptime',default='ivm')
pixfrac = float(default=1.0)
kernel = string(default='square') # drizzle kernel
fillval = string(default='INDEF')
Expand Down
2 changes: 1 addition & 1 deletion jwst/outlier_detection/outlier_detection_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OutlierDetectionStep(Step):
# by the various versions of the outlier_detection algorithms, and each
# version will pick and choose what they need while ignoring the rest.
spec = """
weight_type = option('exptime','error',None,default='exptime')
weight_type = option('ivm','exptime',default='ivm')
pixfrac = float(default=1.0)
kernel = string(default='square') # drizzle kernel
fillval = string(default='INDEF')
Expand Down
58 changes: 11 additions & 47 deletions jwst/resample/gwcs_drizzle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

from drizzle import util
from drizzle import doblot
from drizzle import cdrizzle
from . import resample_utils

Expand All @@ -13,9 +12,8 @@ class GWCSDrizzle:
"""
Combine images using the drizzle algorithm
"""
def __init__(self, product, outwcs=None, single=False,
wt_scl="exptime", pixfrac=1.0, kernel="square",
fillval="INDEF"):
def __init__(self, product, outwcs=None, single=False, wt_scl=None,
pixfrac=1.0, kernel="square", fillval="INDEF"):
"""
Create a new Drizzle output object and set the drizzle parameters.
Expand All @@ -33,10 +31,10 @@ def __init__(self, product, outwcs=None, single=False,
provided, the WCS is taken from product.
wt_scl : str, optional
How each input image should be scaled. The choices are `exptime`
which scales each image by its exposure time, `expsq` which scales
each image by the exposure time squared, or an empty string, which
allows each input image to be scaled individually.
How each input image should be scaled. The choices are `exptime`,
which scales each image by its exposure time, or `expsq`, which scales
each image by the exposure time squared. If not set, then each
input image is scaled by its own weight map.
pixfrac : float, optional
The fraction of a pixel that the pixel flux is confined to. The
Expand Down Expand Up @@ -64,7 +62,10 @@ def __init__(self, product, outwcs=None, single=False,
self.outexptime = 0.0
self.uniqid = 0

self.wt_scl = wt_scl
if wt_scl is None:
self.wt_scl = ""
else:
self.wt_scl = wt_scl
self.kernel = kernel
self.fillval = fillval
self.pixfrac = pixfrac
Expand All @@ -90,23 +91,14 @@ def __init__(self, product, outwcs=None, single=False,
self.outcon = np.reshape(self.outcon, (1,
self.outcon.shape[0],
self.outcon.shape[1]))

elif self.outcon.ndim == 3:
pass

else:
elif self.outcon.ndim != 3:
raise ValueError("Drizzle context image has wrong dimensions: \
{0}".format(product))

# Check field values
if not self.outwcs:
raise ValueError("Either an existing file or wcs must be supplied")

if util.is_blank(self.wt_scl):
self.wt_scl = ''
elif self.wt_scl != "exptime" and self.wt_scl != "expsq":
raise ValueError("Illegal value for wt_scl: %s" % self.wt_scl)

if out_units == "counts":
np.divide(self.outsci, self.outexptime, self.outsci)
elif out_units != "cps":
Expand Down Expand Up @@ -199,34 +191,6 @@ def add_image(self, insci, inwcs, inwht=None, xmin=0, xmax=0, ymin=0, ymax=0,
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
pixfrac=self.pixfrac, kernel=self.kernel, fillval=self.fillval)

def blot_image(self, blotwcs, interp='poly5', sinscl=1.0):
"""
Resample the output image using an input world coordinate system.
Parameters
----------
blotwcs : wcs
The world coordinate system to resample on.
interp : str, optional
The type of interpolation used in the resampling. The
possible values are "nearest" (nearest neighbor interpolation),
"linear" (bilinear interpolation), "poly3" (cubic polynomial
interpolation), "poly5" (quintic polynomial interpolation),
"sinc" (sinc interpolation), "lan3" (3rd order Lanczos
interpolation), and "lan5" (5th order Lanczos interpolation).
sincscl : float, optional
The scaling factor for sinc interpolation.
"""

util.set_pscale(blotwcs)
self.outsci = doblot.doblot(self.outsci, self.outwcs, blotwcs,
1.0, interp=interp, sinscl=sinscl)

self.outwcs = blotwcs

def increment_id(self):
"""
Increment the id count and add a plane to the context image if needed
Expand Down
7 changes: 3 additions & 4 deletions jwst/resample/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ResampleData:
(eventually) a record of metadata from all input models.
"""
def __init__(self, input_models, output=None, single=False, blendheaders=True,
pixfrac=1.0, kernel="square", fillval="INDEF", weight_type="exptime",
pixfrac=1.0, kernel="square", fillval="INDEF", weight_type="ivm",
good_bits=0, pscale_ratio=1.0, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -147,8 +147,7 @@ def do_drizzle(self):
single=self.single,
pixfrac=self.pixfrac,
kernel=self.kernel,
fillval=self.fillval,
wt_scl=self.weight_type)
fillval=self.fillval)

for n, img_exp in enumerate(exposure):
# Make a copy as this is operated on in-place below
Expand All @@ -165,7 +164,7 @@ def do_drizzle(self):
weight_type=self.weight_type,
good_bits=self.good_bits)
driz.add_image(img.data, img.meta.wcs, inwht=inwht,
expin=img.meta.exposure.exposure_time)
expin=img.meta.exposure.exposure_time)

# Update some basic exposure time values based on all the inputs
output_model.meta.exposure.exposure_time = texptime
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 @@ -46,7 +46,7 @@ class ResampleSpecData:

def __init__(self, input_models, output=None, single=False,
blendheaders=False, pixfrac=1.0, kernel="square", fillval=0,
weight_type="exptime", good_bits=0, pscale_ratio=1.0, **kwargs):
weight_type="ivm", good_bits=0, pscale_ratio=1.0, **kwargs):
"""
Parameters
----------
Expand Down
22 changes: 5 additions & 17 deletions jwst/resample/resample_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ResampleStep(Step):
pixfrac = float(default=1.0)
kernel = string(default='square')
fillval = string(default='INDEF')
weight_type = option('exptime', default='exptime')
weight_type = option('ivm', 'exptime', default='ivm')
pixel_scale_ratio = float(default=1.0) # Ratio of input to output pixel scale
single = boolean(default=False)
blendheaders = boolean(default=True)
Expand Down Expand Up @@ -68,8 +68,8 @@ def process(self, input):
self.log.info('Drizpars reference file: {}'.format(ref_filename))
kwargs = self.get_drizpars(ref_filename, input_models)
else:
# Deal with NIRSpec which currently has no default drizpars reffile
self.log.info("No NIRSpec DIRZPARS reffile")
# If there is no drizpars reffile
self.log.info("No DIRZPARS reffile")
kwargs = self._set_spec_defaults()

kwargs['allowed_memory'] = self.allowed_memory
Expand Down Expand Up @@ -113,7 +113,6 @@ def get_drizpars(self, ref_filename, input_models):
pixfrac = float(default=None)
kernel = string(default=None)
fillval = string(default=None)
weight_type = option('exptime', default=None)
Once the defaults are set from the reference file, if the user has
used a resample.cfg file or run ResampleStep using command line args,
Expand Down Expand Up @@ -148,15 +147,13 @@ def get_drizpars(self, ref_filename, input_models):
self.log.error("No row found in %s matching input data.", ref_filename)
raise ValueError

# Define the keys to pull from drizpars reffile table. Note the
# step param 'weight_type' is 'wht_type' in the FITS binary table.
# Define the keys to pull from drizpars reffile table.
# All values should be None unless the user set them on the command
# line or in the call to the step
drizpars = dict(
pixfrac=self.pixfrac,
kernel=self.kernel,
fillval=self.fillval,
wht_type=self.weight_type,
pscale_ratio=self.pixel_scale_ratio,
)

Expand All @@ -177,9 +174,6 @@ def get_drizpars(self, ref_filename, input_models):

all_drizpars = {**reffile_drizpars, **user_drizpars}

# Convert the 'wht_type' key to a 'weight_type' key
all_drizpars['weight_type'] = all_drizpars.pop('wht_type')

kwargs = dict(
good_bits=GOOD_BITS,
single=self.single,
Expand All @@ -188,12 +182,6 @@ def get_drizpars(self, ref_filename, input_models):

kwargs.update(all_drizpars)

if 'wht_type' in kwargs:
raise DeprecationWarning('`wht_type` config keyword has changed ' +
'to `weight_type`; ' +
'please update calls to ResampleStep and resample.cfg files')
kwargs.pop('wht_type')

for k,v in kwargs.items():
self.log.debug(' {}={}'.format(k, v))

Expand All @@ -220,7 +208,7 @@ def _set_spec_defaults(self):
if kwargs['fillval'] is None:
kwargs['fillval'] = 'INDEF'
if kwargs['weight_type'] is None:
kwargs['weight_type'] = 'exptime'
kwargs['weight_type'] = 'ivm'
kwargs['pscale_ratio'] = self.pixel_scale_ratio
kwargs.pop('pixel_scale_ratio')

Expand Down
Loading

0 comments on commit 3057780

Please sign in to comment.