Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable FITS image compression by default #138

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions maps/python/fitsio.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def parse_wcs_header(header):

@core.usefulfunc
def save_skymap_fits(filename, T, Q=None, U=None, W=None, overwrite=False,
compress='GZIP_2', hdr=None):
compress=False, quantize_level=16.0, hdr=None):
"""
Save G3 map objects to a fits file.

Expand Down Expand Up @@ -515,7 +515,13 @@ def save_skymap_fits(filename, T, Q=None, U=None, W=None, overwrite=False,
FITS readers (e.g. idlastro). If defined, the compression algorithm to
be used by the Astropy class astropy.io.fits.CompImageHDU.
Can be: 'RICE_1', 'RICE_ONE', 'PLIO_1', 'GZIP_1', 'GZIP_2' or
'HCOMPRESS_1'. Only GZIP_1 and GZIP_2 are lossless.
'HCOMPRESS_1'. Only GZIP_1 and GZIP_2 are lossless, although only
for integer data.
quantize_level : float
Floating point quantization level for compression. Higher values result
in more accurate floating point representation, but worse compression
ratio. See the astropy FITS image documention for details:
https://docs.astropy.org/en/stable/io/fits/api/images.html
hdr : dict
If defined, extra keywords to be appened to the FITS header. The dict
can contain entries such as ``hdr['NEWKEY'] = 'New value'`` or
Expand Down Expand Up @@ -612,7 +618,12 @@ def save_skymap_fits(filename, T, Q=None, U=None, W=None, overwrite=False,
for m, name in zip(maps, names):
if flat:
if compress:
hdu = astropy.io.fits.CompImageHDU(np.asarray(m), header=header, compression_type=ctype)
hdu = astropy.io.fits.CompImageHDU(
np.asarray(m),
header=header,
compression_type=ctype,
quantize_level=quantize_level,
)
else:
hdu = astropy.io.fits.ImageHDU(np.asarray(m), header=header)
hdu.header['ISWEIGHT'] = False
Expand Down Expand Up @@ -672,7 +683,12 @@ def save_skymap_fits(filename, T, Q=None, U=None, W=None, overwrite=False,

if flat:
if compress:
hdu = astropy.io.fits.CompImageHDU(np.asarray(m), header=header, compression_type=ctype)
hdu = astropy.io.fits.CompImageHDU(
np.asarray(m),
header=header,
compression_type=ctype,
quantize_level=quantize_level,
)
else:
hdu = astropy.io.fits.ImageHDU(np.asarray(m), header=header)
hdu.header['ISWEIGHT'] = True
Expand Down Expand Up @@ -729,7 +745,14 @@ def save_skymap_fits(filename, T, Q=None, U=None, W=None, overwrite=False,


@core.indexmod
def SaveMapFrame(frame, output_file=None, hdr=None, compress='GZIP_2', overwrite=False):
def SaveMapFrame(
frame,
output_file=None,
hdr=None,
compress=False,
quantize_level=16.0,
overwrite=False,
):
"""
Save a map frame to a FITS file. See ``save_skymap_fits`` for details. The
map frame should contain T maps and (optionally) unpolarized weights, or T/Q/U
Expand All @@ -752,7 +775,13 @@ def SaveMapFrame(frame, output_file=None, hdr=None, compress='GZIP_2', overwrite
FITS readers (e.g. idlastro). If defined, the compression algorithm to
be used by the Astropy class astropy.io.fits.CompImageHDU.
Can be: 'RICE_1', 'RICE_ONE', 'PLIO_1', 'GZIP_1', 'GZIP_2' or
'HCOMPRESS_1'. Only GZIP_1 and GZIP_2 are lossless.
'HCOMPRESS_1'. Only GZIP_1 and GZIP_2 are lossless, although only
for integer data.
quantize_level : float
Floating point quantization level for compression. Higher values result
in more accurate floating point representation, but worse compression
ratio. See the astropy FITS image documention for details:
https://docs.astropy.org/en/stable/io/fits/api/images.html
overwrite : bool
If True, any existing file with the same name will be ovewritten.
"""
Expand All @@ -776,5 +805,6 @@ def SaveMapFrame(frame, output_file=None, hdr=None, compress='GZIP_2', overwrite
W=W,
overwrite=overwrite,
compress=compress,
quantize_level=quantize_level,
hdr=hdr,
)
Loading