Skip to content

Commit

Permalink
one more round of comments, thanks @melanieclarke
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Jun 12, 2024
1 parent 960b7a1 commit a780593
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions jwst/badpix_selfcal/badpix_selfcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jwst.datamodels as dm
from jwst.outlier_detection.outlier_detection_ifu import medfilt
from stdatamodels.jwst.datamodels.dqflags import pixel
import warnings


def badpix_selfcal(minimg: np.ndarray,
Expand Down Expand Up @@ -52,7 +53,9 @@ def badpix_selfcal(minimg: np.ndarray,
elif dispaxis == 1:
kern_size = (1, kernel_size)

smoothed = medfilt(minimg, kern_size)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RuntimeWarning, message="All-NaN")
smoothed = medfilt(minimg, kern_size)
minimg_hpf = minimg - smoothed

# Flag outliers using percentile cutoff
Expand Down Expand Up @@ -82,7 +85,7 @@ def apply_flags(input_model: dm.IFUImageModel, flagged_indices: np.ndarray) -> d
Flagged data model
"""

input_model.dq[flagged_indices] += pixel["DO_NOT_USE"] + pixel["OTHER_BAD_PIXEL"]
input_model.dq[flagged_indices] |= pixel["DO_NOT_USE"] + pixel["OTHER_BAD_PIXEL"]

input_model.data[flagged_indices] = np.nan
input_model.err[flagged_indices] = np.nan
Expand Down
9 changes: 6 additions & 3 deletions jwst/badpix_selfcal/badpix_selfcal_step.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


import warnings
from ..stpipe import Step
from . import badpix_selfcal
import numpy as np
Expand Down Expand Up @@ -64,7 +65,7 @@ def process(self, input, selfcal_list=None, bkg_list=None):
are included in the MIN frame from which outliers are detected.
If selfcal_list and/or bkg_list are specified manually, they are appended to any
selfcal or background exposures found in the input association file.
If selfcal_list and bkg_list are both set to None and input is
If selfcal_list and bkg_list are both set to None and input is
a single science exposure, the step will be skipped with a warning unless
the force_single parameter is set True.
In that case, the input exposure will be used as the sole background exposure,
Expand Down Expand Up @@ -96,7 +97,9 @@ def process(self, input, selfcal_list=None, bkg_list=None):
selfcal_3d = []
for i, selfcal_model in enumerate(selfcal_list):
selfcal_3d.append(selfcal_model.data)
minimg = np.nanmin(np.asarray(selfcal_3d), axis=0)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RuntimeWarning, message="All-NaN")
minimg = np.nanmin(np.asarray(selfcal_3d), axis=0)
bad_indices = badpix_selfcal.badpix_selfcal(minimg, self.flagfrac_lower, self.flagfrac_upper, self.kernel_size, dispaxis)

# apply the flags to the science data
Expand Down Expand Up @@ -155,7 +158,7 @@ def _parse_inputs(input, selfcal_list, bkg_list):

if len(sci_models) > 1:
raise ValueError("Input data contains multiple science exposures. "

Check warning on line 160 in jwst/badpix_selfcal/badpix_selfcal_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/badpix_selfcal/badpix_selfcal_step.py#L160

Added line #L160 was not covered by tests
"This is not supported in calwebb_spec2 steps.")
"This is not supported in calwebb_spec2 steps.")
input_sci = sci_models[0]

elif isinstance(input_data, dm.IFUImageModel) or isinstance(input_data, dm.ImageModel):
Expand Down

0 comments on commit a780593

Please sign in to comment.