Communitygithub.com

ASoudy/AGS

Astropy 是天文學領域的核心 Python 套件,為天文研究與資料分析提供基本功能。

AGS 是什麼?

這項技能提供 Astropy 的完整支援,Astropy 是天文學領域的核心 Python 套件,專為天文研究與資料分析設計。它涵蓋多項關鍵功能,包括天體座標系統之間的轉換(如 ICRS、銀道座標、FK5、地平座標等)、物理單位與數量的處理(例如將 Jy 轉換為 mJy、秒差距轉換為公里)、FITS 檔案的讀寫與操作、宇宙學計算(如光度距離、回溯時間、哈伯參數)、精確的時間處理(支援 UTC、TAI、TT、TDB 等多種時間尺度與 JD、MJD、ISO 等格式)、表格資料操作(讀取星表、交叉比對、篩選、合併)、世界座標系統(WCS)的像素與世界座標轉換,以及天文常數與相關計算。這項技能適用於 Claude Code、Codex 等 AI 代理平台,能協助開發者與天文學家有效率地執行數據分析任務。其運作方式基於 Astropy 的官方文件與最佳實務,提供快速入門範例、核心功能說明、常見工作流程(如座標轉換、FITS 檔案分析、宇宙學距離計算、星表交叉比對),以及詳細的參考文件索引。使用時應注意僅在任務明確符合上述範圍時啟用,並避免將其輸出作為環境特定驗證、測試或專家審查的替代方案。

相容平台~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、銀道座標、FK5、地平座標等)
  • 處理物理單位與數量(例如將 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、地平座標等)中建立座標
  • 在座標系統之間進行轉換
  • 計算角距離與位置角
  • 將座標與星表進行匹配
  • 包含距離以進行 3D 座標運算
  • 處理自行與徑向速度
  • 從線上資料庫查詢命名天體

參見: references/coordinates.md 取得詳細的座標框架描述、轉換、觀測者相關框架(地平座標)、星表匹配與效能提示。

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)

精確的時間表示,以及時間尺度與格式之間的轉換。

主要操作:

  • 以多種格式(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}, 中位數: {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.

相關技能