-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Starting to test this, it looks like toggling subset visibility is a little wonky: Screen.Recording.2024-11-01.at.10.18.26.AM.movThe 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. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM!
There was a problem hiding this 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!
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) anddata_menu.add_data(data_label)
- currently viadata_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:
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
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, maintainershould 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.
trivial
label.