-
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
update unit conversion message responses in plugins, add tests #3144
base: main
Are you sure you want to change the base?
Changes from 6 commits
cddd7a8
63f895d
a34fa0b
bfca6aa
d88a49b
8f5cf54
b2bd693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,6 +109,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) | ||||||
|
||||||
aperture_method_items = List().tag(sync=True) | ||||||
aperture_method_selected = Unicode('Center').tag(sync=True) | ||||||
|
@@ -178,7 +180,7 @@ def __init__(self, *args, **kwargs): | |||||
self.session.hub.subscribe(self, SliceValueUpdatedMessage, | ||||||
handler=self._on_slice_changed) | ||||||
self.hub.subscribe(self, GlobalDisplayUnitChanged, | ||||||
handler=self._update_results_units) | ||||||
handler=self._on_gloabl_display_unit_changed) | ||||||
|
||||||
self._update_disabled_msg() | ||||||
|
||||||
|
@@ -313,13 +315,27 @@ 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={}): | ||||||
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.
Suggested change
|
||||||
|
||||||
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 | ||||||
if msg.axis == 'flux': | ||||||
self.flux_unit = str(msg.unit) | ||||||
if msg.axis == 'sb': | ||||||
self.sb_unit = str(msg.unit) | ||||||
|
||||||
@observe('function_selected') | ||||||
def _update_results_units(self, msg={}): | ||||||
self.spectrum_y_units = str(self.app._get_display_unit('spectral_y')) | ||||||
def _update_units_on_function_selection(self, *args): | ||||||
|
||||||
if self.function_selected.lower() == 'sum': | ||||||
self.results_units = str(self.app._get_display_unit('flux')) | ||||||
self.results_units = self.flux_unit | ||||||
else: | ||||||
self.results_units = str(self.app._get_display_unit('sb')) | ||||||
self.results_units = self.sb_unit | ||||||
kecnry marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
@observe('function_selected', 'aperture_method_selected') | ||||||
def _update_aperture_method_on_function_change(self, *args): | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -528,7 +528,7 @@ def _check_model_component_compat(self, axes=['x', 'y'], display_units=None): | |
self._check_model_equation_invalid() | ||
|
||
def _on_global_display_unit_changed(self, msg): | ||
axis = {'spectral': 'x', 'flux': 'y'}.get(msg.axis) | ||
axis = {'spectral': 'x', 'spectral_y': 'y'}.get(msg.axis) | ||
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. this probably needs some logic to skip if the |
||
|
||
# update internal tracking of current units | ||
self._units[axis] = str(msg.unit) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,21 +230,22 @@ def _on_flux_unit_changed(self, msg): | |
if not self.flux_unit.choices and self.app.config == 'cubeviz': | ||
return | ||
|
||
flux_or_sb = None | ||
|
||
# when the configuration is Specviz, translation is not currently supported. | ||
# If in Cubeviz, all spectra pass through Spectral Extraction plugin and will | ||
# have a scale factor assigned in the metadata, enabling translation. | ||
current_y_unit = self.spectrum_viewer.state.y_display_unit | ||
|
||
# if the current y display unit is a surface brightness unit, | ||
if self.angle_unit.selected and check_if_unit_is_per_solid_angle(current_y_unit): | ||
flux_or_sb = self._append_angle_correctly( | ||
self.flux_unit.selected, | ||
self.angle_unit.selected | ||
) | ||
else: | ||
flux_or_sb = self.flux_unit.selected | ||
# various plugins are listening for changes in either flux or sb and | ||
# need to be able to filter messages accordingly, so broadcast both when | ||
# flux unit is updated. if data was loaded in a flux unit (i.e MJy), it | ||
# can be reperesented as a per-pixel surface brightness unit | ||
flux_unit = self.flux_unit.selected | ||
sb_unit = self._append_angle_correctly(flux_unit, self.angle_unit.selected) | ||
|
||
self.hub.broadcast(GlobalDisplayUnitChanged("flux", flux_unit, sender=self)) | ||
self.hub.broadcast(GlobalDisplayUnitChanged("sb", sb_unit, sender=self)) | ||
|
||
flux_or_sb = sb_unit if check_if_unit_is_per_solid_angle(current_y_unit) else flux_unit | ||
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. Is there any reason this can't use the Either way, maybe we rename the variable to 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. I think that should work, the traitlet for |
||
|
||
untranslatable_units = self._untranslatable_units | ||
# disable translator if flux unit is untranslatable, | ||
|
@@ -262,8 +263,10 @@ def _on_flux_unit_changed(self, msg): | |
self.spectrum_viewer.state.y_display_unit = yunit | ||
self.spectrum_viewer.reset_limits() | ||
|
||
# and broacast that there has been a change in flux | ||
self.hub.broadcast(GlobalDisplayUnitChanged("flux", flux_or_sb, sender=self)) | ||
# and broacast that there has been a change in the spectral axis y unit | ||
# to either a flux or surface brightness unit, for plugins that specifically | ||
# care about this toggle selection | ||
self.hub.broadcast(GlobalDisplayUnitChanged("spectral_y", flux_or_sb, sender=self)) | ||
|
||
if not check_if_unit_is_per_solid_angle(self.spectrum_viewer.state.y_display_unit): | ||
self.flux_or_sb_selected = 'Flux' | ||
|
@@ -298,10 +301,12 @@ def _translate(self, flux_or_sb=None): | |
spec_units = u.Unit(self.spectrum_viewer.state.y_display_unit) | ||
else: | ||
return | ||
|
||
# on instantiation, we set determine flux choices and selection | ||
# after surface brightness | ||
if not self.flux_unit.choices: | ||
return | ||
|
||
# Surface Brightness -> Flux | ||
if check_if_unit_is_per_solid_angle(spec_units) and flux_or_sb == 'Flux': | ||
spec_units *= u.sr | ||
|
@@ -318,7 +323,9 @@ def _translate(self, flux_or_sb=None): | |
else: | ||
return | ||
|
||
self.hub.broadcast(GlobalDisplayUnitChanged('flux', | ||
# broadcast that there has been a change in the spectrum viewer y axis, | ||
# if translation was completed | ||
self.hub.broadcast(GlobalDisplayUnitChanged('spectral_y', | ||
spec_units, | ||
sender=self)) | ||
self.spectrum_viewer.reset_limits() | ||
|
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.