-
Notifications
You must be signed in to change notification settings - Fork 82
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
[BUG] Specviz: Fix app.py so subset can apply to multiple data #1921
Comments
I might be in the wrong rabbit hole but to some degree, I was able to traverse the tree after I added the following method in --- a/glue/core/subset.py
+++ b/glue/core/subset.py
@@ -1096,6 +1096,11 @@ class CompositeSubsetState(SubsetState):
sym = OPSYM.get(self.op, self.op)
return "(%s %s %s)" % (self.state1, sym, self.state2)
+ def traverse(self):
+ return (self.op,
+ self.state1 if not hasattr(self.state1, 'traverse') else self.state1.traverse(),
+ self.state2 if not hasattr(self.state2, 'traverse') else self.state2.traverse())
+ With the patch above at glue-core, you would get this in Specviz. Here, the composite subset is the second one I created and I used "AND" the first pass with 2 discontinuous regions, and then after that I got back and add XOR to the first sub-region. I don't know why each operator traversal returns in the format of >>> specviz.app.data_collection.subset_groups[1].subset_state.traverse()
(<function _operator.xor(a, b, /)>,
<glue.core.subset.RangeSubsetState at 0x7f3ba140e440>,
(<function _operator.xor(a, b, /)>,
<glue.core.subset.RangeSubsetState at 0x7f3ba140ed10>,
(<function _operator.or_(a, b, /)>,
<glue.core.subset.RangeSubsetState at 0x7f3ba140e5f0>,
(<function _operator.or_(a, b, /)>,
<glue.core.subset.RangeSubsetState at 0x7f3ba14d58a0>,
<glue.core.subset.RangeSubsetState at 0x7f3ba14d4d30>)))) Even without this patch, you can kinda see the traversal pattern by manually accessing the following: >>> specviz.app.data_collection.subset_groups[1].subset_state.op
>>> specviz.app.data_collection.subset_groups[1].subset_state.state1
>>> specviz.app.data_collection.subset_groups[1].subset_state.state2
>>> specviz.app.data_collection.subset_groups[1].subset_state.state2.op # and so on |
Also affects the subset component's jdaviz/jdaviz/core/template_mixin.py Lines 958 to 960 in ecc2658
|
Just to check, what would you have liked to see? Currently you are seeing the result of the very generic way of combining subsets which might not always be e.g. spatial subsets but you could have subsets defined also by e.g. a contour/threshold or even more wild subsets, an each subset in the expression might depend on different data attributes. What I mean is that not all subsets will always be geometrical subsets in the plane of the image being viewed, so not always possible to write in a simpler way. Having said that maybe we could investigate having a way for viewer classes to optionally be able to simplify subset definitions on the fly when they can be simplified. |
@astrofrog , did the tag-up just now answer your question above? |
Yep! |
Hi @astrofrog here is an example of what we were talking about with the |
Here are the notes from the meeting that was had for this topic on 01/18/2023: How do we want subset information returned?
Path forwardWe ended up deciding to do "something else", specifically implement a |
Describe the bug
TLDR: Core methods in app.py assume only one data is loaded at a time, or a subset is applied to only one data at a time.
There are a few issues that this ticket will be pointing out. I will try to link to the code and provide examples where I can
app.get_data_from_viewer()
returns all data that is loaded into a particular viewer. The only time this is not the case is when a subset is applied to multiple data. In that case, only the last data the subset applies to (going by layer order) will be returned withdata[‘Subset 1’]
.jdaviz/jdaviz/app.py
Line 680 in 46f0ae2
The next issue is that
app.get_subset_from_viewer()
uses the data that the subset is applied to (line 680 above) to calculate the bounds of that subsetjdaviz/jdaviz/app.py
Lines 775 to 776 in 46f0ae2
jdaviz/jdaviz/app.py
Line 822 in 46f0ae2
jdaviz/jdaviz/app.py
Lines 826 to 828 in 46f0ae2
This means that if Subset 1 actually applies to multiple data, only the bounds that apply to the latest data will be used. I attempted to fix that last point in this PR
https://github.com/spacetelescope/jdaviz/pull/1886/files
But then we realized that these lines
jdaviz/jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Lines 147 to 148 in 3f851ec
Append subregions to a subset, even if the user is just repositioning the subset. In order to fix this, we would have to include all the glue subset operators
https://jdaviz.readthedocs.io/en/latest/imviz/displayimages.html#defining-spatial-regions
shown at the bottom of those docs so we could arrange the subregions correctly.
We have discussed the possible solution of using a
SubsetCollection
type object to store all the data a subset is applied to, which would help with this particular problem. We have reached out to @astrofrog if there is something like that that already exists but it may be something we have to create in jdaviz.Example of a Subset applied to multiple spectra:

The text was updated successfully, but these errors were encountered: