Skip to content

Commit 1fc83a9

Browse files
committed
Turn all invalid interval warning into error.
Capture log and emit different message and catch RuntimeWarning.
1 parent 4cc7292 commit 1fc83a9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

jwst/msaflagopen/msaflag_open.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
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 (
14+
slitlets_wcs,
15+
_nrs_wcs_set_input_lite,
16+
_get_transforms,
17+
log as nirspec_log,
18+
)
19+
from jwst.lib.basic_utils import LoggingContext
1420

1521
log = logging.getLogger(__name__)
1622
log.setLevel(logging.DEBUG)
@@ -43,9 +49,12 @@ def do_correction(input_model, shutter_refname, wcs_refnames):
4349
"""
4450
# Create a list of failed open slitlets from the msaoper reference file
4551
failed_slitlets = create_slitlets(shutter_refname)
52+
log.info("%d failed open shutters", len(failed_slitlets))
4653

4754
# Flag the stuck open shutters
48-
output_model = flag(input_model, failed_slitlets, wcs_refnames)
55+
with warnings.catch_warnings():
56+
warnings.filterwarnings("ignore", category=RuntimeWarning, message="Invalid interval")
57+
output_model = flag(input_model, failed_slitlets, wcs_refnames)
4958
output_model.meta.cal_step.msa_flagging = "COMPLETE"
5059

5160
return output_model
@@ -79,7 +88,8 @@ def flag(input_datamodel, failed_slitlets, wcs_refnames):
7988
Science data with DQ flags modified.
8089
"""
8190
# Use the machinery in assign_wcs to create a WCS object for the bad shutters
82-
pipeline = slitlets_wcs(input_datamodel, wcs_refnames, failed_slitlets)
91+
with LoggingContext(nirspec_log, level=logging.WARNING):
92+
pipeline = slitlets_wcs(input_datamodel, wcs_refnames, failed_slitlets)
8393
wcs = WCS(pipeline)
8494

8595
# Create output as a copy of the input science data model so we can overwrite

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)