-
Notifications
You must be signed in to change notification settings - Fork 76
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 contour unit conversion #3149
Changes from 10 commits
2b7da9d
a4d2df5
7fafb24
ddf92de
72c37f3
baaf67e
2b81e43
ab25778
1993973
b4bfd6b
d2a9983
f883a95
cd14229
0bed8ba
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import numpy as np | ||
from astropy import units as u | ||
from glue_jupyter.bqplot.image import BqplotImageView | ||
import numpy as np | ||
from traitlets import List, Unicode, observe, Bool | ||
|
||
from jdaviz.core.events import GlobalDisplayUnitChanged | ||
from jdaviz.core.events import GlobalDisplayUnitChanged, AddDataToViewerMessage | ||
from jdaviz.core.registries import tray_registry | ||
from jdaviz.core.template_mixin import (PluginTemplateMixin, UnitSelectPluginComponent, | ||
SelectPluginComponent, PluginUserApi) | ||
|
@@ -92,6 +93,9 @@ def __init__(self, *args, **kwargs): | |
self.spectrum_viewer.state.add_callback('y_display_unit', | ||
self._on_glue_y_display_unit_changed) | ||
|
||
self.session.hub.subscribe(self, AddDataToViewerMessage, | ||
handler=self._find_and_convert_contour_units) | ||
|
||
self.spectral_unit = UnitSelectPluginComponent(self, | ||
items='spectral_unit_items', | ||
selected='spectral_unit_selected') | ||
|
@@ -269,13 +273,41 @@ def _on_flux_unit_changed(self, msg): | |
else: | ||
self.flux_or_sb_selected = 'Surface Brightness' | ||
|
||
# Always send a surface brightness unit to contours | ||
if self.flux_or_sb_selected == 'Flux': | ||
yunit = self._append_angle_correctly(yunit, self.angle_unit.selected) | ||
self._find_and_convert_contour_units(yunit=yunit) | ||
|
||
# for displaying message that PIXAR_SR = 1 if it is not found in the FITS header | ||
if ( | ||
len(self.app.data_collection) > 0 | ||
and not self.app.data_collection[0].meta.get('PIXAR_SR') | ||
): | ||
self.pixar_sr_exists = False | ||
|
||
def _find_and_convert_contour_units(self, msg=None, yunit=None): | ||
if not yunit: | ||
yunit = self.sb_unit_selected | ||
|
||
if msg is not None: | ||
viewers = [self.app.get_viewer(msg.viewer_reference)] | ||
else: | ||
viewers = [viewer._obj for _, viewer in self._app._jdaviz_helper.viewers.items()] | ||
|
||
rosteen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if self.angle_unit_selected is None or self.angle_unit_selected == '': | ||
# Can't do this before the plugin is initialized completely | ||
return | ||
|
||
for viewer in viewers: | ||
if not isinstance(viewer, BqplotImageView): | ||
continue | ||
for layer in viewer.state.layers: | ||
# DQ layer doesn't play nicely with this attribute | ||
if "DQ" in layer.layer.label: | ||
continue | ||
if hasattr(layer, 'attribute_display_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. I'm guessing masks don't either.... could we instead check the units on the layer to make sure they're surface brightness? Eventually we might need to generalize this method to also set display units for images in velocity, etc (from moment maps), but that isn't enabled in unit conversion yet, so is probably safe to ignore. 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 added a second check below for surface brightness - we know DQ doesn't work, so might as well do the fast check first for that still? |
||
layer.attribute_display_unit = yunit | ||
|
||
def _translate(self, flux_or_sb=None): | ||
# currently unsupported, can be supported with a scale factor | ||
if self.app.config == 'specviz': | ||
|
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 if
_find_and_convert_contour_units
just observedsb_unit_selected
which already handles this logic?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.
we discussed that unit conversion probably needs some code moving soon anyways, so I'm fine deferring this until then