导入 astropy
和子包#
为了鼓励用户在导入和使用Astropy功能时保持一致,我们制定了以下指南。
由于Astropy中的大部分功能都位于子包中,因此 astropy
AS::
>>> import astropy
不是很有用。相反,最好使用以下语法导入所需的子包:
>>> from astropy import subpackage
例如,要访问与配合相关的功能,可以导入 astropy.io.fits
用:
>>> from astropy.io import fits
>>> hdulist = fits.open('data.fits')
在特定情况下,我们在文档中为特定的子包推荐了快捷方式。例如::
>>> from astropy import units as u
>>> from astropy import coordinates as coord
>>> coord.SkyCoord(ra=10.68458*u.deg, dec=41.26917*u.deg, frame='icrs')
<SkyCoord (ICRS): (ra, dec) in deg
( 10.68458, 41.26917)>
最后,在某些情况下,大多数所需功能包含在一个类(或几个类)中。在这种情况下,可以直接导入类:
>>> from astropy.cosmology import WMAP7
>>> from astropy.table import Table
>>> from astropy.wcs import WCS
请注意,为清晰起见,并避免任何问题,我们建议 从未 使用导入任何Astropy功能 *
例如:
>>> from astropy.io.fits import * # NOT recommended
Astropy的一些组件最初是作为独立软件包(例如PyFITS、PyWCS)开始的,因此,在需要将Astropy用作替换程序的情况下,以下语法也是可以接受的:
>>> from astropy.io import fits as pyfits
子包入门#
因为不同的子包有非常不同的功能,所以每个子包都有自己的入门指南。这些可以通过浏览中列出的部分找到 用户指南 .
您还可以查看特定包或对象的docstring,或者使用 find_api_page
功能。例如:::
>>> from astropy import find_api_page
>>> from astropy.units import Quantity
>>> find_api_page(Quantity)
将为 Quantity
在浏览器中初始化。