skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.41k stars 211 forks source link

Since 1.37 events missing in twilight calculation #571

Closed mworion closed 3 years ago

mworion commented 3 years ago

@brandon-rhodes Since I moved to 1.37 I observed a change in my app when calculating the twilight data from:

Bildschirmfoto 2021-03-20 um 16 42 44

to:

Bildschirmfoto 2021-03-20 um 16 42 49

I calculate the data with

f = almanac.dark_twilight_day(self.app.ephemeris, location)

When looking to the data I see oscillating value for event codes (second row):


2459381.0 3 14.116666666666667
2459381.0 4 15.833333333333334
2459382.0 3 10.649999999999999
2459382.0 4 15.816666666666666
2459383.0 3 10.649999999999999
2459383.0 2 12.4
2459383.0 3 14.066666666666666
2459383.0 4 15.816666666666666
2459384.0 3 10.666666666666664
2459384.0 2 12.433333333333334
2459384.0 3 14.05
2459384.0 4 15.816666666666666
2459385.0 3 10.666666666666664
2459385.0 4 15.816666666666666

From my point this is impossible. It happened from 1.36 to 1.37.
Michel
brandon-rhodes commented 3 years ago
  1. What Skyfield version were you previously on — can I look for a difference only between 1.36 and 1.37, or did you upgrade from several versions ago?
  2. Is there any chance you could supply a tiny script producing those numbers, so I have a test case to work with? I don't need to plotting code, if that makes it simpler to produce a test case. Thanks!
mworion commented 3 years ago

I switched from 1.36 to 1.37. And I could reproduce this situation just by switching the skyfield version.

    from skyfield.api import Topos, load
    from skyfield import almanac

    location = Topos(longitude_degrees=11,
                     latitude_degrees=47,
                     elevation_m=500)
    ephemeris = load('tests/testData/de421.bsp')
    ts = load.timescale(builtin=True)
    t0 = ts.tt_jd(2459360)
    t1 = ts.tt_jd(2459360 + 30)
    f = almanac.dark_twilight_day(ephemeris, location)
    times, events = almanac.find_discrete(t0, t1, f)

    with open('compare1.36.txt', 'w+') as f:
        for t, e in zip(times, events):
            f.writelines(f'{t.tt:10.4f}, {e}\n')

I see in a diff that th "night" section so event 0 is in 1.36 and misses in 1.37. So to correct it's not oscillating, but missing event. I wrote the content in a file and made a diff. Michel

compare1.36.txt compare1.37.txt

brandon-rhodes commented 3 years ago

Thanks very much for the example script! I've tried it out and done some checking. Try this in your script and let me know if it has an effect:

f.step_days = 0.04
mworion commented 3 years ago

Yes, this sorts it out in my app. Many thanks ! Plot is again OK with 1.37. Added this in my code. Michel

brandon-rhodes commented 3 years ago

For anyone reading this later: the fix went out in Skyfield 1.38.