Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cshanahan1
Copy link
Contributor

@cshanahan1 cshanahan1 commented Aug 9, 2024

This PR improves the messaging from the unit conversion plugin to broadcast changes in selected display unit. Because some plugins are listening for changes to the spectral y axis (either from toggling flux<>sb, changing flux or angle when it is toggled to SB, or changing flux when it is toggled to flux) this is its own message now.

Every time a new selection of 'flux' is made, there are three GlobalDisplayUnitChanged messages broadcasted : 'flux', 'sb', and 'spectral_y'.

While this is not included in this PR, these changes will make it possible for the correct messaging to be broadcasted when a new angle selection is made (always sending a 'sb' message, and if the spectral y axis is in SB also sending a 'spectral_y' message).

Every time there is a toggle between flux<> sb, the GlobalDisplayUnitChanged axis='spectral_y' message is broadcasted.

This PR also updates the plugins listening to unit changes to intercept only the relevant type of GlobalDisplayUnitChanged - before, they were responding to any message of this type.

Finally, this fixes an issue with mouseover in cubeviz and adds test coverage.

@github-actions github-actions bot added specviz imviz plugin Label for plugins common to multiple configurations labels Aug 9, 2024
@cshanahan1 cshanahan1 added this to the 4.0 milestone Aug 9, 2024
@cshanahan1 cshanahan1 added the no-changelog-entry-needed changelog bot directive label Aug 9, 2024
@pllim
Copy link
Contributor

pllim commented Aug 9, 2024

Is a regression test easy to add? Both you and Ricky seemed surprised that CI didn't catch this.

Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.80%. Comparing base (f5c93ab) to head (42d5bae).

Files Patch % Lines
...specviz/plugins/unit_conversion/unit_conversion.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3144      +/-   ##
==========================================
- Coverage   88.82%   88.80%   -0.02%     
==========================================
  Files         112      112              
  Lines       17550    17552       +2     
==========================================
- Hits        15588    15587       -1     
- Misses       1962     1965       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cshanahan1 cshanahan1 changed the title broadcast sb change for mouseover update messaging from unit conversion plugin, fix issue with mouseover, add tests Aug 15, 2024
axis = {'spectral': 'x', 'flux': 'y'}.get(msg.axis)
axis = {'spectral': 'x', 'spectral_y': 'y'}.get(msg.axis)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably needs some logic to skip if the msg.axis is not either spectral or spectral_y (could be by checking if axis is None after the get, or rewriting this into if, elif, else: return.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason this can't use the self.flux_or_sb switch instead of self.spectrum_viewer.state.y_display_unit (maybe @gibsongreen would have some context on that as well)? That could be done as a follow-up if its out of scope.

Either way, maybe we rename the variable to spectral_y to be consistent with the message that is broadcast from this and to avoid confusion with the switch itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should work, the traitlet for self.flux_or_sb at this point in the function should still match that flux or surface brightness selection for the value of self.spectrum_viewer.state.y_display_unit/spectral_y/current_y_unit

@cshanahan1 cshanahan1 changed the title update messaging from unit conversion plugin, fix issue with mouseover, add tests update unit conversion message responses, fix issue with mouseover, add tests Aug 15, 2024
@cshanahan1 cshanahan1 changed the title update unit conversion message responses, fix issue with mouseover, add tests update unit conversion message responses in plugins, add tests Aug 15, 2024
@rosteen rosteen modified the milestones: 4.0, 4.1 Oct 17, 2024
@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
handler=self._on_gloabl_display_unit_changed)
handler=self._on_global_display_unit_changed)

@@ -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={}):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _on_gloabl_display_unit_changed(self, msg={}):
def _on_global_display_unit_changed(self, msg={}):

@rosteen rosteen modified the milestones: 4.1, 4.2 Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imviz no-changelog-entry-needed changelog bot directive plugin Label for plugins common to multiple configurations specviz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants