From 12f8c5602fb5763397162c0a25186d855e8b53e4 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Mon, 22 Jul 2024 16:47:40 -0400 Subject: [PATCH] adding coverage --- lcviz/conftest.py | 1 + lcviz/plugins/ephemeris/ephemeris.py | 63 +++++++++++++++++++-------- lcviz/plugins/ephemeris/ephemeris.vue | 6 +-- lcviz/tests/test_parser.py | 3 +- lcviz/tests/test_plugin_ephemeris.py | 22 ++++++++++ lcviz/tests/test_plugin_markers.py | 5 ++- 6 files changed, 75 insertions(+), 25 deletions(-) diff --git a/lcviz/conftest.py b/lcviz/conftest.py index 767828cb..5be4d226 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 66c05ba6..e24c6c98 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 c5f59c86..ca405e88 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 @@