Skip to content

Commit

Permalink
Merge branch 'master' into release/1.12.x
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Oct 13, 2023
2 parents f43b519 + 69d99a1 commit f80a537
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 62 deletions.
23 changes: 19 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
1.12.3 (unreleased)
1.12.4 (2023-10-12)
===================

cube_build
----------

- Keep data models opened by cube build open until the step completes. [#7998]

general
-------

- Fix numpy 2.0 deprecation warnings in cube_build, photom and wfs_combine. [#7999]

- pinned dependencies for several in-development packages below their next versions to maintain compatibility

1.12.3 (2023-10-03)
===================

documentation
Expand Down Expand Up @@ -41,7 +56,7 @@ extract_1d
flat_field
----------

- Update the ``combine_fast_slow`` function for NIRSpec spectroscopic flats
- Update the ``combine_fast_slow`` function for NIRSpec spectroscopic flats
to use 1D error values provided by F-flat reference files. [#7978]

- For NIRSpec modes, set all DO_NOT_USE pixels to NaN after flat
Expand All @@ -65,7 +80,7 @@ straylight
extract_1d
----------

- For MIRS MRS IFU data allow the user to set the src_type and allow
- For MIRS MRS IFU data allow the user to set the src_type and allow
the user to scale the extraction radius between 0.5 to 3.0 FWHM. [#7883]

- Bug fix for #7883. The input model type is checked to see if the input is
Expand Down Expand Up @@ -245,7 +260,7 @@ pathloss
- Fix interpolation error for point source corrections. [#7799]

- Update the MIRI LRS fixed-slit correction to default to the center of the slit
when the computed target location is outside the slit. Add the parameter
when the computed target location is outside the slit. Add the parameter
"user_slit_loc" to allow specifying the source location to use. [#7806]

photom
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ authors:
given-names: "Maria"
orcid: "https://orcid.org/0000-0003-2314-3453"
title: "JWST Calibration Pipeline"
version: 1.12.2
version: 1.12.4
doi: 10.5281/zenodo.7038885
date-released: 2023-10-02
date-released: 2023-10-12
url: "https://github.com/spacetelescope/jwst"
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ the specified context and less than the context for the next release.

| jwst tag | DMS build | SDP_VER | CRDS_CONTEXT | Released | Ops Install | Notes |
|---------------------|-----------|----------|--------------|------------|-------------|-----------------------------------------------|
| 1.12.2 | B10.0rc3 | 2023.3.x | 1135 | 2023-10-02 | | Third release candidate for B10.0 |
| 1.12.1 | B10.0rc2 | 2023.3.x | 1132 | 2023-09-26 | | Second release candidate for B10.0 |
| 1.12.0 | B10.0rc1 | 2023.3.x | 1130 | 2023-09-18 | | First release candidate for B10.0 |
| 1.11.4 | B9.3.1 | 2023.2.1 | 1107 | 2023-08-14 | | Final release for B9.3.1 patch |
| 1.12.4 | | 2023.3.0 | 1135 | 2023-10-12 | | Pinning dependencies for external users |
| 1.12.3 | B10.0 | 2023.3.0 | 1135 | 2023-10-03 | 2023-12-05 | Final release candidate for B10.0 |
| 1.12.2 | B10.0rc3 | | 1135 | 2023-10-02 | (tentative) | Third release candidate for B10.0 |
| 1.12.1 | B10.0rc2 | | 1132 | 2023-09-26 | | Second release candidate for B10.0 |
| 1.12.0 | B10.0rc1 | | 1130 | 2023-09-18 | | First release candidate for B10.0 |
| 1.11.4 | B9.3.1 | 2023.2.1 | 1107 | 2023-08-14 | 2023-08-24 | Final release for B9.3.1 patch |
| 1.11.3 | B9.3 | 2023.2.0 | 1097 | 2023-07-17 | | Final release candidate for B9.3 |
| 1.11.2 | B9.3rc3 | | 1097 | 2023-07-12 | | Third release candidate for B9.3 |
| 1.11.1 | B9.3rc2 | | 1094 | 2023-06-29 | | Second release candidate for B9.3 |
Expand Down
3 changes: 3 additions & 0 deletions jwst/cube_build/cube_build_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def process(self, input):
# Check for a valid reference file
if par_filename == 'N/A':
self.log.warning('No default cube parameters reference file found')
input_table.close()
return
# ________________________________________________________________________________
# shove the input parameters in to pars to pull out in general cube_build.py
Expand Down Expand Up @@ -299,6 +300,7 @@ def process(self, input):
if instrument == 'MIRI' and self.coord_system == 'internal_cal':
self.log.warning('The output coordinate system of internal_cal is not valid for MIRI')
self.log.warning('use output_coord = ifualign instead')
input_table.close()
return
filenames = master_table.FileMap['filename']

Expand Down Expand Up @@ -402,6 +404,7 @@ def process(self, input):
if status_cube == 1:
self.skip = True

input_table.close()
return cube_container
# ******************************************************************************

Expand Down
50 changes: 30 additions & 20 deletions jwst/cube_build/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ def __init__(self, input, single, output_file, output_dir):

self.input_models = []
self.output_name = None

# open the input with datamodels
# if input is filename or model when it is opened it is a model
# if input if an association name or ModelContainer then it is opened as a container

with datamodels.open(input) as input_models:

if isinstance(input_models, datamodels.IFUImageModel):
# It's a single image that's been passed in as a model
# input is a model
filename = input_models.meta.filename
self.input_models.append(input_models)
self.output_name = self.build_product_name(filename)

elif isinstance(input_models, ModelContainer):
self.output_name = 'Temp'
self.input_models = input_models
if not single: # find the name of the output file from the association
self.output_name = input_models.meta.asn_table.products[0].name
else:
raise TypeError("Failed to process file type {}".format(type(input_models)))
# if the user has set the output name - strip out *.fits
# later suffixes will be added to this name to designate the
# channel, subchannel or grating,filter the data is covers.
input_models = datamodels.open(input)
# if input is a filename, we will need to close the opened file
self._opened = [input_models]

if isinstance(input_models, datamodels.IFUImageModel):
# It's a single image that's been passed in as a model
# input is a model
filename = input_models.meta.filename
self.input_models.append(input_models)
self.output_name = self.build_product_name(filename)

elif isinstance(input_models, ModelContainer):
self.output_name = 'Temp'
self.input_models = input_models
if not single: # find the name of the output file from the association
self.output_name = input_models.meta.asn_table.products[0].name
else:
# close files opened above
self.close()
raise TypeError("Failed to process file type {}".format(type(input_models)))
# If the user has set the output name, strip off *.fits.
# Suffixes will be added to this name later, to designate the
# channel+subchannel (MIRI MRS) or grating+filter (NRS IFU) the output cube covers.


if output_file is not None:
Expand All @@ -102,6 +106,12 @@ def __init__(self, input, single, output_file, output_dir):
if output_dir is not None:
self.output_name = output_dir + '/' + self.output_name

def close(self):
"""
Close any files opened by this instance
"""
[f.close() for f in self._opened]

# _______________________________________________________________________________
def build_product_name(self, filename):
""" Determine the base of output name if an input data is a fits filename.
Expand Down
4 changes: 0 additions & 4 deletions jwst/cube_build/file_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def set_file_table(self,
# ________________________________________________________________________________
# Loop over input list of files and assign fill in the MasterTable with filename
# for the correct (channel-subchannel) or (grating-subchannel)

for model in input_models:
instrument = model.meta.instrument.name.upper()
assign_wcs = model.meta.cal_step.assign_wcs
Expand Down Expand Up @@ -143,9 +142,6 @@ def set_file_table(self,
log.info('Instrument not valid for cube')
pass

model.close()
del model

return instrument


Expand Down
6 changes: 3 additions & 3 deletions jwst/cube_build/ifu_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ def set_geometry(self, corner_a, corner_b, lambda_min, lambda_max):
xilimit = max(np.abs(xi_min), np.abs(xi_max))
etalimit = max(np.abs(eta_min), np.abs(eta_max))

na = math.ceil(xilimit / self.cdelt1) + 1
nb = math.ceil(etalimit / self.cdelt2) + 1
na = math.ceil((xilimit / self.cdelt1).item()) + 1
nb = math.ceil((etalimit / self.cdelt2).item()) + 1

# if the user set the nspax_x or nspax_y then redefine na, nb
# it is assumed that both values are ODD numbers
# We want the central pixel to be the tangent point with na/nb pixels on either
# side of central pixel.
# side of central pixel.
if self.nspax_x is not None:
na = int(self.nspax_x/2)
if self.nspax_y is not None:
Expand Down
62 changes: 58 additions & 4 deletions jwst/cube_build/tests/test_cube_build_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import pytest
from astropy.io import fits

from gwcs import WCS
from stdatamodels.jwst.datamodels import IFUImageModel

from jwst import assign_wcs
from jwst.cube_build import CubeBuildStep
from jwst.cube_build.file_table import ErrorNoAssignWCS
from jwst.cube_build.cube_build import ErrorNoChannels
Expand Down Expand Up @@ -100,8 +102,15 @@ def miri_image():
return image


def test_call_cube_build(_jail, miri_cube_pars, miri_image):
@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build(_jail, miri_cube_pars, miri_image, tmp_path, as_filename):
""" test defaults of step are set up and user input are defined correctly """
if as_filename:
fn = tmp_path / 'miri.fits'
miri_image.save(fn)
step_input = fn
else:
step_input = miri_image

# we do not want to run the CubeBuild through to completion because
# the image needs to be a full image and this take too much time
Expand All @@ -112,7 +121,7 @@ def test_call_cube_build(_jail, miri_cube_pars, miri_image):
step = CubeBuildStep()
step.override_cubepar = miri_cube_pars
step.channel = '3'
step.run(miri_image)
step.run(step_input)

# Test some defaults to step are setup correctly and
# is user specifies channel is set up correctly
Expand All @@ -121,7 +130,7 @@ def test_call_cube_build(_jail, miri_cube_pars, miri_image):
step.channel = '1'

try:
step.run(miri_image)
step.run(step_input)
except ErrorNoAssignWCS:
pass

Expand All @@ -132,8 +141,53 @@ def test_call_cube_build(_jail, miri_cube_pars, miri_image):

# Set Assign WCS has been run but the user input to channels is wrong
miri_image.meta.cal_step.assign_wcs = 'COMPLETE'
# save file with modifications
if as_filename:
miri_image.save(step_input)
with pytest.raises(ErrorNoChannels):
step = CubeBuildStep()
step.override_cubepar = miri_cube_pars
step.channel = '3'
step.run(miri_image)
step.run(step_input)


@pytest.fixture(scope='function')
def nirspec_data():
image = IFUImageModel((2048, 2048))
image.data = np.random.random((2048, 2048))
image.meta.instrument.name = 'NIRSPEC'
image.meta.instrument.detector = 'NRS1'
image.meta.exposure.type = 'NRS_IFU'
image.meta.filename = 'test_nirspec.fits'
image.meta.observation.date = '2023-10-06'
image.meta.observation.time = '00:00:00.000'
# below values taken from regtest using file
# jw01249005001_03101_00004_nrs1_cal.fits
image.meta.instrument.filter = 'F290LP'
image.meta.instrument.grating = 'G395H'
image.meta.wcsinfo.v2_ref = 299.83548
image.meta.wcsinfo.v3_ref = -498.256805
image.meta.wcsinfo.ra_ref = 358.0647567841019
image.meta.wcsinfo.dec_ref = -2.167207258876695
image.meta.cal_step.assign_wcs = 'COMPLETE'
step = assign_wcs.assign_wcs_step.AssignWcsStep()
refs = {}
for reftype in assign_wcs.assign_wcs_step.AssignWcsStep.reference_file_types:
refs[reftype] = step.get_reference_file(image, reftype)
pipe = assign_wcs.nirspec.create_pipeline(image, refs, slit_y_range=[-.5, .5])
image.meta.wcs = WCS(pipe)
return image


@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build_nirspec(_jail, nirspec_data, tmp_path, as_filename):
if as_filename:
fn = tmp_path / 'test_nirspec.fits'
nirspec_data.save(fn)
step_input = fn
else:
step_input = nirspec_data
step = CubeBuildStep()
step.channel = '1'
step.coord_system = 'internal_cal'
step.run(step_input)
12 changes: 6 additions & 6 deletions jwst/cube_build/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def test_coord_trans1():
# and an eta close to diff_dec

xi, eta = coord.radec2std(crval1, crval2, ra, dec)
assert math.isclose(xi, 0.0, abs_tol=0.001)
assert math.isclose(eta, diff_ra, abs_tol=0.001)
assert math.isclose(xi.item(), 0.0, abs_tol=0.001)
assert math.isclose(eta.item(), diff_ra, abs_tol=0.001)


def test_coord_trans2():
Expand All @@ -101,8 +101,8 @@ def test_coord_trans2():
# and an eta close to diff_dec

xi, eta = coord.radec2std(crval1, crval2, ra, dec)
assert math.isclose(xi, -3.535, abs_tol=0.001)
assert math.isclose(eta, diff_ra, abs_tol=0.001)
assert math.isclose(xi.item(), -3.535, abs_tol=0.001)
assert math.isclose(eta.item(), diff_ra, abs_tol=0.001)


def test_coord_trans3():
Expand All @@ -120,8 +120,8 @@ def test_coord_trans3():

xi, eta = coord.radec2std(crval1, crval2, ra, dec)
ra_test, dec_test = coord.std2radec(crval1, crval2, xi, eta)
assert math.isclose(ra, ra_test, abs_tol=0.00001)
assert math.isclose(dec, dec_test, abs_tol=0.00001)
assert math.isclose(ra, ra_test.item(), abs_tol=0.00001)
assert math.isclose(dec, dec_test.item(), abs_tol=0.00001)


def test_wrap_ra():
Expand Down
4 changes: 2 additions & 2 deletions jwst/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def calc_miri(self, ftab):
# Old style ref file; skip the correction
log.info("Skipping MRS MIRI time correction. Extensions not found in the reference file.")
self.mrs_time_correction = False

#if np.any(ftab.timecoeff_ch1['binwave']) and self.mrs_time_correction:
if self.mrs_time_correction:
log.info("Applying MRS IFU time dependent correction.")
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def save_area_nirspec(self, pix_area):
slit.meta.photometry.pixelarea_arcsecsq = 1.
slit.meta.photometry.pixelarea_steradians = 1.
else:
slit.meta.photometry.pixelarea_arcsecsq = float(pixarea[match])
slit.meta.photometry.pixelarea_arcsecsq = float(pixarea[match].item())
slit.meta.photometry.pixelarea_steradians = \
slit.meta.photometry.pixelarea_arcsecsq * A2_TO_SR
if n_failures > 0:
Expand Down
Loading

0 comments on commit f80a537

Please sign in to comment.