diff --git a/CHANGES.rst b/CHANGES.rst index c838bf4..8dccc8c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,8 @@ * Prevent duplicate sub-intervals (quarter/sector/campaign) in data labels. [#120] +* Add feature to query the NASA Exoplanet Archive for exoplanet ephemerides. [#127] + 0.4.3 (unreleased) ------------------ diff --git a/lcviz/conftest.py b/lcviz/conftest.py index 5be4d22..a5bbd36 100644 --- a/lcviz/conftest.py +++ b/lcviz/conftest.py @@ -37,9 +37,15 @@ def light_curve_like_kepler_quarter(seed=42): ) lc['flux_alt'] = flux + 1 lc['flux_alt_err'] = flux_err - lc.meta['MISSION'] = 'KEPLER' - lc.meta['QUARTER'] = 10 - lc.meta['OBJECT'] = 'HAT-P-11' + lc.meta.update( + { + 'MISSION': 'KEPLER', + 'QUARTER': 10, + 'OBJECT': 'HAT-P-11', + 'RA': 297.7101763, + 'DEC': 48.0818635, + } + ) return lc diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py index e24c6c9..b51f618 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -627,7 +627,8 @@ def query_for_ephemeris(self): if self.query_name: # first query by object name: query_result = self.nasa_exoplanet_archive.query_object( - self.query_name, table='pscomppars' + object_name=self.query_name, + table='pscomppars' ) if ( @@ -637,8 +638,9 @@ def query_for_ephemeris(self): # next query by coordinates: coord = SkyCoord(ra=self.query_ra, dec=self.query_dec, unit=u.deg) query_result = self.nasa_exoplanet_archive.query_region( - coord, self.query_radius * u.arcsec, - table='pscomppars' + table='pscomppars', + coordinates=coord, + radius=self.query_radius * u.arcsec, ) if query_result is None or len(query_result) == 0: diff --git a/lcviz/tests/test_plugin_ephemeris.py b/lcviz/tests/test_plugin_ephemeris.py index abc0252..d268e46 100644 --- a/lcviz/tests/test_plugin_ephemeris.py +++ b/lcviz/tests/test_plugin_ephemeris.py @@ -134,6 +134,17 @@ def test_create_phase_viewer(helper, light_curve_like_kepler_quarter): assert len(vc.viewer_types) == 3 +def compare_against_literature_ephemeris(helper, ephem): + # 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 + + def test_ephemeris_queries(helper, light_curve_like_kepler_quarter): helper.load_data(light_curve_like_kepler_quarter) ephem = helper.plugins['Ephemeris'] @@ -146,11 +157,22 @@ def test_ephemeris_queries(helper, light_curve_like_kepler_quarter): 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 + compare_against_literature_ephemeris(helper, ephem) - 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 + +def test_ephemeris_query_no_name(helper, light_curve_like_kepler_quarter): + # test that the query successfully falls back on the RA/Dec: + light_curve_like_kepler_quarter.meta['OBJECT'] = '' + + 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_literature_ephemeris(helper, ephem)