Skip to content

Commit 170ec57

Browse files
committed
Fix logging message in NIRSpec assign_wcs
and turn all invalid interval warning into error Capture log and emit different message and catch RuntimeWarning
1 parent 80c3654 commit 170ec57

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

jwst/assign_wcs/nirspec.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"""
66

77
import logging
8-
import numpy as np
98
import copy
9+
import warnings
1010

11+
import numpy as np
1112
from astropy.modeling import models
1213
from astropy.modeling.models import Mapping, Identity, Const1D, Scale, Tabular1D
1314
from astropy import units as u
@@ -2211,7 +2212,9 @@ def _get_y_range(open_slits):
22112212
transform, wavelength_range, slit_ymin=slit_y_low, slit_ymax=slit_y_high
22122213
)
22132214

2214-
slit_wcs.bounding_box = bb
2215+
with warnings.catch_warnings():
2216+
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Invalid interval")
2217+
slit_wcs.bounding_box = bb
22152218
return slit_wcs
22162219

22172220

jwst/msaflagopen/msaflag_open.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Flag pixels affected by open MSA shutters in NIRSpec exposures."""
22

33
import json
4-
import numpy as np
54
import logging
5+
import warnings
66
from pathlib import Path
77

8+
import numpy as np
89
from gwcs.wcs import WCS
9-
1010
from stdatamodels.jwst import datamodels
1111
from stdatamodels.jwst.transforms.models import Slit
1212

13-
from ..assign_wcs.nirspec import slitlets_wcs, _nrs_wcs_set_input_lite, _get_transforms
13+
from jwst.assign_wcs.nirspec import slitlets_wcs, _nrs_wcs_set_input_lite, _get_transforms
1414

1515
log = logging.getLogger(__name__)
1616
log.setLevel(logging.DEBUG)
@@ -43,9 +43,12 @@ def do_correction(input_model, shutter_refname, wcs_refnames):
4343
"""
4444
# Create a list of failed open slitlets from the msaoper reference file
4545
failed_slitlets = create_slitlets(shutter_refname)
46+
log.info("%d failed open shutters", len(failed_slitlets))
4647

4748
# Flag the stuck open shutters
48-
output_model = flag(input_model, failed_slitlets, wcs_refnames)
49+
with warnings.catch_warnings():
50+
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Invalid interval")
51+
output_model = flag(input_model, failed_slitlets, wcs_refnames)
4952
output_model.meta.cal_step.msa_flagging = "COMPLETE"
5053

5154
return output_model

jwst/msaflagopen/msaflagopen_step.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from stdatamodels.jwst import datamodels
1+
import logging
22

3+
from stdatamodels.jwst import datamodels
34
from stpipe.crds_client import reference_uri_to_cache_path
45

56
from jwst.stpipe import Step
67
from jwst.assign_wcs import AssignWcsStep
8+
from jwst.assign_wcs.nirspec import log as nirspec_log
9+
from jwst.lib.basic_utils import LoggingContext
710
from jwst.msaflagopen import msaflag_open
811

912
__all__ = ["MSAFlagOpenStep"]
@@ -50,7 +53,10 @@ def process(self, input_data):
5053
wcs_reffile_names = create_reference_filename_dictionary(input_model)
5154

5255
# Do the DQ flagging
53-
result = msaflag_open.do_correction(input_model, self.reference_name, wcs_reffile_names)
56+
with LoggingContext(nirspec_log, level=logging.WARNING):
57+
result = msaflag_open.do_correction(
58+
input_model, self.reference_name, wcs_reffile_names
59+
)
5460

5561
# set the step status to complete
5662
result.meta.cal_step.msa_flagging = "COMPLETE"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ filterwarnings = [
239239
"error::ResourceWarning",
240240
"error::DeprecationWarning",
241241
"error::stdatamodels.exceptions.ValidationWarning",
242+
"error:Invalid interval",
242243
"ignore:Models in math_functions:astropy.utils.exceptions.AstropyUserWarning",
243244
]
244245

0 commit comments

Comments
 (0)