from skyfield.api import load
planets = load('data/de421.bsp')
earth, mars = planets['earth'], planets['mars']
ts = load.timescale()
t = ts.now()
astrometric = earth.at(t).observe(mars)
ra, dec, distance = astrometric.radec()
print(ra)
print(dec)
print(distance)
01h 08m 58.49s +07deg 36' 53.9" 0.705051 au
from skyfield.api import Topos
naoc = Topos('40.002 N', '116.38 E')
naocs = earth + naoc
astrometric = naocs.at(t).observe(mars)
alt, az, d = astrometric.apparent().altaz()
alt, az, d
(<Angle 24deg 44' 28.6">, <Angle 101deg 09' 31.2">, <Distance 0.705033 au>)
from skyfield import almanac
from pytz import timezone
zone = timezone('Asia/Shanghai')
f = almanac.dark_twilight_day(planets, naoc)
t0 = ts.utc(2020, 12, 4)
t1 = ts.utc(2020, 12, 10)
t, y = almanac.find_discrete(t0, t1, f)
for ti, e in zip(t, y):
tstr = str(ti.astimezone(zone))[:16]
print(tstr, ' ', almanac.TWILIGHTS[e], 'starts')
2020-12-04 16:49 Civil twilight starts 2020-12-04 17:19 Nautical twilight starts 2020-12-04 17:53 Astronomical twilight starts 2020-12-04 18:25 Night starts 2020-12-05 05:44 Astronomical twilight starts 2020-12-05 06:16 Nautical twilight starts 2020-12-05 06:50 Civil twilight starts 2020-12-05 07:20 Day starts 2020-12-05 16:49 Civil twilight starts 2020-12-05 17:19 Nautical twilight starts 2020-12-05 17:53 Astronomical twilight starts 2020-12-05 18:25 Night starts 2020-12-06 05:45 Astronomical twilight starts 2020-12-06 06:17 Nautical twilight starts 2020-12-06 06:51 Civil twilight starts 2020-12-06 07:21 Day starts 2020-12-06 16:49 Civil twilight starts 2020-12-06 17:19 Nautical twilight starts 2020-12-06 17:53 Astronomical twilight starts 2020-12-06 18:25 Night starts 2020-12-07 05:45 Astronomical twilight starts 2020-12-07 06:18 Nautical twilight starts 2020-12-07 06:52 Civil twilight starts 2020-12-07 07:22 Day starts 2020-12-07 16:48 Civil twilight starts 2020-12-07 17:19 Nautical twilight starts 2020-12-07 17:53 Astronomical twilight starts 2020-12-07 18:25 Night starts 2020-12-08 05:46 Astronomical twilight starts 2020-12-08 06:19 Nautical twilight starts 2020-12-08 06:53 Civil twilight starts 2020-12-08 07:23 Day starts 2020-12-08 16:48 Civil twilight starts 2020-12-08 17:19 Nautical twilight starts 2020-12-08 17:53 Astronomical twilight starts 2020-12-08 18:26 Night starts 2020-12-09 05:47 Astronomical twilight starts 2020-12-09 06:20 Nautical twilight starts 2020-12-09 06:54 Civil twilight starts 2020-12-09 07:24 Day starts 2020-12-09 16:49 Civil twilight starts 2020-12-09 17:19 Nautical twilight starts 2020-12-09 17:53 Astronomical twilight starts 2020-12-09 18:26 Night starts 2020-12-10 05:48 Astronomical twilight starts 2020-12-10 06:21 Nautical twilight starts 2020-12-10 06:54 Civil twilight starts 2020-12-10 07:25 Day starts
t, y = almanac.find_discrete(t0, t1, almanac.sunrise_sunset(planets, naoc))
for ti, e in zip(t, y):
tstr = str(ti.astimezone(zone))[:16]
msg = "日落"
if e:
msg = "日升"
print(tstr, ' ', msg)
2020-12-04 16:49 日落 2020-12-05 07:20 日升 2020-12-05 16:49 日落 2020-12-06 07:21 日升 2020-12-06 16:49 日落 2020-12-07 07:22 日升 2020-12-07 16:48 日落 2020-12-08 07:23 日升 2020-12-08 16:48 日落 2020-12-09 07:24 日升 2020-12-09 16:49 日落 2020-12-10 07:25 日升
from skyfield import almanac_east_asia as almanac_ea
t0 = ts.utc(2020, 12, 15)
t1 = ts.utc(2021, 12, 15)
t, tm = almanac.find_discrete(t0, t1, almanac_ea.solar_terms(planets))
for tmi, ti in zip(tm, t):
print(tmi, almanac_ea.SOLAR_TERMS_ZHS[tmi], ti.utc_iso(' '))
18 冬至 2020-12-21 10:02:20Z 19 小寒 2021-01-05 03:23:26Z 20 大寒 2021-01-19 20:39:52Z 21 立春 2021-02-03 14:58:48Z 22 雨水 2021-02-18 10:43:58Z 23 惊蛰 2021-03-05 08:53:41Z 0 春分 2021-03-20 09:37:29Z 1 清明 2021-04-04 13:35:06Z 2 谷雨 2021-04-19 20:33:24Z 3 立夏 2021-05-05 06:47:10Z 4 小满 2021-05-20 19:37:07Z 5 芒种 2021-06-05 10:52:06Z 6 夏至 2021-06-21 03:32:10Z 7 小暑 2021-07-06 21:05:29Z 8 大暑 2021-07-22 14:26:26Z 9 立秋 2021-08-07 06:53:59Z 10 处暑 2021-08-22 21:34:59Z 11 白露 2021-09-07 09:52:56Z 12 秋分 2021-09-22 19:21:06Z 13 寒露 2021-10-08 01:39:02Z 14 霜降 2021-10-23 04:51:10Z 15 立冬 2021-11-07 04:58:46Z 16 小雪 2021-11-22 02:33:44Z 17 大雪 2021-12-06 21:57:04Z
from skyfield.api import Star
vega = Star(ra_hours=(18, 36, 56.3363), dec_degrees=(+38, 47, 01.280))
t = ts.now()
astrometric = naocs.at(t).observe(vega)
ra, dec, distance = astrometric.radec()
print(ra)
print(dec)
18h 36m 56.34s +38deg 47' 01.3"
app = astrometric.apparent()
alt, az, distance = app.altaz()
print(alt.dstr())
print(az.dstr())
print(distance)
53deg 58' 06.1" 76deg 17' 15.8" 2.06265e+14 au