diff --git a/lcviz/helper.py b/lcviz/helper.py index 9b2c6618..295d4477 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -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 @@ -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: @@ -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 = ( @@ -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): """ diff --git a/lcviz/parsers.py b/lcviz/parsers.py index 97317dee..70d8673d 100644 --- a/lcviz/parsers.py +++ b/lcviz/parsers.py @@ -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: @@ -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): diff --git a/lcviz/plugins/binning/binning.py b/lcviz/plugins/binning/binning.py index 97384eb5..904d9d16 100644 --- a/lcviz/plugins/binning/binning.py +++ b/lcviz/plugins/binning/binning.py @@ -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 @@ -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] diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py index 494b5baf..9baa72ca 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -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'] @@ -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') diff --git a/lcviz/plugins/viewer_creator/viewer_creator.py b/lcviz/plugins/viewer_creator/viewer_creator.py index 8975973c..8830e8be 100644 --- a/lcviz/plugins/viewer_creator/viewer_creator.py +++ b/lcviz/plugins/viewer_creator/viewer_creator.py @@ -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'] @@ -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) diff --git a/lcviz/tests/test_parser.py b/lcviz/tests/test_parser.py index c4585e4f..e3c4cd20 100644 --- a/lcviz/tests/test_parser.py +++ b/lcviz/tests/test_parser.py @@ -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: @@ -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" diff --git a/lcviz/tests/test_plugin_binning.py b/lcviz/tests/test_plugin_binning.py index 6011b7b7..4eabfd23 100644 --- a/lcviz/tests/test_plugin_binning.py +++ b/lcviz/tests/test_plugin_binning.py @@ -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 diff --git a/lcviz/tests/test_plugin_flatten.py b/lcviz/tests/test_plugin_flatten.py index 1be2e9a6..0d428b5d 100644 --- a/lcviz/tests/test_plugin_flatten.py +++ b/lcviz/tests/test_plugin_flatten.py @@ -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 diff --git a/lcviz/tests/test_plugin_frequency_analysis.py b/lcviz/tests/test_plugin_frequency_analysis.py index 7fa9cec7..1d2766ac 100644 --- a/lcviz/tests/test_plugin_frequency_analysis.py +++ b/lcviz/tests/test_plugin_frequency_analysis.py @@ -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() diff --git a/lcviz/tests/test_plugin_markers.py b/lcviz/tests/test_plugin_markers.py index 9ab8c071..a86f6862 100644 --- a/lcviz/tests/test_plugin_markers.py +++ b/lcviz/tests/test_plugin_markers.py @@ -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 mp = helper.plugins['Markers'] label_mouseover = mp._obj.coords_info diff --git a/lcviz/tests/test_translator.py b/lcviz/tests/test_translator.py index cedf88b5..9ceb1f99 100644 --- a/lcviz/tests/test_translator.py +++ b/lcviz/tests/test_translator.py @@ -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'] diff --git a/lcviz/tests/test_viewers.py b/lcviz/tests/test_viewers.py index 71d3fca3..11943b51 100644 --- a/lcviz/tests/test_viewers.py +++ b/lcviz/tests/test_viewers.py @@ -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)