def resize_hdul(hdul, newshape, region, extensions=None, window=None, scale=1, fill=0.0, conserve=True): from numina.frame import resize_hdu if extensions is None: extensions = [0] nhdul = [None] * len(hdul) for ext, hdu in enumerate(hdul): if ext in extensions: nhdul[ext] = resize_hdu(hdu, newshape, region, fill=fill, window=window, scale=scale, conserve=conserve) else: nhdul[ext] = hdu return fits.HDUList(nhdul)
def resize_fits(fitsfile, newfilename, newshape, region, window=None, scale=1, fill=0.0, clobber=True, conserve=True): close_on_exit = False if isinstance(fitsfile, six.string_types): hdulist = fits.open(fitsfile, mode='readonly') close_on_exit = True else: hdulist = fitsfile try: hdu = hdulist['primary'] newhdu = resize_hdu(hdu, newshape, region, fill=fill, window=window, scale=scale, conserve=conserve) with warnings.catch_warnings(): warnings.simplefilter('ignore') newhdu.writeto(newfilename, clobber=clobber) finally: if close_on_exit: hdulist.close()