[AstroPy] modifying FITS data

Erik Bray embray at stsci.edu
Tue May 31 12:17:29 EDT 2011

On 05/31/2011 12:01 PM, Frédéric Grollier wrote:
> On Tue, May 31, 2011 at 04:53:55PM +0200, Jean-Luc Menut wrote:
>> Hello All,
> [snip]
>> What I would like to do is to replace these value by some others
>> (actually interpolated from other FITS data).
>> By example, if I try to do
>> In [80]: orig['OI_VIS'].data['VISAMP']=tuple(ones(14))
>> I obtain:
>> ValueError: field named VISAMP not found.
> Hello,
> doing this with a loop should work:
> for i in range(orig['OS_VIS'].data.shape[0]):
>      orig['OI_VIS'].data.field('VISAMP')[i] = the_value

Rather than looping it might be better (certainly faster) to do a slice 

orig['OI_VIS'].data['VISAMP'][:] = the_value

If the_value is not the same size/dimensions as the array being assigned 
to, then you can modify the slice accordingly.  For example:

orig['OI_VIS'].data['VISAMP'][:len(the_value)] = the_value

This works because the lookup by field name returns a numpy array that 
can be manipulated as such.  Why direct assignment like you tried 
originally isn't implemented I'm not entirely sure.


More information about the AstroPy mailing list