Skip to content

Instantly share code, notes, and snippets.

@cdeil
Created April 21, 2014 20:00
Show Gist options
  • Select an option

  • Save cdeil/11154616 to your computer and use it in GitHub Desktop.

Select an option

Save cdeil/11154616 to your computer and use it in GitHub Desktop.
import numpy as np
from astropy.io import fits
def test(filename='test.fits'):
noise = np.random.normal(size=(1000, 1000))
chdu1 = fits.CompImageHDU(data=noise, compressionType='GZIP_1')
# First make a test image with lossy compression and make sure it
# wasn't compressed perfectly. This shouldn't happen ever, but just to
# make sure the test non-trivial.
chdu1.writeto(filename, clobber=True)
with fits.open(filename) as h:
assert np.abs(noise - h[1].data).max() > 0.0
del h
chdu2 = fits.CompImageHDU(data=noise, compressionType='GZIP_1',
quantizeLevel=0.0) # No quantization
#with ignore_warnings():
chdu2.writeto(filename, clobber=True)
with fits.open(filename) as h:
assert (noise == h[1].data).all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment