Cropping very large files using specified boundaries

I have a file with large files (over 30,000 x 30,000). IRAF cannot handle this image size. How can I crop a file of this size while maintaining the correct header information, as IRAF does when using the standard cropping mode?

+4
source share
1 answer

You can do this crop with help astropy.io.fits, although this is not trivial yet. Since it astropy.io.fitsuses memory mapping by default , it should be able to process arbitrarily large files (within some practical limits). If you want solutions other than python, look here for details on creating postage stamps.

from astropy.io import fits
from astropy import wcs
f = fits.open('file.fits')
w = wcs.WCS(f[0].header)
newf = fits.PrimaryHDU()
newf.data = f[0].data[100:-100,100:-100]
newf.header = f[0].header
newf.header.update(w[100:-100,100:-100].to_header())

See also this pull request , which implements a convenient function Cutout2D, although it is not yet available in the released version of astrometry. Its use can be seen in the documentation modified to enable WCS:

from astropy.nddata import Cutout2D
position = (49.7, 100.1)
shape = (40, 50)
cutout = Cutout2D(f[0].data, position, shape, wcs=w)

Examples here

+5
source

Source: https://habr.com/ru/post/1608593/


All Articles