Cropping very large fits files using specified boundaries
Asked Answered
E

1

7

I have a large fits file (over 30,000 x 30,000) pixels. IRAF cannot handle this size of image. How can one crop a file of this size while retaining correct header information, as IRAF does when using its standard cropping mode?

Estafette answered 22/9, 2015 at 22:44 Comment(1)
Your question should contain specific code problems. They way your question is currently framed, it would be a matter of opinion or too broad for this site.Exine
M
10

You can do this sort of cropping with astropy.io.fits, though it's not trivial yet. Since astropy.io.fits uses memory mapping by default, it should be able to handle arbitrarily large files (within some practical limits). If you want non-python solutions, look here for details about postage stamp creation.

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())

There is also a convenience Cutout2D function. Its usage can be seen in the documentation, modified to include WCS:

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

There are more examples here

Marlenmarlena answered 23/9, 2015 at 6:8 Comment(1)
The question and answer are quite old, so I just want to add that Cutout2D has been now for long in the stable branch of astropy, so for stable documentation see here: docs.astropy.org/en/stable/api/…Fridge

© 2022 - 2024 — McMap. All rights reserved.