LoginSignup
0
2

More than 5 years have passed since last update.

astropy や pyfits の writeto 関数でfitsの行列データが書き出せないバグのチェック方法

Last updated at Posted at 2019-01-17

astropy/pyfits のバグチェックの方法

fitsファイルが行列データを含む場合、astropy/pyfitsのwriteto関数では書き出せないバグが存在する。bug は fix されているので新しいバージョンを使えば解決できる。古いバージョンを使っていて bug に出会った人はご一読ください。

対処方法

pyfits の bug が含まれるバージョン

  • pyfits 2.2.2 バグなし
  • pyfits 2.3.1 バグあり
  • pyfits 2.4.0 以降は bug が fix されている

pyfits は version 2.4.0 以降を使えば良い。

astropy の bug が含まれるバージョン

  • astropy 1.1.2 バグあり
  • astropy 2.0.11 バグなし

astropy は version 2.0.11 以降を使えばよい(はず)。

確認方法

中身の説明

「すざく」衛星の姿勢ファイルを開いて、オイラー角度を[0,0,0]に変更して保存し、その通りに変更されたかを確認するだけのもの。

必要なスクリプトとファイル
- ae905005010_short.att
- check_att.py

check_att.py
import numpy as np
import astropy
from astropy.io import fits

print "astropy version = ", astropy.__version__
print "open ae905005010_short.att"
f1 = fits.open("ae905005010_short.att")
print f1[1].data.field("EULER")[0]
f1[1].data.field("EULER")[0] = [0,0,0]
print f1[1].data.field("EULER")[0]

print "write attgen1.fits"
f1.writeto("attgen1.fits",clobber=True)

print "open attgen1.fits"
g1 = fits.open("attgen1.fits")
print g1[1].data.field("EULER")[0]

ダメな例

> python check_att.py
astropy version =  1.1.2
open ae905005010_short.att
[ 262.67212651  111.49207819  177.54302463]
[ 0.  0.  0.]
write attgen1.fits
open attgen1.fits
[ 262.67212651  111.49207819  177.54302463] <== 変更箇所が反映されてない。

成功例

>python check_att.py
astropy version =  2.0.11
open ae905005010_short.att
[ 262.67212651  111.49207819  177.54302463]
[ 0.  0.  0.]
write attgen1.fits
open attgen1.fits
[ 0.  0.  0.] <== 正しく変更箇所が保存されている

最後に

2011年にpyfitsのこのバグで結構ハマった。2019年になって、同じバグで astropy でハマった。fitsのライブラリは枯れてると思いがちだが気をつけよう。。

0
2
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
0
2