我想用PyFITS在FITS文件中編寫一個布爾結構數組。 我有一些問題。這是一個簡單的例子。用PyFITS編寫布爾結構數組
我創建測試字典並將其轉換爲結構化數組。
In [241]: test = {'p':np.array([True]*10+[False]*10,dtype='b')}
In [242]: test = np.core.records.fromarrays(list(test.values()), names=list(test.keys()))
這是測試結構陣列我想在一個.fit要打印的文件。
In [243]: test
Out[243]:
rec.array([(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (0,),
(0,), (0,), (0,), (0,), (0,), (0,), (0,), (0,), (0,)],
dtype=[('p', 'i1')])
我使用pyfits
In [244]: pyfits.writeto('./test.fit',test,clobber=True)
In [245]: d = pyfits.open('./test.fit')
In [246]: d = d[1].data
但是打印測試在一個合適的文件,所有參賽作品現在設置爲False值,具體如下:
In [247]: d
Out[247]:
FITS_rec([(False), (False), (False), (False), (False), (False), (False),
(False), (False), (False), (False), (False), (False), (False),
(False), (False), (False), (False), (False), (False)],
dtype=[('p', 'i1')])
而且,似乎原始測試數組也可以通過pyfits進行修改。
In [248]: prova
Out[248]:
rec.array([(70,), (70,), (70,), (70,), (70,), (70,), (70,), (70,), (70,),
(70,), (70,), (70,), (70,), (70,), (70,), (70,), (70,), (70,),
(70,), (70,)],
dtype=[('p', 'i1')])
你能幫我解決這個問題嗎?非常感謝你!