Communitygithub.com

Astropy(天体物理学Pythonパッケージ)

天体物理研究とデータ解析に不可欠な機能を提供するPythonパッケージ。座標変換、単位計算、FITSファイル操作、宇宙論計算、時刻処理、テーブル操作、画像処理などをサポートします。

Astropy(天体物理学Pythonパッケージ) とは?

Astropyは、天文学研究のためのコアPythonパッケージです。このスキルは、開発者やAIエージェントが天文学的データ分析タスクを効率的に実行できるように設計されています。具体的には、ICRSや銀河座標などの天体座標系間の変換、物理単位と数量の取り扱い、FITSファイルの読み書き、プランク18などの標準宇宙モデルを用いた光度距離やルックバックタイムの計算、UTC/TAI/TT/TDBなどの異なる時間スケール間の変換、カタログのクロスマッチングや結合といったテーブル操作、ピクセル座標と天体座標の変換(WCS)をサポートします。サポートプラットフォームはPython環境全般で、`uv pip install astropy` でインストール可能です。このスキルは、エージェントが天文学的なデータ処理を自動化し、コードを生成する際に、正確で一貫性のある結果を得るために役立ちます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AbobakrDiara61/railway-system/tree/HEAD/frontend/skills/astropy

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Astropy

概要

Astropyは、天文学研究とデータ解析に不可欠な機能を提供する、天文学のためのコアPythonパッケージです。このスキルは、座標変換、単位と数量の計算、FITSファイル操作、宇宙論計算、高精度な時刻処理、表形式データの操作、天文画像処理などに使用します。

このスキルを使うタイミング

Astropyは以下のタスクに使用します:

  • 天体座標系(ICRS、銀河座標、FK5、地平座標など)間の変換
  • 物理単位と数量の操作(JyからmJyへの変換、パーセクからkmへの変換など)
  • 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)

天体の位置を表現し、異なる座標フレーム間で変換します。

主要な操作:

  • 任意のフレーム(ICRS、銀河座標、FK5、地平座標など)で SkyCoord を使用して座標を作成
  • 座標系間の変換
  • 角分離と位置角の計算
  • カタログへの座標マッチング
  • 3D座標操作のための距離を含める
  • 固有運動と視線速度の処理
  • オンラインデータベースからの天体名の問い合わせ

参照: references/coordinates.md に、詳細な座標フレームの説明、変換、観測者依存フレーム(地平座標)、カタログマッチング、およびパフォーマンスのヒントが記載されています。

3. 宇宙論計算(astropy.cosmology)

標準宇宙モデルを使用して宇宙論計算を実行します。

主要な操作:

  • 組み込み宇宙モデル(Planck18、WMAP9など)の使用
  • カスタム宇宙モデルの作成
  • 距離の計算(光度距離、共動距離、角直径距離)
  • 年齢とルックバックタイムの計算
  • 任意の赤方偏移におけるハッブルパラメータの決定
  • 密度パラメータと体積の計算
  • 逆計算(与えられた距離に対する赤方偏移の探索)

参照: references/cosmology.md に、利用可能なモデル、距離計算、時刻計算、密度パラメータ、ニュートリノ効果が記載されています。

4. FITSファイル処理(astropy.io.fits)

FITS(Flexible Image Transport System)ファイルの読み取り、書き込み、操作を行います。

主要な操作:

  • コンテキストマネージャーを使用したFITSファイルのオープン
  • インデックスまたは名前によるHDU(Header Data Unit)へのアクセス
  • ヘッダー(キーワード、コメント、履歴)の読み取りと変更
  • 画像データ(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 次元データセットのためのコンテナ。

Modeling

天文データに数学モデルを作成して適合させるためのフレームワーク。

Visualization

適切なストレッチとスケーリングによる天文画像表示のためのツール。

Constants

適切な単位を持つ物理定数および天文定数(光速、太陽質量、プランク定数など)。

Convolution

平滑化とフィルタリングのための画像処理カーネル。

Statistics

シグマクリッピングや外れ値除去を含むロバスト統計関数。

インストール

# 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ファイルではコンテキストマネージャーを使用する: ファイルが適切に閉じられることを保証します。
  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

関連スキル