def __init__(self, filename, xdim, ydim, zdim, voxel_width): '''Assumes cubic voxels''' self.phantom = EGSPhant(None, xdim, ydim, zdim) # TODO: don't overwrite pre-existing file self.phantom.phantfilename = filename self.phantom.nmaterials = 6 self.phantom.materials = [] self.phantom.materials.append('AIR700ICRU') #self.phantom.materials.append('H2O700ICRU') self.phantom.materials.append('LUNG700ICRU') self.phantom.materials.append('ICRUTISSUE700ICRU') self.phantom.materials.append('ICRPBONE700ICRU') self.phantom.materials.append('ECLIPSE') self.phantom.materials.append('CERAMCOC3') self.phantom.estepe = ones(self.phantom.nmaterials, type=Float32) self.phantom.xedges = zeros(self.phantom.dimensions[0]+1, type=Float32) self.phantom.yedges = zeros(self.phantom.dimensions[1]+1, type=Float32) self.phantom.zedges = zeros(self.phantom.dimensions[2]+1, type=Float32) # make the x-y slices center on (x=0, y=0) x_start = self.phantom.dimensions[0] * voxel_width / 2. y_start = self.phantom.dimensions[1] * voxel_width / 2. for i in range(self.phantom.dimensions[0]+1): self.phantom.xedges[i] = -x_start + i * voxel_width for i in range(self.phantom.dimensions[1]+1): self.phantom.yedges[i] = -y_start + i * voxel_width for i in range(self.phantom.dimensions[2]+1): self.phantom.zedges[i] = i * voxel_width self.phantom.materialscan = zeros([self.phantom.dimensions[2],self.phantom.dimensions[1], self.phantom.dimensions[0]], type=Int32) # set all slices to be tissue self.phantom.materialscan[:,:,:] = self.phantom.materialscan[:,:,:] + 3 * ones((self.phantom.dimensions[2], self.phantom.dimensions[1], self.phantom.dimensions[0]), type=Int32) self.phantom.densityscan = zeros([self.phantom.dimensions[2],self.phantom.dimensions[1], self.phantom.dimensions[0]], type=Float32) # fix only the artificial materials self.phantom.fix_density()
class BlankPhant: def __init__(self, filename, xdim, ydim, zdim, voxel_width): '''Assumes cubic voxels''' self.phantom = EGSPhant(None, xdim, ydim, zdim) # TODO: don't overwrite pre-existing file self.phantom.phantfilename = filename self.phantom.nmaterials = 6 self.phantom.materials = [] self.phantom.materials.append('AIR700ICRU') #self.phantom.materials.append('H2O700ICRU') self.phantom.materials.append('LUNG700ICRU') self.phantom.materials.append('ICRUTISSUE700ICRU') self.phantom.materials.append('ICRPBONE700ICRU') self.phantom.materials.append('ECLIPSE') self.phantom.materials.append('CERAMCOC3') self.phantom.estepe = ones(self.phantom.nmaterials, type=Float32) self.phantom.xedges = zeros(self.phantom.dimensions[0]+1, type=Float32) self.phantom.yedges = zeros(self.phantom.dimensions[1]+1, type=Float32) self.phantom.zedges = zeros(self.phantom.dimensions[2]+1, type=Float32) # make the x-y slices center on (x=0, y=0) x_start = self.phantom.dimensions[0] * voxel_width / 2. y_start = self.phantom.dimensions[1] * voxel_width / 2. for i in range(self.phantom.dimensions[0]+1): self.phantom.xedges[i] = -x_start + i * voxel_width for i in range(self.phantom.dimensions[1]+1): self.phantom.yedges[i] = -y_start + i * voxel_width for i in range(self.phantom.dimensions[2]+1): self.phantom.zedges[i] = i * voxel_width self.phantom.materialscan = zeros([self.phantom.dimensions[2],self.phantom.dimensions[1], self.phantom.dimensions[0]], type=Int32) # set all slices to be tissue self.phantom.materialscan[:,:,:] = self.phantom.materialscan[:,:,:] + 3 * ones((self.phantom.dimensions[2], self.phantom.dimensions[1], self.phantom.dimensions[0]), type=Int32) self.phantom.densityscan = zeros([self.phantom.dimensions[2],self.phantom.dimensions[1], self.phantom.dimensions[0]], type=Float32) # fix only the artificial materials self.phantom.fix_density() def fix_all_density(self): '''Fixes up the density scan''' # if tissue, want density to be 1.0 # otherwise, set to the mean density for that material # (to be accurate, only "mean" in the sense of middle of the # range of possible densities.) for k in range(self.phantom.dimensions[2]): for j in range(self.phantom.dimensions[1]): for i in range(self.phantom.dimensions[0]): mat = self.phantom.material(self.phantom.materialscan[k,j,i]) if not self.phantom.density_correct_p(k,j,i): mat = self.phantom.material(self.phantom.materialscan[k,j,i]) self.phantom.debug_print(mat) if mat == 'ICRUTISSUE700ICRU': proper_dens = 1.0 else: proper_dens = 0.5 (self.phantom.density[mat][0] + self.phantom.density[mat][1]) self.phantom.densityscan[k,j,i] = proper_dens def save(self): self.phantom.save(self.phantom.phantfilename)
#!/usr/bin/env python2.4 # $Id: pickle_these.py 86 2007-11-12 22:11:40Z dwchin $ import os import pickle from EGSPhant import * from MCDose import * # loop over all egsphant and 3ddose file, and pickle them for o in sys.argv: if o.endswith('3ddose'): d = MCDose(o) picklename = o.split('.3ddose')[0] + '_3ddose.pickle' f = open(picklename, 'wo') pickle.dump(d, f) f.close() elif o.endswith('egsphant'): p = EGSPhant(o) picklename = o.split('.egsphant')[0] + '_egsphant.pickle' f = open(picklename, 'wo') pickle.dump(p, f) f.close() else: pass
#!/usr/bin/env python2.4 from EGSPhant import * if len(sys.argv) == 1: print 'Need name of egsphant file' sys.exit(1) p = EGSPhant(sys.argv[1]) # set the density for tissue and bone voxels for k in range(p.dimensions[2]): for j in range(p.dimensions[1]): for i in range(p.dimensions[0]): mat = p.material(p.materialscan[k, j, i]) if mat == 'ICRPBONE700ICRU': print '%s, %f g/cc' % (mat, p.densityscan[k, j, i])
#!/usr/bin/env python2.4 import sys from EGSPhant import * if len(sys.argv) == 1: print "Need one argument, name of phantom file to fix" else: try: phant = EGSPhant(sys.argv[1]) except IOError: raise suffix = '.egsphant' phant.fix_density() basename = sys.argv[1].split(suffix)[0] newname = basename + '_fixed' + suffix phant.save(newname)
#!/usr/bin/env python from EGSPhant import * from MCDose import * from pylab import * d = MCDose('block_amalgam.3ddose') d.make_absolute('6MV', 100) p = EGSPhant('block_amalgam.egsphant') X, Y = meshgrid(d.x, d.y) Z = d.dose[11, :, :] CS = contourf(X, Y, p.densityscan[11, :, :], cmap=cm.bone, origin='lower') #CS2 = contourf(X, Y, Z, 10, cmap=cm.jet, origin='lower', alpha='0.5') CS2 = imshow(X, Y, Z, 10, cmap=cm.jet, origin='lower', alpha='0.5') title('Example isodose plot') xlabel('X (cm)') ylabel('Y (cm)') #CS2 = contour(X, Y, Z, CS.levels, colors='white', origin='lower', hold='on') ax_cbar = colorbar(CS, tickfmt='%1.2f') ax_cbar.set_ylabel('dose (foo units)') show()