diff --git a/astroplan/periodic.py b/astroplan/periodic.py index 74fb5105..5d7a6432 100644 --- a/astroplan/periodic.py +++ b/astroplan/periodic.py @@ -232,6 +232,46 @@ def next_secondary_eclipse_time(self, time, n_eclipses=1): np.arange(n_eclipses) * self.period) return eclipse_times + def next_eclipse(self, time, n_eclipses=1): + """ + Times of the next eclipses after ``time``. + + .. warning:: + Barycentric offsets are ignored in the current implementation. + + Parameters + ---------- + time : `~astropy.time.Time` + Find the next eclipse after ``time`` + n_eclipses : int (optional) + Return the times of eclipse for the next ``n_eclipses`` after + ``time``. Default is 1. + + Returns + ------- + table: `~astropy.table.Table` + Table of the next ``n_eclipses`` eclipses after ``time``. + """ + from astropy.table import Table + + primary_times = self.next_primary_eclipse_time(time, n_eclipses) + secondary_times = self.next_secondary_eclipse_time(time, n_eclipses) + + all_times = np.concatenate([primary_times.jd, secondary_times.jd]) + all_types = np.concatenate( + [np.repeat("P", n_eclipses), np.repeat("S", n_eclipses)] + ) + + sort_idx = np.argsort(all_times) + all_times = all_times[sort_idx] + all_types = all_types[sort_idx] + + table = Table() + table["time"] = Time(all_times, format="jd") + table["type"] = all_types + + return table + def next_primary_ingress_egress_time(self, time, n_eclipses=1): """ Calculate the times of ingress and egress for the next ``n_eclipses`` diff --git a/astroplan/tests/test_periodic.py b/astroplan/tests/test_periodic.py index 2c3ded0b..40c6a6ba 100644 --- a/astroplan/tests/test_periodic.py +++ b/astroplan/tests/test_periodic.py @@ -28,12 +28,14 @@ def test_primary_secondary_eclipse(): ap_primary = es.next_primary_eclipse_time(epoch) ap_secondary = es.next_secondary_eclipse_time(epoch) + table = es.next_eclipse(epoch) soln_primary = Time(['2016-01-04 00:00']) soln_secondary = Time(['2016-01-02 12:00']) # Tolerance of 1 second assert_allclose([ap_primary.jd, ap_secondary.jd], + [table["time"][0].jd, table["time"][1].jd], [soln_primary.jd, soln_secondary.jd], atol=PRECISION)