diff --git a/lcviz/helper.py b/lcviz/helper.py index 79f9c25a..e2e19727 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -57,6 +57,23 @@ def _link_new_data(app, reference_data=None, data_to_be_linked=None): return +def _get_display_unit(app, axis): + if app._jdaviz_helper is None or app._jdaviz_helper.plugins.get('Unit Conversion') is None: # noqa + # fallback on native units (unit conversion is not enabled) + if axis == 'time': + return u.dimensionless_unscaled + elif axis == 'flux': + return app._jdaviz_helper.default_time_viewer._obj.data()[0].flux.unit + else: + raise ValueError(f"could not find units for axis='{axis}'") + try: + # TODO: need to implement and add unit conversion plugin for this to be able to work + return getattr(app._jdaviz_helper.plugins.get('Unit Conversion')._obj, + f'{axis}_unit_selected') + except AttributeError: + raise ValueError(f"could not find display unit for axis='{axis}'") + + class LCviz(ConfigHelper): _default_configuration = { 'settings': {'configuration': 'lcviz', @@ -92,6 +109,10 @@ def __init__(self, *args, **kwargs): lambda *args, **kwargs: _link_new_data(self.app, *args, **kwargs) ) + self.app._get_display_unit = ( + lambda *args, **kwargs: _get_display_unit(self.app, *args, **kwargs) + ) + # inject custom css from lcviz_style.vue (on top of jdaviz styles) self.app._add_style((__file__, 'lcviz_style.vue')) diff --git a/lcviz/plugins/time_selector/time_selector.py b/lcviz/plugins/time_selector/time_selector.py index da1f40d8..76acaee5 100644 --- a/lcviz/plugins/time_selector/time_selector.py +++ b/lcviz/plugins/time_selector/time_selector.py @@ -47,7 +47,7 @@ def __init__(self, *args, **kwargs): handler=self._on_ephemeris_changed) @property - def slice_axis(self): + def slice_display_unit_name(self): # global display unit "axis" corresponding to the slice axis return 'time' diff --git a/lcviz/viewers.py b/lcviz/viewers.py index 642e9201..a2e79103 100644 --- a/lcviz/viewers.py +++ b/lcviz/viewers.py @@ -103,6 +103,10 @@ def slice_component_label(self): # calling data_collection_item.get_component(slice_component_label) must work return 'dt' + @property + def slice_display_unit_name(self): + return 'time' + def data(self, cls=None): data = [] @@ -334,6 +338,10 @@ def slice_index(self): # index in viewer.slices corresponding to the slice axis return 0 + @property + def slice_display_unit_name(self): + return 'time' + def _initial_x_axis(self, *args): # Make sure that the x_att/y_att is correct on data load # called via a callback set upstream in CubevizImageView when reference_data is changed