||
PyEphem为Python下的一个程序包, 用来进行天文历算, 虽然是爱好者编写的, 但是由于使用VOS87行星运动数据, 计算精度达到了很高的精度, 足以满足一般的观测需要。 详情参见 http://rhodesmill.org/pyephem/ 本文是学习该程序包的读书笔记。
import ephem m = ephem.Mars('2018') print(ephem.constellation(m))
('Lib', 'Libra')
from ephem import * mars = Mars('1970') # 火星 print('%s, %s, %.10f' % (mars.name, mars.elong, mars.size)) sun = Sun('1970') # 太阳 print('%s, %s, %.10f' % (sun.name, sun.elong, sun.size)) moon = Moon('1970') # 月亮 print('%s, %s, %.10f' % (moon.name, moon.elong, moon.size)) mercury = Mercury('1970') # 水星 print('%s, %s, %.10f' % (mercury.name, mercury.elong, mercury.size)) venus = Venus('1970') # 金星 print('%s, %s, %.10f' % (venus.name, venus.elong, venus.size)) jupiter = Jupiter('1970') # 木星 print('%s, %s, %.10f' % (jupiter.name, jupiter.elong, jupiter.size)) saturn = Saturn('1970') # 土星 print('%s, %s, %.10f' % (saturn.name, saturn.elong, saturn.size)) uranus = Uranus('1970') # 天王星 print('%s, %s, %.10f' % (uranus.name, uranus.elong, uranus.size)) neptune = Neptune('1970') # 海王星 print('%s, %s, %.10f' % (neptune.name, neptune.elong, neptune.size)) pluto = Pluto('1970') # 冥王星 print('%s, %s , %.10f' % (pluto.name, pluto.elong, pluto.size))
Mars, 62:04:48.0, 5.9295825958 Sun, 0:00:00.0, 1951.8359375000 Moon, -89:27:48.3, 1831.0117187500 Mercury, 18:52:17.4, 7.5804867744 Venus, -5:42:32.4, 9.9605798721 Jupiter, -67:50:24.1, 34.2474060059 Saturn, 111:52:32.6, 18.8122367859 Uranus, -91:26:29.1, 3.8586533070 Neptune, -40:17:59.5, 2.1982953548 Pluto, -102:16:48.8 , 0.2606950402
### a_ra — Astrometric geocentric right ascension for the epoch specified ### a_dec — Astrometric geocentric declination for the epoch specified ### g_ra and ra — Apparent geocentric right ascension for the epoch-of-date ### g_dec and dec — Apparent geocentric declination for the epoch-of-date ### elong — Elongation (angle to sun) ### mag — Magnitude ### size — Size (diameter in arcseconds) ### radius — Size (radius as an angle) ### circumpolar — whether it stays above the horizon ### neverup — whether is stays below the horizon ############################################ hlon — Heliocentric longitude (see next paragraph) ### hlat — Heliocentric latitude (see next paragraph) ### sun_distance — Distance to Sun (AU) ### earth_distance — Distance to Earth (AU) ### phase — Percent of surface illuminated
gatech = Observer() gatech.lon = '114.169576' gatech.lat = '22.451939' gatech.elevation = 5 gatech.date = '2014/9/22 22:30:00' v = Venus(gatech) print('%s, %s' % (v.alt, v.az))
11:47:49.3, 89:41:14.6
line = "C/2002 Y1 (Juels-Holvorcem),e,103.7816,166.2194,128.8232,242.5695, 0.0002609,0.99705756,0.0000,04/13.2508/2003,2000,g 6.5,4.0" yh = ephem.readdb(line) yh.compute('2007/10/1') print('%.10f' % yh.earth_distance) print(yh.mag)
14.8046731949 23.96
## 已知人造卫星的轨道根数, 计算其在任意时刻的高度和方位
### 读取 xephem格式用 readdb 方法 ### 写出 xepheme格式, 用 writedb 方法 ######### 人造卫星为 tle格式, 这里用readtle方法来阅读 line1 = "ISS (ZARYA)" line2 = "1 25544U 98067A 03097.78853147 .00021906 00000-0 28403-3 0 8652" line3 = "2 25544 51.6361 13.7980 0004256 35.6671 59.2566 15.58778559250029" iss = ephem.readtle(line1, line2, line3) iss.compute('2003/3/23') print('%s %s' % (iss.sublong, iss.sublat))
-76:24:18.3 13:05:31.1 ('Sgr', 'Sagittarius') 50.54 V2 - P274 V2 - P135 V1 - P273
m = Moon('1980/6/1') print(constellation(m))
('Sgr', 'Sagittarius')
####### Uranometria by Johannes Bayer. ####### Uranometria 2000.0 edited by Wil Tirion. ####### Millennium Star Atlas by Roger W. Sinnott and Michael A. C. Perryman. ra, dec = '7:16:00', '-6:17:00'print(ephem.uranometria(ra, dec)) print(ephem.uranometria2000(ra, dec)) print(ephem.millennium_atlas(ra, dec))
ephem.julian_date('2000/1/1')
print(ephem.delta_t('1980'))
m1 = ephem.Moon('1970/1/16') m2 = ephem.Moon('1970/1/17') s = ephem.separation(m1, m2) print("In one day the Moon moved %s" % s)
In one day the Moon moved 12:33:28.5
np = Equatorial('0', '90', epoch='2000') g = Galactic(np) print('%s %s' % (g.lon, g.lat)) #### Equatorial #### ra — right ascension #### dec — declination #### epoch — epoch of the coordinate #### Ecliptic #### lon — ecliptic longitude (+E) #### lat — ecliptic latitude (+N) #### epoch — epoch of the coordinate #### Galactic #### lon — galactic longitude (+E) #### lat — galactic latitude (+N) #### epoch — epoch of the coordinate
122:55:54.9 27:07:41.7
#### Describes a position on Earth’s surface.lowell = ephem.Observer() lowell.lon = '-111:32.1' lowell.lat = '35:05.8' lowell.elevation = 2198 lowell.date = '1986/3/13' j = ephem.Jupiter() j.compute(lowell) print('%s %s' % (j.alt, j.az)) ## Attributes can be set: ## date — Date and time ## epoch — Epoch for astrometric RA/dec ## lat — Latitude (+N) ## lon — Longitude (+E) ## elevation — Elevation (m) ## temp — Temperature (°C) ## pressure — Atmospheric pressure (mBar) ## ## The date defaults to now(). ## The epoch defaults to '2000'. ## The temp defaults to 25°C. ## The pressure defaults to 1010mBar. ## Other attributes default to zero.
0:57:44.7 256:41:01.3
############## 内置的城市位置数据 city = city('Beijing') print('%s %s' % (city.lat, city.lon)) ############# 天体的升降和中天 sitka = Observer() sitka.date = '1999/6/27' sitka.lat = '57:10' sitka.lon = '-135:15'm = Mars() print(sitka.next_transit(m)) print('%s %s' % (m.alt, m.az)) print(sitka.next_rising(m, start='1999/6/28')) print('%s %s' % (m.alt, m.az)) #### 给定观测者之后, 每个天体可以使用方法 (人造卫星除外) ### previous_transit() ### next_transit() ### previous_antitransit() ### next_antitransit() ### previous_rising() ### next_rising() ### previous_setting() ### next_setting()
39:54:15.2 116:24:26.7 1999/6/27 04:22:45 21:18:33.6 180:00:00.0 1999/6/28 23:28:25 -0:00:05.8 111:10:41.6
##### 某年某月某日, 某地, 计算人造卫星掠过的时刻 line1 = "IRIDIUM 80 [+]" line2 = "1 25469U 98051C 09119.61415140 -.00000218 00000-0 -84793-4 0 4781" line3 = "2 25469 86.4029 183.4052 0002522 86.7221 273.4294 14.34215064557061" iridium_80 = ephem.readtle(line1, line2, line3) city.date = '2009/5/1' info = city.next_pass(iridium_80) print("Rise time: %s azimuth: %s" % (info[0], info[1])) #### 返回值的时刻#### 0 Rise time#### 1 Rise azimuth#### 2 Transit time#### 3 Transit altitude#### 4 Set time#### 5 Set azimuth ##############################################
Rise time: 2009/5/1 00:45:05 azimuth: 6:13:37.5
sun = Sun() greenwich = Observer() greenwich.lat = '51:28:38' print(greenwich.horizon) greenwich.date = '2007/10/1' r1 = greenwich.next_rising(sun) greenwich.pressure = 0 greenwich.horizon = '-0:34' greenwich.date = '2007/10/1' r2 = greenwich.next_rising(sun) print('Visual sunrise: %s' % r1) print('Naval Observatory sunrise: %s' % r2)
0:00:00.0 Visual sunrise: 2007/10/1 05:59:30 Naval Observatory sunrise: 2007/10/1 05:59:50
madrid = ephem.city('Madrid') madrid.date = '1978/10/3 11:32' print(madrid.sidereal_time())
12:04:28.09 2000/3/20 07:35:17 2000/6/21 01:47:51 Spring lasted 92.8 days
d1 = ephem.next_equinox('2000') print(d1) d2 = ephem.next_solstice(d1) print(d2) t = d2 - d1 print("Spring lasted %.1f days" % t) #### 相应的方法 #### previous_solstice() #### next_solstice() ######## previous_equinox() #### next_equinox() ######## previous_vernal_equinox() #### next_vernal_equinox()
d1 = ephem.next_full_moon('1984') print(d1) d2 = ephem.next_new_moon(d1) print(d2) ### 朔 ### previous_new_moon() ### next_new_moon() ### 上弦月 ### previous_first_quarter_moon() ### next_first_quarter_moon() ### 望 ### previous_full_moon() ### next_full_moon() ### 下弦月 ### previous_last_quarter_moon() ### next_last_quarter_moon()
1984/1/18 14:05:10 1984/2/1 23:46:25
a = ephem.degrees('180:00:00') print(a) a print("180° is %f radians" % a) h = ephem.hours('1:00:00') deg = ephem.degrees(h) print("1h right ascension = %s°" % deg) ## 时间和角度输入 ephem.degrees(ephem.pi / 32) ephem.degrees('5.625') ephem.degrees('5:37.5') ephem.degrees('5:37:30') ephem.degrees('5:37:30.0') ephem.hours('0.375') ephem.hours('0:22.5') ephem.hours('0:22:30') ephem.hours('0:22:30.0')
180:00:00.0 180° is 3.141593 radians 1h right ascension = 15:00:00.0°
#### 日期时间的输入d = ephem.Date('1997/3/9 5:13') print(d) d d.triple() d.tuple() d + ephem.hour print(ephem.date(d + ephem.hour)) print(ephem.date(d + 1)) ### 输入日期的格式ephem.Date(35497.7197916667) ephem.Date('1997/3/10.2197916667') ephem.Date('1997/3/10 05.275') ephem.Date('1997/3/10 05:16.5') ephem.Date('1997/3/10 05:16:30') ephem.Date('1997/3/10 05:16:30.0') ephem.Date((1997, 3, 10.2197916667)) ephem.Date((1997, 3, 10, 5, 16, 30.0))
1997/3/9 05:13:00 1997/3/9 06:13:00 1997/3/10 05:13:00 35497.71979166667
rigel = ephem.star('Rigel') print('%s %s' % (rigel._ra, rigel._dec))
5:14:32.30 -8:12:06.0
stuttgart = ephem.city('Stuttgart') print(stuttgart) print(stuttgart.lon)
<ephem.Observer date='2018/8/27 05:17:01' epoch='2000/1/1 12:00:00' lon='9:10:50.8' lat='48:46:37.6' elevation=249.205185m horizon=0:00:00.0 temp=15.0C pressure=983.6685758505818mBar> 9:10:50.8
#### PyEphem provides constants for the dates of a few major star-atlas epochs: #### 不同历元# B1900# B1950# J2000 ### PyEphem provides, for reference, the length of four distances, all in meters: ### 天文常量print(ephem.meters_per_au) print(ephem.earth_radius) print(ephem.moon_radius) print(ephem.sun_radius) #### PyEphem provides the speed of light in meters per second: ## 光速 m/sprint(ephem.c)
149597870000.0 6378160.0 1740000.0 695000000.0 299792458.0
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-22 18:15
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社