Communitygithub.com

ComeOnOliver/skillshub

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

skillshub 是什么?

Astropy 是一个专为天文学研究设计的核心 Python 库,提供了处理天文数据的完整工具链。该技能涵盖了坐标转换、单位与量值、FITS 文件、宇宙学计算、精确时间、表格操作和 WCS 等核心模块,并提供了详细的参考文档和实用工作流示例。适用于 Claude Code、Cursor、Codex 等 AI 代理平台,帮助开发者快速完成从天体坐标转换到星系目录交叉匹配的复杂任务。其设计强调类型安全(如强制使用 `astropy.units`)和性能优化(如数组操作),并随附了最佳实践指南和官方文档链接,确保用户能高效、准确地开展天文数据分析。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/K-Dense-AI/claude-scientific-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)

表示天体位置并在不同坐标系之间转换。

关键操作:

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

请参阅: 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 信息的多维数据集容器。

建模

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

可视化

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

常数

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

卷积

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

统计

稳健的统计函数,包括 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 - 表格创建、输入/输出和操作
  • 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.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能