Skip to content
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/10464.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove usages of the schema-undefined model.meta.wcsinfo for MultiSlitModel types and use wcsinfo from the model's member slits instead
1 change: 1 addition & 0 deletions changes/10464.pipeline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add S_REGION to output MultiSlitModel products in spec2pipeline for WFSS modes
34 changes: 22 additions & 12 deletions jwst/assign_mtwcs/moving_target_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ def assign_moving_target_wcs(input_models):
# map index in science_indices to index in mt_ra/mt_dec arrays
# mt_ra, mt_dec have length equal to number of science exposures
j = science_indices.index(i)
mt_ra[j] = meta["meta"]["wcsinfo"]["mt_ra"]
mt_dec[j] = meta["meta"]["wcsinfo"]["mt_dec"]
if "slits" in meta:
# if it's a MultiSlitModel take this from the 0th slit
slit = meta["slits"][0]
mt_ra[j] = slit["meta"]["wcsinfo"]["mt_ra"]
mt_dec[j] = slit["meta"]["wcsinfo"]["mt_dec"]
else:
mt_ra[j] = meta["meta"]["wcsinfo"]["mt_ra"]
mt_dec[j] = meta["meta"]["wcsinfo"]["mt_dec"]

# Compute the mean MT RA/Dec over all exposures
if not mt_valid:
Expand All @@ -72,8 +78,6 @@ def assign_moving_target_wcs(input_models):
with input_models:
for i in science_indices:
model = input_models.borrow(i)
model.meta.wcsinfo.mt_avra = mt_avra
model.meta.wcsinfo.mt_avdec = mt_avdec
if isinstance(model, datamodels.MultiSlitModel):
for ind, slit in enumerate(model.slits):
new_wcs = add_mt_frame(
Expand All @@ -85,6 +89,8 @@ def assign_moving_target_wcs(input_models):
)
del model.slits[ind].meta.wcs
model.slits[ind].meta.wcs = new_wcs
model.slits[ind].meta.wcsinfo.mt_avra = mt_avra
model.slits[ind].meta.wcsinfo.mt_avdec = mt_avdec
else:
new_wcs = add_mt_frame(
model.meta.wcs,
Expand All @@ -95,6 +101,8 @@ def assign_moving_target_wcs(input_models):
)
del model.meta.wcs
model.meta.wcs = new_wcs
model.meta.wcsinfo.mt_avra = mt_avra
model.meta.wcsinfo.mt_avdec = mt_avdec
if model.meta.exposure.type.lower() in IMAGING_TYPES:
update_s_region_imaging(model)
record_step_status(model, "assign_mtwcs", True)
Expand Down Expand Up @@ -162,14 +170,16 @@ def _is_mt_meta_valid(meta):
bool
True if valid, False otherwise.
"""
# check all the slits
for slit in meta.get("slits", []):
if (
slit["meta"]["wcsinfo"].get("mt_ra", None) is None
or slit["meta"]["wcsinfo"].get("mt_dec", None) is None
):
return False
# check the top-level wcsinfo
has_slits = "slits" in meta and len(meta["slits"]) > 0
if has_slits:
# check all the slits
for slit in meta["slits"]:
if (
slit["meta"]["wcsinfo"].get("mt_ra", None) is None
or slit["meta"]["wcsinfo"].get("mt_dec", None) is None
):
return False
return True
if (
meta["meta"]["wcsinfo"].get("mt_ra", None) is None
or meta["meta"]["wcsinfo"].get("mt_dec", None) is None
Expand Down
4 changes: 2 additions & 2 deletions jwst/assign_mtwcs/tests/test_mtwcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def test_index_with_background():
with result:
bkg_exposure = result.borrow(0)
sci_exposure_1 = result.borrow(1)
assert not bkg_exposure.meta.wcsinfo.hasattr("mt_avra")
assert sci_exposure_1.meta.wcsinfo.hasattr("mt_avra")
assert not bkg_exposure.slits[0].meta.wcsinfo.hasattr("mt_avra")
assert sci_exposure_1.slits[0].meta.wcsinfo.hasattr("mt_avra")
result.shelve(bkg_exposure, 0, modify=False)
result.shelve(sci_exposure_1, 1, modify=False)

Expand Down
5 changes: 5 additions & 0 deletions jwst/extract_2d/grisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@ def extract_grism_objects(
new_slit.bunit_err = input_model.meta.bunit_err
slits.append(new_slit)
output_model.slits.extend(slits)

# update s_region of 0th slit to match input model
if output_model.slits:
output_model.slits[0].meta.wcsinfo.s_region = input_model.meta.wcsinfo.s_region

# In the case that there are no spectra to extract deleting the variables
# will fail so add the try block.
try:
Expand Down
1 change: 0 additions & 1 deletion jwst/pipeline/calwebb_spec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ def _process_nirspec_msa_slits(self, data):

# First process MOS slits through all remaining steps
calib_mos.update(calibrated)
calib_mos.meta.wcsinfo = calibrated.meta.wcsinfo.instance
if len(calib_mos.slits) > 0:
calib_mos = self.master_background_mos.run(calib_mos)
calib_mos = self.wavecorr.run(calib_mos)
Expand Down
2 changes: 1 addition & 1 deletion jwst/pipeline/calwebb_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def _populate_wfss_sregion(self, wfss_model, cal_model_list):
# introduced for a specific slit won't matter
wcs = cal_model_list[0].slits[0].meta.wcs
try:
input_sregions = [w.meta.wcsinfo.s_region for w in cal_model_list]
input_sregions = [w.slits[0].meta.wcsinfo.s_region for w in cal_model_list]
except AttributeError:
log.warning(
"One or more input model(s) are missing an `s_region` attribute; "
Expand Down
Loading