-
Notifications
You must be signed in to change notification settings - Fork 76
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
View spectrum from single spaxel on hover #2647
Conversation
What if instead we just have it overlay with a normalized y-axis (the values would no longer match the left y-axis, but you would be able to see the shape of the spectrum at the pixel) 🤔 ? |
Interesting idea, definitely has some pros and cons. Probably a question for the POs on their preference. |
Agreed. Either way... I definitely think that:
|
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.
Is this smart enough to know when it is hovering over something that isn't a flux cube or does it not matter?
What if you have it active, and then do unit conversion? Is that possible yet?
Right now it just grabs the first visible layer in the viewer, I should add a check to make sure it's 3D at least. And unit conversion is not available in Cubeviz currently. |
Hmmm, that's a good point though, you could in theory have the uncertainty or mask cube in that viewer, and so maybe we should use the logic from #2646 to always use the flux-cube, since that is what creating the subset will end up doing anyways (I think). |
a410c78
to
cb3b1ed
Compare
This already respected the user-set x-limits, I just implemented reverting to the previous zoom on |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2647 +/- ##
==========================================
- Coverage 91.53% 91.52% -0.01%
==========================================
Files 161 161
Lines 20056 20196 +140
==========================================
+ Hits 18358 18485 +127
- Misses 1698 1711 +13 ☔ View full report in Codecov by Sentry. |
This is what the other zoom option for the preview (overlaying it over current zoom) would look like. I was leaning toward zooming to the preview, but now I think this might be nicer so that you don't potentially have other spectra constantly moving around as the zoom changes. The downside is not being able to see what the flux values of the preview are. Screen.Recording.2024-01-09.at.12.36.33.PM.mov |
628f38c
to
cb3b1ed
Compare
def activate(self): | ||
self.viewer.add_event_callback(self.on_mouse_move, events=['mousemove', 'mouseleave']) | ||
if self._spectrum_viewer is None: | ||
self._spectrum_viewer = self.viewer.jdaviz_helper.app.get_viewer('spectrum-viewer') |
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.
can we avoid hardcoding 'spectrum-viewer'
here by using the helper attributes?
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.
still think this might be worth doing to avoid future headache
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.
Done, grabs the first profile viewer now.
y = int(np.round(data['domain']['y'])) | ||
|
||
# Use first visible layer for now | ||
cube_data = [layer.layer for layer in self.viewer.layers if layer.state.visible][0] |
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.
should this use similar logic as #2646 to ensure its pulling from the flux cube? What happens when there are no visible layers (I'm guessing a traceback... we might want to just skip that case gracefully)?
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 changed this to return on an empty result, good catch.
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.
The logic in 2646 might be useful, but I don't think it's worth holding this up for that to be merged. We could potentially do that if/when we change the axis handling.
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.
ok, but the first visible layer now could still be a flat image, or the uncertainty or mask cubes, 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.
I added a check to at least only use 3D data, avoiding a traceback if something like a collapsed image is displayed.
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.
thinking about this more... I think this should listen to the layer selection in mouseover itself, which also might fix the bug with the uncertainty cube failing to display. That or we just ALWAYS pull the flux cube, regardless of the viewer and whether it is an active layer in that viewer or not 🤷
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.
The spectrum changing is so responsive, nice work!
if len(cube_data) == 0: | ||
return | ||
cube_data = cube_data[0] | ||
spectrum = cube_data.get_object(statistic=None) |
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.
is it worth caching this?
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 thought about getting this on activation but was worried about data changing while the tool is active, and since it seems performant I didn't think it was worth the overhead of adding a hub listener or something along those lines.
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 think this might not be performant on large cubes (or anything where get_object
is expensive), but haven't tested. I guess we can leave that for future improvement, since depending on the decision of how to handle layer selection, you may need to have a listener to invalidate the cache
@kecnry This now tries to preview the same data as selected for the coords info hover, before falling back on any 3D data available if the selected layer isn't 3D. I also fixed the uncertainty preview. Mind giving this another look? |
else: | ||
for layer in self.viewer.layers: | ||
if layer.layer.label == coords_info_dataset and layer.visible: | ||
if isinstance(layer, BqplotImageSubsetLayerArtist): | ||
# cannot expose info for spatial subset layers | ||
continue | ||
cube_data = layer.layer | ||
break |
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.
can this rely on dataset.selected_obj
(which will then get caching for free)? Or do you need some layer info that isn't accessible there?
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 also then might let you mouseover the uncertainty viewer but access the mouseover from the flux cube (if selected manually in the mouseover cycler) which would be super cool!
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 was just copying the logic from coords_info
, using selected_obj
seems to work with an extra check for glue Data vs Spectrum1D. I do worry that it will be confusing for users rather than a good feature that if they select the hover option in a viewer, they might be seeing the data from another viewer if it's selected at the top level.
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.
hmmm true, I think most people don't even use the cycler though, so probably won't run into this except for advanced use-cases. Might be worth some user-testing or just see if anyone complains about confusion.
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 well! Just a few comments above and I think this is good to go! (Although would be nice to get code coverage a little higher if that isn't too difficult - many of the uncovered lines are just different mouseout situations which probably don't need specific coverage)
* Working on adding spectrum-from-spaxel on hover * First working version of spectrum on hover * Handle NaNs properly * Update docs and changelog * Add simple test Codestyle Codestyle * Revert zoom after preview view * Address review comments * Only use 3D data * Fix preview spectrum for uncertainty cube * Use the same layer selection as coords_info if possible * Codestyle * Use selected_obj and get first profile viewer rather than spectrum-viewer specifically * Remove unused import * Improve test coverage
Now shows spectrum and auto-scales spectrum viewer when hovering with the single-spaxel subset tool activated, see demo:
Screen.Recording.2024-01-05.at.11.59.02.AM.mov
Opened as draft since I still need to add tests and update docs. Outstanding question: do we want to reset the spectrum viewer limits to the default when deactivating the tool/leaving the viewer area?