Skip to content

Commit

Permalink
Use upstream updates to plugin plots (spacetelescope#55)
Browse files Browse the repository at this point in the history
* update freq analysis plot to use glue-viewers
* improve axes styling/padding (in plugin plots)
* update jdaviz pin to 3.8
* update tests
* add binning.show_live_preview to user-api (wasn't failing before because jdaviz didn't enforce not setting non-exposed attributes)
  • Loading branch information
kecnry authored and bmorris3 committed Dec 8, 2023
1 parent 500867c commit 2482a51
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def not_from_binning_plugin(data):

@property
def user_api(self):
expose = ['dataset', 'ephemeris', 'input_lc',
expose = ['show_live_preview', 'dataset', 'ephemeris', 'input_lc',
'n_bins', 'add_results', 'bin']
return PluginUserApi(self, expose=expose)

Expand Down
28 changes: 20 additions & 8 deletions lcviz/plugins/frequency_analysis/frequency_analysis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
from functools import cached_property
from traitlets import Bool, Float, List, Unicode, observe

Expand Down Expand Up @@ -69,8 +70,11 @@ def __init__(self, *args, **kwargs):
selected='xunit_selected',
manual_options=['frequency', 'period'])

self.plot.add_line('line', color='gray', marker_size=12)
self.plot.figure.axes[1].label = 'power'
self.plot.figure.fig_margin = {'top': 60, 'bottom': 60, 'left': 65, 'right': 15}
self.plot.viewer.axis_y.num_ticks = 5
self.plot.viewer.axis_y.tick_format = '0.2e'
self.plot.viewer.axis_y.label_offset = '55px'
self._update_xunit()

# TODO: remove if/once inherited from jdaviz
Expand Down Expand Up @@ -110,7 +114,7 @@ def periodogram(self):
except Exception as err:
self.spinner = False
self.err = str(err)
self.plot.clear_all_marks()
self.plot.update_style('periodogram', visible=False)
return None
elif self.method == 'Lomb-Scargle':
try:
Expand All @@ -120,7 +124,7 @@ def periodogram(self):
except Exception as err:
self.spinner = False
self.err = str(err)
self.plot.clear_all_marks()
self.plot.update_style('periodogram', visible=False)
return None
else:
self.spinner = False
Expand All @@ -134,9 +138,15 @@ def periodogram(self):
def _update_xunit(self, *args):
per = self.periodogram
if per is not None:
self.plot.marks['line'].x = getattr(per, self.xunit_selected)
x = getattr(per, self.xunit_selected).value
self.plot._update_data('periodogram', x=x)
self.plot.update_style('periodogram', visible=True)
old_xmin, old_xmax = self.plot.viewer.state.x_min, self.plot.viewer.state.x_max
new_xmin = old_xmax ** -1 if old_xmax > 0 else np.nanmin(x)
new_xmax = old_xmin ** -1 if old_xmin > 0 else np.nanmax(x)
self.plot.set_limits(x_min=new_xmin, x_max=new_xmax)
else:
self.plot.clear_all_marks()
self.plot.update_style('periodogram', visible=False)

self._update_periodogram_labels(per)

Expand Down Expand Up @@ -168,8 +178,10 @@ def _update_periodogram(self, *args):

per = self.periodogram
if per is not None:
line = self.plot.marks['line']
line.x, line.y = getattr(per, self.xunit_selected).value, per.power.value
self.plot._update_data('periodogram',
x=getattr(per, self.xunit_selected),
y=per.power.value)
self.plot.update_style('periodogram', line_visible=True, markers_visible=False)
self._update_periodogram_labels(per)
else:
self.plot.clear_all_marks()
self.plot.update_style('periodogram', visible=False)
6 changes: 3 additions & 3 deletions lcviz/tests/test_plugin_frequency_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ def test_plugin_frequency_analysis(helper, light_curve_like_kepler_quarter):

freq.xunit = 'period'
assert freq._obj.plot.figure.axes[0].label == 'period (d)'
line_x = freq._obj.plot.marks['line'].x
line_x = freq._obj.plot.layers['periodogram'].layer['x']
assert_allclose((line_x.min(), line_x.max()), (0.3508333334885538, 31.309906458683404))

freq.auto_range = False
assert_allclose((freq.minimum, freq.maximum), (1, 10))
while freq._obj.spinner:
pass
line_x = freq._obj.plot.marks['line'].x
line_x = freq._obj.plot.layers['periodogram'].layer['x']
assert_allclose((line_x.min(), line_x.max()), (1, 10.00141))

freq.xunit = 'frequency'
assert_allclose((freq.minimum, freq.maximum), (0.1, 1))
while freq._obj.spinner:
pass
line_x = freq._obj.plot.marks['line'].x
line_x = freq._obj.plot.layers['periodogram'].layer['x']
assert_allclose((line_x.min(), line_x.max()), (0.0999859, 1))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dependencies = [
"astropy>=5.2",
"jdaviz>=3.7.1",
"jdaviz>=3.8",
"lightkurve@git+https://github.com/lightkurve/lightkurve", # until https://github.com/lightkurve/lightkurve/pull/1342 is in a release (anything after 2.4.0)
]
dynamic = [
Expand Down

0 comments on commit 2482a51

Please sign in to comment.