def test_vox_cum(self): """Verify gammas file for voxel sampling with cumulative bins""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, cumulative=True) self.compare_gammas(outfile, gammas7)
def test_uni_seq_bias(self): """Verify gammas file for uniform sampling with sequential bins and biasing""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, sampling='u', do_bias=True) self.compare_gammas(outfile, gammas2)
def test_direct_with_bias(self): """Tests a run-through with: direct discrete + bias Note: biasing is not enabled with direct discrete, so code defaults to regular direct discrete behavior. """ self.assertEqual(write_gammas.gen_gammas_file_from_h5m( \ self.sm, outfile, do_bias=True), 1)
def test_direct_alias_erg_bins(self): """Tests a run-through with: direct discrete + erg alias bins.""" self.assertEqual(write_gammas.gen_gammas_file_from_h5m( \ self.sm, outfile), 1)
def test_gen_gammas(self): """Tests a run-through with defaults; direct discrete.""" self.assertEqual(write_gammas.gen_gammas_file_from_h5m( \ self.sm, outfile), 1)
def test_vox_seq(self): """Verify gammas file for voxel sampling with sequential bins""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile) self.compare_gammas(outfile, gammas5)
def test_uni_cum(self): """Verify gammas file for uniform sampling with cumulative bins""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, sampling='u', cumulative=True) self.compare_gammas(outfile, gammas3)
def test_voxel_alias_with_bias_and_erg_alias_bins(self): """Tests a run-through with: voxel sampling with biasing.""" self.assertEqual(write_gammas.gen_gammas_file_from_h5m( \ self.sm, outfile, do_bias=True), 1)
def test_voxel_alias(self): """Tests a run-through with: voxel sampling specified. Note: do_alias must be True for voxel sampling gammas to be made, so code defaults to regular direct discrete behavior""" self.assertEqual(write_gammas.gen_gammas_file_from_h5m( \ self.sm, outfile), 1)
def test_vox_cum_bias(self): """Verify gammas file for voxel sampling with cumulative bins and biasing""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, do_bias=True, cumulative=True) self.compare_gammas(outfile, gammas8)
def test_vox_seq_bias(self): """Verify gammas file for voxel sampling with sequential bins and biasing""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, do_bias=True) self.compare_gammas(outfile, gammas6)
def handle_phtn_data(datafile, phtn_src, opt_isotope, opt_cooling, \ opt_sampling, opt_bias, opt_cumulative, cust_ergbins, resample, uni_resamp_all, gammas="gammas"): """Loads phtn_src data, tags this to mesh, and generates 'gammas' file. Parameters ---------- datafile : string Path to structured mesh file (e.g. .h5m file) phtn_src : string Path to phtn_src file opt_isotope : string The isotope identifier as listed in phtn_src file opt_cooling : int or string The cooling step, either as a numeric index (from 0) or a string identifier as listed in phtn_src file opt_sampling : ['v', 'u'] Type of sampling to generate the 'gammas' file for; v=voxel; u=uniform opt_bias : boolean If true, look for bias values on the mesh and include them in 'gammas' opt_cumulative : boolean If true, write energy bins' relative probabilities cumulatively cust_ergbins : boolean If true, look for custom energy bins on the mesh and include them in 'gammas' resample : boolean If true, 'r' flag is added to gammas, and resampling of particles starting in void regions of voxels is enabled. uni_resamp_all : boolean If true, 'a' flag is added to gammas, and particles starting in void regions of voxels, during uniform sampling, are resampled over the entire problem, rather than resampling just the voxel. This has the potential to result in an unfair game. gammas : string (optional) File name for 'gammas' file. Defaults to 'gammas'. Returns ------- mesh : ScdMesh object or iMesh.Mesh object MOAB mesh object Notes ----- Only creates gammas file if mesh is an ScdMesh. """ print "Loading step one data file '{0}'".format(datafile) try: mesh = ScdMesh.fromFile(datafile) except ScdMeshError: mesh = iMesh.Mesh() mesh.load(datafile) # Tagging mesh print "Reading ALARA photon source '{0}'".format(phtn_src) read_alara_phtn.read_to_h5m(phtn_src, mesh, isotope=opt_isotope, \ coolingstep=opt_cooling, retag=True, totals=True) print "Saving photon source information to '{0}'".format(datafile) if isinstance(mesh, ScdMesh): mesh.imesh.save(datafile) with open(phtn_src, 'r') as fr: try: coolingstepstring = read_alara_phtn.get_cooling_step_name( \ opt_cooling, fr)[0] except ValueError: coolingstepstring = opt_cooling print "Writing gammas file" write_gammas.gen_gammas_file_from_h5m(mesh, outfile=gammas, \ sampling=opt_sampling, do_bias=opt_bias, \ cumulative=opt_cumulative, cust_ergbins=cust_ergbins, \ resample=resample, uni_resamp_all=uni_resamp_all, \ coolingstep=coolingstepstring, isotope=opt_isotope) else: voxels = list(mesh.iterate(iBase.Type.region, iMesh.Topology.all)) write_gammas.calc_total_source_strength(mesh, voxels) mesh.save(datafile) print "\n" return mesh
def test_uni_seq(self): """Verify gammas file for uniform sampling with sequential bins""" self.meshfile = meshfile_g self.sm = ScdMesh.fromFile(self.meshfile) write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, sampling='u') self.compare_gammas(outfile, gammas1)