Communitygithub.com

Astropy (天文パッケージ)

Astropyは天文学研究のためのコアPythonパッケージで、天体座標変換、単位・物理量計算、FITSファイル操作、宇宙論計算、精密時刻処理、表形式データ操作、天体画像処理などの機能を提供します。

Astropy (天文パッケージ) とは?

このスキルは、天文学研究とデータ解析に特化したPythonパッケージ「Astropy」を活用するための包括的なガイドです。ユーザーは、天体座標系(ICRS、銀河座標、AltAzなど)間の変換、物理単位を含む量の計算(JyからmJy、パーセクからkmなど)、FITSファイルの読み書き・操作、プランク18などの標準宇宙モデルを用いた距離・年齢計算、UTC・TAI・TDBなどの異なる時間スケール間の精密時刻変換、カタログのクロスマッチを含むテーブル操作、WCSを用いたピクセル座標と天体座標の変換などを実行できます。AstropyはPython 3.8以降をサポートし、`uv pip install astropy`で簡単にインストール可能で、Tutorialsや公式ドキュメントも充実しています。コード例では座標変換、FITSファイル解析、宇宙論的距離計算、カタログクロスマッチなどの実践的なワークフローを紹介しており、天文学関連のAIエージェントタスクに直接活用できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/K-Dense-AI/claude-scientific-skills/astropy

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

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

ドキュメント

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

概要

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

このスキルを使用すべき場面

以下のタスクでAstropyを活用してください:

  • 天体座標系(ICRS、銀河座標、FK5、AltAzなど)間の変換
  • 物理単位と物理量の操作(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、AltAzなど)で SkyCoord を使用して座標を作成
  • 座標系間の変換
  • 角度分離と位置角の計算
  • カタログへの座標マッチング
  • 3D座標操作のための距離を含める
  • 固有運動と視線速度の処理
  • オンラインデータベースからの名前付きオブジェクトのクエリ

参照: references/coordinates.md に、詳細な座標フレームの説明、変換、観測者依存フレーム (AltAz)、カタログマッチング、パフォーマンスのヒントがあります。

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

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

主要な操作:

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

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

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

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

主要な操作:

  • コンテキストマネージャを使用してFITSファイルを開く
  • インデックスまたは名前でHDU(ヘッダーデータユニット)にアクセス
  • ヘッダー(キーワード、コメント、履歴)の読み取りと変更
  • 画像データ(NumPy配列)の操作
  • テーブルデータ(バイナリテーブルおよびASCIIテーブル)の処理
  • 新しいFITSファイルの作成(単一拡張または複数拡張)
  • 大規模ファイルのためのメモリマッピングの使用
  • リモートFITSファイル(S3、HTTP)へのアクセス

参照: references/fits.md に、ファイル操作、ヘッダー操作、画像およびテーブル処理、複数拡張ファイル、パフォーマンスに関する包括的なドキュメントがあります。

5. テーブル操作 (astropy.table)

単位、メタデータ、さまざまなファイル形式をサポートする表形式データを扱います。

主要な操作:

  • 配列、リスト、または辞書からテーブルを作成
  • 複数の形式(FITS、CSV、HDF5、VOTable)でテーブルを読み書き
  • 列と行にアクセスして変更
  • テーブルのソート、フィルタリング、インデックス作成
  • データベーススタイルの操作(結合、グループ化、集約)の実行
  • テーブルのスタックと連結
  • 単位認識列(QTable)の操作
  • マスキングによる欠損データの処理

参照: references/tables.md に、テーブル作成、入出力操作、データ操作、ソート、フィルタリング、結合、グループ化、パフォーマンスのヒントがあります。

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情報を含む多次元データセットのためのコンテナ。

モデリング

天文データに数学的モデルを作成しフィッティングするためのフレームワーク。

可視化

適切な引き伸ばしとスケーリングによる天体画像表示のためのツール。

定数

適切な単位付きの物理定数と天文定数(光速度、太陽質量、プランク定数など)。

畳み込み

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

統計

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

インストール

# 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 - テーブルの作成、入出力、操作
  • 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.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

関連スキル