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

Cubeviz spectral regions fixes #1046

Merged
merged 10 commits into from
Jan 31, 2022
Merged

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Jan 20, 2022

Description

This allows Cubeviz to successfully return spectral regions with multiple subregions via app.get_subsets_from_viewer. It also makes the returned spectral regions from Cubeviz SpectralRegions, to match the output when the method is used in Specviz. Some changes were also required to the moment maps plugin to work with this change - the rest of the plugins seemed ok, but I'm leaving this as draft for now because I think this may be a good time to make one or two other subset-related tweaks to the moment maps UI (and potentially other plugins).

Fixes #959

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set? Milestone is only currently required for PRs related to Imviz MVP.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@rosteen rosteen changed the title Cubeviz gimme regions Cubeviz spectral regions fixes Jan 21, 2022
@rosteen rosteen marked this pull request as ready for review January 21, 2022 16:01
@rosteen
Copy link
Collaborator Author

rosteen commented Jan 21, 2022

This is ready for review, but will require astropy/specutils#911 for the tests to pass. I'm hoping to do a specutils release early next week so we can merge this before the end of the week.

@pllim
Copy link
Contributor

pllim commented Jan 21, 2022

Should I withhold review until specutils is released then?

@pllim pllim added this to the 2.3 milestone Jan 21, 2022
@rosteen
Copy link
Collaborator Author

rosteen commented Jan 21, 2022

I was thinking that it's reviewable now, we can just wait to hit the merge button until tests pass.

@pllim
Copy link
Contributor

pllim commented Jan 21, 2022

But we have to install astropy/specutils#911 to review this, right?

@rosteen
Copy link
Collaborator Author

rosteen commented Jan 21, 2022

No, unless you have an overriding urge to use the Unit Conversion plugin to change units to frequency space before testing it.

@pllim
Copy link
Contributor

pllim commented Jan 21, 2022

Oh, you mean this? 😸

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.

Seems to work well and as expected (pending tests passing) and is definitely a huge improvement over returning a messy nested object.

Note that the scope here only applies to spectral regions - image regions work when adding multiple subregions but still break when using "remove" logic, for instance.

jdaviz/app.py Outdated
continue
elif subset_type == "spatial" and this_type == RangeSubsetState:
continue
if subset_type == "spectral" or viewer_reference == "spectrum-viewer":
Copy link
Member

Choose a reason for hiding this comment

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

is hardcoding the viewer-reference string ever going to cause issues (also in line 618)? (See #1038, for example). As far as I can tell, we always currently use "spectrum-viewer" for spectrum viewers. We could check if viewer is a SpecvizProfileView instance, but I'm not sure if that's better or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as @havok2063 does not overwrite this on MAST side, we should be 99% safe...

Copy link
Collaborator

Choose a reason for hiding this comment

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

We currently don't override anything within the viewer-area section of the configurations. I don't think we have any plans to but one never knows. Items in settings, toolbar, and tray we do reconfigure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checking for SpecvizProfileView seems like it's probably the more stable solution for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, better to look for BqplotProfileView. I'll make that change shortly.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Is Cubeviz moment map plugin the only thing affected by this? Seems like a very significant change. No other plugins currently access this API and expecting the old object class?

jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py Outdated Show resolved Hide resolved
jdaviz/tests/test_subsets.py Outdated Show resolved Hide resolved
jdaviz/tests/test_subsets.py Outdated Show resolved Hide resolved
CHANGES.rst Outdated
@@ -30,6 +30,9 @@ Bug Fixes
Cubeviz
^^^^^^^

- Subsets from the spectrum viewer are now returned as SpectralRegion objects, and
Copy link
Contributor

Choose a reason for hiding this comment

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

The first entry is technically API change, not just a bug fix. I propose we split this entry into different "API change" and "Bug fix" entries.

jdaviz/tests/test_subsets.py Outdated Show resolved Hide resolved
temp_data = self.get_data_from_viewer(viewer_reference, value.label)
if isinstance(temp_data, Spectrum1D):
# Note that we look for mask == False here, rather than True above,
# because specutils masks are the reverse of Glue (of course)
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, specutils at least follows Numpy masked array convention (where mask==True means the pixel is masked). 🤷

jdaviz/app.py Outdated Show resolved Hide resolved
@pllim
Copy link
Contributor

pllim commented Jan 24, 2022

p.s. You said this fixes "multiple subregions" use case. Maybe add a test for that? 😅

Thanks!

@rosteen rosteen force-pushed the cubeviz-gimme-regions branch from 25c0e73 to 3211fbd Compare January 27, 2022 21:17
@rosteen
Copy link
Collaborator Author

rosteen commented Jan 27, 2022

@pllim I merged your suggestions and added a test for a two-region Subset, as well as updating the specutils pin to the new release. I think this is good for final review.

@pllim
Copy link
Contributor

pllim commented Jan 28, 2022

There is a conflict in the change log, so this needs rebasing. Thanks!

@rosteen rosteen force-pushed the cubeviz-gimme-regions branch from 3211fbd to e445fbd Compare January 31, 2022 14:16
@rosteen
Copy link
Collaborator Author

rosteen commented Jan 31, 2022

Rebased!

@rosteen rosteen force-pushed the cubeviz-gimme-regions branch from e445fbd to 0cd349d Compare January 31, 2022 15:15
@codecov
Copy link

codecov bot commented Jan 31, 2022

Codecov Report

Attention: Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.22%. Comparing base (bd81723) to head (0cd349d).
Report is 2727 commits behind head on main.

Files Patch % Lines
...configs/cubeviz/plugins/moment_maps/moment_maps.py 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1046      +/-   ##
==========================================
+ Coverage   74.03%   74.22%   +0.18%     
==========================================
  Files          75       75              
  Lines        5639     5637       -2     
==========================================
+ Hits         4175     4184       +9     
+ Misses       1464     1453      -11     

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

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Works as advertised. Thanks!

@pllim pllim merged commit e30907a into spacetelescope:main Jan 31, 2022
@pllim pllim mentioned this pull request Feb 1, 2022
12 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.

Collapsing Spectrum1d and creating multiple subregions causes traceback
4 participants