diff --git a/lcviz/conftest.py b/lcviz/conftest.py
index 767828c..5be4d22 100644
--- a/lcviz/conftest.py
+++ b/lcviz/conftest.py
@@ -39,6 +39,7 @@ def light_curve_like_kepler_quarter(seed=42):
lc['flux_alt_err'] = flux_err
lc.meta['MISSION'] = 'KEPLER'
lc.meta['QUARTER'] = 10
+ lc.meta['OBJECT'] = 'HAT-P-11'
return lc
diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py
index 66c05ba..e24c6c9 100644
--- a/lcviz/plugins/ephemeris/ephemeris.py
+++ b/lcviz/plugins/ephemeris/ephemeris.py
@@ -15,6 +15,7 @@
SelectPluginComponent, EditableSelectPluginComponent,
with_spinner)
from jdaviz.core.user_api import PluginUserApi
+from jdaviz.core.events import SnackbarMessage
from lightkurve import periodogram, FoldedLightCurve
@@ -137,6 +138,10 @@ def __init__(self, *args, **kwargs):
selected='method_selected',
manual_options=['Lomb-Scargle', 'Box Least Squares'])
+ self.query_result = SelectPluginComponent(self,
+ items='query_result_items',
+ selected='query_result_selected')
+
# TODO: could optimize by only updating for the new data entry only
# (would require some refactoring and probably wouldn't have significant gains)
self.hub.subscribe(self, DataCollectionAddMessage, handler=self._update_all_phase_arrays)
@@ -153,7 +158,7 @@ def user_api(self):
'times_to_phases', 'phases_to_times', 'get_data',
'dataset', 'method', 'period_at_max_power',
'adopt_period_at_max_power', 'query_for_ephemeris',
- 'query_result'
+ 'query_result', 'adopt_from_catalog', 'adopt_from_catalog_in_new_viewer'
]
return PluginUserApi(self, expose=expose)
@@ -641,24 +646,25 @@ def query_for_ephemeris(self):
return None
else:
- self.query_result = query_result
- self.query_result.add_index('pl_name')
+ query_result.sort('pl_name')
+ self.astroquery_result = query_result
+ self.astroquery_result.add_index('pl_name')
self.query_result_items = [
{
- 'name': name,
+ 'label': name, # required key for SelectPluginComponent
'period': period,
'epoch': epoch if not np.isnan(epoch) else 0
}
for name, period, epoch in zip(
- sorted(list(self.query_result['pl_name'])),
- np.array(self.query_result['pl_orbper'].to_value(u.day)),
- np.array(self.query_result['pl_tranmid'].to_value(u.day))
+ list(self.astroquery_result['pl_name']),
+ np.array(self.astroquery_result['pl_orbper'].to_value(u.day)),
+ np.array(self.astroquery_result['pl_tranmid'].to_value(u.day))
)
]
@observe('query_result_selected')
def _select_query_result(self, *args):
- selected_query_result = self.query_result.loc[self.query_result_selected]
+ selected_query_result = self.astroquery_result.loc[self.query_result_selected]
self.period_from_catalog = selected_query_result['pl_orbper'].base.to_value(u.day)
ref_time = self.app.data_collection[0].coords.reference_time.jd
if np.isnan(selected_query_result['pl_tranmid'].base.to_value(u.day)):
@@ -673,19 +679,38 @@ def vue_query_for_ephemeris(self, *args):
self.query_for_ephemeris()
def adopt_from_catalog(self, *args):
- if not np.any(np.isnan([self.period_from_catalog, self.t0_from_catalog])):
- self.period = self.period_from_catalog
- self.t0 = self.t0_from_catalog
-
- # reset the phase axis wrap to feature the primary transit:
- self.wrap_at = 0.5
- viewer = self._get_phase_viewers()[0]
- viewer.reset_limits()
+ if len(self._get_phase_viewers()):
+ # if a phase viewer is available, adopt the ephemeris in the phase viewer:
+ if not np.any(np.isnan([self.period_from_catalog, self.t0_from_catalog])):
+ self.period = self.period_from_catalog
+ self.t0 = self.t0_from_catalog
+
+ # reset the phase axis wrap to feature the primary transit:
+ self.wrap_at = 0.5
+ viewer = self._get_phase_viewers()[0]
+ viewer.reset_limits()
+ else:
+ # otherwise, adopt the ephemeris in a new phase viewer:
+ self.adopt_from_catalog_in_new_viewer()
def vue_adopt_from_catalog(self, *args):
self.adopt_from_catalog()
+ def adopt_from_catalog_in_new_viewer(self, *args):
+ new_component_label = self.query_result_selected.replace(' ', '')
+ if len(self._get_phase_viewers(new_component_label)):
+ # warn the user that an ephemeris component already exists with this label,
+ # a second won't be added:
+ self.hub.broadcast(
+ SnackbarMessage(
+ f"Ephemeris component {new_component_label} already exists, skipping",
+ sender=self, color="warning"
+ )
+ )
+ else:
+ self.add_component(new_component_label)
+ self.create_phase_viewer()
+ self.adopt_from_catalog()
+
def vue_adopt_from_catalog_in_new_viewer(self, *args):
- self.add_component(self.query_result_selected.replace(' ', ''))
- self.create_phase_viewer()
- self.adopt_from_catalog()
+ self.adopt_from_catalog_in_new_viewer()
diff --git a/lcviz/plugins/ephemeris/ephemeris.vue b/lcviz/plugins/ephemeris/ephemeris.vue
index c5f59c8..ca405e8 100644
--- a/lcviz/plugins/ephemeris/ephemeris.vue
+++ b/lcviz/plugins/ephemeris/ephemeris.vue
@@ -212,7 +212,7 @@
:menu-props="{ left: true }"
attach
:items="query_result_items"
- :item-value="item => item.name"
+ :item-value="item => item.label"
v-model="query_result_selected"
label="Ephemerides available"
:hint="'Ephemeris parameters from ' + query_result_items.length + ' available query result(s)'"
@@ -222,12 +222,12 @@
- {{ item.name }}
+ {{ item.label }}
- {{ item.name }}
+ {{ item.label }}
Period: {{ item.period }} d, Epoch: {{ item.epoch }} d
diff --git a/lcviz/tests/test_parser.py b/lcviz/tests/test_parser.py
index ff3be3c..9dc7ce8 100644
--- a/lcviz/tests/test_parser.py
+++ b/lcviz/tests/test_parser.py
@@ -124,7 +124,8 @@ def test_apply_yrangerois(helper, light_curve_like_kepler_quarter):
def test_data_label(helper, light_curve_like_kepler_quarter):
# add data without specifying data label:
helper.load_data(light_curve_like_kepler_quarter)
- assert helper.app.data_collection[-1].label == 'Light curve [Q10]'
+ object_name = helper.app.data_collection[-1].meta['OBJECT']
+ assert helper.app.data_collection[-1].label == f'{object_name} [Q10]'
# specify label, check that quarter isn't appended:
data_label = 'Cool target'
diff --git a/lcviz/tests/test_plugin_ephemeris.py b/lcviz/tests/test_plugin_ephemeris.py
index ac01e75..abc0252 100644
--- a/lcviz/tests/test_plugin_ephemeris.py
+++ b/lcviz/tests/test_plugin_ephemeris.py
@@ -132,3 +132,25 @@ def test_create_phase_viewer(helper, light_curve_like_kepler_quarter):
ephem.add_component('new')
assert len(vc.viewer_types) == 3
+
+
+def test_ephemeris_queries(helper, light_curve_like_kepler_quarter):
+ helper.load_data(light_curve_like_kepler_quarter)
+ ephem = helper.plugins['Ephemeris']
+
+ ephem.query_for_ephemeris()
+ # this should be HAT-P-11 b:
+ planet = ephem.query_result.choices[0]
+ assert planet == 'HAT-P-11 b'
+
+ ephem.query_result = planet
+ ephem.adopt_from_catalog()
+
+ # compare against best/recent parameters:
+ period_yee_2018 = 4.88780244
+ assert abs(1 - period_yee_2018 / ephem.period) < 1e-3
+
+ epoch_kokori_2022 = 2455109.335119
+ ref_time = helper.app.data_collection[0].coords.reference_time.jd
+ expected_t0 = (epoch_kokori_2022 - ref_time) % period_yee_2018
+ assert abs(1 - expected_t0 / ephem.t0) < 1e-3
diff --git a/lcviz/tests/test_plugin_markers.py b/lcviz/tests/test_plugin_markers.py
index b185373..e391930 100644
--- a/lcviz/tests/test_plugin_markers.py
+++ b/lcviz/tests/test_plugin_markers.py
@@ -81,7 +81,8 @@ def test_plugin_markers(helper, light_curve_like_kepler_quarter):
'Phase 0.45833',
'Flux 9.67587e-01')
- _assert_dict_allclose(label_mouseover.as_dict(), {'data_label': 'Light curve [Q10]',
+ object_name = helper.app.data_collection[-1].meta['OBJECT']
+ _assert_dict_allclose(label_mouseover.as_dict(), {'data_label': f'{object_name} [Q10]',
'time': 5.458333374001086,
'time:unit': 'd',
'phase': 0.4583333730697632,