Skip to content
New issue

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

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

Already on GitHub? # to your account

data-menu: add subsets/data #3263

Merged
merged 13 commits into from
Nov 1, 2024
Merged

data-menu: add subsets/data #3263

merged 13 commits into from
Nov 1, 2024

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Oct 31, 2024

Description

This pull request extends on #3254 by implementing the "+" menu to add data and subsets to the current viewer. This also exposes data_menu.create_subset(subset_type) (to enable the matching subset tool in that viewer's toolbar) and data_menu.add_data(data_label) - currently via data_menu = viz.viewers[viewer_label]._obj.data_menu (although the necessity for the _obj will be removed once the data-menu is ready to be exposed to users.

This PR does include logic so that the listed available data entries are applicable to that specific viewer.

This PR does not include the ability to remove data from the viewer or app in the new data-menu: that will be implemented in #3264. Until then, remove data from the old data-menu or from the API for testing purposes, or create data in a plugin but do not tell it to immediately plot in the viewer.

As in #3254, until finished and officially exposed, the data-menu must be enabled via:

for viewer in viz.viewers.values():
    viewer._obj.data_menu._obj.dev_data_menu = True
Screen.Recording.2024-10-31.at.9.13.47.AM.mov
Screen.Recording.2024-10-31.at.9.14.13.AM.mov

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. Bugfix milestone also needs an accompanying backport label.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@kecnry kecnry added this to the 4.1 milestone Oct 31, 2024
@github-actions github-actions bot added cubeviz specviz mosviz imviz plugin Label for plugins common to multiple configurations labels Oct 31, 2024
Comment on lines +3543 to +3560
def is_image_not_spectrum(data):
return (is_image(data)
and not getattr(data.coords, 'is_spectral', True))

def is_cube(data):
return len(data.shape) == 3

def is_cube_or_image(data):
return len(data.shape) >= 2

def is_spectrum(data):
return (len(data.shape) == 1
and data.coords is not None
and getattr(data.coords, 'is_spectral', True))

def is_2d_spectrum_or_trace(data):
return (data.ndim == 2
and data.coords is not None
and getattr(data.coords, 'is_spectral', True)) or 'Trace' in data.meta
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if this is the best way to determine if a data collection is a spectrum or not (as opposed to an image in the 2d case, or a trace or light curve in the 1d case). @pllim suggested checking the presence and dimensions of the flux component, which should work for the trace case, but might not if we ever want to support light curves side-by-side. For now we don't need to worry about light curves though, so if there is a case where the data.coords check would fail (uncalibrated spectra, for example), that might be the better way to go for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

My other suggestion was to inject such data type into Data metadata on load (in the parser). Then the lookup would always be O(1).

Copy link
Member Author

Choose a reason for hiding this comment

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

that is probably the cheapest and simplest since we likely have access to the actual specutils object at that piont, the only downside is that we then have to remember to set that metadata for any future tests, etc. I'm honestly not sure which is the best - I'll see if anyone else has thoughts and then we can just pick one and cross our fingers it was the right choice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Setting the data type in the metadata sounds good to me. It would make things more explicit than checking coords and shape, although maybe we would keep that as a fallback in case the data type is not set.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW in three years when specutils 2 is out we'll have spectral_axis_index in the meta for anything loaded as a Spectrum1D - I'm ok with adding something else to the meta for now if it makes this check easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm worried that adding something to metadata might blow up a bit in scope - any objections to leaving as is now (unless someone can think of a case that fails this test) and revisit some sort of metadata addition as we generalize parsers, etc, down the road?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's fine with me, I was just agreeing that could be an ok strategy, not demanding we implement that strategy.

* can re-implement during UI tweaks at end of data-menu effort
@rosteen
Copy link
Collaborator

rosteen commented Nov 1, 2024

Starting to test this, it looks like toggling subset visibility is a little wonky:

Screen.Recording.2024-11-01.at.10.18.26.AM.mov

The WCS-only layer showing up when toggling the subset back on also happens on main through the plot options (it goes from "mixed state" to showing everything), we might want to think a little more about how to better handle that layer. But it does seem a little unclear what's happening with the subset when clicking the things in this menu.

@kecnry
Copy link
Member Author

kecnry commented Nov 1, 2024

it looks like toggling subset visibility is a little wonk

Yes, these are both known bugs filed as a follow-up tickets (delayed state issues and mixed state for image subsets from WCS layer) that likely block enabling the new data-menu for users (and we are hoping is addressed by requests for upstream changes, but if those don't come in time we will need to implement workaround). This PR is specifically for the "+" button in the top right.

Copy link
Contributor

@javerbukh javerbukh left a comment

Choose a reason for hiding this comment

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

LTGM!

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Works in my testing and I don't see anything in the code that I object to - it's actually a smaller diff than I expected!

@kecnry kecnry merged commit 0094168 into spacetelescope:main Nov 1, 2024
21 of 23 checks passed
@kecnry kecnry deleted the dm-add-data branch November 1, 2024 17:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants