-
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
Add ability to retrieve only spectral or spatial subsets #736
Add ability to retrieve only spectral or spatial subsets #736
Conversation
Woah, it looks like my local main branch might be a bit messed up. Whoops. |
Codecov Report
@@ Coverage Diff @@
## main #736 +/- ##
==========================================
+ Coverage 62.83% 62.86% +0.03%
==========================================
Files 65 65
Lines 4286 4290 +4
==========================================
+ Hits 2693 2697 +4
Misses 1593 1593
Continue to review full report at Codecov.
|
538d6bb
to
76899b0
Compare
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.
Interesting solution by adding subset_type
. I don't see anything wrong with it, but I also wonder if it is really necessary, or can your logic apply by simply comparing with isinstance
.
Also, is it possible to add tests? |
I want this to be available to users without them needing to know what Glue subset attribute to look for to distinguish. It also seemed more elegant to have the I'll see about adding a test later today. |
@@ -453,7 +453,7 @@ def get_data_from_viewer(self, viewer_reference, data_label=None, | |||
|
|||
return data | |||
|
|||
def get_subsets_from_viewer(self, viewer_reference, data_label=None): | |||
def get_subsets_from_viewer(self, viewer_reference, data_label=None, subset_type=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.
New subset_type
needs to be documented. Is "spatial" here only for spectroscopy context? What about imagers?
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.
"spatial" is specifically to get subsets made in image viewers. I just updated the dosctring to (hopefully) make that clearer.
I added a test for using each option of the @pllim I also happened to use the new glue-jupyter functionality you added that resets the subset selection when a new tool is selected ( |
Confirmed that this works and I approve. |
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.
Imviz seems to still work fine with this patch.
I encountered weird behavior after deleting a few interactive regions back to back, but I don't think it is related (probably that lag wrecking havoc on app state).
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 as expected, and I appreciate the direction this PR takes subset handling.
As I understand the original intent of subset scope, subsets were originally meant to exist globally outside the context of a particular datatype (i.e. Spatial subsets have a spectral component and vice versa). Unfortunately, users have repeatedly gotten confused between the two to the point I think it may be best to start dividing subsets explicitly into "Spatial" and "Spectral" subsets, as this PR details. E.g. when a spatial subset is created in Cubeviz, a second, spectral, subset would be defined alongside the spatial subset, and an association would be presented to show the spectral subset was autogenerated from the spatial subset. This would be opposed to my understanding of how things happen currently: A spatial subset is drawn, which has a "spectral" definition as well, but are both defined by the same "spatially-defined" subset
jdaviz_app.data_collection.new_subset_group( | ||
subset_state=subset_state, label='rectangular') | ||
jdaviz_app.get_viewer("spectrum-viewer").apply_roi(XRangeROI(1, 3.5)) |
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 do wonder about this approach of creating an roi through a viewer. It matches our UI paradigm (as you can't define an roi without a viewer), but that's more of a context thing. Ideally, through code, you wouldn't need a viewer in order to define a ROI that is supposed to be viewer-independent, right? I'm surprised you can't go even deeper into Glue and define the ROI even lower
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 point was specifically to go less deep into the stack, I wanted to do it in a way that replicates what happens when you use a region selection tool in a 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.
For example, this way it matters what the Subset selection state (e.g. "Create new" vs "Subset 1" selected) is rather than injecting the subset deeper with a label. Later in the test I trigger the switch back to "Create new" that Pey Lian added by selecting another tool, so we get to make sure that's working as a bonus.
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.
Pey Lian added by selecting another tool
To be fair... I tried to implement it, but @astrofrog ended up rewriting everything anyway in my PR. So the credit really goes to him... 😅
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.
Ah, well, nevertheless!
Fixes a bug when calling
cubeviz.specviz.get_spectral_regions()
where it would crash if there were circular spatial subsets defined in the image viewer (and would return rectangular spatial subsets like they were spectral regions).Also prevents rectangular spatial regions from showing up as spectral regions in the Collapse plugin (see screenshot below), and opens up other usage that would require this capability.
Someone more familiar with Glue should look at this as well in case there are any pitfalls with doing the check this way that I don't appreciate. This is the best attribute on the Subsets I could find to determine whether they are spatial or spectral.