pylegs.io.compress_fits_image#
- compress_fits_image(file: str | Path | BytesIO, save_path: str | Path = None, overwrite: bool = True, compress_type: Literal['RICE_1', 'RICE_ONE', 'PLIO_1', 'GZIP_1', 'GZIP_2', 'HCOMPRESS_1', 'NOCOMPRESS'] = 'NOCOMPRESS', hcomp_scale: int = 3, quantize_level: int = 10, quantize_method: Literal[-1, 1, 2] = -1, tile_shape: Tuple[int, int] = None, dither_seed: int = 0, ext: int = 0)[source]#
Compress a FITS image and optionally save the compressed image to a file.
- Parameters:
- file
PathOrFile The path to the FITS file to be compressed. This can be a string or a
pathlib.Pathobject.- save_path
strorPath, optional The path where the compressed FITS image will be saved. If None, the compressed image is not saved. Defaults to None.
- overwritebool, optional
If
True, overwrite the existing file atsave_path. Defaults toTrue.- compress_type
str, optional The compression algorithm to use. Supported values include
'HCOMPRESS_1','RICE_1','GZIP_1','PLIO_1'. Defaults to ‘HCOMPRESS_1’.- hcomp_scale
int, optional The scale parameter for HCOMPRESS. Defaults to 3.
- quantize_level
int, optional The quantization level for compression. Defaults to 10.
- quantize_method
int, optional The quantization method to use. Defaults to -1.
- ext
int, optional The
extof the FITS file to compress. Defaults to 0.- random_seed
int, optional The seed for random number generation used in dithering. Defaults to 42.
- file
- Returns:
fits.CompImageHDUThe compressed image HDU.
- Raises:
ValueErrorIf the specified FITS
extis out of range.
Notes
If
save_pathis provided andoverwriteis True, the compressed image will be saved to the specified path. Otherwise, the function returns the compressed image HDU.Examples
>>> compress_fits_image('input.fits', save_path='compressed.fits', compress_type='RICE_1') <astropy.io.fits.hdu.compressed.CompImageHDU object at 0x...>