[ PROMPT_NODE_26220 ]
astropy
[ SKILL_DOCUMENTATION ]
# Astropy
## 概述
Astropy 是天文学的核心 Python 包,为天文研究和数据分析提供了必要的功能。使用 Astropy 进行坐标转换、单位和量值计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据操作以及天文图像处理。
## 何时使用此技能
当任务涉及以下内容时使用 Astropy:
- 在天球坐标系之间进行转换(ICRS、Galactic、FK5、AltAz 等)
- 处理物理单位和量值(将 Jy 转换为 mJy,秒差距转换为 km 等)
- 读取、写入或操作 FITS 文件(图像或表格)
- 宇宙学计算(光度距离、回溯时间、哈勃参数)
- 使用不同时间尺度(UTC、TAI、TT、TDB)和格式(JD、MJD、ISO)进行精确时间处理
- 表格操作(读取目录、交叉匹配、过滤、连接)
- 像素坐标与世界坐标之间的 WCS 转换
- 天文常数和计算
## 快速入门
python
import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.io import fits
from astropy.table import Table
from astropy.cosmology import Planck18
# 单位和量值
distance = 100 * u.pc
distance_km = distance.to(u.km)
# 坐标
coord = SkyCoord(ra=10.5*u.degree, dec=41.2*u.degree, frame='icrs')
coord_galactic = coord.galactic
# 时间
t = Time('2023-01-15 12:30:00')
jd = t.jd # 儒略日
# FITS 文件
data = fits.getdata('image.fits')
header = fits.getheader('image.fits')
# 表格
table = Table.read('catalog.fits')
# 宇宙学
d_L = Planck18.luminosity_distance(z=1.0)
## 核心能力
### 1. 单位和量值 (`astropy.units`)
处理带有单位的物理量,执行单位转换,并确保计算中的维度一致性。
**关键操作:**
- 通过将数值与单位相乘来创建量值
- 使用 `.to()` 方法在单位之间进行转换
- 执行带有自动单位处理的算术运算
- 使用等价性进行特定领域的转换(光谱、多普勒、视差)
- 处理对数单位(星等、分贝)
**参见:** `references/units.md` 获取全面的文档、单位系统、等价性、性能优化和单位算术。
### 2. 坐标系 (`astropy.coordinates`)
表示天体位置并在不同的坐标系之间进行转换。
**关键操作:**
- 创建坐标