def test_cooling_string_fail(self): """We send an invalid string value for the cooling step. String is not in file and should return 0""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep="never"), 0)
def test_retag_totals_fail(self): """We try to tag the same mesh, and also include totals; Should have no problems. should not be reached before """ self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True, totals=True), 1)
def test_retag_and_totals_ok(self): """We enable retagging and also make sure that the totals get retagged. """ self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True, totals=True), 1)
def test_unobtanium(self): """Supplied isotope doesn't exist in file.""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, "unobtanium"), 0)
def test_simple_with_totals(self): """Tag a mesh; tagging again should fail; then tagging again should succeed when we add the retag=True option""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, totals=True), 1)
def test_simple(self): self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm), 1)
def test_retag_totals_fail(self): """We try again to tag the same mesh. An error should be returned. This test should be redundant as totals should not be reached before the method fails.""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, totals=True), 0)
def test_retag_totals_fail(self): """We try to tag the same mesh, and also include totals; Should have no problems. should not be reached before """ self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True, totals=True), 1)
def test_cooling_string_pass(self): """We send a valid string value for the cooling step. Should return 1""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep="1 s"), 1)
def setUp(self): os.system("cp " + meshfile_orig + " " + meshfile) self.sm = ScdMesh.fromFile(meshfile) read_alara_phtn.read_to_h5m(inputfile, self.sm)
def test_cooling_string_pass(self): """We send a valid string value for the cooling step. Should return 1""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep="1 s"), 1)
def test_cooling_num_pass(self): """We send a numeric value for the cooling step. Should return 1""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep=3) , 1)
def test_cooling_num_fail2(self): """We send an invalid numeric value for the cooling step. Should return 0""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep=-3), 0)
def test_cooling_num_pass(self): """We send a numeric value for the cooling step. Should return 1""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep=3), 1)
def test_unobtanium(self): """Supplied isotope doesn't exist in file.""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, "unobtanium"), 0)
def test_simple_with_totals(self): """Tag a mesh; tagging again should fail; then tagging again should succeed when we add the retag=True option""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, totals=True), 1)
def test_cooling_num_fail2(self): """We send an invalid numeric value for the cooling step. Should return 0""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep=-3), 0)
def test_retag_fail(self): """We try again to tag the same mesh. An error should be returned""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm), 0)
def test_cooling_string_fail(self): """We send an invalid string value for the cooling step. String is not in file and should return 0""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, coolingstep="never"), 0)
def test_retag_totals_fail(self): """We try again to tag the same mesh. An error should be returned. This test should be redundant as totals should not be reached before the method fails.""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, totals=True), 0)
def test_retag_ok(self): """We try to tag the same mesh, but with the retag parameter = True Should succeed fine.""" self.assertEqual( read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True), 1)
def test_retag_ok(self): """We try to tag the same mesh, but with the retag parameter = True Should succeed fine.""" self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True), 1)
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_retag_and_totals_ok(self): """We enable retagging and also make sure that the totals get retagged. """ self.assertEqual(read_alara_phtn.read_to_h5m(inputfile, self.sm, retag=True, totals=True), 1)