[AstroPy] Variable Length Array Tables in PyFits/Numpy
Rudolph van der Merwe
rudolph at ska.ac.za
Wed Jan 10 05:52:32 CST 2007
I'm running into trouble trying to use PyFITS 1.1b3 (built against
Numpy) to create a binary variable length array table (section 6.2.1
in the PyFITS manual).
The manual states that for such a table, the field data (attribute
'array') must be a numarray objects array. If I use the equivalent
Numpy object array, i.e.
numpy.array([a, b], dtype=object)
PyFits aborts with an error. Here is a full listing of my sessions:
In [2]: import numpy as np
In [3]: import pyfits as pf
In [4]: a=np.array([1,2,3], dtype=int)
In [5]: b=np.array([4,5], dtype=int)
In [6]: x=np.array([a,b], dtype=object)
In [7]: c1 = pf.Column(name='var', format='PJ()', array=x)
In [8]: cols = pf.ColDefs([c1])
In [9]: tbHDU = pf.new_table(cols)
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most
recent call last)
/usr/lib/python2.4/site-packages/pyfits/NP_pyfits.py in
new_table(input, header, nrows, fill, tbtype)
3110 elif isinstance(tmp._recformats[i], _FormatP):
3111 # hdu.data._convert[i] =
_makep(tmp._arrays[i][:n], hdu.data._parent.field(i)[:n],
tmp._recformats[i]._dtype)
-> 3112 hdu.data._convert[i] =
_makep(tmp._arrays[i][:n], rec.recarray.field(hdu.data,i)[:n],
tmp._recformats[i]._dtype)
3113 else:
3114 if tbtype == 'TableHDU':
/usr/lib/python2.4/site-packages/pyfits/NP_pyfits.py in _makep(input,
desp_output, dtype)
2584
2585 _offset = 0
-> 2586 data_output = _VLF([None]*len(input))
2587 data_output._dtype = dtype
2588
TypeError: an integer is required
In [10]:
Any idea how to address this?
R.
--
Rudolph van der Merwe
KAT (Karoo Array Telescope) / www.kat.ac.za
More information about the AstroPy
mailing list