在皮耶芬查行星或月亮的名字?

2024-05-23 19:02:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在写一个小的pyephem程序,用户输入一个行星或月亮的名字,然后这个程序对它做一些计算。我找不到如何通过名字来查找行星或月亮,就像你用星星一样(以弗所星('Arcturus')),所以我的程序目前有一个行星和月亮名称的查找表。皮耶芬能做到吗?如果没有,是否值得补充?在


Tags: 用户程序名称行星名字pyephem月亮arcturus
3条回答

您可以找到教程here。在

例如:

>>> import ephem
>>> u = ephem.Uranus()
>>> u.compute('1781/3/13')
>>> print u.ra, u.dec, u.mag
5:35:45.28 23:32:54.1 5.6
>>> print ephem.constellation(u)
('Tau', 'Taurus')

我想你可以在那里找到更多的细节。在

import ephem
from ephem import *

## Planet name plus () and return
## just to show what the name must be

buscar = 'Jupiter()' + '\n'
aqui = city('Bogota')
aqui.date = now() - 5/24     ## Substract the time zone hours from UTC


if buscar[-3:-1] == '()':    ## Delete unwanted chars
    astro = buscar[:-3]
    cuerpo = getattr(ephem, astro)() ## YOUR ANSWER

## Body test
cuerpo.compute(aqui)
print(aqui.name, aqui.date)
print(cuerpo.name, cuerpo.az, cuerpo.alt)

一个有趣的问题!确实存在底层_libastro用来告诉ephem本身支持哪些对象的内部方法:

import ephem
from pprint import pprint
pprint(ephem._libastro.builtin_planets())

哪个打印:

^{pr2}$

您只需要这三项中的最后一项,因此可以构建一个名称列表,例如:

>>> pprint([name for _0, _1, name in ephem._libastro.builtin_planets()])

返回:

['Mercury',
 'Venus',
 'Mars',
 'Jupiter',
 'Saturn',
 'Uranus',
 'Neptune',
 'Pluto',
 'Sun',
 'Moon',
 'Phobos',
 'Deimos',
 'Io',
 'Europa',
 'Ganymede',
 'Callisto',
 'Mimas',
 'Enceladus',
 'Tethys',
 'Dione',
 'Rhea',
 'Titan',
 'Hyperion',
 'Iapetus',
 'Ariel',
 'Umbriel',
 'Titania',
 'Oberon',
 'Miranda']

然后,您可以通过一个简单的name调用来获取这些对象中的任何一个。在

相关问题 更多 >