1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Astropyで3次元FITSのWCSを扱う際のSIPエラーと対処法

Last updated at Posted at 2025-12-02

はじめに

Astropy で WCS を使って FITS の座標変換をしようとしたときに、以下のエラーが出ることがあります:

ValueError: 
FITS WCS distortion paper lookup tables and SIP distortions only work
in 2 dimensions.  However, WCSLIB has detected 3 dimensions in the
core WCS keywords.  To use core WCS in conjunction with FITS WCS
distortion paper lookup tables or SIP distortion, you must select or
reduce these to 2 dimensions using the naxis kwarg.

この原因と対処を簡潔にまとめます。

原因

このエラーは、FITS が 3 次元構造を持つ場合に発生します。

例としては次のようなものがあります:

  • RGB 画像(3チャネル)
  • 複数フレームを含む画像(multi-extension, multi-frame)
  • 波長方向を持つ cube FITS(分光データなど)

Astropy は FITS の軸を
(x, y, channel) のような 3軸として認識します。

しかし、SIP distortion や WCS の distortion は (x, y) の2次元のみ対応であるため、3軸検出によってエラーになります。

対処法

from astropy.io import fits
from astropy.wcs import WCS

# FITS を開く
hdul = fits.open("image.fits")
header = hdul[0].header

# WCS を 2次元として読み込む ← ここがポイント
w = WCS(header, naxis=2)

重要なのは naxis=2 を指定することです。
これにより WCS を「2次元として強制的に扱う」ことになり、エラーが解消します。
これは画像データは3Dでも、WCSとしてはXY座標のみを使うという指定になります。

まとめ

  • このエラーは 3次元 FITS(RGB / cube / マルチフレーム) で起きる
  • WCS が3軸を認識することが原因
  • naxis=2 を指定し、XYの2次元としてWCSを読み込めば解決
  • FITSは3DでもWCSは2Dで扱える

同じエラーで悩んでいる方は、まず naxis=2 を試してみてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?