重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
astropy by k-dense-ai/claude-scientific-skills
npx skills add https://github.com/k-dense-ai/claude-scientific-skills --skill astropyAstropy 是天文学领域的核心 Python 包,为天文研究和数据分析提供基本功能。使用 astropy 进行坐标转换、单位和量值计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据操作以及天文图像处理。
当任务涉及以下内容时,请使用 astropy:
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)
astropy.units)广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
处理带单位的物理量,执行单位转换,并确保计算中的量纲一致性。
关键操作:
.to() 方法在单位之间转换参见: references/units.md 获取完整的文档、单位系统、等效关系、性能优化和单位算术运算。
astropy.coordinates)表示天体位置并在不同坐标框架之间转换。
关键操作:
SkyCoord 创建坐标参见: references/coordinates.md 获取详细的坐标框架描述、转换、观测者相关框架(AltAz)、星表匹配和性能提示。
astropy.cosmology)使用标准宇宙学模型执行宇宙学计算。
关键操作:
参见: references/cosmology.md 获取可用模型、距离计算、时间计算、密度参数和中微子效应。
astropy.io.fits)读取、写入和操作 FITS(灵活图像传输系统)文件。
关键操作:
参见: references/fits.md 获取全面的文件操作、头信息操作、图像和表格处理、多扩展文件以及性能考虑。
astropy.table)处理表格数据,支持单位、元数据和各种文件格式。
关键操作:
参见: references/tables.md 获取表格创建、I/O 操作、数据操作、排序、筛选、连接、分组和性能提示。
astropy.time)精确的时间表示以及在时间尺度和格式之间的转换。
关键操作:
参见: references/time.md 获取时间格式、时间尺度、转换、算术运算、观测特性以及精度处理。
astropy.wcs)在图像中的像素坐标与世界坐标之间转换。
关键操作:
参见: references/wcs_and_other_modules.md 获取 WCS 操作和转换。
references/wcs_and_other_modules.md 文件还涵盖:
用于 n 维数据集的容器,包含元数据、不确定性、掩码和 WCS 信息。
为天文数据创建和拟合数学模型的框架。
用于天文图像显示的工具,具有适当的拉伸和缩放功能。
具有适当单位的物理和天文常数(光速、太阳质量、普朗克常数等)。
用于平滑和滤波的图像处理核。
稳健的统计函数,包括 sigma 裁剪和异常值剔除。
# 安装 astropy
uv pip install astropy
# 安装完整功能所需的可选依赖项
uv pip install astropy[all]
from astropy.coordinates import SkyCoord
import astropy.units as u
# 创建坐标
c = SkyCoord(ra='05h23m34.5s', dec='-69d45m22s', frame='icrs')
# 转换为银道坐标
c_gal = c.galactic
print(f"l={c_gal.l.deg}, b={c_gal.b.deg}")
# 转换为地平坐标(需要时间和位置)
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz
observing_time = Time('2023-06-15 23:00:00')
observing_location = EarthLocation(lat=40*u.deg, lon=-120*u.deg)
aa_frame = AltAz(obstime=observing_time, location=observing_location)
c_altaz = c.transform_to(aa_frame)
print(f"Alt={c_altaz.alt.deg}, Az={c_altaz.az.deg}")
from astropy.io import fits
import numpy as np
# 打开 FITS 文件
with fits.open('observation.fits') as hdul:
# 显示结构
hdul.info()
# 获取图像数据和头信息
data = hdul[1].data
header = hdul[1].header
# 访问头信息值
exptime = header['EXPTIME']
filter_name = header['FILTER']
# 分析数据
mean = np.mean(data)
median = np.median(data)
print(f"Mean: {mean}, Median: {median}")
from astropy.cosmology import Planck18
import astropy.units as u
import numpy as np
# 计算 z=1.5 处的距离
z = 1.5
d_L = Planck18.luminosity_distance(z)
d_A = Planck18.angular_diameter_distance(z)
print(f"Luminosity distance: {d_L}")
print(f"Angular diameter distance: {d_A}")
# 该红移处的宇宙年龄
age = Planck18.age(z)
print(f"Age at z={z}: {age.to(u.Gyr)}")
# 回溯时间
t_lookback = Planck18.lookback_time(z)
print(f"Lookback time: {t_lookback.to(u.Gyr)}")
from astropy.table import Table
from astropy.coordinates import SkyCoord, match_coordinates_sky
import astropy.units as u
# 读取星表
cat1 = Table.read('catalog1.fits')
cat2 = Table.read('catalog2.fits')
# 创建坐标对象
coords1 = SkyCoord(ra=cat1['RA']*u.degree, dec=cat1['DEC']*u.degree)
coords2 = SkyCoord(ra=cat2['RA']*u.degree, dec=cat2['DEC']*u.degree)
# 查找匹配项
idx, sep, _ = coords1.match_to_catalog_sky(coords2)
# 按分离阈值筛选
max_sep = 1 * u.arcsec
matches = sep < max_sep
# 创建匹配的星表
cat1_matched = cat1[matches]
cat2_matched = cat2[idx[matches]]
print(f"Found {len(cat1_matched)} matches")
有关特定模块的详细信息:
references/units.md - 单位、量值、转换和等效关系references/coordinates.md - 坐标系、转换和星表匹配references/cosmology.md - 宇宙学模型和计算references/fits.md - FITS 文件操作和处理references/tables.md - 表格创建、I/O 和操作references/time.md - 时间格式、尺度和计算references/wcs_and_other_modules.md - WCS、NDData、建模、可视化、常数和实用工具每周安装次数
54
代码仓库
GitHub 星标数
17.3K
首次出现
2026年1月20日
安全审计
安装于
opencode47
codex46
gemini-cli45
claude-code43
cursor43
github-copilot42
Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis. Use astropy for coordinate transformations, unit and quantity calculations, FITS file operations, cosmological calculations, precise time handling, tabular data manipulation, and astronomical image processing.
Use astropy when tasks involve:
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
# Units and quantities
distance = 100 * u.pc
distance_km = distance.to(u.km)
# Coordinates
coord = SkyCoord(ra=10.5*u.degree, dec=41.2*u.degree, frame='icrs')
coord_galactic = coord.galactic
# Time
t = Time('2023-01-15 12:30:00')
jd = t.jd # Julian Date
# FITS files
data = fits.getdata('image.fits')
header = fits.getheader('image.fits')
# Tables
table = Table.read('catalog.fits')
# Cosmology
d_L = Planck18.luminosity_distance(z=1.0)
astropy.units)Handle physical quantities with units, perform unit conversions, and ensure dimensional consistency in calculations.
Key operations:
.to() methodSee: references/units.md for comprehensive documentation, unit systems, equivalencies, performance optimization, and unit arithmetic.
astropy.coordinates)Represent celestial positions and transform between different coordinate frames.
Key operations:
SkyCoord in any frame (ICRS, Galactic, FK5, AltAz, etc.)See: references/coordinates.md for detailed coordinate frame descriptions, transformations, observer-dependent frames (AltAz), catalog matching, and performance tips.
astropy.cosmology)Perform cosmological calculations using standard cosmological models.
Key operations:
See: references/cosmology.md for available models, distance calculations, time calculations, density parameters, and neutrino effects.
astropy.io.fits)Read, write, and manipulate FITS (Flexible Image Transport System) files.
Key operations:
See: references/fits.md for comprehensive file operations, header manipulation, image and table handling, multi-extension files, and performance considerations.
astropy.table)Work with tabular data with support for units, metadata, and various file formats.
Key operations:
See: references/tables.md for table creation, I/O operations, data manipulation, sorting, filtering, joins, grouping, and performance tips.
astropy.time)Precise time representation and conversion between time scales and formats.
Key operations:
See: references/time.md for time formats, time scales, conversions, arithmetic, observing features, and precision handling.
astropy.wcs)Transform between pixel coordinates in images and world coordinates.
Key operations:
See: references/wcs_and_other_modules.md for WCS operations and transformations.
The references/wcs_and_other_modules.md file also covers:
Containers for n-dimensional datasets with metadata, uncertainty, masking, and WCS information.
Framework for creating and fitting mathematical models to astronomical data.
Tools for astronomical image display with appropriate stretching and scaling.
Physical and astronomical constants with proper units (speed of light, solar mass, Planck constant, etc.).
Image processing kernels for smoothing and filtering.
Robust statistical functions including sigma clipping and outlier rejection.
# Install astropy
uv pip install astropy
# With optional dependencies for full functionality
uv pip install astropy[all]
from astropy.coordinates import SkyCoord
import astropy.units as u
# Create coordinate
c = SkyCoord(ra='05h23m34.5s', dec='-69d45m22s', frame='icrs')
# Transform to galactic
c_gal = c.galactic
print(f"l={c_gal.l.deg}, b={c_gal.b.deg}")
# Transform to alt-az (requires time and location)
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz
observing_time = Time('2023-06-15 23:00:00')
observing_location = EarthLocation(lat=40*u.deg, lon=-120*u.deg)
aa_frame = AltAz(obstime=observing_time, location=observing_location)
c_altaz = c.transform_to(aa_frame)
print(f"Alt={c_altaz.alt.deg}, Az={c_altaz.az.deg}")
from astropy.io import fits
import numpy as np
# Open FITS file
with fits.open('observation.fits') as hdul:
# Display structure
hdul.info()
# Get image data and header
data = hdul[1].data
header = hdul[1].header
# Access header values
exptime = header['EXPTIME']
filter_name = header['FILTER']
# Analyze data
mean = np.mean(data)
median = np.median(data)
print(f"Mean: {mean}, Median: {median}")
from astropy.cosmology import Planck18
import astropy.units as u
import numpy as np
# Calculate distances at z=1.5
z = 1.5
d_L = Planck18.luminosity_distance(z)
d_A = Planck18.angular_diameter_distance(z)
print(f"Luminosity distance: {d_L}")
print(f"Angular diameter distance: {d_A}")
# Age of universe at that redshift
age = Planck18.age(z)
print(f"Age at z={z}: {age.to(u.Gyr)}")
# Lookback time
t_lookback = Planck18.lookback_time(z)
print(f"Lookback time: {t_lookback.to(u.Gyr)}")
from astropy.table import Table
from astropy.coordinates import SkyCoord, match_coordinates_sky
import astropy.units as u
# Read catalogs
cat1 = Table.read('catalog1.fits')
cat2 = Table.read('catalog2.fits')
# Create coordinate objects
coords1 = SkyCoord(ra=cat1['RA']*u.degree, dec=cat1['DEC']*u.degree)
coords2 = SkyCoord(ra=cat2['RA']*u.degree, dec=cat2['DEC']*u.degree)
# Find matches
idx, sep, _ = coords1.match_to_catalog_sky(coords2)
# Filter by separation threshold
max_sep = 1 * u.arcsec
matches = sep < max_sep
# Create matched catalogs
cat1_matched = cat1[matches]
cat2_matched = cat2[idx[matches]]
print(f"Found {len(cat1_matched)} matches")
For detailed information on specific modules:
references/units.md - Units, quantities, conversions, and equivalenciesreferences/coordinates.md - Coordinate systems, transformations, and catalog matchingreferences/cosmology.md - Cosmological models and calculationsreferences/fits.md - FITS file operations and manipulationreferences/tables.md - Table creation, I/O, and operationsreferences/time.md - Time formats, scales, and calculationsreferences/wcs_and_other_modules.md - WCS, NDData, modeling, visualization, constants, and utilitiesWeekly Installs
54
Repository
GitHub Stars
17.3K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode47
codex46
gemini-cli45
claude-code43
cursor43
github-copilot42
Apify Actor 输出模式生成工具 - 自动化创建 dataset_schema.json 与 output_schema.json
1,600 周安装