Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP-3682: split outlier detection into separate steps for each mode #8722

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

emolter
Copy link
Collaborator

@emolter emolter commented Aug 22, 2024

Resolves JP-3682

Closes #8634

This PR addresses splitting outlier detection into separate steps for coronagraphy, IFU, imaging, spectroscopy, and TSO data. This was motivated by large differences in input parameters and algorithms that are implemented for each mode.

Tasks

  • request a review from someone specific, to avoid making the maintainers review every PR
  • add a build milestone, i.e. Build 11.3 (use the latest build if not sure)
  • Does this PR change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • update or add relevant tests
    • update relevant docstrings and / or docs/ page
    • start a regression test and include a link to the running job (click here for instructions)
      • Do truth files need to be updated ("okified")?
        • after the reviewer has approved these changes, run okify_regtests to update the truth files
  • if a JIRA ticket exists, make sure it is resolved properly

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 67.10526% with 75 lines in your changes missing coverage. Please review.

Project coverage is 76.91%. Comparing base (03ca10f) to head (060ef25).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...st/outlier_detection/outlier_detection_ifu_step.py 16.66% 35 Missing ⚠️
.../outlier_detection/outlier_detection_coron_step.py 76.66% 7 Missing ⚠️
...st/outlier_detection/outlier_detection_tso_step.py 75.00% 7 Missing ⚠️
jwst/pipeline/calwebb_coron3.py 14.28% 6 Missing ⚠️
jwst/pipeline/calwebb_spec3.py 14.28% 6 Missing ⚠️
...t/outlier_detection/outlier_detection_spec_step.py 84.84% 5 Missing ⚠️
...utlier_detection/outlier_detection_imaging_step.py 88.57% 4 Missing ⚠️
jwst/pipeline/calwebb_tso3.py 40.00% 3 Missing ⚠️
jwst/outlier_detection/utils.py 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8722      +/-   ##
==========================================
- Coverage   76.92%   76.91%   -0.01%     
==========================================
  Files         498      498              
  Lines       45810    45830      +20     
==========================================
+ Hits        35240    35252      +12     
- Misses      10570    10578       +8     
Flag Coverage Δ *Carryforward flag
nightly 77.37% <ø> (-0.01%) ⬇️ Carriedforward from a6e0858

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emolter emolter added this to the Build 11.3 milestone Jan 9, 2025
@emolter
Copy link
Collaborator Author

emolter commented Jan 9, 2025

@emolter emolter requested a review from braingram January 9, 2025 20:27
@github-actions github-actions bot added installation automation Continuous Integration (CI) and testing automation tools labels Jan 9, 2025
@emolter emolter marked this pull request as ready for review January 9, 2025 21:30
@emolter emolter requested review from a team as code owners January 9, 2025 21:30
@emolter emolter requested a review from melanieclarke January 9, 2025 21:30
@emolter emolter requested review from tapastro and jemorrison January 9, 2025 21:30
@emolter
Copy link
Collaborator Author

emolter commented Jan 9, 2025

@tapastro @melanieclarke let me know what I can do to get the parameter reference files changed over.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on. The code changes look good to me. I left a few comments about suffixes and docs (I didn't finish looking over all the docs changes). The refactoring looks much cleaner.

For the reference files perhaps @stscieisenhamer has some suggestions on how to handle the transition from a single pars-outlierdetectionstep reftype to the multiple pars-outlierdetectionifustep etc pars files. To propose a plan maybe we define the new reftypes on crds, start using them with this PR and leave the existing pars-outlierdetectionstep reftype up (so previous cal versions can still use the context) for some period of time (it looks like the unused drizpars is still in the current context).
Related to the transition, I think this refactoring warrants a migration guide in the docs. Something that describes to a user that if they previously used strun outlierdetection they now need to do .... Is that in the updated docs (and I missed it)?

@@ -85,8 +86,10 @@ def process(self, input):
# Setup sub-step defaults
self.master_background.suffix = 'mbsub'
self.mrs_imatch.suffix = 'mrs_imatch'
self.outlier_detection.suffix = 'crf'
self.outlier_detection.save_results = self.save_results
self.outlier_detection_spec.suffix = 'crf'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the suffix now one-to-one for the split steps (eg outlier_detection_spec always uses crf)? If so I suggest we define them in the class instead of assigning in the pipeline.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's now 1:1, will define them in the spec of each step

"""Minimal base class holding common methods for outlier detection steps."""

@abstractmethod
def search_attr(self, attr, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What required defining this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. These were carried over from the draft of this PR several months ago. They no longer appear to be necessary, if they ever were necessary in the first place.

pass

@abstractmethod
def _make_output_path(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What required defining this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

class OutlierDetectionTSOStep(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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ModelContainer supported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I will update the docstring

jwst/lib/suffix.py Show resolved Hide resolved
@emolter
Copy link
Collaborator Author

emolter commented Jan 10, 2025

I'm working through regtest failures now, most of which are due to the need to change e.g. --steps.outlier_detection.save_results to --steps.outlier_detection_spec.save_results

Comment on lines 67 to 68
step = OutlierDetectionCoronStep()
step.call(input.fits, save_intermediate_results=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
step = OutlierDetectionCoronStep()
step.call(input.fits, save_intermediate_results=True)
OutlierDetectionCoronStep.call(input.fits, save_intermediate_results=True)

call is a class method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, my bad, will fix

Comment on lines 74 to 75
from jwst.pipeline import calwebb_image3
calwebb_image3(input.fits, steps={'outlier_detection_coron': {'save_intermediate_results': True}})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from jwst.pipeline import calwebb_image3
calwebb_image3(input.fits, steps={'outlier_detection_coron': {'save_intermediate_results': True}})
from jwst.pipeline import Image3Pipeline
Image3Pipeline.call(input.fits, steps={'outlier_detection_coron': {'save_intermediate_results': True}})


Parameters
-----------
input_data : asn file or ~jwst.datamodels.ModelContainer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be input_models?

with a ModelContainer. DQ arrays are modified in place.
Parameters
-----------
input_data : ~jwst.datamodels.ModelContainer or str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be input_models?

See `OutlierDetectionStep.spec` for documentation of these arguments.
Parameters
-----------
input_data : ~jwst.datamodels.CubeModel or str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be input_model?

"""Minimal base class holding common methods for outlier detection steps."""

def _get_asn_id(self, input_models):
"""Find association ID for any allowed input model type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring missing "Parameter" section describing the input parameter.

return

def _set_status(self, input_models, status):
"""Record step exit status, handling both filenames and open models."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring missing "Parameters" section describing the input parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split OutlierDetectionStep into multiple steps
4 participants