Skip to content

Commit

Permalink
update flattening plugin to use skip_if_no_updates_since_last_active
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Sep 22, 2023
1 parent 146d0d0 commit 89c81e1
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lcviz/plugins/flatten/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from jdaviz.core.events import ViewerAddedMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin,
DatasetSelectMixin, AddResultsMixin)
DatasetSelectMixin, AddResultsMixin,
skip_if_no_updates_since_last_active)
from jdaviz.core.user_api import PluginUserApi

from lcviz.marks import LivePreviewTrend, LivePreviewFlattened
Expand Down Expand Up @@ -159,16 +160,25 @@ def _clear_marks(self):
mark.clear()
mark.visible = False

@observe('show_live_preview', 'is_active',
@observe('is_active', 'show_live_preview')
def _toggle_marks(self, event={}):
visible = self.show_live_preview and self.is_active

trend_marks, flattened_marks = self.marks
for mark in trend_marks.values():
mark.visible = visible
for mark in flattened_marks.values():
mark.visible = visible

if visible:
self._live_update(event)

@observe('is_active', 'show_live_preview',
'dataset_selected',
'window_length', 'polyorder', 'break_tolerance',
'niters', 'sigma')
@skip_if_no_updates_since_last_active()
def _live_update(self, event={}):
if not self.show_live_preview or not self.is_active:
self._clear_marks()
self.flatten_err = ''
return

try:
output_lc, trend_lc = self.flatten(add_data=False)
except Exception as e:
Expand All @@ -188,10 +198,8 @@ def _live_update(self, event={}):
for mark in trend_marks.values():
# TODO: need to account for phasing
mark.update_ty(times.value, trend_lc.flux.value)
mark.visible = True
for mark in flattened_marks.values():
mark.update_ty(times.value, output_flux)
mark.visible = True

def vue_apply(self, *args, **kwargs):
try:
Expand Down

0 comments on commit 89c81e1

Please sign in to comment.