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

Add option to see full glue state tree for spectral subsets #2138

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

javerbukh
Copy link
Contributor

Description

This pull request is to allow us to access the full glue state tree for creating a composite spectral subset. The way to access it is:
specviz.app.get_subsets(simplify_spectral=False)
This PR also gives access to the subset state object in the dictionary that is returned by get_subsets. That can be accessed using:
specviz.app.get_subsets('Subset 1')[0]['subset_state']

Fixes #2134

Change log entry

  • Is a change log needed? If yes, is it added to CHANGES.rst? If you want to avoid merge conflicts,
    list the proposed change log here for review and add to CHANGES.rst before merge. If no, maintainer
    should add a no-changelog-entry-needed label.

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 milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Patch coverage: 95.42% and project coverage change: +0.02 🎉

Comparison is base (1904937) 91.93% compared to head (e6195b8) 91.96%.

❗ Current head e6195b8 differs from pull request most recent head 77ce881. Consider uploading reports for the commit 77ce881 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2138      +/-   ##
==========================================
+ Coverage   91.93%   91.96%   +0.02%     
==========================================
  Files         143      146       +3     
  Lines       15781    15939     +158     
==========================================
+ Hits        14509    14659     +150     
- Misses       1272     1280       +8     
Impacted Files Coverage Δ
jdaviz/configs/imviz/plugins/viewers.py 91.13% <ø> (ø)
jdaviz/core/events.py 94.61% <86.66%> (-0.58%) ⬇️
jdaviz/configs/imviz/plugins/compass/compass.py 93.10% <93.33%> (-0.23%) ⬇️
jdaviz/app.py 93.39% <95.23%> (-0.02%) ⬇️
...nfigs/imviz/plugins/rotate_canvas/rotate_canvas.py 95.58% <95.58%> (ø)
jdaviz/configs/cubeviz/helper.py 98.85% <100.00%> (+0.05%) ⬆️
...nfigs/cubeviz/plugins/tests/test_cubeviz_helper.py 100.00% <100.00%> (ø)
jdaviz/configs/imviz/plugins/__init__.py 100.00% <100.00%> (ø)
...iz/configs/imviz/plugins/rotate_canvas/__init__.py 100.00% <100.00%> (ø)
.../plugins/rotate_canvas/tests/test_rotate_canvas.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

@@ -828,7 +828,7 @@ def get_subsets_from_viewer(self, viewer_reference, data_label=None, subset_type
return regions

def get_subsets(self, subset_name=None, spectral_only=False,
spatial_only=False, object_only=False):
spatial_only=False, object_only=False, simplify_spectral=True):
Copy link
Member

Choose a reason for hiding this comment

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

I think we'll eventually want this to default to False (or perhaps not have the kwarg at all and have a separate simplify_spectral_subsets() method which applies the change directly to the glue state). Is that the eventual goal or do others have different thoughts on the eventual direction?

This may still be the simplest incremental step towards that direction though and if so, is ok with me for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camipacifici mentioned that users would prefer the simplified version since it makes sense with what they're seeing visually. I can only see the non-simplified version being useful for Subset Plugin, although even there we may decide to stick with the simplified version. The reason being that there are multiple states (i.e. subset_state.state1, state1.state2, state1.state2.state1, etc.) that are duplicates and editing one may not reflect the changes in the viewer.

Copy link
Member

@kecnry kecnry Apr 7, 2023

Choose a reason for hiding this comment

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

ok, then simplify_spectral=True (as the default) could call the method first before exposing the information in the same dictionary format? I just think it would be nice to have a consistent output-format (between spectral and spatial subsets) for default kwargs. Right now, the default returned object is quite different between spectral and spatial 🤷 . I also worry if we are going to show the actual state in the plugin by default, but the simplified representation in the API, that that could cause some confusion for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in the event of confusion we should default to the simpler version. Is the main reason to keep the non-simplified version consistency with the spatial subset? They are different things so I think it makes sense to represent them differently.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but it is the same method and the output formatting changes based on the "context" (rather than user-inputs). In other words imviz.app.get_subsets() returns these dictionary structures (non-simplified), whereas specviz.app.get_subsets() returns a completely different type of object and which is now simplified and doesn't match what we'll eventually want to show in the plugin. I just think this is difficult for an API where users might want to parse the returned object, since they'll need to add custom logic to determine how to parse it.

But if this is staying within the app-level, we could also address this issue when exposing it to the helper or plugin API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is this is staying in the app-level and certain features can be exposed by helper methods.

Copy link
Member

Choose a reason for hiding this comment

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

if its staying in app-level, then maybe the argument of what users would find most convenient doesn't apply yet 😉 . Ok, I won't hold up the PR for this and we can revisit later, but I am concerned that changing output formats will be a headache as we start to use this as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'm less concerned with changing the output format with this argument, than I am with the fact that the format within the same output dictionary is mixed in the Cubeviz case when you have both spatial and spectral subsets defined. The first solution that comes to mind is returning only the spectral subsets if simplify_spectral is True, but that would necessitate changing the default to False so that you always get everything back by default.

@rosteen
Copy link
Collaborator

rosteen commented Apr 10, 2023

This surprised me, I think it's a bug but I'm not sure. In the screenshot below I used the add subset selection mode a few times to make the subregion on the left for Subset 2. Using get_subsets returned five subregions for Subset 2, and using simplify_spectral dropped the number of subregions from five to four. I would have expected two subregions in the simplified case.

Screen Shot 2023-04-10 at 9 55 43 AM

@javerbukh
Copy link
Contributor Author

@rosteen I'm not able to reproduce, @kecnry are you able to?

@rosteen
Copy link
Collaborator

rosteen commented Apr 10, 2023

I think it only happens if you also have spatial subsets defined.

Edit: And the spatial subset has to be defined first. Defining a spectral subset like this and then a spatial subset doesn't trigger it.

@kecnry
Copy link
Member

kecnry commented Apr 10, 2023

I'm guessing that isn't directly related to this PR (can you check if it happens on main)? Maybe we can consider out-of-scope for the review here and file an issue/ticket?

@rosteen
Copy link
Collaborator

rosteen commented Apr 10, 2023

Ahh, right, this only implements the non-simplified output. The bug is also present on main, I'll open a separate ticket for that. My other comment applies to main as well then, I'll approve 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.

Let's get this in and revisit default behavior and output formats as the plugin UI as well as the helper and plugin-level APIs are iterated. Thanks!

@pllim
Copy link
Contributor

pllim commented Apr 12, 2023

Any user facing stuff that warrants a change log?

all_subsets[label] = [reg['region'] for reg in subset_region]
else:
all_subsets[label] = subset_region
elif spatial_only and not is_spectral:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would something be spatial and spectral at the same time? Pondering for another day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is_spectral is a bool for whether the subset in question is spectral or not. So if the spatial_only flag is true and is_spectral is False then we add the subset information to the returned list.

@pllim pllim enabled auto-merge (squash) April 12, 2023 15:36
@pllim pllim merged commit 27165e5 into spacetelescope:main Apr 12, 2023
@javerbukh javerbukh deleted the update-subset-plugin branch April 12, 2023 17:43
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.

Save composite spectral subset the same as a spatial subset
4 participants