-
Notifications
You must be signed in to change notification settings - Fork 74
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
Enable spectral conversion in cubeviz #2758
Enable spectral conversion in cubeviz #2758
Conversation
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 found two things in initial testing:
- The moment map plugin still breaks if you've changed spectral units and use "Surrounding" for the continuum, looks like it's getting an empty array for the continuum due to the differing units.
- We should probably also change the units shown in the Spectral Extraction plugin if the display units have changed. The plugin still works as-is, but the wavelength is in the original units.
I also left one comment on the code.
xunit = _valid_glue_display_unit(self.spectral_unit.selected, self.spectrum_viewer, 'x') | ||
if self.spectrum_viewer.state.x_display_unit != xunit: | ||
self.spectrum_viewer.state.x_display_unit = xunit | ||
self.hub.broadcast(GlobalDisplayUnitChanged('spectral', |
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 these messages actually go inside the if
block? We don't need to broadcast this if the unit didn't actually change, do we?
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.
What was the reason for changing the order? I'm trying to think if there are any (unintentional) consequences to that... but hopefully it is fine if its needed for something else.
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 using the spectrum_viewer
to get the spectral units while developing so I moved it to after that change. Now that it is in the if statement I don't know if it matters anymore.
How does/will the "per sterdian" thingy fit into this? |
This is to prepare for that by bringing the plugin in and enable conversion to the spectral axis, intentionally deferring flux so that we can decide whether to lump flux and surface brightness together or have as separate dropdowns, etc. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2758 +/- ##
==========================================
+ Coverage 88.72% 88.79% +0.07%
==========================================
Files 110 110
Lines 16353 16607 +254
==========================================
+ Hits 14509 14746 +237
- Misses 1844 1861 +17 ☔ View full report in Codecov by Sentry. |
@rosteen @gibsongreen The problems Ricky was seeing should be fixed, please re-review when you can. |
@rosteen Seems like if you avoid using model fitting, everything else works with spectral unit conversion. Any ideas why that might be happening? Edit: it does work in specviz, just not cubeviz. |
b94cc85
to
7e64afd
Compare
spec_axis = layer.layer.data.get_object(cls=Spectrum1D).spectral_axis | ||
display_spectral_units = self.jdaviz_app._get_display_unit('spectral') | ||
if display_spectral_units is not '' and spec_axis.unit != display_spectral_units: | ||
converted_axis = spec_axis.to(display_spectral_units).value | ||
else: | ||
converted_axis = spec_axis.value |
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 making slice selection much slower but I do not have a great solution for this at the moment.
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 hoping that it only slowed down slice selection after the spectral axis had been converted, but it does seem a little bit slower right from the start as well. Probably not a deal-breaker but a little frustrating.
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 just cache the scale factor between native and display units so that we don't need to do units math here repeatedly?
It looks like the bugs I found are fixed, but the test failures look real. One other thing - although slicing works now, when you change units the slice indicator does still end up off the screen initially. Maybe we can set the slice indicator to the same pixel index after changing units? Looking much closer to ready to merge! |
Should we remilestone this to 3.10 just so we don't accidentally merge this shortly before the 3.9 release and we don't get a chance to test it properly? |
del self.slice_values | ||
self.slice_values |
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 would really benefit from #2253, but for now, should be:
del self.slice_values | |
self.slice_values | |
if 'slice_values' in self.__dict__: | |
del self.__dict__['slice_values'] |
(and same for the other case)
a03ba2b
to
268f6d2
Compare
Add message to flux conversion dropdown in cubeviz Have moment map units update after conversion Update continuum, moment maps, and spectral extraction Fix model fitting and aperture plugins and add tests Update slice_values to account for unit conversion Remove print statment and unused import Fix style Fix moment map and slice tests Fix style 2 Add LinkSameWithUnits and slice indicator updates
2214759
to
bfcf69d
Compare
I just pushed a commit to fix the slice indicator behavior after unit conversion. Basically, the indicator mark and the slice plugin itself both had logic to convert to the new unit, but neither knew that it had already been done by the other so it was happening twice. My commit overrides the method inherited from the base |
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 might have a conflict of interest now that I committed code, but I think this is good to go at this point.
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.
Awesome to see this in and performant, I'm excited to rebase and start trying spectral/flux/sb conversions all together. Great work!
jdaviz/configs/specviz/plugins/unit_conversion/unit_conversion.vue
Outdated
Show resolved
Hide resolved
@@ -2871,8 +2872,8 @@ def _get_continuum(self, dataset, spatial_subset, spectral_subset, update_marks= | |||
'center': spectral_axis.value, | |||
'right': []} | |||
else: | |||
mark_x = {'left': spectral_axis_nanmasked[spectral_axis.value < sr_lower.value], | |||
'right': spectral_axis_nanmasked[spectral_axis.value > sr_upper.value]} | |||
mark_x = {'left': spectral_axis_nanmasked[spectral_axis < sr_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.
I am unable to tell from a quick glance if mark_x
is going into any front-end message. Looks like you are now passing Quantity instead of float arrays? Is the front-end JSON thingy able to handle this without warning?
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.
From my testing it is, did you experience a bug relating to 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.
In the past, I had seen warnings polluting the notebook cell outputs when JSON is trying to serialize something fancy like Quantity. But if you don't see it, then maybe it is not a problem here. Just double checking. Thanks!
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 quantity is just being used to determine the indices though, right? spectral_axis_nanmasked
is unchanged here.
jdaviz/configs/cubeviz/plugins/spectral_extraction/spectral_extraction.py
Show resolved
Hide resolved
@property | ||
def slice_display_unit_name(self): | ||
return 'spectral' |
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.
same thing here (can we rename to slice_axis
or rename slice_axis
in slice to 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 changed slice_axis
to slice_display_unit_name
, let me know if another name sounds more appropriate. Otherwise I can merge once CI passes (whatever can run right now at least).
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 now able to write the overrides in lcviz to handle these changes - so thanks for your patience with all my requests (/demands) to try to generalize this so much!
I do think a rename of the property to be consistent between here and the slice plugin would help make it less confusing internally in the future, but otherwise I think this is good to go and any further generalization can be handled as needed when actually integrating into lcviz. Thanks!
* Add unit conversion plugin with flux conversion disabled Add message to flux conversion dropdown in cubeviz Have moment map units update after conversion Update continuum, moment maps, and spectral extraction Fix model fitting and aperture plugins and add tests Update slice_values to account for unit conversion Remove print statment and unused import Fix style Fix moment map and slice tests Fix style 2 Add LinkSameWithUnits and slice indicator updates * Use cached_property for slice_values * Use correct cache clearing protocol Running CI without cached_property Fix everything except todo statements Uncommented code needed for uncert viewer to change slice Remove comments * Fix message handlers * Remove space * Minor changes * Override display unit handling in slice mark so we don't change value twice * Simplify and generalize viewer slice values code * Fix style * Move code out of try except block * Address review comments * Generalize display unit call in spectral extraction * Fix test failure * Rename slice_axis property to slice_display_unit_name * Add changelog --------- Co-authored-by: Ricky O'Steen <rosteen@stsci.edu>
* Add unit conversion plugin with flux conversion disabled Add message to flux conversion dropdown in cubeviz Have moment map units update after conversion Update continuum, moment maps, and spectral extraction Fix model fitting and aperture plugins and add tests Update slice_values to account for unit conversion Remove print statment and unused import Fix style Fix moment map and slice tests Fix style 2 Add LinkSameWithUnits and slice indicator updates * Use cached_property for slice_values * Use correct cache clearing protocol Running CI without cached_property Fix everything except todo statements Uncommented code needed for uncert viewer to change slice Remove comments * Fix message handlers * Remove space * Minor changes * Override display unit handling in slice mark so we don't change value twice * Simplify and generalize viewer slice values code * Fix style * Move code out of try except block * Address review comments * Generalize display unit call in spectral extraction * Fix test failure * Rename slice_axis property to slice_display_unit_name * Add changelog --------- Co-authored-by: Ricky O'Steen <rosteen@stsci.edu>
Description
This pull request enables unit conversion in cubeviz only for spectral conversions. The following plugins also need to be updated to account for possible spectral axis unit changes:
Potential follow-up efforts:
None
) not working with frequency unitsChange 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.