Communitygithub.com

ASoudy/AGS

Astropy 是天文学的核心 Python 包,提供天文研究和数据分析的基本功能。

AGS 是什么?

Astropy 是天文学领域的核心 Python 软件包,为天文研究和数据分析提供全面的功能支持。该技能适用于需要处理天体坐标转换、物理单位与量值计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据操作以及天文图像处理的任务。它支持多种开发环境,包括 Claude Code、Cursor、Codex 等集成 AI 助手的工作流。核心功能涵盖 `astropy.units`(物理单位与量值)、`astropy.coordinates`(坐标系统与变换)、`astropy.cosmology`(宇宙学模型与距离计算)、`astropy.io.fits`(FITS 文件读写与操作)、`astropy.table`(表格数据处理)、`astropy.time`(时间表示与转换)以及 `astropy.wcs`(像素与世界坐标之间的变换)。此外,还包括 NDData 多维数据容器、建模与拟合框架、天文图像可视化、物理与天文常数、图像卷积处理以及稳健统计功能。使用时建议始终配合单位操作、优先使用数组而非循环以提高性能、并注意坐标参考系与时间尺度。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ASoudy/AGS/tree/HEAD/AGAS/plugins/antigravity-awesome-skills-claude/skills/astropy

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Astropy

概述

Astropy 是天文学的核心 Python 包,为天文研究和数据分析提供基本功能。使用 astropy 进行坐标转换、单位和量值计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据处理和天文图像处理。

何时使用此技能

当任务涉及以下内容时使用 astropy:

  • 在天体坐标系之间进行转换(ICRS、Galactic、FK5、AltAz 等)
  • 处理物理单位和量值(将 Jy 转换为 mJy、秒差距转换为公里等)
  • 读取、写入或操作 FITS 文件(图像或表格)
  • 宇宙学计算(光度距离、回溯时间、哈勃参数)
  • 使用不同时间尺度(UTC、TAI、TT、TDB)和格式(JD、MJD、ISO)进行精确时间处理
  • 表格操作(读取星表、交叉匹配、过滤、连接)
  • 像素坐标与世界坐标之间的 WCS 变换
  • 天文常数和计算

快速入门

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)

表示天体位置并在不同坐标框架之间进行转换。

关键操作:

  • 在任意框架(ICRS、Galactic、FK5、AltAz 等)中使用 SkyCoord 创建坐标
  • 在坐标系统之间进行转换
  • 计算角距离和位置角
  • 将坐标匹配到星表
  • 包含距离以进行三维坐标操作
  • 处理自行和径向速度
  • 从在线数据库查询命名天体

参见: references/coordinates.md 获取详细的坐标框架描述、变换、与观测者相关的框架(AltAz)、星表匹配和性能提示。

3. 宇宙学计算(astropy.cosmology)

使用标准宇宙学模型执行宇宙学计算。

关键操作:

  • 使用内置宇宙学模型(Planck18、WMAP9 等)
  • 创建自定义宇宙学模型
  • 计算距离(光度距离、共动距离、角直径距离)
  • 计算宇宙年龄和回溯时间
  • 计算任意红移下的哈勃参数
  • 计算密度参数和体积
  • 执行逆向计算(根据给定距离求红移)

参见: references/cosmology.md 获取可用模型、距离计算、时间计算、密度参数和中微子效应。

4. FITS 文件处理(astropy.io.fits)

读取、写入和操作 FITS(灵活图像传输系统)文件。

关键操作:

  • 使用上下文管理器打开 FITS 文件
  • 按索引或名称访问 HDU(头数据单元)
  • 读取和修改头信息(关键词、注释、历史记录)
  • 处理图像数据(NumPy 数组)
  • 处理表格数据(二进制和 ASCII 表)
  • 创建新的 FITS 文件(单扩展或多扩展)
  • 对大文件使用内存映射
  • 访问远程 FITS 文件(S3、HTTP)

参见: references/fits.md 获取全面的文件操作、头信息修改、图像和表格处理、多扩展文件及性能考虑。

5. 表格操作(astropy.table)

处理表格数据,支持单位、元数据和多种文件格式。

关键操作:

  • 从数组、列表或字典创建表格
  • 以多种格式(FITS、CSV、HDF5、VOTable)读写表格
  • 访问和修改列和行
  • 对表格进行排序、过滤和索引
  • 执行数据库风格操作(连接、分组、聚合)
  • 堆叠和拼接表格
  • 处理带单位的列(QTable)
  • 使用掩码处理缺失数据

参见: references/tables.md 获取表格创建、I/O 操作、数据处理、排序、过滤、连接、分组和性能提示。

6. 时间处理(astropy.time)

精确的时间表示以及时间尺度和格式之间的转换。

关键操作:

  • 以多种格式(ISO、JD、MJD、Unix 等)创建 Time 对象
  • 在不同时间尺度之间转换(UTC、TAI、TT、TDB 等)
  • 使用 TimeDelta 执行时间算术运算
  • 为观测者计算恒星时
  • 计算光行时修正(质心、日心)
  • 高效处理时间数组
  • 处理掩码(缺失)时间

参见: references/time.md 获取时间格式、时间尺度、转换、算术运算、观测功能和精度处理。

7. 世界坐标系统(astropy.wcs)

在图像像素坐标与世界坐标之间进行变换。

关键操作:

  • 从 FITS 头信息读取 WCS
  • 将像素坐标转换为世界坐标(反之亦然)
  • 计算图像覆盖区域
  • 访问 WCS 参数(参考像素、投影、比例)
  • 创建自定义 WCS 对象

参见: references/wcs_and_other_modules.md 获取 WCS 操作和变换方法。

附加功能

references/wcs_and_other_modules.md 文件还涵盖以下内容:

NDData 和 CCDData

多维数据集的容器,支持元数据、不确定性、掩码和 WCS 信息。

建模(Modeling)

用于创建数学模型并拟合天文数据的框架。

可视化(Visualization)

用于天文图像显示的工具,具有适当的拉伸和缩放功能。

常数(Constants)

具有适当单位的物理和天文常数(光速、太阳质量、普朗克常数等)。

卷积(Convolution)

用于平滑和滤波的图像处理核。

统计学(Statistics)

稳健的统计函数,包括 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}")

读取和分析 FITS 文件

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"光度距离: {d_L}")
print(f"角直径距离: {d_A}")

# 在该红移处的宇宙年龄
age = Planck18.age(z)
print(f"z={z}, 年龄: {age.to(u.Gyr)}")

# 回溯时间
t_lookback = Planck18.lookback_time(z)
print(f"回溯时间: {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"找到 {len(cat1_matched)} 个匹配")

最佳实践

  1. 始终使用单位:为量值附加单位,以避免错误并确保量纲一致性
  2. 对 FITS 文件使用上下文管理器:确保文件正确关闭
  3. 优先使用数组而非循环:将多个坐标/时间作为数组处理,以获得更好的性能
  4. 检查坐标框架:在进行变换之前验证框架
  5. 选择合适的宇宙学模型:为分析选择正确的宇宙学模型
  6. 处理缺失数据:对包含缺失值的表格使用掩码列
  7. 指定时间尺度:对于精确计时,明确时间尺度(UTC、TT、TDB)
  8. 使用 QTable 处理带单位的表格:当表列包含单位时
  9. 检查 WCS 有效性:在使用变换之前验证 WCS
  10. 缓存频繁使用的值:可以对耗费时间的计算(例如宇宙学距离)进行缓存

文档和资源

参考文件

有关特定模块的详细信息:

  • 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、建模、可视化、常数和工具

限制

  • 仅当任务明确符合上述范围时使用此技能。
  • 不要将输出视为环境特定验证、测试或专家审查的替代。
  • 如果缺少所需的输入、权限、安全边界或成功标准,请停下来询问澄清。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ASoudy/AGS

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

ASoudy/AGS

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

ASoudy/AGS

One sentence - what this skill does and when to invoke it

ASoudy/AGS

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

ASoudy/AGS

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

ASoudy/AGS

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

ASoudy/AGS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

ASoudy/AGS

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

ASoudy/AGS

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

ASoudy/AGS

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

ASoudy/AGS

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

ASoudy/AGS

Next.js App Router principles. Server Components, data fetching, routing patterns.

ASoudy/AGS

Expert integration of Supabase Auth with Next.js App Router

ASoudy/AGS

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

ASoudy/AGS

Best practices for Remotion - Video creation in React

ASoudy/AGS

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

ASoudy/AGS

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

ASoudy/AGS

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

ASoudy/AGS

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

ASoudy/AGS

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

相关技能