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

Respect loaded mask cube properly in spectral extraction. #3319

Merged
merged 11 commits into from
Dec 11, 2024

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Nov 25, 2024

Fixes #3312.

Close #2718

@rosteen rosteen added bug Something isn't working cubeviz backport-v4.0.x on-merge: backport to v4.0.x labels Nov 25, 2024
@rosteen rosteen added this to the 4.0.1 milestone Nov 25, 2024
@github-actions github-actions bot added specviz plugin Label for plugins common to multiple configurations labels Nov 25, 2024
@rosteen rosteen force-pushed the extract-cube-masks-fix branch 3 times, most recently from bab8070 to 6ee7daf Compare November 25, 2024 22:02
@@ -22,6 +22,7 @@ class Cubeviz(CubeConfigHelper, LineListMixin):

_loaded_flux_cube = None
_loaded_uncert_cube = None
_loaded_mask_cube = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe give @javerbukh co-author credit given #2718 ?

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

The code itself looks good to me - just a few workflow related questions to consider:

Do we want (now or as a a follow-up ticket) to have a dropdown to select the mask cube? Should the default be to apply the mask or to not apply it?

What happens if the intersection between an aperture and the mask results in no pixels?

Should the mask be used in other plugins as well (aperture photometry, moment map, collapse, etc)?

@camipacifici
Copy link
Contributor

I think that if it is used, it should be used everywhere (it can be a follow up issue). Can there maybe be an option at load_data to load AND use the mask?

I would not set it to use by default, but maybe there could be a warning at loading like "there is a mask extension, if you want to load it do blah"

@camipacifici
Copy link
Contributor

Visualize the mask cube would be very useful!

@gibsongreen
Copy link
Contributor

Code seems straightforward, testing this on top of #3307 and the non-finite warning above the Fit Model button goes away with this PR.

In 3307, I was still seeing a model in the spectrum-viewer/table after model fitting, and there wasn't a traceback (but there was a warning was in the log).

I'll hold off approving for now and re-review if/once the above comments are decided on and if they go into this PR or follow-ups.

@rosteen
Copy link
Collaborator Author

rosteen commented Dec 2, 2024

Visualize the mask cube would be very useful!

Hm, is the mask a subset of the DQ flags we're showing? Or is it the set of all the flagged pixels? I'm not completely sure what the difference is between the two things or whether we're losing anything by not showing the mask vs DQ.

@rosteen rosteen force-pushed the extract-cube-masks-fix branch from 6ee7daf to b97ea9f Compare December 2, 2024 19:51
@rosteen
Copy link
Collaborator Author

rosteen commented Dec 2, 2024

@kecnry I just tested, if you define an aperture that is totally covered by the mask, it extracts a flat spectrum at 0 flux.

@rosteen
Copy link
Collaborator Author

rosteen commented Dec 3, 2024

I think I figured out the test failure - the science validation cube has NaNs in the mask/DQ array where the data isn't masked rather than 0s (btw, I did confirm that what we're storing from reading the mask array is what we're showing as the DQ data entry). This is awful, but easy to handle.

@rosteen rosteen force-pushed the extract-cube-masks-fix branch from 3ed5820 to 572e716 Compare December 3, 2024 16:26
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.80%. Comparing base (6c946d3) to head (6caa76a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
jdaviz/configs/cubeviz/plugins/parsers.py 37.50% 5 Missing ⚠️
...plugins/spectral_extraction/spectral_extraction.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3319      +/-   ##
==========================================
- Coverage   88.80%   88.80%   -0.01%     
==========================================
  Files         125      125              
  Lines       19137    19155      +18     
==========================================
+ Hits        16995    17010      +15     
- Misses       2142     2145       +3     

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

@rosteen
Copy link
Collaborator Author

rosteen commented Dec 5, 2024

I removed the lines storing the JWST DQ array as the original mask, and added a note in the docs as well as a Snackbar message indicating the original mask was applied during extraction, to address @camipacifici's concerns.

Screenshot 2024-12-05 at 1 11 40 PM

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Do we have any existing test data that we can send through spectral extraction to add coverage to these logic paths? Otherwise looks good to me until we can get the full support in to allow mask selection across all relevant plugins.

@rosteen rosteen force-pushed the extract-cube-masks-fix branch from 1ab3d1b to a53be86 Compare December 9, 2024 16:31
Copy link
Contributor

@gibsongreen gibsongreen left a comment

Choose a reason for hiding this comment

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

The recent code updates look good to me and behavior has been maintained since my last review!

@rosteen rosteen merged commit bf8cb26 into spacetelescope:main Dec 11, 2024
17 of 19 checks passed
Copy link

lumberbot-app bot commented Dec 11, 2024

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v4.0.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 bf8cb2614ba7c823e7566b2fa8528d0de0e1c6ee
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #3319: Respect loaded mask cube properly in spectral extraction.'
  1. Push to a named branch:
git push YOURFORK v4.0.x:auto-backport-of-pr-3319-on-v4.0.x
  1. Create a PR against branch v4.0.x, I would have named this PR:

"Backport PR #3319 on branch v4.0.x (Respect loaded mask cube properly in spectral extraction.)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

rosteen added a commit to rosteen/jdaviz that referenced this pull request Dec 11, 2024
…cope#3319)

* Track loaded mask cube in cubeviz

* First pass at handling mask cube in extraction

* Fix type

* Add changelog

* Handle mask cubes that have NaNs instead of 0s

* Act on copy of this mask array

* Don't save DQ array as loaded_mask for JWST

* Add snackbar warning and note in docs

* codestyle

* Add extraction test on file with mask

* Codestyle

(cherry picked from commit bf8cb26)
kecnry pushed a commit that referenced this pull request Dec 13, 2024
… in spectral extraction.) (#3348)

---------

Co-authored-by: Brett M. Morris <morrisbrettm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v4.0.x on-merge: backport to v4.0.x bug Something isn't working cubeviz plugin Label for plugins common to multiple configurations specviz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Masks not handled properly in cube spectral extraction
5 participants