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

Add Julian calendar dates for earlier historical calculations #450

Closed
willismonroe opened this issue Sep 16, 2020 · 19 comments
Closed

Add Julian calendar dates for earlier historical calculations #450

willismonroe opened this issue Sep 16, 2020 · 19 comments

Comments

@willismonroe
Copy link

It would be useful if the Skyfield library had the ability to convert to Julian dates for periods before the Gregorian calendar in order to more closely align with historical calculations of astronomical observations.

(see discussion here: https://stackoverflow.com/questions/63855845/differences-between-pyephem-and-skyfield-for-calculating-ancient-phenomena/63865680?noredirect=1#comment112978745_63865680)

@brandon-rhodes
Copy link
Member

Thanks for opening an issue! I'll see if I can get to this within the next few weeks.

brandon-rhodes added a commit that referenced this issue Sep 17, 2020
This prepares the way for support for input of Julian calendar dates.
See #450.
@willismonroe
Copy link
Author

Great, let me know if I can help or test anything along the way.

brandon-rhodes added a commit that referenced this issue Sep 17, 2020
A simplification I maybe should have seen earlier; was I trying to avoid
what’s probably a small hit in speed?  For #450.
brandon-rhodes added a commit that referenced this issue Sep 17, 2020
Now that it only has one use, its logic can live in the class.  Another
step towards #450.
brandon-rhodes added a commit that referenced this issue Sep 17, 2020
Another simplification, at the expense of another function call and
level of indirection.  With all calendar interpretation going through a
single internal function, it will be easier to make #450 happen.
@brandon-rhodes
Copy link
Member

@willismonroe — All right, I think I have something working! If you install Skyfield from the repository:

pip install https://github.com/skyfielders/python-skyfield/archive/master.zip

— then you should be able to tell your Timescale object on what Julian date you want it to switch from the Julian calendar to the Gregorian calendar. Constants are provided for two common choices: the adoption by the Church in Rome, and the adoption by the English. Thus:

from skyfield import api

ts = api.load.timescale()
ts.julian_calendar_cutoff = api.GREGORIAN_START  # in Rome

print(ts.tt_jd(2299159.5).tt_strftime())
print(ts.tt_jd(2299160.5).tt_strftime())

print(ts.utc(1582, 10, 4).tt)
print(ts.utc(1582, 10, 15).tt)

print(ts.utc(1582, 10, 15) - ts.utc(1582, 10, 4))

Could you try it out and see if it works for you? The cutoff setting should affect all calendar inputs and outputs, assuming I didn't miss any. Thanks!

@brandon-rhodes
Copy link
Member

@willismonroe — I will be away from the keyboard next week, and so instead of doing a Skyfield release for this feature and then perhaps being unavailable if there's a problem, I am planning to hold Skyfield at 1.27 until my return. So there's no rush to test this feature within the next couple of days! I'll check again when I'm back at the keyboard at the end of next week, and consider making a release then.

@willismonroe
Copy link
Author

@brandon-rhodes no worries! I've been quite busy, hoping to test this soon!

@brandon-rhodes
Copy link
Member

I have just released Skyfield 1.28 which includes this new feature across all calendars support by the timescale object:

https://rhodesmill.org/skyfield/time.html#ancient-and-modern-dates

Let me know if you run into any problems. Enjoy!

@willismonroe
Copy link
Author

willismonroe commented Sep 25, 2020

Hi @brandon-rhodes this works perfectly:

Calculated new moons

Parker and Duberstein 537 BCE

I was able to calculate the new moons for 537 BCE matching Parker and Duberstein's calculations from 1942 (off by one day, but that's fine for what I'm doing).

By the way, I had to add a numpy.array.any() to timelib.py so that I could pass a time range to ts.tt(). Line 799 for me now reads:

if (julian_before is None) or array(J >= julian_before).any():

that's probably not the right way to do it, and I can certainly see problems when your date range cross the Gregorian start date...

brandon-rhodes added a commit that referenced this issue Sep 25, 2020
If a Julian calendar cutoff was specified, arrays of dates were failing
to turn into JDs but raising an exception instead.  See #450.
@brandon-rhodes
Copy link
Member

@willismonroe — Thank you for altering me to this bug! I have just pushed a fix, along with a test to try to keep it fixed. Could you try installing the development version of Skyfield to try it out on your machine?

pip install https://github.com/skyfielders/python-skyfield/archive/master.zip

Thanks!

@willismonroe
Copy link
Author

Can confirm, works as expected.

By the way, is there a reason that Time.tt doesn't return a CalendarTuple like Time.utc? It would make string formatting easier.

@brandon-rhodes
Copy link
Member

Does .tt_calendar() or .tt_strftime() do what you need, or is neither of them quite what you are looking for?

@willismonroe
Copy link
Author

willismonroe commented Sep 25, 2020 via email

@brandon-rhodes
Copy link
Member

Oh, I see! I hadn't realized that the other calendar routines were returning normal tuples instead of the special calendar tuples.

If you’ll open an issue, I can see about adding those fields to Skyfield within the next few weeks. Thanks for the idea!

@brandon-rhodes
Copy link
Member

@willismonroe — Oh, and: I'm a bit worried that those dates are off so consistently by one day, except for maybe one date that instead agrees exactly? I suppose Cyrus was in a time zone several hours earlier than Greenwich, but I still would have expected at least ¾ of the events to line up on the same dates.

@willismonroe
Copy link
Author

willismonroe commented Sep 25, 2020 via email

@brandon-rhodes
Copy link
Member

@willismonroe — That's true, the orbit parameters would not have been as exact in 1942!

And I just thought of something else: dates that long ago are going to be several hours (I think? at least a few dozen minutes?) off of the midnight/noon schedule of our modern atomic clocks, so TT and TAI will be way off from what folks at that time actually experienced as midnight, sunrise, noon, and sunset. It’s UT1 that might provide a guess as to where the day really stood back then. Could you try UT1 and see what your script prints?

@willismonroe
Copy link
Author

Hmm, I'm unable to iterate over a UT1 Time array:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-c4978c2e661b> in <module>
      8 r = ts.ut1(start_year, 1, range(1,365))
      9 print(f"New moons for year {abs(start_year)+1} BCE:")
---> 10 for time in r:
     11     e = earth.at(time)
     12     _, slon, _ = e.observe(sun).apparent().ecliptic_latlon()

~/.local/lib/python3.8/site-packages/skyfield/timelib.py in __getitem__(self, index)
    346             value = getattr(self, name, None)
    347             if value is not None:
--> 348                 setattr(t, name, value[index])
    349         return t
    350 

TypeError: 'float' object is not subscriptable

I looked into it, and the value is just 0.0 when name is ut1_fraction, for the other two names it's a full array of the fractions.

brandon-rhodes added a commit that referenced this issue Sep 25, 2020
Instead of: `TypeError: 'float' object is not subscriptable`
@brandon-rhodes
Copy link
Member

@willismonroe — You are doing an exemplary job of finding bugs! Wow! I've submitted a patch, can you try a fresh install?

pip install https://github.com/skyfielders/python-skyfield/archive/master.zip

Thanks!

@brandon-rhodes
Copy link
Member

(As it's Friday night and I will be away from keyboard starting tomorrow, I'll go ahead and cut a release to fix at least these two problems!)

@willismonroe
Copy link
Author

willismonroe commented Sep 28, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants