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-3207 ifu outlier detection #7590

Merged

Conversation

jemorrison
Copy link
Collaborator

@jemorrison jemorrison commented May 18, 2023

Resolves JP-3207

Closes #

This PR changes the way outlier detection is done on IFU data, implementing a completely new algorithm developed by @drlaw1558. A change to the outlierpars data models was needed [spacetelescope/stdatamodels#164 for stdatamodels]. In addition, a new data model outlierifuoutput was added to stdatamodels to support analysis of the new algorithm. If save_intermediate_results = True then an output file following outlierifuoutput is created.

Order of work flow:

  1. Get PR 164 in stdatamodels merged. (Done)
  2. Get PR 167 in stdatamodels merged (Done)
  3. Add the new NIRSpec and MIRI outlierpars reference files. [if not in CRDS will use defaults set in outlier_detection. We can use these defaults for NIRSpec get the PR merged and later load the NIRSpec ref file if they need more time]
  4. Merge this PR.

Checklist for maintainers

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • Make sure the JIRA ticket is resolved properly

@jemorrison jemorrison requested a review from a team as a code owner May 18, 2023 00:32
@jemorrison
Copy link
Collaborator Author

@hbushouse @tapastro I am stuck. I have the ifu outlier rejection code flagging outliers. The way the outlier_detection_step is set up I can not figure out how to update the input models. with the flagged dqs The flag dq arrays and corresponding sci arrays (that are nan) are not returned so the output files written are not flagged.
I am going continue to work on this but could use a fresh set of eye on the problem
The outlier_detection_step is set up use in class defined in outlier_detection.py
Depending on the type of data a different module is called. In IFU data the outlier_detection_ifu.py step is called
All the modules have a do_detection(self) module that does the bulk of the work.

I can not figure out the way that outlier_detection is set up how to return the updated arrays. I have looked in detail at how
outlier_detection.py works and tried to do something similar but it just does not work.

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Patch coverage: 5.50% and project coverage change: -0.26 ⚠️

Comparison is base (991678e) 77.27% compared to head (0ae1eb7) 77.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7590      +/-   ##
==========================================
- Coverage   77.27%   77.01%   -0.26%     
==========================================
  Files         456      456              
  Lines       36629    36625       -4     
==========================================
- Hits        28304    28208      -96     
- Misses       8325     8417      +92     
Flag Coverage Δ *Carryforward flag
nightly 77.44% <ø> (-0.05%) ⬇️ Carriedforward from 94f6f13

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

Impacted Files Coverage Δ
jwst/outlier_detection/outlier_detection_step.py 87.87% <ø> (-0.13%) ⬇️
jwst/outlier_detection/outlier_detection_ifu.py 16.26% <4.62%> (-75.01%) ⬇️
jwst/outlier_detection/outlier_detection.py 89.90% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jemorrison
Copy link
Collaborator Author

@hbushouse I did not mean to put requirements-max.txt into this PR. I think I removed it. But could you check I did that correctly before we merge

@jemorrison
Copy link
Collaborator Author

@hbushouse So how do we record changes made in datamodels in stdatamodels ? I put a note under datamodels and I put a note in the stdatamodels CHANGE log.

@hbushouse
Copy link
Collaborator

@hbushouse So how do we record changes made in datamodels in stdatamodels ? I put a note under datamodels and I put a note in the stdatamodels CHANGE log.

You can include a link to the stdatamodels PR using the following syntax:

[#7590, spacetelescope/stdatamodels#164]

@jemorrison jemorrison requested review from drlaw1558 and tapastro June 5, 2023 18:43
Copy link
Collaborator

@drlaw1558 drlaw1558 left a comment

Choose a reason for hiding this comment

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

Looks good to me; I've tested it on a few example data sets and it seems to be working as expected.

@drlaw1558
Copy link
Collaborator

pars files are ready for both outlier_detection and an updated spec3. The spec3 file contains updated extract1d calls too for the MRS PR on extract1d changes.
Question though: when these pars files go live, they contain keywords not in the current MAST pipeline, and offline testing suggests that this will cause crashes in old code versions. How should we deal with that?

@jemorrison jemorrison force-pushed the JP-3207_IFU_outlier_detection branch from f8276df to 36b4829 Compare June 9, 2023 20:05
CHANGES.rst Show resolved Hide resolved
docs/jwst/outlier_detection/arguments.rst Outdated Show resolved Hide resolved
docs/jwst/outlier_detection/arguments.rst Outdated Show resolved Hide resolved
docs/jwst/outlier_detection/outlier_detection_ifu.rst Outdated Show resolved Hide resolved
docs/jwst/outlier_detection/outlier_detection_ifu.rst Outdated Show resolved Hide resolved
jwst/outlier_detection/outlier_detection_ifu.py Outdated Show resolved Hide resolved
jwst/outlier_detection/outlier_detection_ifu.py Outdated Show resolved Hide resolved
jwst/outlier_detection/outlier_detection_ifu.py Outdated Show resolved Hide resolved
jwst/outlier_detection/outlier_detection_ifu.py Outdated Show resolved Hide resolved
@nden
Copy link
Collaborator

nden commented Jun 9, 2023

@jemorrison I believe requirements-max.txt is removed erroneously in this PR.

Also have you run the code with at least two different detectors? I'm trying to figure out the logic.

@braingram
Copy link
Collaborator

braingram commented Jun 9, 2023

While looking at the open files issues in stdatamodels and jwst I noticed that this PR should include an update to:
https://github.com/spacetelescope/jwst/blob/master/jwst/datamodels/__init__.py
as the jwst test suite compares stdatamodels.jwst.datamodels to jwst.datamodels

def test_stdatamodels_api(model):

and the addition of a new submodule and model in spacetelescope/stdatamodels#164 will cause the above test to fail.

@jemorrison
Copy link
Collaborator Author

@nden I have run this code on NIRSpec and MIRI data using an association for each instrument that contains 2 detectors. The algorithm pulls the data from 1 detector and is basically trying to find bad pixels that are not in the bad pixel mask because the bad pixels vary with time. So it looks for outliers with adjacent pixels that are outliers on all then input data for that detector.

@jemorrison
Copy link
Collaborator Author

@nden I needed requirements-max.txt locally to be changed so that I could use the newer version that I created to update the outlierParsModel. I added that to the PR by mistake. I guess I did not mean to remove requirements-max.txt completely just my update to it. Is that what you are saying I did ?

@jemorrison jemorrison requested a review from nden June 12, 2023 16:26
@jemorrison
Copy link
Collaborator Author

@nden made the changes you requested. I remove a few things that were not needed. I am going to run the regression tests now- more just to make sure nothing breaks. The regression results for IFU outlier detection will be completely different

@jemorrison jemorrison force-pushed the JP-3207_IFU_outlier_detection branch from c25307c to 72b366b Compare June 12, 2023 17:01
@jemorrison jemorrison force-pushed the JP-3207_IFU_outlier_detection branch from b04c0f3 to 0d02f2a Compare June 14, 2023 20:24
@jemorrison jemorrison requested a review from hbushouse June 14, 2023 20:45
@jemorrison
Copy link
Collaborator Author

@nden @hbushouse
This PR should now be ready for final review. Thanks for all the suggestions it has made this step better (and I learned a few things along the way).

@hbushouse
Copy link
Collaborator

Another (hopefully final?) regtest run started at https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/743/

@hbushouse
Copy link
Collaborator

hbushouse commented Jun 15, 2023

Not sure I understand why the CI tests are still failing due to some kind of error with not finding jwst.datamodels.outlierifuoutput.py, even though that module is now included in this PR and I think it also has the appropriate change to jwst/setup.cfg to use stdatamodels/master. Everything seems to run fine when using this PR branch in regression tests, so maybe it's just something unique in what the CI tests are trying to test. @zacharyburnett @braingram any ideas?

@braingram
Copy link
Collaborator

braingram commented Jun 15, 2023

Not sure I understand why the CI tests are still failing due to some kind of error with not finding jwst.datamodels.outlierifuoutput.py, even though that module is now included in this PR and I think it also has the appropriate change to jwst/setup.cfg to use stdatamodels/master. Everything seems to run fine when using this PR branch in regression tests, so maybe it's just something unique in what the CI tests are trying to test. @zacharyburnett @braingram any ideas?

I believe the CI is throwing errors because the file jwst/datamodels/outlierifuoutput.py added in the PR conflicts with the module shadowing added in #7605 jwst/datamodels/outlierifuoutput.py can be removed from this PR which should fix the error.

The 2 errors are because pytest is inspecting jwst/datamodels/outlierifuoutput.py to look for tests. After it attempts to import the file (which instead triggers importing the corresponding file from stdatamodels), the module appears at a different path (because of the changes in #7605) and pytest gives up with an error.

I believe the regression tests aren't showing the same error because they don't search the jwst/datamodels directory for tests (assuming it's using the pytest --bigdata jwst/regtest in the readme.

Let me know if it's helpful to document any of this. There is an open issue about improving the documentation on adding a new datamodel which is likely related: #4436

@hbushouse
Copy link
Collaborator

@braingram OK, I'll try removing the outlierifuoutput.py module from this PR and see what happens.

@hbushouse
Copy link
Collaborator

Yay! CI tests now succeed. Thanks @braingram

@hbushouse
Copy link
Collaborator

Looks like the doc module https://raw.githubusercontent.com/spacetelescope/jwst/master/docs/jwst/outlier_detection/outlier_detection.rst also has some references to IFU mode, which will need updating. If you don't mind, I'll take a stab at updating that and pushing to this PR branch.

@jemorrison jemorrison force-pushed the JP-3207_IFU_outlier_detection branch from 99ed8c3 to a887537 Compare June 20, 2023 20:09
@hbushouse
Copy link
Collaborator

Woot! CI success. As soon as the latest regtest run at https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/751/console finishes, I'll be merging this.

@hbushouse hbushouse merged commit 3866c80 into spacetelescope:master Jun 21, 2023
mairanteodoro pushed a commit to mairanteodoro/jwst that referenced this pull request Jun 28, 2023
@jemorrison jemorrison deleted the JP-3207_IFU_outlier_detection branch September 13, 2023 16:32
@melanieclarke melanieclarke mentioned this pull request Aug 6, 2024
8 tasks
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.

5 participants