<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Dear Daniel,<br>
<br>
<br>
On 10/23/2017 03:49 PM, Daniel Evans wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CANnaQaYi0ZGM5OwpSnxibchHpjtCPwrAWbSfaET688OWxS-GQA@mail.gmail.com">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>
<div>
<div>Dear Sebastien,<br>
<br>
</div>
I suspect you're right that astropy is undoing your
modifications as it thinks the header no longer matches the
data. The solutions I can think of for your problem are:<br>
<br>
</div>
<div>1. Simply modify the array once read into Python to turn
it into a 2D array, suitable for matplotlib.pyplot.imshow
(or similar). This is relatively standard for viewing images
in datacubes anyway, and requires very little effort in
Python:<br>
<br>
a = astropy.io.fits.open(sys.argv[<wbr>1])<br>
</div>
<div> image4D = a[0].data<br>
</div>
<div> a.close()<br>
<br>
</div>
<div> image2D = image4D[0, 0]<br>
</div>
<div> matplotlib.pyplot.imshow(image2D)<br>
</div>
<div> matplotlib.pyplot.show()<br>
<br>
</div>
<div>2. If you do want to modify the fits file, you can
convert the array from 4D to 2D, and reinsert this into the
file. astropy will update the header to match:<br>
<br>
a = astropy.io.fits.open(sys.argv[<wbr>1], mode =
"update")<br>
</div>
<div> a[0].data = a[0].data[0, 0]<br>
</div>
<div> a.close()<br>
</div>
</div>
</div>
</blockquote>
<br>
I was focusing on editing the header, but actually "editing" the
data works great! Thanks.<br>
<br>
Do you know what would be the best syntax to add a trailing
dimension from a 2D image? I mean, in a clever way without doubling
the memory consumption.<br>
<br>
<br>
<blockquote type="cite"
cite="mid:CANnaQaYi0ZGM5OwpSnxibchHpjtCPwrAWbSfaET688OWxS-GQA@mail.gmail.com">
<div dir="ltr">
<div>
<div><br>
</div>
<div>John ZuHone - the issue is presumably that matplotlib is
being asked to display a 2D image, but is being passed a 4D
array - I've done this many times with 3D datacubes!<br>
</div>
</div>
</div>
</blockquote>
<br>
@ John ZuHone: I am not a Matplotlib user (I am in charge of
reading/writing the FITS files), and I had just a comment about a
Matplotlib error without more details. But Daniel is probably right
here.<br>
<br>
Thanks,<br>
<br>
Sebastien<br>
<br>
</body>
</html>