skyfielders / python-skyfield

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

can't find the error #900

Closed heinkurz closed 1 year ago

heinkurz commented 1 year ago

I get the error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" in line # but don't know why.

from datetime import *
from skyfield import almanac
from skyfield.api import E, S, W, N, wgs84, load
#import numpy

# THAT DON'T WORK

ts = load.timescale()
eph = load('de421.bsp')
vienna = wgs84.latlon(48.107158 * N, 16.349668 * E)
today = datetime.now()
y = today.year
m = today.month
dm = 31
if m == 2:
    dm = 28
if m == 4 or m == 6 or m == 9 or m == 11:
    dm = 30
for d in range(1, dm + 1):
    t0 = ts.utc(y, m, d, 4)
    t1 = ts.utc(y, m, d + 1, 4)
    #f = almanac.dark_twilight_day(eph, vienna)
    f = almanac.sunrise_sunset(eph, vienna)
    t, y = almanac.find_discrete(t0, t1, f)             # <<<<<<<<<<<<<<  ERROR
    print(y,m,d,t0,t1) #, t.utc_iso(), y, f(t0))

# THAT WORKS although it's the same as above !?!? Only d is a fixed number instead of a variable.

t0 = ts.utc(y, m, 7, 4)
t1 = ts.utc(y, m, 8, 4)
f = almanac.sunrise_sunset(eph, vienna)
t, y = almanac.find_discrete(t0, t1, f)
print(t.utc_iso())
heinkurz commented 1 year ago

sorry, I'm an idiot, there are 2 diffent deffinitiones for y

brandon-rhodes commented 1 year ago

I'm glad you found the solution quickly!