Skip to content

Commit 481d36d

Browse files
committed
basic phase-viewer support
1 parent 4de13b3 commit 481d36d

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

lcviz/plugins/ephemeris/ephemeris.py

+22-15
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ def user_api(self):
130130
'dataset', 'method', 'period_at_max_power', 'adopt_period_at_max_power']
131131
return PluginUserApi(self, expose=expose)
132132

133-
def _phase_comp_lbl(self, component):
133+
def _phase_comp_lbl(self, component=None):
134+
if component is None:
135+
component = self.component_selected
134136
if self.app._jdaviz_helper is None:
135137
# duplicate logic from helper in case this is ever called before the helper
136138
# is fully intialized
@@ -139,9 +141,11 @@ def _phase_comp_lbl(self, component):
139141

140142
@property
141143
def phase_comp_lbl(self):
142-
return self._phase_comp_lbl(self.component_selected)
144+
return self._phase_comp_lbl()
143145

144-
def _phase_viewer_id(self, component):
146+
def _phase_viewer_id(self, component=None):
147+
if component is None:
148+
component = self.component_selected
145149
return f'flux-vs-phase:{component}'
146150

147151
@property
@@ -152,7 +156,7 @@ def phase_viewer_ids(self):
152156

153157
@property
154158
def phase_viewer_id(self):
155-
return self._phase_viewer_id(self.component_selected)
159+
return self._phase_viewer_id()
156160

157161
@property
158162
def default_phase_viewer(self):
@@ -269,31 +273,34 @@ def _update_all_phase_arrays(self, *args, ephem_component=None):
269273
dc.add_link(new_links)
270274

271275
# update any plugin markers
272-
# TODO: eventually might need to loop over multiple matching viewers
273-
phase_viewer_id = self._phase_viewer_id(ephem_component)
274-
if phase_viewer_id in self.app.get_viewer_ids():
275-
phase_viewer = self.app.get_viewer(phase_viewer_id)
276-
for mark in phase_viewer.custom_marks:
276+
for viewer in self._get_phase_viewers(ephem_component):
277+
for mark in viewer.custom_marks:
277278
if hasattr(mark, 'update_phase_folding'):
278279
mark.update_phase_folding()
279280

280281
return phase_comp_lbl
281282

282-
def create_phase_viewer(self):
283+
def create_phase_viewer(self, ephem_component=None):
283284
"""
284285
Create a new phase viewer corresponding to ``component`` and populate the phase arrays
285286
with the current ephemeris, if necessary.
287+
288+
Parameters
289+
----------
290+
ephem_component : str, optional
291+
label of the component. If not provided or ``None``, will default to plugin value.
286292
"""
287-
phase_viewer_id = self.phase_viewer_id
293+
phase_viewer_id = self._phase_viewer_id(ephem_component)
294+
phase_comp_lbl = self._phase_comp_lbl(ephem_component)
288295
dc = self.app.data_collection
289296

290297
# check to see if this component already has a phase array. We'll just check the first
291298
# item in the data-collection since the rest of the logic in this plugin /should/ populate
292299
# the arrays across all entries.
293-
if self.phase_comp_lbl not in [comp.label for comp in dc[0].components]:
300+
if phase_comp_lbl not in [comp.label for comp in dc[0].components]:
294301
self.update_ephemeris() # calls _update_all_phase_arrays
295302

296-
create_phase_viewer = not self.phase_viewer_exists
303+
create_phase_viewer = len(self._get_phase_viewers(ephem_component)) == 0
297304
if create_phase_viewer:
298305
# TODO: stack horizontally by default?
299306
self.app._on_new_viewer(NewViewerMessage(PhaseScatterView, data=None, sender=self.app),
@@ -308,7 +315,7 @@ def create_phase_viewer(self):
308315
pv = self.app.get_viewer(phase_viewer_id)
309316
if create_phase_viewer:
310317
pv.state.x_min, pv.state.x_max = (self.wrap_at-1, self.wrap_at)
311-
pv.state.x_att = self.app._jdaviz_helper._component_ids[self.phase_comp_lbl]
318+
pv.state.x_att = self.app._jdaviz_helper._component_ids[phase_comp_lbl]
312319
return pv.user_api
313320

314321
def vue_create_phase_viewer(self, *args):
@@ -410,7 +417,7 @@ def update_ephemeris(self, ephem_component=None, t0=None, period=None, dpdt=None
410417
411418
Parameters
412419
----------
413-
component : str, optional
420+
ephem_component : str, optional
414421
label of the component. If not provided or ``None``, will default to plugin value.
415422
t0 : float, optional
416423
value of t0 to replace

lcviz/plugins/viewer_creator/viewer_creator.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from jdaviz.configs.default.plugins import ViewerCreator
22
from jdaviz.core.registries import tool_registry, viewer_registry
33
from lcviz.events import EphemerisComponentChangedMessage
4+
from lcviz.viewers import ephem_component_from_phase_viewer_name
45

56
__all__ = ['ViewerCreator']
67

@@ -38,13 +39,15 @@ def vue_create_viewer(self, name):
3839

3940
if label in self.app._jdaviz_helper.viewers:
4041
# clone whenever possible
42+
# TODO: update this to not rely directly on the label for phase-viewers, but rather
43+
# checking for the same ephemeris
4144
self.app._jdaviz_helper.viewers[label]._obj.clone_viewer()
4245
return
4346

4447
if name == 'lcviz-phase-viewer':
45-
# TODO: parse label to get ephemeris
46-
# TODO: copy of plugin and set the correct ephemeris (or allow create_phase_viewer to take ephem component)
47-
self.app._jdaviz_helper.plugins['Ephemeris'].create_phase_viewer()
48+
ephem_comp = ephem_component_from_phase_viewer_name(label)
49+
ephem_plg = self.app._jdaviz_helper.plugins['Ephemeris']
50+
ephem_plg.create_phase_viewer(ephem_comp)
4851
return
4952

5053
super().vue_create_viewer(name)

lcviz/viewers.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
from lightkurve import LightCurve
2121

2222

23-
__all__ = ['TimeScatterView', 'PhaseScatterView']
23+
__all__ = ['TimeScatterView', 'PhaseScatterView', 'ephem_component_from_phase_viewer_name']
24+
25+
26+
def ephem_component_from_phase_viewer_name(label):
27+
return label.split('[')[0].split(':')[-1]
2428

2529

2630
@viewer_registry("lcviz-time-viewer", label="flux-vs-time")
@@ -249,7 +253,7 @@ def clone_viewer(self):
249253
class PhaseScatterView(TimeScatterView):
250254
@property
251255
def ephemeris_component(self):
252-
return self.reference.split('[')[0].split(':')[-1]
256+
return ephem_component_from_phase_viewer_name(self.reference)
253257

254258
def _set_plot_x_axes(self, dc, component_labels, light_curve):
255259
# setting of y_att will be handled by ephemeris plugin

0 commit comments

Comments
 (0)