[AstroPy] question on saving fits files
Grigoris Maravelias
gr.maravelias at gmail.com
Wed Feb 10 15:49:54 EST 2016
Exactly! I forgot that what I was manipulating was just a variable and
that the object hdu remained in memory unchanged.
Now it works as it should be!
Thanks Marcio!
@Leticia : I have already tried that but it was not working for the
above reason.
@Doug : no problem! thanks anyway!
On 02/10/2016 06:06 PM, Marcio Melendez wrote:
> 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
> <mailto: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 <mailto: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 <mailto:AstroPy at scipy.org>
> https://mail.scipy.org/mailman/listinfo/astropy
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org <mailto: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160210/2c484a5e/attachment.html>
More information about the AstroPy
mailing list