Communitygithub.com

AbobakrDiara61/railway-system

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

railway-system 是什么?

Astropy 是 Python 天文学领域的核心库,为天文研究和数据分析提供了全面的基础功能。该技能涵盖了坐标转换、物理单位与量值计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据处理以及天文图像处理等关键领域。它支持多种天文坐标系统(如 ICRS、Galactic、FK5、AltAz)之间的转换,能够处理物理单位换算(如 Jy 到 mJy、秒差距到千米),并允许读写 FITS 文件。宇宙学计算功能包括本动距离、回看时间和哈勃参数的计算。此外,Astropy 还提供了精确的时间处理(支持 UTC、TAI、TT、TDB 等时标和 JD、MJD、ISO 等格式)、世界坐标系统(WCS)的像素与世界坐标转换,以及表格数据的交叉匹配、过滤和连接。该技能适用于任何需要标准天文工具的开发环境,例如 Claude Code、Cursor 或 Codex,并能够有效处理从图像分析到目录操作的各种天文任务。最佳实践包括始终使用单位、使用上下文管理器处理 FITS 文件、优先使用数组处理多个坐标或时间点、以及明确指定时间尺度。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AbobakrDiara61/railway-system/tree/HEAD/frontend/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 等)中创建坐标
  • 在坐标系统之间进行转换
  • 计算角分离和位置角
  • 将坐标匹配到星表
  • 包含距离以进行 3D 坐标操作
  • 处理自行和径向速度
  • 从在线数据库查询命名对象

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

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

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

关键操作:

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

参见: 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)

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

关键操作:

  • 以各种格式创建 Time 对象(ISO、JD、MJD、Unix 等)
  • 在不同时间尺度之间进行转换(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 信息的 n 维数据集的容器。

建模

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

可视化

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

常数

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

卷积

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

统计学

包括 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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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 悬停效果

AbobakrDiara61/railway-system

Best practices for Remotion - Video creation in React

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

Automate TikTok tasks via Rube MCP (Composio): upload/publish videos, post photos, manage content, and view user profiles/stats. Always search tools first for current schemas.

AbobakrDiara61/railway-system

Video and audio perception, indexing, and editing. Ingest files/URLs/live streams, build visual/spoken indexes, search with timestamps, edit timelines, add overlays/subtitles, generate media, and create real-time alerts.

AbobakrDiara61/railway-system

Upload, stream, search, edit, transcribe, and generate AI video and audio using the VideoDB SDK.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

Automate YouTube tasks via Rube MCP (Composio): upload videos, manage playlists, search content, get analytics, and handle comments. Always search tools first for current schemas.

AbobakrDiara61/railway-system

Extract transcripts from YouTube videos and generate comprehensive, detailed summaries using intelligent analysis frameworks

相关技能