Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add utility next_eclipse function #610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions astroplan/periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
2 changes: 2 additions & 0 deletions astroplan/tests/test_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Loading