[AstroPy] Unable to Save Compressed HDU

Harsh Mathur harshmathur.1990 at gmail.com
Wed Jan 30 12:04:03 EST 2019


Hi,

Please find the steps to reproduce:

1. Download the data and header pickled from here (
https://drive.google.com/drive/folders/10V7ruXr3As9dD5o416VLTh_ZIMAH3POw?usp=sharing
)

2. Python code:

*import* *pickle*

*import* *sunpy.io.fits*

*from* *astropy.io <http://astropy.io>* *import* fits

data = pickle.loads(open('fits_data.data', 'rb').read())

header = pickle.loads(open('header.data', 'rb').read())

sunpy.io.fits.write('sample.fits', data, header, hdu_type=fits.CompImageHDU)

3. Before saving we can also confirm the data is correct by

*import* *matplotlib.pyplot* *as* *plt*

plt.imshow(data, cmap='gray')

plt.show()

Attached is the plt.show() output.

Thanks for looking into this.

Regards
Harsh Mathur
harshmathur.1990 at gmail.com

*“Perseverance is the hard work you do after you get tired of doing the
hard work you already did."*


On Wed, Jan 30, 2019 at 2:29 PM Christoph Deil <
deil.christoph at googlemail.com> wrote:

>
>
> On 30. Jan 2019, at 09:41, Harsh Mathur <harshmathur.1990 at gmail.com>
> wrote:
>
> Hi,
> I have a fits file which normally takes around 132 MB. I want to save it
> with compressed HDU.
>
> I tried both with astropy and sunpy, but for some reason it is
> not working. To be specific, it is saving empty HDU (i.e. the grid is only
> filled with nans).
>
> Here's what I did with astropy:
>
> from astropy.io import fits
> header_object = self._get_header_object(header)
> comp_hdu = fits.CompImageHDU(data=data, header=header_object)
> comp_hdu.writeto(filename, output_verify='fix')
>
> Here's what I did with sunpy:
> import sunpy.io.fits
> sunpy.io.fits.write(
>             filename,
>             data,
>             header,
>             hdu_type=fits.CompImageHDU
>         )
>
> I tried to debug using ipdb and checked just before the save instruction,
> the data and header are present and not empty, just that its not saving.
>
> The worst thing is, there is no error for me debug. Any help is
> appreciated.
>
> Thank you in advance.
>
> Regards
> Harsh Mathur
> harshmathur.1990 at gmail.com
>
> *“Perseverance is the hard work you do after you get tired of doing the
> hard work you already did."*
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
>
>
> Hi Harsh,
>
> Can you try to create a standalone test case that we can run to try and
> reproduce / debug the issue?
> E.g. make up some data using numpy.ones or numpy.random, provide a code
> snippet we can just copy & paste & run.
>
> Also please mention your Numpy and Astropy version number.
>
> It’s probably not your exact issue, but there is this issue
> https://github.com/astropy/astropy/issues/2150
> which causes issues sometimes, but only when writing certain Numpy arrays
> and when using compression.
>
> Without an example to reproduce, it’s likely hard to help figure out
> exactly what goes wrong in your case.
>
> Christoph
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20190130/1f424f94/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2019-01-30 at 10.32.25 PM.png
Type: image/png
Size: 95686 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20190130/1f424f94/attachment-0001.png>


More information about the AstroPy mailing list