# Masks werid-shaped volumes in a FitsFile from a list of coordinates # Input format : x, y, z, 0/1 # If 0, value in new file will be zero, if 1, equal to the original value. import math import numpy import pyfits import os infile = '7448Group_nosmooth.fits' textfile = 'VolumeCoords.txt' outfile = str(infile.split('.fits')[0])+str('_Masked.fits') os.system('cls') # Changes to the directory where the script is located abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) FitsFile = pyfits.open(infile) image = FitsFile[0].data header =FitsFile[0].header sizez = image.shape[0] sizey = image.shape[1] sizex = image.shape[2] print sizez,sizey,sizex coords = open(textfile,'r') for line in coords: x, y, z, v = line.split(): xp = int(x) yp = int(y) zp = int(z) if int(v) == 0: image[zp,yp,xp] = 0.0 FitsFile = pyfits.writeto(outfile, image, header=header)