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

Jonathan Eisenhamer eisenhamer at stsci.edu
Wed Feb 25 10:53:00 EST 2015


Then worry I shall not. In anticipation of just this answer I have done the end-around.

Thanks!
jde


-------- Original message --------
From: Erik Bray
Date:2015/02/25 10:36 (GMT-05:00)
To: astropy at scipy.org
Subject: Re: [AstroPy] Fits table creation: format repeats array: should I expect this?

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

_______________________________________________
AstroPy mailing list
AstroPy at scipy.org
http://mail.scipy.org/mailman/listinfo/astropy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150225/369de48a/attachment.html>


More information about the AstroPy mailing list