<div dir="ltr">Hi <span style="font-size:12.8000001907349px;font-weight:bold;white-space:nowrap">Grigoris, </span><div><span style="font-size:12.8000001907349px;font-weight:bold;white-space:nowrap"><br></span></div><div><span style="font-size:12.8000001907349px;font-weight:bold;white-space:nowrap">Try to open the file for writing like this:</span></div><div><span style="font-size:12.8000001907349px;font-weight:bold;white-space:nowrap"><br></span></div><div><span style="font-size:12.8000001907349px;font-weight:bold;white-space:nowrap"> </span><span style="font-size:12.8000001907349px">hdulist = fits.open('small.fits', mode='update')</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">BR</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-10 14:06 GMT-03:00 Marcio Melendez <span dir="ltr"><<a href="mailto:marcio.melendez@gmail.com" target="_blank">marcio.melendez@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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 <span style="font-size:12.8000001907349px">dt = dt*1000 with </span><span style="font-size:12.8000001907349px">hdu.data = </span><span style="font-size:12.8000001907349px">dt*1000. Alternatively you can create another object (if you want to keep hdu intact) by:<br></span>







<p><span>hdu_new = pyfits.PrimaryHDU(dt) # where dt = </span><span style="font-size:12.8000001907349px">hdu.data</span><span style="font-size:12.8000001907349px">*1000</span></p>
<div>hdu_new.writeto('<span style="font-size:12.8000001907349px">small_mod.</span><span style="font-size:12.8000001907349px">fits</span>')<span style="font-size:12.8000001907349px"> </span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Remember to add </span>clobber = True to your writeto if you want to overwrite the file. </div><div><br></div><div>I hope this help, </div>







<div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Wed, Feb 10, 2016 at 11:42 AM, Doug Burke <span dir="ltr"><<a href="mailto:dburke.gw@gmail.com" target="_blank">dburke.gw@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div>Grigoris,</div><div><br></div><div>If you change 'dt = dt * 1000' to 'dt *= 1000' do you get what you expect?</div><div><br></div><div>Doug</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 10, 2016 at 11:30 AM Grigoris Maravelias <<a href="mailto:gr.maravelias@gmail.com" target="_blank">gr.maravelias@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<br>
I have a problem with a rather simple process, but I cannot understand<br>
what I am doing wrong. I have an image in a fits file that i want to<br>
open and process its data values, and save it as another file (including<br>
some extra information on the header for what I did). So according to<br>
the astropy docs [1] I did the following:<br>
<br>
hdulist = fits.open('small.fits')<br>
hdu = hdulist[0]<br>
hd = hdu.header<br>
dt = hdu.data<br>
<br>
hd.append(('HISTORY', 'blabla '), bottom=True)<br>
<br>
print dt            # check data before<br>
dt = dt*1000<br>
print dt            # and after<br>
<br>
hdulist.writeto('small_mod.fits')<br>
<br>
If I print dt before and after their modification (multiplied by 1000) I<br>
can see that they are indeed different (properly multiplied), but when I<br>
save the fits file I just see the original data values (however, the<br>
HISTORY line is added properly in the primary header).<br>
<br>
What am I missing here?<br>
<br>
Best<br>
Grigoris<br>
<br>
<br>
[1] <a href="http://docs.astropy.org/en/stable/io/fits/usage/headers.html" rel="noreferrer" target="_blank">http://docs.astropy.org/en/stable/io/fits/usage/headers.html</a><br>
<br>
<br>
_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org" target="_blank">AstroPy@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/astropy</a><br>
</blockquote></div>
<br>_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org" target="_blank">AstroPy@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/astropy</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Marcio B. Melendez, Ph.D</div>







<div><span style="font-size:12.8000001907349px">JWST ISIM Optics Support Scientist</span><br><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Wyle </span><span style="font-size:12.8000001907349px">Science, Technology and Engineering Group</span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">NASA Goddard Space Flight Center  Greenbelt, MD  20771  </span></div><div style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Bldg. 29 Rm. T29-10, phone: 301-286-8517</span></div></div></div></div></div></div></div>
</font></span></div></div>
<br>_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/astropy</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Leticia.<br></div><div><br>Technical Contact<br></div><div></div>NOVA - Virtual Observatory Argentina<br><a href="http://nova.conicet.gov.ar" target="_blank">http://nova.conicet.gov.ar</a><br></div></div>
</div>