Skip to content

Commit

Permalink
allow flexibility for deleting original time-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Mar 7, 2024
1 parent 3277d4d commit 050626d
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 35 deletions.
18 changes: 10 additions & 8 deletions lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from glue.core.component_id import ComponentID
from glue.core.link_helpers import LinkSame
from jdaviz.core.helpers import ConfigHelper
from lcviz.viewers import TimeScatterView

__all__ = ['LCviz']

_default_time_viewer_reference_name = 'flux-vs-time'

custom_components = {'plugin-ephemeris-select': 'components/plugin_ephemeris_select.vue'}

# Register pure vue component. This allows us to do recursive component instantiation only in the
Expand All @@ -22,11 +21,7 @@


def _get_range_subset_bounds(self, subset_state, *args, **kwargs):
# Instead of overriding the jdaviz version of this method on jdaviz.Application,
# we could put in jdaviz by (1) checking if helper has a
# _default_time_viewer_reference_name, (2) using the LCviz version if so, and (3)
# using the jdaviz version otherwise.
viewer = self.get_viewer(self._jdaviz_helper._default_time_viewer_reference_name)
viewer = self._jdaviz_helper.default_time_viewer._obj
light_curve = viewer.data()[0]
reference_time = light_curve.meta['reference_time']
if viewer:
Expand Down Expand Up @@ -86,7 +81,6 @@ class LCviz(ConfigHelper):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._default_time_viewer_reference_name = _default_time_viewer_reference_name

# override jdaviz behavior to support temporal subsets
self.app._get_range_subset_bounds = (
Expand Down Expand Up @@ -152,6 +146,14 @@ def get_data(self, data_label=None, cls=LightCurve, subset=None):
"""
return super()._get_data(data_label=data_label, mask_subset=subset, cls=cls)

@property
def default_time_viewer(self):
tvs = [viewer for vid, viewer in self.app._viewer_store.items()
if isinstance(viewer, TimeScatterView)]
if not len(tvs):
raise ValueError("no time viewers exist")
return tvs[0].user_api

@property
def _tray_tools(self):
"""
Expand Down
15 changes: 6 additions & 9 deletions lcviz/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from jdaviz.core.registries import data_parser_registry
import lightkurve

from lcviz.viewers import PhaseScatterView
from lcviz.viewers import PhaseScatterView, TimeScatterView

__all__ = ["light_curve_parser"]


@data_parser_registry("light_curve_parser")
def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kwargs):
time_viewer_reference_name = app._jdaviz_helper._default_time_viewer_reference_name

# load local FITS file from disk by its path:
if isinstance(file_obj, str) and os.path.exists(file_obj):
if data_label is None:
Expand Down Expand Up @@ -44,13 +42,12 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw
app.add_data(data, new_data_label)

if show_in_viewer:
app.add_data_to_viewer(time_viewer_reference_name, new_data_label)

# add to any known phase viewers
# add to any known time/phase viewers
for viewer_id, viewer in app._viewer_store.items():
if not isinstance(viewer, PhaseScatterView):
continue
app.add_data_to_viewer(viewer_id, new_data_label)
if isinstance(viewer, TimeScatterView):
app.add_data_to_viewer(viewer_id, new_data_label)
elif isinstance(viewer, PhaseScatterView):
app.add_data_to_viewer(viewer_id, new_data_label)


def _data_with_reftime(app, light_curve):
Expand Down
6 changes: 3 additions & 3 deletions lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

from lcviz.components import FluxColumnSelectMixin
from lcviz.events import EphemerisChangedMessage
from lcviz.helper import _default_time_viewer_reference_name
from lcviz.marks import LivePreviewBinning
from lcviz.parsers import _data_with_reftime
from lcviz.viewers import TimeScatterView
from lcviz.components import EphemerisSelectMixin


Expand Down Expand Up @@ -129,11 +129,11 @@ def _set_results_viewer(self, event={}):

def viewer_filter(viewer):
if self.ephemeris_selected in self.ephemeris._manual_options:
return viewer.reference == _default_time_viewer_reference_name
return isinstance(viewer, TimeScatterView)
if 'flux-vs-phase:' not in viewer.reference:
# ephemeris selected, but no active phase viewers
return False
return viewer.reference.split('flux-vs-phase:')[1] == self.ephemeris_selected
return viewer._ephemeris_component == self.ephemeris_selected

self.add_results.viewer.filters = [viewer_filter]

Expand Down
4 changes: 2 additions & 2 deletions lcviz/plugins/ephemeris/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from lightkurve import periodogram, FoldedLightCurve

from lcviz.events import EphemerisComponentChangedMessage, EphemerisChangedMessage
from lcviz.viewers import PhaseScatterView
from lcviz.viewers import PhaseScatterView, TimeScatterView

__all__ = ['Ephemeris']

Expand Down Expand Up @@ -304,7 +304,7 @@ def create_phase_viewer(self, ephem_component=None):
self._check_if_phase_viewer_exists()

# set default data visibility
time_viewer_item = self.app._get_viewer_item(self.app._jdaviz_helper._default_time_viewer_reference_name) # noqa
time_viewer_item = self.app._get_viewer_item(self.app._jdaviz_helper.default_time_viewer._obj.reference) # noqa
for data in dc:
data_id = self.app._data_id_from_label(data.label)
visible = time_viewer_item['selected_data_items'].get(data_id, 'hidden')
Expand Down
11 changes: 8 additions & 3 deletions lcviz/plugins/viewer_creator/viewer_creator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from jdaviz.configs.default.plugins import ViewerCreator
from jdaviz.core.registries import tool_registry, viewer_registry
from jdaviz.core.events import NewViewerMessage
from jdaviz.core.registries import tool_registry
from lcviz.events import EphemerisComponentChangedMessage
from lcviz.viewers import TimeScatterView

__all__ = ['ViewerCreator']

Expand Down Expand Up @@ -35,8 +37,11 @@ def vue_create_viewer(self, name):
ephem_plg = self.app._jdaviz_helper.plugins['Ephemeris']
ephem_plg.create_phase_viewer(ephem_comp)
return
if name == 'flux-vs-time':
if name in ('flux-vs-time', 'lcviz-time-viewer'):
# allow passing label and map to the name for upstream support
name = 'lcviz-time-viewer'
viewer_id = self.app._jdaviz_helper._get_clone_viewer_reference('flux-vs-time')
self.app._on_new_viewer(NewViewerMessage(TimeScatterView, data=None, sender=self.app),
vid=viewer_id, name=viewer_id)
return

super().vue_create_viewer(name)
4 changes: 2 additions & 2 deletions lcviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_synthetic_lc(helper):
def test_apply_xrangerois(helper, light_curve_like_kepler_quarter):
lc = light_curve_like_kepler_quarter
helper.load_data(lc)
viewer = helper.app.get_viewer(helper._default_time_viewer_reference_name)
viewer = helper.default_time_viewer._obj
subset_plugin = helper.plugins['Subset Tools']

# the min/max of temporal regions can be defined in two ways:
Expand All @@ -95,7 +95,7 @@ def test_apply_xrangerois(helper, light_curve_like_kepler_quarter):
def test_apply_yrangerois(helper, light_curve_like_kepler_quarter):
lc = light_curve_like_kepler_quarter
helper.load_data(lc)
viewer = helper.app.get_viewer(helper._default_time_viewer_reference_name)
viewer = helper.default_time_viewer._obj
subset_plugin = helper.plugins['Subset Tools']

subset_plugin._obj.subset_selected = "Create New"
Expand Down
2 changes: 1 addition & 1 deletion lcviz/tests/test_plugin_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_docs_snippets(helper, light_curve_like_kepler_quarter):

def test_plugin_binning(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)
tv = helper.app.get_viewer(helper._default_time_viewer_reference_name)
tv = helper.default_time_viewer._obj

b = helper.plugins['Binning']
b._obj.plugin_opened = True
Expand Down
2 changes: 1 addition & 1 deletion lcviz/tests/test_plugin_flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_docs_snippets(helper, light_curve_like_kepler_quarter):

def test_plugin_flatten(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)
tv = helper.app.get_viewer(helper._default_time_viewer_reference_name)
tv = helper.default_time_viewer._obj

ephem = helper.plugins['Ephemeris']
pv = ephem.create_phase_viewer()._obj
Expand Down
1 change: 0 additions & 1 deletion lcviz/tests/test_plugin_frequency_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_docs_snippets(helper, light_curve_like_kepler_quarter):

def test_plugin_frequency_analysis(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)
# tv = helper.app.get_viewer(helper._default_time_viewer_reference_name)

freq = helper.plugins['Frequency Analysis']
freq.open_in_tray()
Expand Down
2 changes: 1 addition & 1 deletion lcviz/tests/test_plugin_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_docs_snippets(helper, light_curve_like_kepler_quarter):

def test_plugin_markers(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)
tv = helper.app.get_viewer(helper._default_time_viewer_reference_name)
tv = helper.default_time_viewer._obj

mp = helper.plugins['Markers']
label_mouseover = mp._obj.coords_info
Expand Down
4 changes: 1 addition & 3 deletions lcviz/tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def test_round_trip(helper):
'2009-05-02 03:52'
], format='iso')

viewer = helper.app.get_viewer(
helper._default_time_viewer_reference_name
)
viewer = helper.default_time_viewer._obj
viewer.apply_roi(XRangeROI(*near_transit))

columns_to_check = ['time', 'flux', 'flux_err']
Expand Down
2 changes: 1 addition & 1 deletion lcviz/tests/test_viewers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

def test_reset_limits(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)
tv = helper.app.get_viewer(helper._default_time_viewer_reference_name)
tv = helper.default_time_viewer._obj

orig_xlims = (tv.state.x_min, tv.state.x_max)
orig_ylims = (tv.state.y_min, tv.state.y_max)
Expand Down

0 comments on commit 050626d

Please sign in to comment.