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

Jonathan Eisenhamer eisenhamer at stsci.edu
Wed Feb 25 11:17:39 EST 2015


The end around is basically what you describe: read out the table into an np.array, do the required rearrangement, then simply create a new table.

Before I was trying to cheat by just just modifying the arrays directly. An admittedly bad approach. It just took me by surprise as to exactly where the cheat broke things.


-------- Original message --------
From: Erik Bray
Date:2015/02/25 10:56 (GMT-05:00)
To: Astronomical Python mailing list
Subject: Re: [AstroPy] Fits table creation: format repeats array: should I expect this?

Out of curiosity, what was the end-around?  Was there something specific you
were trying to accomplish?

I think in general if you want the Column's array to have the correct shape when
the Column is created, then the array should just be given the correct shape in
the first place.  I think later when you add a Column to the table, it creates
the recarray structure *first* based on the formats specified for the Columns.
Then it takes the arrays already attached to those columns and fills the columns
in the recarray with them (in the case of your example that's where the
broadcasting kicks in, and it fills all 4096 elements in that column).


On 02/25/2015 10:53 AM, Jonathan Eisenhamer wrote:
> 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
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>

_______________________________________________
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/f8b40019/attachment.html>


More information about the AstroPy mailing list