WARNING: FITSFixedWarning: The WCS transformation has more axes (3) than the image it is associated with (2) [astropy.wcs.wcs]

Pythonでfitsファイルを保存しようとしたときに出たエラー。

2次元のファイル(COの積分強度図でNAXIS=2)なのに
Headerの中に速度方向の軸(3軸目)の情報が入っていたのが原因らしい。

Headerの名前をco_headerとしていたので、

from astropy.io import fits  #fitsファイルをいじるためのモジュール

co=fits.open("co_mom0.fits")  #fitsファイルを読み込んで
co_image=co[0].data  #データと
co_header=co[0].header  #ヘッダーに分けて

co_header.remove("CTYPE3",ignore_missing=True)  #ヘッダーのCTYPE3を消す
co_header.remove("CRVAL3",ignore_missing=True)  #無かったら無視する
co_header.remove("CRPIX3",ignore_missing=True)
co_header.remove("CDELT3",ignore_missing=True)
#ignore_missing=True で 無かったら無視する

ってしたらうまく保存できました。

コメント

このブログの人気の投稿

TypeError: ufunc 'bitwise_xor' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

overleafで画像が表示されない!

エラー: ""C:\U" で始まる文字列の中で 8 進文字なしに '\U' が使われています