diff --git a/lcviz/plugins/binning/binning.py b/lcviz/plugins/binning/binning.py index bc43edcc..84f141f6 100644 --- a/lcviz/plugins/binning/binning.py +++ b/lcviz/plugins/binning/binning.py @@ -1,5 +1,7 @@ +import numpy as np +from time import time from astropy.time import Time -from traitlets import Bool, observe +from traitlets import Bool, Float, observe from glue.config import data_translator from jdaviz.core.custom_traitlets import IntHandleEmpty @@ -46,6 +48,10 @@ class Binning(PluginTemplateMixin, DatasetSelectMixin, EphemerisSelectMixin, Add n_bins = IntHandleEmpty(100).tag(sync=True) bin_enabled = Bool(True).tag(sync=True) + last_live_time = Float(0).tag(sync=True) + previews_temp_disable = Bool(False).tag(sync=True) + spinner = Bool(False).tag(sync=True) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -145,7 +151,7 @@ def _toggle_marks(self, event={}): self._live_update(event) @observe('dataset_selected', 'ephemeris_selected', - 'n_bins') + 'n_bins', 'previews_temp_disable') @skip_if_no_updates_since_last_active() def _live_update(self, event={}): if not self.show_live_preview or not self.is_active: @@ -153,6 +159,11 @@ def _live_update(self, event={}): self.bin_enabled = self.n_bins != '' and self.n_bins > 0 return + if self.previews_temp_disable: + return + + start = time() + if event.get('name', '') not in ('is_active', 'show_live_preview'): # mark visibility hasn't been handled yet self._toggle_marks() @@ -189,6 +200,10 @@ def _live_update(self, event={}): mark.times = [] mark.update_xy(times, lc.flux.value) + self.last_live_time = np.round(time() - start, 2) + if self.last_live_time > 0.3: + self.previews_temp_disable = True + def _on_ephemeris_update(self, msg): if not self.show_live_preview or not self.is_active: return @@ -199,7 +214,7 @@ def _on_ephemeris_update(self, msg): self._live_update() def bin(self, add_data=True): - + self.spinner = True if self.n_bins == '' or self.n_bins <= 0: raise ValueError("n_bins must be a positive integer") @@ -245,6 +260,7 @@ def bin(self, add_data=True): # by resetting x_att, the preview marks may have dissappeared self._live_update() + self.spinner = False return lc def vue_apply(self, event={}): diff --git a/lcviz/plugins/binning/binning.vue b/lcviz/plugins/binning/binning.vue index 5dbac90b..c280da46 100644 --- a/lcviz/plugins/binning/binning.vue +++ b/lcviz/plugins/binning/binning.vue @@ -57,6 +57,24 @@ + + Live-updating is temporarily disabled (last update took {{last_live_time}}s) + + + + disable previews + + + + + + + update preview + + + + + diff --git a/lcviz/plugins/flatten/flatten.py b/lcviz/plugins/flatten/flatten.py index 742e9299..7f09f9bc 100644 --- a/lcviz/plugins/flatten/flatten.py +++ b/lcviz/plugins/flatten/flatten.py @@ -1,6 +1,7 @@ import numpy as np +from time import time -from traitlets import Bool, Unicode, observe +from traitlets import Bool, Float, Unicode, observe from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty from jdaviz.core.events import ViewerAddedMessage @@ -57,6 +58,10 @@ class Flatten(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin): sigma = FloatHandleEmpty(3).tag(sync=True) unnormalize = Bool(False).tag(sync=True) + last_live_time = Float(0).tag(sync=True) + previews_temp_disable = Bool(False).tag(sync=True) + spinner = Bool(False).tag(sync=True) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -133,6 +138,7 @@ def flatten(self, add_data=True): trend_lc : `~lightkurve.LightCurve` The trend used to flatten the light curve. """ + self.spinner = True input_lc = self.dataset.selected_obj if input_lc is None: # pragma: no cover raise ValueError("no input dataset selected") @@ -155,6 +161,7 @@ def flatten(self, add_data=True): data = _data_with_reftime(self.app, output_lc) self.add_results.add_results_from_plugin(data) + self.spinner = False return output_lc, trend_lc def _clear_marks(self): @@ -182,9 +189,13 @@ def _toggle_marks(self, event={}): @observe('dataset_selected', 'window_length', 'polyorder', 'break_tolerance', - 'niters', 'sigma') + 'niters', 'sigma', 'previews_temp_disable') @skip_if_no_updates_since_last_active() def _live_update(self, event={}): + if self.previews_temp_disable: + return + + start = time() try: output_lc, trend_lc = self.flatten(add_data=False) except Exception as e: @@ -211,6 +222,10 @@ def _live_update(self, event={}): for mark in flattened_marks.values(): mark.update_ty(times.value, output_flux) + self.last_live_time = np.round(time() - start, 2) + if self.last_live_time > 0.3: + self.previews_temp_disable = True + def vue_apply(self, *args, **kwargs): try: self.flatten(add_data=True) diff --git a/lcviz/plugins/flatten/flatten.vue b/lcviz/plugins/flatten/flatten.vue index 9667b1b8..b0e503a9 100644 --- a/lcviz/plugins/flatten/flatten.vue +++ b/lcviz/plugins/flatten/flatten.vue @@ -138,6 +138,24 @@ Live preview is unnormalized, but flattening will normalize. + + Live-updating is temporarily disabled (last update took {{last_live_time}}s) + + + + disable previews + + + + + + + update preview + + + + +