# Clip everything outside a specified channel range import numpy import pyfits import os # Changes to the directory where the script is located abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) infile = 'M33Clouds.fits' outfile = 'M33Clouds_clipped.fits' chan1 = 32 chan2 = 85 FitsFile = pyfits.open(infile) image= FitsFile[0].data header=FitsFile[0].header chans = image.shape[0] for i in range(chans): if (i < chan1) or (i > chan2): image[i,:,:] = 0.0 FitsFile = pyfits.writeto(outfile,image,header=header)