Skip to content

Commit

Permalink
migrate temporary disabling previews upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Feb 27, 2024
1 parent d93c8cb commit b69d1f0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 64 deletions.
19 changes: 3 additions & 16 deletions lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np
from time import time
from astropy.time import Time
from traitlets import Bool, Float, observe
from glue.config import data_translator
Expand All @@ -10,7 +8,7 @@
from jdaviz.core.template_mixin import (PluginTemplateMixin,
DatasetSelectMixin, AddResultsMixin,
skip_if_no_updates_since_last_active,
with_spinner)
with_spinner, with_temp_disable)
from jdaviz.core.user_api import PluginUserApi

from lcviz.components import FluxColumnSelectMixin
Expand Down Expand Up @@ -54,9 +52,6 @@ class Binning(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin,
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)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -157,20 +152,16 @@ def _toggle_marks(self, event={}):

@observe('flux_column_selected', 'dataset_selected',
'ephemeris_selected',
'n_bins', 'previews_temp_disable')
'n_bins', 'previews_temp_disabled')
@skip_if_no_updates_since_last_active()
@with_temp_disable(timeout=0.3)
def _live_update(self, event={}):
self.bin_enabled = self.n_bins != '' and self.n_bins > 0

if not self.show_live_preview or not self.is_active or not self.bin_enabled:
self._clear_marks()
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 @@ -207,10 +198,6 @@ 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 Down
22 changes: 5 additions & 17 deletions lcviz/plugins/binning/binning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,11 @@
</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-previews-temp-disabled
:previews_temp_disabled.sync="previews_temp_disabled"
:previews_last_time="previews_last_time"
:show_live_preview.sync="show_live_preview"
/>

<plugin-add-results
:label.sync="results_label"
Expand Down
18 changes: 4 additions & 14 deletions lcviz/plugins/flatten/flatten.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from time import time

from traitlets import Bool, Float, Unicode, observe
from traitlets import Bool, Unicode, observe

from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty
from jdaviz.core.events import ViewerAddedMessage
Expand All @@ -10,7 +9,7 @@
DatasetSelectMixin,
AutoTextField,
skip_if_no_updates_since_last_active,
with_spinner)
with_spinner, with_temp_disable)
from jdaviz.core.user_api import PluginUserApi

from lcviz.components import FluxColumnSelectMixin
Expand Down Expand Up @@ -70,9 +69,6 @@ class Flatten(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin):
flux_label_invalid_msg = Unicode('').tag(sync=True)
flux_label_overwrite = Bool(False).tag(sync=True)

last_live_time = Float(0).tag(sync=True)
previews_temp_disable = Bool(False).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -217,16 +213,14 @@ def _toggle_marks(self, event={}):

@observe('dataset_selected', 'flux_column_selected',
'window_length', 'polyorder', 'break_tolerance',
'niters', 'sigma', 'previews_temp_disable')
'niters', 'sigma', 'previews_temp_disabled')
@skip_if_no_updates_since_last_active()
@with_temp_disable(0.3)
def _live_update(self, event={}):
if self.previews_temp_disable:
return
if self.dataset_selected == '' or self.flux_column_selected == '':
self._clear_marks()
return

start = time()
try:
output_lc, trend_lc = self.flatten(add_data=False)
except Exception as e:
Expand All @@ -253,10 +247,6 @@ 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)
Expand Down
23 changes: 6 additions & 17 deletions lcviz/plugins/flatten/flatten.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,12 @@
hint="Label for flux column."
></plugin-auto-label>

<v-alert v-if="previews_temp_disable && (show_live_preview || show_trend_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 trend and flattened previews (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; show_trend_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-previews-temp-disabled
:previews_temp_disabled.sync="previews_temp_disabled"
:previews_last_time="previews_last_time"
:show_live_preview="show_live_preview || show_trend_preview"
@disable_previews="() => {show_live_preview=false; show_trend_preview=false}"
/>

<v-row justify="end">
<j-tooltip tooltipcontent="Flatten and select the new column as the adopted flux column">
Expand Down

0 comments on commit b69d1f0

Please sign in to comment.