Communitygithub.com

Anhvu1107/all-agent-skill

始终在请求涉及 Astropy 时使用此技能:Astropy 是天文学领域的核心 Python 包,为天文研究和数据分析提供基本功能。

all-agent-skill 是什么?

该技能专为 AI 代理(如 Claude Code 或 Cursor)设计,在处理与天文学相关的任务时自动加载 Astropy 相关的文档和最佳实践。它适用于一切涉及天体坐标转换、单位与物理量计算、FITS 文件操作、宇宙学计算、精确时间处理、表格数据操作、WCS 变换以及天文图像处理的工作。技能内置了选择性读取规则,仅在任务匹配时加载必要的参考文件(如单位、坐标、宇宙学、FITS、表格、时间、WCS 等),避免不必要的上下文膨胀。通过提供快速入门示例、核心功能概览和常见工作流程(如坐标系统间转换、FITS 文件分析、宇宙学距离计算、星表交叉匹配),该技能帮助代理高效地编写正确的天文分析代码,并遵循始终使用单位、使用上下文管理器管理 FITS 文件、验证坐标框架等最佳实践。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/astropy

在你喜欢的 AI 中提问

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

文档

Astropy(Astropy 天文学核心包)

选择性读取规则

开始时:

  • references/senior-master-standard.md
  • references/usage-routing.md
  • references/quality-checklist.md

然后仅加载与用户实际任务匹配的继承文档、脚本、资源或示例。

概述

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

何时使用此技能

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

  • 在天体坐标系之间转换(ICRS、银河系、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、银河系、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 信息的 N 维数据集容器。

建模

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

可视化

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

常数

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

卷积

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

统计量

稳健的统计函数,包括西格玛修剪和离群值剔除。

安装

# 安装 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}, 中位数: {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.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches 007: Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Agentfolio: Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Animejs Animation: Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astro: Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Emotional ARC Designer: One sentence - what this skill does and when to invoke it

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Fixing Motion Performance: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches I18n Localization: Internationalization and localization patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Interactive Portfolio: Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches JQ: Expert jq usage for JSON querying, filtering, transformation, and pipeline integration.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Landing Page Generator: Generates high-converting Next.js/React landing pages with Tailwind CSS.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches LEX: Centralized ''Truth Engine'' for cross-jurisdictional legal context (US, EU, CA) and contract scaffolding.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Magic Animator: AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Makepad Animation: CRITICAL: Use for Makepad animation system.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs APP Router Patterns: Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Anhvu1107/all-agent-skill

ALWAYS use this when the user mentions Nextjs Best Practices, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on Nextjs Best Practices; scope: Next.js App Router principles. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output.

Anhvu1107/all-agent-skill

description: ALWAYS use this when the work is specifically about modern Next.js or React architecture, data flow, rendering strategy, routing, or performance-sensitive frontend behavior.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs Supabase Auth: Expert integration of Supabase Auth with Next.js App Router

Anhvu1107/all-agent-skill

ALWAYS use this when the task involves reading, extracting, splitting, merging, rotating, creating, validating, OCR-ing, form-filling, or otherwise producing or modifying PDF files.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches React Nextjs Development: React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when working with Remotion code, video compositions, rendering logic, timing, media assets, or React-based motion workflows.

相关技能