From 16cdfe14c467fa09a3ac0faba77a58295b3e21be Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 8 Mar 2024 13:53:48 -0500 Subject: [PATCH] update binning and flatten plugins to handle addl phased viewers --- lcviz/plugins/binning/binning.py | 26 +++++++++++++++++--------- lcviz/plugins/flatten/flatten.py | 10 +++++----- lcviz/tests/test_plugin_binning.py | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lcviz/plugins/binning/binning.py b/lcviz/plugins/binning/binning.py index 23f424ab..f2440404 100644 --- a/lcviz/plugins/binning/binning.py +++ b/lcviz/plugins/binning/binning.py @@ -68,7 +68,8 @@ def not_from_binning_plugin(data): return data.meta.get('Plugin', None) != self.__class__.__name__ self.dataset.add_filter(not_from_binning_plugin) - self.hub.subscribe(self, ViewerAddedMessage, handler=self._set_results_viewer) + # TODO: viewer added also needs to repopulate marks + self.hub.subscribe(self, ViewerAddedMessage, handler=self._on_add_viewer) self.hub.subscribe(self, ViewerRemovedMessage, handler=self._set_results_viewer) self.hub.subscribe(self, EphemerisChangedMessage, handler=self._on_ephemeris_update) @@ -95,15 +96,15 @@ def input_lc(self): @property def marks(self): marks = {} - for id, viewer in self.app._viewer_store.items(): + for viewer in self.app._viewer_store.values(): for mark in viewer.figure.marks: if isinstance(mark, LivePreviewBinning): - marks[id] = mark + marks[viewer.reference] = mark break else: mark = LivePreviewBinning(viewer, visible=self.is_active) viewer.figure.marks = viewer.figure.marks + [mark] - marks[id] = mark + marks[viewer.reference] = mark return marks def _clear_marks(self): @@ -137,17 +138,23 @@ def viewer_filter(viewer): self.add_results.viewer.filters = [viewer_filter] + def _on_add_viewer(self, msg): + self._set_results_viewer() + self._live_update() + @observe('is_active', 'show_live_preview') def _toggle_marks(self, event={}): visible = self.show_live_preview and self.is_active - for viewer_id, mark in self.marks.items(): + for viewer_ref, mark in self.marks.items(): if not visible: this_visible = False elif self.ephemeris_selected == 'No ephemeris': this_visible = True else: - this_visible = viewer_id.split(':')[-1] == self.ephemeris_selected + viewer = self.app.get_viewer(viewer_ref) + viewer_ephem = getattr(viewer, '_ephemeris_component', None) + this_visible = viewer_ephem == self.ephemeris_selected mark.visible = this_visible @@ -260,10 +267,11 @@ def bin(self, add_data=True): if self.ephemeris_selected != 'No ephemeris': # prevent phase axis from becoming a time axis: - viewer_id = self.ephemeris_plugin._obj.phase_viewer_id - pv = self.app.get_viewer(viewer_id) + ephemeris_plugin = self.app._jdaviz_helper.plugins['Ephemeris'] phase_comp_lbl = self.app._jdaviz_helper._phase_comp_lbl(self.ephemeris_selected) - pv.state.x_att = self.app._jdaviz_helper._component_ids[phase_comp_lbl] + phase_comp = self.app._jdaviz_helper._component_ids[phase_comp_lbl] + for pv in ephemeris_plugin._obj._get_phase_viewers(self.ephemeris_selected): + pv.state.x_att = phase_comp # by resetting x_att, the preview marks may have dissappeared self._live_update() diff --git a/lcviz/plugins/flatten/flatten.py b/lcviz/plugins/flatten/flatten.py index 94f2d685..172ff904 100644 --- a/lcviz/plugins/flatten/flatten.py +++ b/lcviz/plugins/flatten/flatten.py @@ -102,26 +102,26 @@ def marks(self): trend_marks = {} flattened_marks = {} - for id, viewer in self.app._viewer_store.items(): + for viewer in self.app._viewer_store.values(): needs_trend = isinstance(viewer, TimeScatterView) and not isinstance(viewer, PhaseScatterView) # noqa needs_flattened = isinstance(viewer, (TimeScatterView, PhaseScatterView)) for mark in viewer.figure.marks: if isinstance(mark, LivePreviewTrend): - trend_marks[id] = mark + trend_marks[viewer.reference] = mark needs_trend = False elif isinstance(mark, LivePreviewFlattened): - flattened_marks[id] = mark + flattened_marks[viewer.reference] = mark needs_flattened = False if not needs_trend and not needs_flattened: break if needs_trend: mark = LivePreviewTrend(viewer, visible=self.is_active) viewer.figure.marks = viewer.figure.marks + [mark] - trend_marks[id] = mark + trend_marks[viewer.reference] = mark if needs_flattened: mark = LivePreviewFlattened(viewer, visible=self.is_active) viewer.figure.marks = viewer.figure.marks + [mark] - flattened_marks[id] = mark + flattened_marks[viewer.reference] = mark return trend_marks, flattened_marks diff --git a/lcviz/tests/test_plugin_binning.py b/lcviz/tests/test_plugin_binning.py index 4eabfd23..7ce3bade 100644 --- a/lcviz/tests/test_plugin_binning.py +++ b/lcviz/tests/test_plugin_binning.py @@ -32,7 +32,7 @@ def test_plugin_binning(helper, light_curve_like_kepler_quarter): with b.as_active(): assert b.ephemeris == 'No ephemeris' assert len(_get_marks_from_viewer(tv)) == 1 - assert len(_get_marks_from_viewer(pv)) == 0 + assert len(_get_marks_from_viewer(pv)) == 1 assert b._obj.ephemeris_dict == {} # update ephemeris will force re-phasing