Skip to content

Commit

Permalink
implement basic (not yet functional) slice plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Feb 14, 2024
1 parent b40f93b commit 016f5ea
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
33 changes: 33 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,39 @@ visible when the plugin is opened.
Jdaviz documentation on the Markers plugin.


.. _slice:

Slice
=====

The slice plugin allows defining 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.

.. code-block:: python
from lcviz import LCviz
lc = search_lightcurve("HAT-P-11", mission="Kepler",
cadence="long", quarter=10).download().flatten()
lcviz = LCviz()
lcviz.load_data(lc)
lcviz.show()
sl = lcviz.plugins['Slice']
sl.open_in_tray()
.. seealso::

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



.. _flatten:

Flatten
Expand Down
3 changes: 2 additions & 1 deletion lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ 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', 'flatten', 'frequency-analysis', 'ephemeris',
'lcviz-markers', 'lcviz-slice',
'flatten', 'frequency-analysis', 'ephemeris',
'binning', 'lcviz-export-plot'],
'viewer_area': [{'container': 'col',
'children': [{'container': 'row',
Expand Down
1 change: 1 addition & 0 deletions lcviz/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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 .metadata_viewer.metadata_viewer import * # noqa
from .plot_options.plot_options import * # noqa
from .subset_plugin.subset_plugin import * # noqa
1 change: 1 addition & 0 deletions lcviz/plugins/slice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .slice import * # noqa
58 changes: 58 additions & 0 deletions lcviz/plugins/slice/slice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from glue_jupyter.bqplot.scatter import BqplotScatterView

from jdaviz.configs.cubeviz.plugins import Slice
from jdaviz.core.registries import tray_registry

__all__ = ['Slice']


@tray_registry('lcviz-slice', label="Slice")
class Slice(Slice):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.docs_link = f"https://lcviz.readthedocs.io/en/{self.vdocs}/plugins.html#slice"
self.docs_description = "Select time to show in the image viewer. 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'

for id, viewer in self.app._viewer_store.items():
if isinstance(viewer, BqplotScatterView) or len(viewer.data()):
self._watch_viewer(viewer, True)

@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

def _watch_viewer(self, viewer, watch=True):
super()._watch_viewer(viewer, watch=watch)
# image viewer watching handled upstream
if isinstance(viewer, BqplotScatterView):
if self._x_all is None and len(viewer.data()):
# cache values (wavelengths/freqs) so that value <> slice conversion can efficient
self._update_data(viewer.data()[0].time)

if viewer not in self._indicator_viewers:
self._indicator_viewers.append(viewer)
# if the units (or data) change, we need to update internally
# viewer.state.add_callback("reference_data",
# self._update_reference_data)

def _update_reference_data(self, reference_data):
if reference_data is None:
return # pragma: no cover
self._update_data(reference_data.get_object().time)

@property
def slice_axis(self):
return 'time'

def _viewer_slices_changed(self, value):
if len(value) == 3:
self.slice = float(value[0])

def _set_viewer_to_slice(self, viewer, value):
viewer.state.slices = (value, 0, 0)
14 changes: 12 additions & 2 deletions lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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

Expand Down Expand Up @@ -60,13 +60,14 @@ def clone_viewer(self):


@viewer_registry("lcviz-time-viewer", label="flux-vs-time")
class TimeScatterView(JdavizViewerMixin, CloneViewerMixin, BqplotScatterView):
class TimeScatterView(JdavizViewerMixin, CloneViewerMixin, WithSliceIndicator, BqplotScatterView):
# categories: zoom resets, zoom, pan, subset, select tools, shortcuts
tools_nested = [
['jdaviz:homezoom', 'jdaviz:prevzoom'],
['jdaviz:boxzoom', 'jdaviz:xrangezoom', 'jdaviz:yrangezoom'],
['jdaviz:panzoom', 'jdaviz:panzoom_x', 'jdaviz:panzoom_y'],
['bqplot:xrange', 'bqplot:yrange', 'bqplot:rectangle'],
['jdaviz:selectslice'],
['lcviz:viewer_clone', 'jdaviz:sidebar_plot', 'jdaviz:sidebar_export']
]
default_class = LightCurve
Expand Down Expand Up @@ -248,6 +249,15 @@ def apply_roi(self, roi, use_current=False):

@viewer_registry("lcviz-phase-viewer", label="phase-vs-time")
class PhaseScatterView(TimeScatterView):
# categories: zoom resets, zoom, pan, subset, select tools, shortcuts
tools_nested = [
['jdaviz:homezoom', 'jdaviz:prevzoom'],
['jdaviz:boxzoom', 'jdaviz:xrangezoom', 'jdaviz:yrangezoom'],
['jdaviz:panzoom', 'jdaviz:panzoom_x', 'jdaviz:panzoom_y'],
['bqplot:xrange', 'bqplot:yrange', 'bqplot:rectangle'],
['lcviz:viewer_clone', 'jdaviz:sidebar_plot', 'jdaviz:sidebar_export']
]

@property
def ephemeris_component(self):
return self.reference.split('[')[0].split(':')[-1]
Expand Down

0 comments on commit 016f5ea

Please sign in to comment.