def test_response_hdf5_to_mesh(): """Tests the function photon source_h5_to_mesh.""" for response in responses: # read output.txt and write h5 file filename = os.path.join(thisdir, "files_test_activation_responses", ''.join([response, '_output.txt'])) h5_filename = os.path.join(thisdir, "files_test_activation_responses", ''.join([response, '.h5'])) response_to_hdf5(filename, response) assert_true(os.path.exists(h5_filename)) mesh = Mesh(structured=True, structured_coords=[[0, 1], [0, 1], [0, 1]]) tags = {('h-3', 'shutdown'): 'tag1', ('TOTAL', '12 h'): 'tag2'} response_hdf5_to_mesh(mesh, h5_filename, tags, response) # create lists of lists of expected results tag1_answers = [9.5258e-18] tag2_answers = [9.5251e-18] ves = list(mesh.structured_iterate_hex("xyz")) for i, ve in enumerate(ves): assert_equal(mesh.tag1[ve], tag1_answers[i]) assert_equal(mesh.tag2[ve], tag2_answers[i]) if os.path.isfile(h5_filename): os.remove(h5_filename)
def test_response_to_hdf5(): """ This function test alara.response_to_hdf5, with response of: - decay_heat - specific_activity - alpha_heat - beta_heat - gamma_heat - wdr - photon_source """ # skip test if h5diff not exist is_h5diff = os.system("which h5diff") if is_h5diff != 0: raise SkipTest for response in responses: # read output.txt and write h5 file filename = os.path.join( thisdir, "files_test_activation_responses", "".join([response, "_output.txt"]), ) h5_filename = os.path.join(thisdir, "files_test_activation_responses", "".join([response, ".h5"])) response_to_hdf5(filename, response) # generate expected h5 file exp_h5_filename = os.path.join( thisdir, "files_test_activation_responses", "".join(["exp_", response, ".h5"]), ) _generate_exp_h5(filename, response, exp_h5_filename) # compare two h5 files command = "".join(["h5diff ", h5_filename, " ", exp_h5_filename]) diff_flag = os.system(command) # return value 0 if no difference, 1 if differences found, 2 if error assert_equal(diff_flag, 0) # remove generated files os.remove(h5_filename) os.remove(exp_h5_filename)
def test_responses_to_hdf5_multiple(): """ This function test alara.response_to_hdf5, read output.txt of multiple responses: - decay_heat - specific_activity - alpha_heat - beta_heat - gamma_heat - wdr - photon_source """ # skip test if h5diff not exist is_h5diff = os.system('which h5diff') if is_h5diff != 0: raise SkipTest for response in responses: # read output.txt and write h5 file filename = os.path.join(thisdir, "files_test_activation_responses", 'multiple_output.txt') h5_filename = os.path.join(thisdir, "files_test_activation_responses", ''.join([response, '.h5'])) response_to_hdf5(filename, response) # generate expected h5 file exp_h5_filename = os.path.join(thisdir, "files_test_activation_responses", ''.join(['exp_', response, '.h5'])) _generate_exp_h5(filename, response, exp_h5_filename) # compare two h5 files command = ''.join(['h5diff ', h5_filename, ' ', exp_h5_filename]) diff_flag = os.system(command) # return value 0 if no difference, 1 if differences found, 2 if error assert_equal(diff_flag, 0) # remove generated files os.remove(h5_filename) os.remove(exp_h5_filename)
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') decay_times = config.get('step2', 'decay_times').split(',') try: alara_out = config.get('step2', 'alara_out') except: alara_out = "output.txt" responses = config.get('general', 'responses').split(',') for response in responses: response_to_hdf5(alara_out, response) tag_name = response for i, dt in enumerate(decay_times): print('Writing {0} for decay time: {1}'.format(response, dt)) mesh = Mesh(structured=structured, mesh='blank_mesh.h5m') tags = {('TOTAL', dt): tag_name} response_hdf5_to_mesh(mesh, ''.join([response, '.h5']), tags, response) mesh.write_hdf5('{0}_{1}.h5m'.format(response, i + 1)) print('Activation_response step2 complete.')
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean("general", "structured") decay_times = config.get("step2", "decay_times").split(",") try: alara_out = config.get("step2", "alara_out") except: alara_out = "output.txt" responses = config.get("general", "responses").split(",") for response in responses: response_to_hdf5(alara_out, response) tag_name = response for i, dt in enumerate(decay_times): print("Writing {0} for decay time: {1}".format(response, dt)) mesh = Mesh(structured=structured, mesh="blank_mesh.h5m") tags = {("TOTAL", dt): tag_name} response_hdf5_to_mesh(mesh, "".join([response, ".h5"]), tags, response) mesh.write_hdf5("{0}_{1}.h5m".format(response, i + 1)) print("Activation_response step2 complete.")