Communitygithub.com

AbobakrDiara61/railway-system

Astropy 是天文學的核心 Python 套件,提供天文研究與數據分析所需的基本功能。

railway-system 是什麼?

此技能旨在協助開發者與 AI 代理使用 Astropy 套件執行天文數據分析任務。Astropy 是天文學的標準 Python 函式庫,涵蓋座標轉換、單位與量值計算、FITS 檔案操作、宇宙學計算、精確時間處理、表格數據處理及天文影像處理等核心功能。技能詳細說明了何時應使用 Astropy(例如處理天球座標系轉換、單位換算、宇宙學距離計算等),並提供快速入門範例及常見工作流程(如跨系統座標轉換、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(彈性影像傳輸系統)檔案。

主要操作:

  • 使用 context manager 開啟 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"Luminosity distance: {d_L}")
print(f"Angular diameter distance: {d_A}")

# 該紅移下的宇宙年齡
age = Planck18.age(z)
print(f"Age at z={z}: {age.to(u.Gyr)}")

# 回溯時間
t_lookback = Planck18.lookback_time(z)
print(f"Lookback time: {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"Found {len(cat1_matched)} matches")

最佳實踐

  1. 始終使用單位:為量值附加單位以避免錯誤並確保量綱一致性
  2. 對 FITS 檔案使用 context manager:確保檔案正確關閉
  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

相關技能