-
Notifications
You must be signed in to change notification settings - Fork 72
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
fix spectral extraction previews on unit change #3157
Draft
kecnry
wants to merge
4
commits into
spacetelescope:main
Choose a base branch
from
kecnry:spec-ext-previews
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+44
−28
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
from jdaviz.core.user_api import PluginUserApi | ||
from jdaviz.configs.cubeviz.plugins.parsers import _return_spectrum_with_correct_units | ||
from jdaviz.configs.cubeviz.plugins.viewers import WithSliceIndicator | ||
from jdaviz.utils import _eqv_pixar_sr | ||
|
||
|
||
__all__ = ['SpectralExtraction'] | ||
|
@@ -109,8 +110,8 @@ class SpectralExtraction(PluginTemplateMixin, ApertureSubsetSelectMixin, | |
|
||
results_units = Unicode().tag(sync=True) | ||
spectrum_y_units = Unicode().tag(sync=True) | ||
flux_unit = Unicode().tag(sync=True) | ||
sb_unit = Unicode().tag(sync=True) | ||
flux_units = Unicode().tag(sync=True) | ||
sb_units = Unicode().tag(sync=True) | ||
|
||
aperture_method_items = List().tag(sync=True) | ||
aperture_method_selected = Unicode('Center').tag(sync=True) | ||
|
@@ -180,7 +181,7 @@ def __init__(self, *args, **kwargs): | |
self.session.hub.subscribe(self, SliceValueUpdatedMessage, | ||
handler=self._on_slice_changed) | ||
self.hub.subscribe(self, GlobalDisplayUnitChanged, | ||
handler=self._on_gloabl_display_unit_changed) | ||
handler=self._on_global_display_unit_changed) | ||
|
||
self._update_disabled_msg() | ||
|
||
|
@@ -315,31 +316,33 @@ def _update_mark_scale(self, *args): | |
else: | ||
self.background.scale_factor = self.slice_spectral_value/self.reference_spectral_value | ||
|
||
def _on_gloabl_display_unit_changed(self, msg={}): | ||
def _on_global_display_unit_changed(self, msg=None): | ||
if msg is None: | ||
self.flux_units = str(self.app._get_display_unit('flux')) | ||
self.sb_units = str(self.app._get_display_unit('sb')) | ||
self.spectrum_y_units = str(self.app._get_display_unit('spectral_y')) | ||
|
||
if msg.axis == 'spectral_y': | ||
self.spectrum_y_units = str(msg.unit) | ||
|
||
# a 'flux' and 'sb' message should be recieved back to back from | ||
# the unit conversion plugin, so don't need to sync them immediatley | ||
# within each message recieved | ||
elif msg.axis == 'flux': | ||
self.flux_unit = str(msg.unit) | ||
self.flux_units = str(msg.unit) | ||
elif msg.axis == 'sb': | ||
self.sb_unit = str(msg.unit) | ||
self.sb_units = str(msg.unit) | ||
elif msg.axis == 'spectral_y': | ||
self.spectrum_y_units = str(msg.unit) | ||
# no need to update results_units | ||
return | ||
else: | ||
# ignore | ||
return | ||
|
||
# and set results_units, which depends on function selected | ||
# update results_units based on flux_units, sb_units, and currently selected function | ||
self._update_units_on_function_selection() | ||
|
||
@observe('function_selected') | ||
def _update_units_on_function_selection(self, *args): | ||
|
||
if self.function_selected.lower() == 'sum': | ||
self.results_units = self.flux_unit | ||
self.results_units = self.flux_units | ||
else: | ||
self.results_units = self.sb_unit | ||
self.results_units = self.sb_units | ||
# any changes to results_units will trigger _live_update_marks | ||
|
||
@observe('function_selected', 'aperture_method_selected') | ||
def _update_aperture_method_on_function_change(self, *args): | ||
|
@@ -542,7 +545,9 @@ def _preview_x_from_extracted(self, extracted): | |
return extracted.spectral_axis.value | ||
|
||
def _preview_y_from_extracted(self, extracted): | ||
return extracted.flux.value | ||
# TODO: use extracted's PIXAR_SR instead (but for some reason isn't populated here...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does anyone know why this is (I'm guessing its just populated later when actually loading into the app)? Ultimately, I think the extracted spectrum just gets a copy of PIXAR_SR from the input cube, so this shouldn't matter, it just would read more cleanly if it did. |
||
return extracted.flux.to_value(self.spectrum_y_units, | ||
equivalencies=_eqv_pixar_sr(self.dataset.selected_obj.meta.get('PIXAR_SR', 1.0))) # noqa: | ||
|
||
@with_spinner() | ||
def extract(self, return_bg=False, add_data=True, **kwargs): | ||
|
@@ -726,8 +731,15 @@ def _clear_marks(self): | |
'wavelength_dependent', 'bg_wavelength_dependent', 'reference_spectral_value', | ||
'function_selected', | ||
'aperture_method_selected', | ||
'spectrum_y_units', 'results_units', | ||
'previews_temp_disabled') | ||
def _live_update_marks(self, event={}): | ||
if self.spectrum_y_units == '': | ||
# ensure that units are populated | ||
# which in turn will make a call back here | ||
# from the observe on spectrum_y_units | ||
self._on_global_display_unit_changed(None) | ||
return | ||
self._update_marks(event) | ||
|
||
@skip_if_not_tray_instance() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just to be consistent with the traitlets above, I was confusing myself when writing code later in the plugin and having to switch between singular and plural