[AstroPy] question on saving fits files

Leticia Rodriguez iafe.leticia at gmail.com
Wed Feb 10 12:07:42 EST 2016


Hi Grigoris,

Try to open the file for writing like this:

 hdulist = fits.open('small.fits', mode='update')

BR

2016-02-10 14:06 GMT-03:00 Marcio Melendez <marcio.melendez at gmail.com>:

> The problem is that you just changed a variable, dt, and not your object
> hdu (the one that you are writing to). So you need to replace dt =
> dt*1000 with hdu.data = dt*1000. Alternatively you can create another
> object (if you want to keep hdu intact) by:
>
> hdu_new = pyfits.PrimaryHDU(dt) # where dt = hdu.data*1000
> hdu_new.writeto('small_mod.fits')
>
> Remember to add clobber = True to your writeto if you want to overwrite
> the file.
>
> I hope this help,
>
> On Wed, Feb 10, 2016 at 11:42 AM, Doug Burke <dburke.gw at gmail.com> wrote:
>
>>
>> Grigoris,
>>
>> If you change 'dt = dt * 1000' to 'dt *= 1000' do you get what you expect?
>>
>> Doug
>>
>> On Wed, Feb 10, 2016 at 11:30 AM Grigoris Maravelias <
>> gr.maravelias at gmail.com> wrote:
>>
>>> Hello!
>>>
>>> I have a problem with a rather simple process, but I cannot understand
>>> what I am doing wrong. I have an image in a fits file that i want to
>>> open and process its data values, and save it as another file (including
>>> some extra information on the header for what I did). So according to
>>> the astropy docs [1] I did the following:
>>>
>>> hdulist = fits.open('small.fits')
>>> hdu = hdulist[0]
>>> hd = hdu.header
>>> dt = hdu.data
>>>
>>> hd.append(('HISTORY', 'blabla '), bottom=True)
>>>
>>> print dt            # check data before
>>> dt = dt*1000
>>> print dt            # and after
>>>
>>> hdulist.writeto('small_mod.fits')
>>>
>>> If I print dt before and after their modification (multiplied by 1000) I
>>> can see that they are indeed different (properly multiplied), but when I
>>> save the fits file I just see the original data values (however, the
>>> HISTORY line is added properly in the primary header).
>>>
>>> What am I missing here?
>>>
>>> Best
>>> Grigoris
>>>
>>>
>>> [1] http://docs.astropy.org/en/stable/io/fits/usage/headers.html
>>>
>>>
>>> _______________________________________________
>>> AstroPy mailing list
>>> AstroPy at scipy.org
>>> https://mail.scipy.org/mailman/listinfo/astropy
>>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
>>
>>
>
>
> --
> Marcio B. Melendez, Ph.D
> JWST ISIM Optics Support Scientist
> Wyle Science, Technology and Engineering Group
> NASA Goddard Space Flight Center  Greenbelt, MD  20771
> Bldg. 29 Rm. T29-10, phone: 301-286-8517
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
>
>


-- 
Leticia.

Technical Contact
NOVA - Virtual Observatory Argentina
http://nova.conicet.gov.ar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160210/65897345/attachment.html>


More information about the AstroPy mailing list