question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Eclipse Functionality

See original GitHub issue

I noticed in the file TODO.rst adding the functionality for lunar/solar eclipses.

I am not sure if you intend to calculate this information or rather draw from a table. For what it’s worth, below is a code sample I use in my application to extract eclipse information from tables I took from NASA. If any of the code is useful, please use it in Skyfield.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


# Lunar/solar eclipse tables up to 2099.
# Courtesy of Fred Espenak and Jean Meeus.


import datetime


# Eclipse Types.
ECLIPSE_TYPE_ANNULAR = "A"
ECLIPSE_TYPE_HYBRID = "H"
ECLIPSE_TYPE_PARTIAL = "P"
ECLIPSE_TYPE_PENUMBRAL = "N"
ECLIPSE_TYPE_TOTAL = "T"


# Gets the upcoming eclipse, lunar or solar.
#
# dateTimeUTC - Current date/time in UTC as a python datetime.datetime object.
# isLunar - If True, finds the next lunar eclipse; otherwise finds the next solar eclipse.
#
# Returns a tuple of strings describing the next eclipse:
#    dateTime (format of YYYY-MM-DD HH:MM:SS)
#    eclipseType ("A" = Annular, "H" = Hybrid, "N" = Penumbral, "P" = Partial, "T" = Total)
#    latitude (south is negative)
#    longitude (east is negative).
def getEclipse( dateTimeUTC, isLunar ):
    if isLunar:
        eclipseData = __lunarEclipseData

    else:
        eclipseData = __solarEclipseData

    eclipseInfo = None
    for eclipse in eclipseData:
        dateTime = datetime.datetime.strptime( eclipse[ 0 ] + ", " + eclipse[ 1 ] + ", " + eclipse[ 2 ] + ", " + eclipse[ 3 ], "%Y, %m, %d, %H:%M:%S" )
        dateTime = dateTime - datetime.timedelta( seconds = int( eclipse[ 4 ] ) ) # Need to subtract delta T (https://eclipse.gsfc.nasa.gov/LEcat5/deltat.html).
        if dateTimeUTC <= dateTime:
            latitude = eclipse[ 6 ][ 0 : len( eclipse[ 6 ] ) - 1 ]
            if eclipse[ 6 ][ -1 ] == "S":
                latitude = "-" + latitude

            longitude = eclipse[ 7 ][ 0 : len( eclipse[ 7 ] ) - 1 ]
            if eclipse[ 7 ][ -1 ] == "E":
                longitude = "-" + longitude

            eclipseInfo = ( str( dateTime ), eclipse[ 5 ], latitude, longitude )
            break

    return eclipseInfo


# https://eclipse.gsfc.nasa.gov/5MCLE/5MKLEcatalog.txt
#
# Title: Five Millennium Catalog of Lunar Eclipses: -1999 to +3000 (2000 BCE to 3000CE)
# Authors: Fred Espenak and Jean Meeus
# Source: NASA Technical Publication NASA/TP-2009-214173
# On Web: https://eclipse.gsfc.nasa.gov/SEpubs/5MKLE.html
# Catalog Key: https://eclipse.gsfc.nasa.gov/LEcat5/LEcatkey.html
# Date: 2011 May 23
#
#      Year   Month  Day   HH:MM:SS    DT   Type  Lat   Long
__lunarEclipseData = [
    [ "2020", "11", "30", "09:44:01", "72", "N", "21N", "148W" ],
    [ "2021", "05", "26", "11:19:53", "72", "T", "21S", "170W" ],
    [ "2021", "11", "19", "09:04:06", "73", "P", "19N", "139W" ],
    # <snip>
    [ "2099", "09", "29", "10:36:38", "202", "N", "3N", "161W" ] ]


# https://eclipse.gsfc.nasa.gov/SEpubs/5MKSE.html
# https://eclipse.gsfc.nasa.gov/5MCSE/5MKSEcatalog.txt
#
# Title: Five Millennium Catalog of Solar Eclipses: -1999 to +3000 (2000 BCE to 3000CE)
# Authors: Fred Espenak and Jean Meeus
# Source: NASA Technical Publication NASA/TP-2008-214170
# Catalog Key: https://sunearth.gsfc.nasa.gov/eclipse/SEcat5/catkey.html
# Date: 2008 10 07
#
#      Year   Month  Day   HH:MM:SS    DT   Type  Lat      Long
__solarEclipseData = [
    [ "2020", "12", "14", "16:14:39", "72", "T", "40.3S", "67.9W" ],
    [ "2021", "06", "10", "10:43:07", "72", "A", "80.8N", "66.8W" ],
    [ "2021", "12", "04", "07:34:38", "73", "T", "76.8S", "46.2W" ],
    # <snip>
    [ "2099", "09", "14", "16:57:53", "202", "T", "23.4N", "62.8W" ] ]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bernmeistercommented, Sep 16, 2020

I’ll have a crack at it…

0reactions
brandon-rhodescommented, Nov 14, 2020

Only noticed it after you’ve pointed it out…oh well.

If you were following the issue but GitHub didn‘t light up your notifications, I’ll be happy in the future to make a comment after a commit to try to draw attention to it.

… in the end, I wrote code to implement the formulae in the book(s).

My approach with the commit above was similar: reading, followed by just converting their formulae into Python, with a focus on getting the right answer rather than understanding immediately. 🙂

Only once it worked did I review the text, figure out what the symbols meant, and substituted in some cases meaningful names for what had been plain variables in the original formulae.

Hopefully your code helps other folks who need eclipse data before solar eclipses are implemented in Skyfield, which probably won’t be for a few weeks, even if I put it at the front of my to-do list! My guess is that it would be hard to incorporate into official Skyfield code, because I think many of those equations are approximations for things Skyfield does at high precision, like TDB time, and the Sun and Moon positions — but to untangle which are which, we would need to hunt down the source of all of the coefficients in your example code. Of which, wow, there are a lot! You did a lot of work to successfully bring them into Python, and I’m glad for the moment that they provide a good match for at least the times of both lunar and solar eclipses.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eclipse Platform Technical Overview
The Eclipse Platform is designed for building integrated development environments (IDEs), and arbitrary tools. This paper is a general technical ...
Read more >
Eclipse Features - Learning Java, 4th Edition [Book] - O'Reilly
Eclipse offers a number of tools under the collective title refactoring. These include the ability to rename and move members, automatically tracking down ......
Read more >
Eclipse Tutorial: Most Popular Features To Help You Code ...
This Tutorial Covers Common Eclipse Features Such As Perspectives & Views, Importing/Exporting Programs, Refactoring, Quick Fix Etc. To Make ...
Read more >
Using the Eclipse IDE for Java programming - Tutorial
Content assist is a functionality in Eclipse which allows the developer to get context-sensitive code completion in an editor upon user request.
Read more >
Eclipse Tutorial - Tutorialspoint
We will give special emphasis on Java project. Audience. This tutorial has been prepared for beginners to help them understand basic functionality of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found