Skip to content

Commit

Permalink
update binning and flatten plugins to handle addl phased viewers
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Mar 8, 2024
1 parent 5fd7a8a commit 16cdfe1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
26 changes: 17 additions & 9 deletions lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions lcviz/plugins/flatten/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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
Expand Down

0 comments on commit 16cdfe1

Please sign in to comment.