Closed colorfuldarkgray closed 1 year ago
Try printing out cdmx.lon
and cdmx.lat
— since you provided floating point numbers, PyEphem probably assumed you were providing radian angles instead of degrees.
My mistakes:
I was passing my coordinates as floating numbers instead of strings. I was swaping latitude and longitude
Correction:
cdmx = ephem.Observer()
cdmx.lat, cdmx.lon = '19.432441', '-99.133221'
sun = ephem.Sun()
cdmx.lon, cdmx.lat
out: (-1.7302011045571857, 0.33916007714953944)
Now I am getting positive and negative altitudes for the sun:
for j in range(24):
d_str=f'2022/12/18 {j}:04'
d = ephem.Date(d_str)
cdmx.date = ephem.localtime(d)
sun.compute(cdmx)
print(d_str, sun.alt)
out: 2022/12/18 0:04 46:38:29.6 2022/12/18 1:04 46:32:06.1 2022/12/18 2:04 41:46:16.5 2022/12/18 3:04 33:31:16.6 2022/12/18 4:04 23:04:20.5 2022/12/18 5:04 11:19:29.2 2022/12/18 6:04 -0:37:28.1 2022/12/18 7:04 -14:26:19.3 2022/12/18 8:04 -27:51:19.8 2022/12/18 9:04 -41:28:34.3 2022/12/18 10:04 -55:12:39.8 2022/12/18 11:04 -68:57:02.9 2022/12/18 12:04 -82:11:22.5 2022/12/18 13:04 -81:46:11.4 2022/12/18 14:04 -68:28:41.0 2022/12/18 15:04 -54:44:09.1 2022/12/18 16:04 -41:00:15.3 2022/12/18 17:04 -27:23:24.5 2022/12/18 18:04 -13:59:01.5 2022/12/18 19:04 -0:16:50.3 2022/12/18 20:04 11:44:11.9 2022/12/18 21:04 23:26:49.7 2022/12/18 22:04 33:49:58.2 2022/12/18 23:04 41:58:48.5
But I am still wrong somewhere since I have negative altitudes during day times and positive altitudes during night times for the sun.
I think localtime()
might be going in the opposite direction from what you need—it goes from UTC to your timezone. But it looks like what you want is to start with a time in your timezone, and turn it into PyEphem's UTC?
Finally!!!
for j in range(8):
local = datetime(2021, 11, 26, j+6, 17).astimezone()
d = ephem.Date(local)
cdmx.date = d
sun.compute(cdmx)
print(d, sun.alt)
out:
2021/11/26 12:17:00 -8:23:05.5 2021/11/26 13:17:00 4:54:22.0 2021/11/26 14:17:00 17:21:10.5 2021/11/26 15:17:00 28:57:25.0 2021/11/26 16:17:00 38:59:21.1 2021/11/26 17:17:00 46:19:34.7 2021/11/26 18:17:00 49:28:02.2 2021/11/26 19:17:00 47:28:09.4
Thank you!
I'm glad your script is working now—Merry Christmas!
I am obtaining always negative altitude during 24 hrs. lapse but I expected positive altitude (sun over the horizon) for half of samples:
input
####### output ####### 2022/12/18 0:04 -28:49:54.2 2022/12/18 1:04 -30:49:49.4 2022/12/18 2:04 -32:18:28.7 2022/12/18 3:04 -33:08:17.0 2022/12/18 4:04 -33:14:45.8 2022/12/18 5:04 -32:37:19.6 2022/12/18 6:04 -31:19:23.0 2022/12/18 7:04 -29:27:43.7 2022/12/18 8:04 -27:11:28.3 2022/12/18 9:04 -24:40:54.6 2022/12/18 10:04 -22:06:35.7 2022/12/18 11:04 -19:38:40.8 2022/12/18 12:04 -17:26:26.9 2022/12/18 13:04 -15:37:58.6 2022/12/18 14:04 -14:19:48.0 2022/12/18 15:04 -13:36:36.9 2022/12/18 16:04 -13:31:01.0 2022/12/18 17:04 -14:03:21.0 2022/12/18 18:04 -15:11:40.3 2022/12/18 19:04 -16:51:53.2 2022/12/18 20:04 -18:57:58.5 2022/12/18 21:04 -21:22:17.3 2022/12/18 22:04 -23:55:51.9 2022/12/18 23:04 -26:28:46.2
####################################
What am I doing wrong? What am I not understanding?
Thank you!