Skip to content

Commit

Permalink
JP-3682: split outlier detection into multiple steps
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Jan 9, 2025
1 parent 8b2d425 commit 319e349
Show file tree
Hide file tree
Showing 23 changed files with 602 additions and 684 deletions.
12 changes: 10 additions & 2 deletions jwst/outlier_detection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from .outlier_detection_step import OutlierDetectionStep
from .outlier_detection_coron_step import OutlierDetectionCoronStep
from .outlier_detection_ifu_step import OutlierDetectionIFUStep
from .outlier_detection_spec_step import OutlierDetectionSpecStep
from .outlier_detection_imaging_step import OutlierDetectionImagingStep
from .outlier_detection_tso_step import OutlierDetectionTSOStep

__all__ = ['OutlierDetectionStep']
__all__ = ['OutlierDetectionCoronStep',
'OutlierDetectionIFUStep',
'OutlierDetectionSpecStep',
'OutlierDetectionImagingStep',
'OutlierDetectionTSOStep']
2 changes: 1 addition & 1 deletion jwst/outlier_detection/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _make_blot_model(input_model, blot, blot_err):
def _save_intermediate_output(model, suffix, make_output_path):
"""Save an intermediate output from outlier detection.
Ensure all intermediate outputs from OutlierDetectionStep have
Ensure all intermediate outputs from the steps have
consistent file naming conventions.
Parameters
Expand Down
67 changes: 0 additions & 67 deletions jwst/outlier_detection/coron.py

This file was deleted.

101 changes: 0 additions & 101 deletions jwst/outlier_detection/imaging.py

This file was deleted.

81 changes: 81 additions & 0 deletions jwst/outlier_detection/outlier_detection_coron_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Submodule for performing outlier detection on coronagraphy data.
"""

import logging

import numpy as np

from stdatamodels.jwst import datamodels
from jwst.stpipe import Step

from jwst.resample.resample_utils import build_mask

from .utils import create_cube_median, flag_model_crs, OutlierDetectionStepBase
from ._fileio import save_median

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


__all__ = ["OutlierDetectionCoronStep"]


class OutlierDetectionCoronStep(Step, OutlierDetectionStepBase):
"""Flag outlier bad pixels and cosmic rays in DQ array of each input image.
Input images can be listed in an input association file or already opened
with a ModelContainer. DQ arrays are modified in place.
Parameters
-----------
input_model : ~jwst.datamodels.CubeModel
CubeModel or filename pointing to a CubeModel
"""

class_alias = "outlier_detection_coron"

spec = """
maskpt = float(default=0.7)
snr = float(default=5.0)
save_intermediate_results = boolean(default=False)
good_bits = string(default="~DO_NOT_USE") # DQ flags to allow
"""

def process(self, input_model):
"""Perform outlier detection processing on input data."""

# determine the asn_id (if not set by the pipeline)
asn_id = self._get_asn_id(input_model)
self.log.info(f"Outlier Detection asn_id: {asn_id}")

if not isinstance(input_model, datamodels.JwstDataModel):
input_model = datamodels.open(input_model)

if not isinstance(input_model, datamodels.CubeModel):
raise TypeError(f"Input must be a CubeModel: {input_model}")

# FIXME weight_type could now be used here. Similar to tso data coron
# data was previously losing var_rnoise due to the conversion from a cube
# to a ModelContainer (which makes the default ivm weight ignore var_rnoise).
# Now that it's handled as a cube we could use the var_rnoise.
input_model.wht = build_mask(input_model.dq, self.good_bits).astype(np.float32)

# Perform median combination on set of drizzled mosaics
median_data = create_cube_median(input_model, self.maskpt)

if self.save_intermediate_results:
# make a median model
median_model = datamodels.ImageModel(median_data)
median_model.update(input_model)
median_model.meta.wcs = input_model.meta.wcs

save_median(median_model, self.make_output_path)
del median_model

# Perform outlier detection using statistical comparisons between
# each original input image and its blotted version of the median image
flag_model_crs(
input_model,
median_data,
self.snr,
)
return self._set_status(input_model, True)
Loading

0 comments on commit 319e349

Please sign in to comment.