[AstroPy] Fits table creation: format repeats array: should I expect this?

Erik Bray embray at stsci.edu
Wed Feb 25 10:36:08 EST 2015


On 02/24/2015 06:06 PM, Jonathan Eisenhamer wrote:
> Greetings,
>
> Basic FITS io question. I do the following, which comes basically from the
> example in the astropy docs:
> from astropy.io import fits
> import numpy as np
>
>     a = np.arange(100.0)
>     col = fits.Column(name='a100', format='4096E', array=a)
>     coldefs = fits.ColDefs([col])
>     hdu = fits.BinTableHDU.from_columns(coldefs)
>
> The array association with the column is "correct", in that the shape of a is
> (100,).
>
> Except after it has been put into the HDU. Now the array for the column has
> shape (100, 4096):
>
>     hdu.columns[0].array.shape
>     -> (100, 4096)
>
> Clearly this is because of the format. And at some level this makes sense, but a
> couple questions:
>
>   * Why does the format not affect the array until the HDU is created? I.e. The
>     col has just the basic array in it.
>   * Is this expected behavior?
>
> Thank you for your time,

(FWIW since I'm the only one who actually works on the FITS module this is 
basically just a question for me, especially for something at this level.)

Is this expected behavior?  Yes and no.  It's expected to me because I read the 
code.  It may not be expected to a user (in your case it wasn't).  There's 
nothing particularly deliberate or designed about that--it just has to do with 
where the code that does various manipulations live.

The pyfits "Column" class is not as well designed as the astropy.table Column 
class, and shouldn't generally be used on its own outside the context of setting 
up a table.  The fact that you can get to its .array attribute (or that that 
even exists at all) is a somewhat unfortunate misfeature I've had the "fun" of 
having to carry around.  So I wouldn't worry about this.

Erik




More information about the AstroPy mailing list