Skip to content

Commit

Permalink
WIP: support upstream refactor
Browse files Browse the repository at this point in the history
* removes need for context-aware as the plugin is now always relevant with synced time indicators
* renames "Slice" plugin to "Time Selector"
  • Loading branch information
kecnry committed Feb 19, 2024
1 parent 682ce00 commit c92ea66
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 114 deletions.
19 changes: 10 additions & 9 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,19 @@ visible when the plugin is opened.
Jdaviz documentation on the Markers plugin.


.. _slice:
.. _time-indicator:

Slice
=====
Time Selector
==============

The slice plugin allows defining the time at which all image cubes are displayed.
The time selector plugin allows defining the time indicated in all light curve viewers
(time and phase viewers) as well as the time at which all image cubes are displayed.


.. admonition:: User API Example
:class: dropdown

See the :class:`~lcviz.plugins.slice.slice.Slice` user API documentation for more details.
See the :class:`~lcviz.plugins.time_selector.time_selector.TimeSelector` user API documentation for more details.

.. code-block:: python
Expand All @@ -201,14 +202,14 @@ The slice plugin allows defining the time at which all image cubes are displayed
lcviz.load_data(lc)
lcviz.show()
sl = lcviz.plugins['Slice']
sl.open_in_tray()
ts = lcviz.plugins['Time Selector']
ts.open_in_tray()
.. seealso::

:ref:`Jdaviz Markers <jdaviz:markers-plugin>`
Jdaviz documentation on the Markers plugin.
:ref:`Jdaviz Slice Plugin <jdaviz:slice>`
Jdaviz documentation on the Slice plugin.



Expand Down
2 changes: 1 addition & 1 deletion lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LCviz(ConfigHelper):
'toolbar': ['g-data-tools', 'g-subset-tools', 'lcviz-coords-info'],
'tray': ['lcviz-metadata-viewer', 'flux-column',
'lcviz-plot-options', 'lcviz-subset-plugin',
'lcviz-markers', 'lcviz-slice',
'lcviz-markers', 'time-selector',
'flatten', 'frequency-analysis', 'ephemeris',
'binning', 'lcviz-export-plot'],
'viewer_area': [{'container': 'col',
Expand Down
2 changes: 1 addition & 1 deletion lcviz/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .flux_column.flux_column import * # noqa
from .frequency_analysis.frequency_analysis import * # noqa
from .markers.markers import * # noqa
from .slice.slice import * # noqa
from .time_selector.time_selector import * # noqa
from .metadata_viewer.metadata_viewer import * # noqa
from .plot_options.plot_options import * # noqa
from .subset_plugin.subset_plugin import * # noqa
1 change: 0 additions & 1 deletion lcviz/plugins/slice/__init__.py

This file was deleted.

87 changes: 0 additions & 87 deletions lcviz/plugins/slice/slice.py

This file was deleted.

1 change: 1 addition & 0 deletions lcviz/plugins/time_selector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .time_selector import * # noqa
32 changes: 32 additions & 0 deletions lcviz/plugins/time_selector/time_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from jdaviz.configs.cubeviz.plugins import Slice
from jdaviz.core.registries import tray_registry

from lcviz.viewers import CubeView

__all__ = ['TimeSelector']


@tray_registry('time-selector', label="Time Selector")
class TimeSelector(Slice):
_cube_viewer_cls = CubeView
_cube_viewer_default_label = 'image'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.docs_link = f"https://lcviz.readthedocs.io/en/{self.vdocs}/plugins.html#time-selector"
self.docs_description = "Select time to sync across all viewers (as an indicator in all time/phase viewers or to select the active slice in any image/cube viewers). The slice can also be changed interactively in any time viewer by activating the slice tool." # noqa
self.value_label = 'Time'
self.value_unit = 'd'

@property
def slice_axis(self):
# global display unit "axis" corresponding to the slice axis
return 'time'

@property
def user_api(self):
api = super().user_api
# can be removed after deprecated upstream attributes for wavelength/wavelength_value
# are removed in the lowest supported version of jdaviz
api._expose = [e for e in api._expose if e not in ('wavelength', 'wavelength_value', 'show_wavelength')] # noqa
return api
13 changes: 0 additions & 13 deletions lcviz/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from glue.viewers.common.tool import Tool

from jdaviz.core.tools import SidebarShortcutPlotOptions, SidebarShortcutExportPlot
from jdaviz.configs.cubeviz.plugins.tools import SelectSlice

from lcviz.viewers import CubeView

ICON_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), 'data', 'icons'))

Expand All @@ -18,16 +15,6 @@
__all__ = ['ViewerClone']


def _slice_is_visible(self):
if getattr(self.viewer, 'jdaviz_helper', None) is None:
return False
return len([viewer for viewer in self.viewer.jdaviz_helper.viewers.values()
if isinstance(viewer._obj, CubeView)]) > 0


SelectSlice.is_visible = _slice_is_visible


@viewer_tool
class ViewerClone(Tool):
icon = os.path.join(ICON_DIR, 'viewer_clone')
Expand Down
21 changes: 19 additions & 2 deletions lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from jdaviz.core.events import NewViewerMessage
from jdaviz.core.registries import viewer_registry
from jdaviz.configs.cubeviz.plugins.viewers import CubevizImageView, WithSliceIndicator
from jdaviz.configs.cubeviz.plugins.viewers import (CubevizImageView,
WithSliceIndicator, WithSliceSelection)
from jdaviz.configs.default.plugins.viewers import JdavizViewerMixin
from jdaviz.configs.specviz.plugins.viewers import SpecvizProfileView

Expand Down Expand Up @@ -275,9 +276,13 @@ def times_to_phases(self, times):

return ephem.times_to_phases(times, ephem_component=self.ephemeris_component)

def _set_slice_indicator_value(self, value):
# NOTE: on first call, this will initialize the indicator itself
self.slice_indicator.value = self.times_to_phases(value)


@viewer_registry("lcviz-cube-viewer", label="cube")
class CubeView(CloneViewerMixin, CubevizImageView):
class CubeView(CloneViewerMixin, CubevizImageView, WithSliceSelection):
# categories: zoom resets, zoom, pan, subset, select tools, shortcuts
tools_nested = [
['jdaviz:homezoom', 'jdaviz:prevzoom'],
Expand Down Expand Up @@ -307,6 +312,18 @@ def __init__(self, *args, **kwargs):
# * _default_flux_viewer_reference_name
# * _default_uncert_viewer_reference_name

@property
def slice_component_label(self):
# label of the component in the cubes corresponding to the slice axis
# calling data_collection_item.get_component(slice_component_label) on any
# input cube-data must work
return 'dt'

@property
def slice_index(self):
# index in viewer.slices corresponding to the slice axis
return 0

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 c92ea66

Please sign in to comment.