Skip to content

Commit

Permalink
updates to handle jdaviz PR 2758
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Apr 15, 2024
1 parent 6311b8e commit 7842fc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 61 in lcviz/helper.py

View check run for this annotation

Codecov / codecov/patch

lcviz/helper.py#L61

Added line #L61 was not covered by tests
# 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

Check warning on line 66 in lcviz/helper.py

View check run for this annotation

Codecov / codecov/patch

lcviz/helper.py#L63-L66

Added lines #L63 - L66 were not covered by tests
else:
raise ValueError(f"could not find units for axis='{axis}'")
try:

Check warning on line 69 in lcviz/helper.py

View check run for this annotation

Codecov / codecov/patch

lcviz/helper.py#L68-L69

Added lines #L68 - L69 were not covered by tests
# 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,

Check warning on line 71 in lcviz/helper.py

View check run for this annotation

Codecov / codecov/patch

lcviz/helper.py#L71

Added line #L71 was not covered by tests
f'{axis}_unit_selected')
except AttributeError:
raise ValueError(f"could not find display unit for axis='{axis}'")

Check warning on line 74 in lcviz/helper.py

View check run for this annotation

Codecov / codecov/patch

lcviz/helper.py#L73-L74

Added lines #L73 - L74 were not covered by tests


class LCviz(ConfigHelper):
_default_configuration = {
'settings': {'configuration': 'lcviz',
Expand Down Expand Up @@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion lcviz/plugins/time_selector/time_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 8 additions & 0 deletions lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check warning on line 108 in lcviz/viewers.py

View check run for this annotation

Codecov / codecov/patch

lcviz/viewers.py#L108

Added line #L108 was not covered by tests

def data(self, cls=None):
data = []

Expand Down Expand Up @@ -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'

Check warning on line 343 in lcviz/viewers.py

View check run for this annotation

Codecov / codecov/patch

lcviz/viewers.py#L343

Added line #L343 was not covered by tests

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
Expand Down

0 comments on commit 7842fc4

Please sign in to comment.