Skip to content

Commit

Permalink
Fix #361 by adding a lunar node almanac routine
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-rhodes committed Apr 22, 2020
1 parent 785f374 commit f6d76d3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ Changelog
* To hopefully fix the ``SSL: CERTIFICATE_VERIFY_FAILED`` errors that
some users encounter when downloading timescale files, took the risk
of switching away from Python’s default SSL certificates to the
certificate bundle in the `certifi` package.
certificate bundle in the ``certifi`` package.
`#317 <https://github.com/skyfielders/python-skyfield/issues/317>`_

* Added a new almanac routine for finding :ref:`lunar-nodes`.
`#361 <https://github.com/skyfielders/python-skyfield/issues/361>`_

* Gave topos objects a new :meth:`~skyfield.toposlib.Topos.itrf_xyz()`
method that returns their raw ITRF coordinates.
`#354 <https://github.com/skyfielders/python-skyfield/issues/354>`_
Expand Down
25 changes: 25 additions & 0 deletions skyfield/almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ def moon_phase_at(t):
moon_phase_at.rough_period = 7.0 # one lunar phase per week
return moon_phase_at

MOON_NODES = [
'descending',
'ascending',
]

def moon_nodes(ephemeris):
"""Build a function of time that identifies lunar nodes.
This returns a function taking a :class:`~skyfield.timelib.Time` and
returning ``True`` if the Moon is above the ecliptic else ``False``.
See :ref:`lunar-nodes` for how to use this routine.
"""
earth = ephemeris['earth']
moon = ephemeris['moon']

def moon_node_at(t):
"""Return the phase of the moon 0 through 3 at time `t`."""
e = earth.at(t)
lat, _, _ = e.observe(moon).apparent().ecliptic_latlon('date')
return lat.radians > 0.0

moon_node_at.rough_period = 14.0 # one node each half lunar month
return moon_node_at

CONJUNCTIONS = [
'conjunction',
'opposition',
Expand Down
25 changes: 25 additions & 0 deletions skyfield/documentation/almanac.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,31 @@ corresponding array of Moon phases with 0 for New Moon and 3 for Last
Quarter. You can use the array ``MOON_PHASES`` to retrieve names for
each phase.

.. _lunar-nodes:

Lunar Nodes
===========

The Moon’s ascending node and descending node are the moments each lunar
month when the Moon crosses the plane of Earth’s orbit and eclipses are
possible.

.. testcode::

t0 = ts.utc(2020, 4, 22)
t1 = ts.utc(2020, 5, 22)
t, y = almanac.find_discrete(t0, t1, almanac.moon_nodes(e))

print(t.utc_iso())
print(y)
print([almanac.MOON_NODES[yi] for yi in y])

.. testoutput::

['2020-04-27T17:54:17Z', '2020-05-10T09:01:42Z']
[ True False]
['ascending', 'descending']

.. _oppositions-conjunctions:

Opposition and Conjunction
Expand Down
2 changes: 2 additions & 0 deletions skyfield/documentation/api-almanac.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ times of sunrise, sunset, and the phases of the moon.

.. autofunction:: moon_phases

.. autofunction:: moon_nodes

.. autofunction:: oppositions_conjunctions

.. autofunction:: sunrise_sunset
Expand Down

0 comments on commit f6d76d3

Please sign in to comment.