I would like to write a Boolean structured array with PyFITS in a FITS file. I had some issues. Here is a simple example.
I create the test dictionary and transform it into a structured array.
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()))
Here it is the test structured array I would like to print in a .fit file.
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')])
I print test in a fit file using pyfits
In [244]: pyfits.writeto('./test.fit',test,clobber=True)
In [245]: d = pyfits.open('./test.fit')
In [246]: d = d[1].data
However, all entries are now set to the False value, as follows:
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')])
Furthermore, it seems that the original test array is also somehow modified by 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')])
Could you please help me to solve this issue? Thank you very much!