Skip to content

Commit

Permalink
binning: disable live-updating when slow
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 9, 2023
1 parent 4f774cd commit 2278c63
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -145,14 +151,19 @@ 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:
self._clear_marks()
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()
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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={}):
Expand Down
18 changes: 18 additions & 0 deletions lcviz/plugins/binning/binning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
</v-text-field>
</v-row>

<v-alert v-if="previews_temp_disable && show_live_preview" type='warning' style="margin-left: -12px; margin-right: -12px">
Live-updating is temporarily disabled (last update took {{last_live_time}}s)
<v-row justify='center'>
<j-tooltip tooltipcontent='hide live preview (can be re-enabled from the settings section in the plugin).' span_style="width: 100%">
<v-btn style='width: 100%' @click="show_live_preview = false">
disable previews
</v-btn>
</j-tooltip>
</v-row>
<v-row justify='center'>
<j-tooltip tooltipcontent='manually update live-previews based on current plugin inputs.' span_style="width: 100%">
<v-btn style='width: 100%' @click="previews_temp_disable = false">
update preview
</v-btn>
</j-tooltip>
</v-row>
</v-alert>

<plugin-add-results
:label.sync="results_label"
:label_default="results_label_default"
Expand Down

0 comments on commit 2278c63

Please sign in to comment.