-
Notifications
You must be signed in to change notification settings - Fork 79
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
Remove dependency on spectral-cube #1006
Conversation
|
||
# FIXME: Does not work. | ||
# collapsed_spec = spec.collapse(self.selected_func.lower(), axis=self.selected_axis) | ||
# data = Data(coords=collapsed_spec.wcs) |
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 am not sure how to use specutils.Spectrum1D.collapse
to get spatial-spectral object correctly here. Particularly, the axis order might not be the same as spectral-cube
; not sure, as the warnings about flipping axis from specutils
is very confusing.
But more importantly, do we really need so many options for axis if people only ever wants to collapse to get spatial-spatial?
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.
In offline discussion we decided that giving "spectral" and "spatial" collapse options rather than numerical axes is the way to go here. None of us could think of a use case for collapsing only one spatial axis. FYI the specutils collapse method should take those two strings as valid axis
inputs, so it is hopefully easy to implement.
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.
As discussed in 2021-12-16 tag-up, "spectral" collapse already happens automatically on load, so having it also in the plugin would be redundant.
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 forgot what's the conclusion here. Do we still support "spectral" collapse or just get rid of it?
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 would say leave it in 🤷
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 cannot make sense of the previous implementation using spectral-cube, so I removed "axis" option altogether. #yolo
@pllim I'm hoping that astropy/specutils#911 resolves the |
02498bf
to
511da6d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1006 +/- ##
==========================================
+ Coverage 75.32% 75.42% +0.09%
==========================================
Files 80 80
Lines 6059 6042 -17
==========================================
- Hits 4564 4557 -7
+ Misses 1495 1485 -10 ☔ View full report in Codecov by Sentry. |
@@ -111,11 +111,6 @@ try a different OS/browser combo. | |||
Specviz | |||
------- | |||
|
|||
Collapse Plugin spectral bounds do not match selected region |
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.
This entry is misleading because Specviz does not load Collapse and there is already a similar entry above for Cubeviz.
@@ -16,28 +14,15 @@ | |||
__all__ = ['Collapse'] | |||
|
|||
|
|||
spaxel = u.def_unit('spaxel', 1 * u.Unit("")) |
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.
This is not used. Not sure why it is here. It is also defined in at least two other places in this package but removing those is out of scope here.
@@ -108,14 +88,14 @@ def vue_list_subsets(self, event): | |||
temp_dict = {} | |||
# Attempt to filter out spatial subsets | |||
for key, region in temp_subsets.items(): | |||
if type(region) == RectanglePixelRegion: | |||
if type(region) == SpectralRegion: |
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 was overlooked in #1046 ?
|
||
snackbar_message = SnackbarMessage( | ||
f"Data set '{self._selected_data.label}' collapsed successfully.", | ||
color="success", | ||
sender=self) | ||
self.hub.broadcast(snackbar_message) | ||
|
||
if self.selected_axis == 0 and self.selected_viewer != 'None': | ||
# Spatial-spatial image only. | ||
if self.selected_viewer != 'None': | ||
# replace the contents in the selected viewer with the results from this plugin | ||
self.app.add_data_to_viewer(self.viewer_to_id.get(self.selected_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.
@kecnry , I noticed something weird where while the collapsed image shows in the selected viewer, I am unable to use Layers menu to change the display. I have to deselect it from Data and re-select for Layers to work again. Not sure if this is a known issue or not.
Also, the spectral Subset somehow colors the whole collapsed image in the tint of the Subset color. I can disable it by clicking the eye icon on the Layers dropdown. I think this is a separate known issue already.
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 know both of these are known issues. The second I think is expected behavior (so long as the current slice is within the subset), but I agree that we may want to reconsider that default once the slice indicator in #1013 is merged as there will already be visual indication of the slice being in a subset.
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.
p.s. While it is expected behavior, I wonder if it is the wrong behavior. I cannot see the image properly with the tint all over it, but yes, it is a separate issue for another time.
coll.add_replace_results = False | ||
coll.vue_collapse() | ||
|
||
assert len(dc) == 2 | ||
assert dc[1].label == 'Collapsed 1 test' | ||
assert len(dc.external_links) == 3 | ||
assert len(dc.external_links) == 2 |
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 results changed here but I don't know what it means. Plugin seems to work though. 🤷
@@ -70,8 +70,6 @@ def test_region_from_subset_profile(jdaviz_app, spectral_cube_wcs): | |||
subsets = jdaviz_app.get_subsets_from_viewer('spectrum-viewer', subset_type='spectral') | |||
reg = subsets.get('Subset 1') | |||
|
|||
print(reg) |
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.
Leftover debugging from #1046 .
519ab0f
to
54d04b4
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This rotation does not seem to occur in main (when choosing axis=0). |
8c24245
to
96ed69e
Compare
if data_label not in self.data_collection.labels: | ||
return | ||
self._selected_data = self.data_collection[self.data_collection.labels.index(data_label)] | ||
self._selected_cube = self._selected_data.get_object(cls=Spectrum1D, 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.
Note: I feel like there is no point to extract the cube multiple times across the plugin. Here, I change it to extracting it only once when data is selected.
warnings.filterwarnings('ignore', message='No observer defined on WCS') | ||
spec = spectral_slab(self._selected_cube, spec_min, spec_max) | ||
# Spatial-spatial image only. | ||
collapsed_spec = spec.collapse(self.selected_func.lower(), axis=-1).T # Quantity |
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.
Note: Transpose here fixes the orientation problem that @javerbukh found.
|
||
from jdaviz.configs.default.plugins.collapse.collapse import Collapse | ||
|
||
|
||
@pytest.mark.filterwarnings('ignore') | ||
def test_linking_after_collapse(spectral_cube_wcs): | ||
def test_linking_after_collapse(cubeviz_helper, spectral_cube_wcs): |
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.
Note: Might as well use Cubeviz here to be more realistic.
|
||
coll.selected_data_item = 'test' | ||
# This is automatically called in notebook but not in this test. |
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 don't know if this is frontend weirdness in unit test or a bug. Seems to work find in the plugin but please double check!
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 the intention here to update the populated spectral bounds? I think that's scheduled to be removed in the future anyways, but I am seeing it not being populated at start in this PR (but populated at start in main)...
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.
Correct. Because it is my impression that this would automatically be picked up by @observe
. So the way I refactored it, setting, self.selected_data_item
actually calls self.selected_subset
at the end, which I thought would kick off self._on_subset_selected()
automatically to populate the bounds. Am I misunderstanding how @observe
works?
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.
Yes, except the default values set when creating the traitlets don't trigger those. Your setup should work if you have the traitlet default to an empty string instead of "None"
and let it update to "None"
(and the bounds populate) when the data is loaded.
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 wasn't aware of that subtlety. I pushed a commit. Please see if that's correct. Thanks!
ignore::DeprecationWarning:glue | ||
ignore::DeprecationWarning:bqplot | ||
ignore::DeprecationWarning:bqplot_image_gl | ||
ignore::DeprecationWarning:bqscales | ||
ignore::DeprecationWarning:traittypes | ||
ignore::DeprecationWarning:voila |
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 see a new warning locally, so I need this line so the tests would run on my machine.
and refactor Collapse plugin to work with specutils. Remove axis option from Collapse plugin. Change Collapse function default to sum from mean. Minor code clean-ups. Updated test and doc.
96ed69e
to
762bb87
Compare
Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
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.
Looks good! I'm still seeing that bug you mentioned of not being able to set the contrast and bias options for the collapsed data, but I think that's outside the scope of this PR. Nice work!
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.
Everything still seems to work (and am glad to be rid of the confusing axis options)! I think all of the remaining comments existed before and/or can be addressed later.
selected_func = Unicode('Mean').tag(sync=True) | ||
selected_func = Unicode('Sum').tag(sync=True) |
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.
All in favor of this change... but just a note that the default "function" for the spectral-viewer is still "Maximum" (that change is out-of-scope - I would have objected to a change here if this had been Max as well, but it was already different so 🤷♂️ )
Thanks for all the great reviews! |
Description
This pull request is to remove dependency on
spectral-cube
but to do that we also need to refactor theCollapse
plugin.Fixes #922
Blocked by:
Collapse
refactoring, e.g., do we even need to collapse to get spatial-spectral data?specutils
release beyond v1.5.0 forSpectrum1D.collapse()
.Blocks:
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.CHANGES.rst
?