def test_half_life(): f = StringIO(ensdf3_sample) f.seek(0) hl = ensdf.half_life(f) assert_equal(hl, [(10030, 0.0, 20030, to_sec(12.32, 'Y'), 1.0), (20030, 0.0, 20030, np.inf, 1.0), (20030, 0.0, 20030, np.inf, 1.0), ])
def test_half_life(): f = StringIO(ensdf3_sample) f.seek(0) hl = ensdf.half_life(f) assert_equal(hl, [ (10030, 0.0, 20030, to_sec(12.32, 'Y'), 1.0), (20030, 0.0, 20030, np.inf, 1.0), (20030, 0.0, 20030, np.inf, 1.0), ])
def _to_time(tstr, errstr): t = tstr.strip() # This accepts questionable levels t = t.replace('?', '') tobj = [s.strip(' ()') for s in t.split()] if len(tobj) == 2: t, t_unit = tobj t, terr = _get_val_err(t, errstr) tfinal = to_sec(t, t_unit) tfinalerr = None if type(terr) == float: tfinalerr = to_sec(terr, t_unit) elif terr is not None: tfinalerr = to_sec(terr[0], t_unit), to_sec(terr[1], t_unit) elif 'STABLE' in t: tfinal = np.inf tfinalerr = None else: tfinal = None tfinalerr = None return tfinal, tfinalerr
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean("general", "structured") sub_voxel = config.getboolean("general", "sub_voxel") decay_times = config.get("step2", "decay_times").split(",") output = config.get("step2", "output") tot_phtn_src_intensities = config.get("step2", "tot_phtn_src_intensities") tag_name = "source_density" if sub_voxel: geom = config.get("step1", "geom") load(geom) cell_mats = cell_materials(geom) else: cell_mats = None h5_file = "phtn_src.h5" if not isfile(h5_file): photon_source_to_hdf5(filename="phtn_src", nucs="total") intensities = "Total photon source intensities (p/s)\n" e_bounds = phtn_src_energy_bounds("alara_inp") for i in range(len(e_bounds)): e_bounds[i] /= 1.0e6 # convert unit from eV to MeV for i, dt in enumerate(decay_times): print("Writing source for decay time: {0} to mesh".format(dt)) mesh = Mesh(structured=structured, mesh="blank_mesh.h5m") tags = {("TOTAL", dt): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel, cell_mats=cell_mats) p_src_filename = "{0}_{1}.h5m".format(output, i + 1) intensity = total_photon_source_intensity(mesh, tag_name, sub_voxel=sub_voxel) mesh = tag_e_bounds(mesh, e_bounds) mesh = tag_source_intensity(mesh, intensity) # get and tag decay time decay_time = to_sec(float(dt.split()[0]), dt.split()[1]) mesh = tag_decay_time(mesh, decay_time) # set version manually when changing the information of source.h5m mesh = tag_version(mesh) mesh.write_hdf5("{0}_{1}.h5m".format(output, i + 1)) intensities += "{0}: {1}\n".format(dt, intensity) with open(tot_phtn_src_intensities, "w") as f: f.write(intensities) print("R2S step2 complete.")
def _convert_unit_to_s(dc): """ This function return a float number represent a time in unit of s. Parameters ---------- dc : string. Contain a num and an unit. Returns ------- a float number """ # get num and unit num, unit = dc.split() return to_sec(float(num), unit)
def step2(): config = ConfigParser.ConfigParser() config.read(config_filename) structured = config.getboolean('general', 'structured') sub_voxel = config.getboolean('general', 'sub_voxel') decay_times = config.get('step2', 'decay_times').split(',') output = config.get('step2', 'output') tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities') tag_name = "source_density" if sub_voxel: geom = config.get('step1', 'geom') load(geom) cell_mats = cell_materials(geom) else: cell_mats = None h5_file = 'phtn_src.h5' if not isfile(h5_file): photon_source_to_hdf5(filename='phtn_src', nucs='total') intensities = "Total photon source intensities (p/s)\n" e_bounds = phtn_src_energy_bounds("alara_inp") for i in range(len(e_bounds)): e_bounds[i] /= 1.0e6 # convert unit from eV to MeV for i, dt in enumerate(decay_times): print('Writing source for decay time: {0} to mesh'.format(dt)) mesh = Mesh(structured=structured, mesh='blank_mesh.h5m') tags = {('TOTAL', dt): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags, sub_voxel=sub_voxel, cell_mats=cell_mats) intensity = total_photon_source_intensity(mesh, tag_name, sub_voxel=sub_voxel) mesh = tag_e_bounds(mesh, e_bounds) mesh = tag_source_intensity(mesh, intensity) # get and tag decay time decay_time = to_sec(float(dt.split()[0]), dt.split()[1]) mesh = tag_decay_time(mesh, decay_time) # set version manually when changing the information of source.h5m mesh = tag_version(mesh) mesh.write_hdf5('{0}_{1}.h5m'.format(output, i+1)) intensities += "{0}: {1}\n".format(dt, intensity) with open(tot_phtn_src_intensities, 'w') as f: f.write(intensities) print('R2S step2 complete.')
def _convert_unit_to_s(dt): """ This function return a float number represent a time in unit of s. Parameters ---------- dt : string. Decay time. Contain a num and an unit. Returns ------- a float number """ dt = str_to_unicode(dt) # get num and unit if dt == "shutdown": num, unit = "0.0", "s" else: num, unit = dt.split() return to_sec(float(num), unit)
def half_life(ensdf): """Grabs the half-lives from an ENSDF file. Parameters ---------- ensdf : str or file-like object ENSDF file to inspect for half-life data Returns ------- data : list of 5-tuples List of tuples where the indices match 1. from_nuclide, int (zzaaam) 2. level, float (MeV) - from_nuc's energy level 3. to_nuclide, int (zzaaam) 4. half_life, float (seconds) 5. branch_ratio, float (frac) """ opened_here = False if isinstance(ensdf, basestring): ensdf = open(ensdf, 'r') opened_here = True data = [] from_nuc = 0 half_life = 0.0 level = 0.0 valid_from_nuc = False # Run through the file lines = ensdf.readlines() for i, line in enumerate(lines): # See if the line matches m = _level_regex.match(line) if m is not None: g = m.groups() # grab the from nuclide try: from_nuc = _to_zzaaam(g[0], g[-2], g[-1]) valid_from_nuc = True except: valid_from_nuc = False continue # parse energy level try: level = float(g[1]) * 1E-3 except ValueError: pass # Grab the half-lives time_info = g[2].replace('?', '').strip() if 0 == len(time_info): valid_from_nuc = False elif time_info == 'STABLE': half_life = np.inf data += [(from_nuc, 0.0, from_nuc, half_life, 1.0)] else: time_unit = [s.strip() for s in time_info.split()] if 2 == len(time_unit): hl, unit = time_unit half_life = to_sec(float(hl), unit) continue m = _level_cont_regex.match(line) if m is not None and valid_from_nuc: g = m.groups() dat = dict([d.split('=')[:2] for d in g[-1].replace('$', ' ').split() if '=' in d]) dat = dict([(_decay_to[key](from_nuc), _to_float(val)*0.01) for key, val in dat.items() if key in _decay_to.keys()]) data += [(from_nuc, level, to_nuc, half_life, br) for to_nuc, br in dat.items() if 0.0 < br] continue if opened_here: ensdf.close() return data
def test_to_sec(): assert_equal(120.0, utils.to_sec(2, 'M'))
def test_to_sec(): # as assert_equal(2e-18, utils.to_sec(2, 'AS')) assert_equal(2e-18, utils.to_sec(2, 'attosec')) assert_equal(2e-18, utils.to_sec(2, 'attosecond')) assert_equal(2e-18, utils.to_sec(2, 'attoseconds')) # fs assert_equal(2e-15, utils.to_sec(2, 'FS')) assert_equal(2e-15, utils.to_sec(2, 'femtosec')) assert_equal(2e-15, utils.to_sec(2, 'femtosecond')) assert_equal(2e-15, utils.to_sec(2, 'femtoseconds')) # ps assert_equal(2e-12, utils.to_sec(2, 'PS')) assert_equal(2e-12, utils.to_sec(2, 'picosec')) assert_equal(2e-12, utils.to_sec(2, 'picosecond')) assert_equal(2e-12, utils.to_sec(2, 'picoseconds')) # ns assert_equal(2e-9, utils.to_sec(2, 'NS')) assert_equal(2e-9, utils.to_sec(2, 'nanosec')) assert_equal(2e-9, utils.to_sec(2, 'nanosecond')) assert_equal(2e-9, utils.to_sec(2, 'nanoseconds')) # us assert_equal(2e-6, utils.to_sec(2, 'US')) assert_equal(2e-6, utils.to_sec(2, 'microsec')) assert_equal(2e-6, utils.to_sec(2, 'microsecond')) assert_equal(2e-6, utils.to_sec(2, 'microseconds')) # ms assert_equal(2e-3, utils.to_sec(2, 'MS')) assert_equal(2e-3, utils.to_sec(2, 'millisec')) assert_equal(2e-3, utils.to_sec(2, 'millisecond')) assert_equal(2e-3, utils.to_sec(2, 'milliseconds')) # s assert_equal(2.0, utils.to_sec(2, 'S')) assert_equal(2.0, utils.to_sec(2, 'sec')) assert_equal(2.0, utils.to_sec(2, 'second')) assert_equal(2.0, utils.to_sec(2, 'seconds')) # m assert_equal(120.0, utils.to_sec(2, 'M')) assert_equal(120.0, utils.to_sec(2, 'min')) assert_equal(120.0, utils.to_sec(2, 'minute')) assert_equal(120.0, utils.to_sec(2, 'minutes')) # h assert_equal(7200.0, utils.to_sec(2, 'H')) assert_equal(7200.0, utils.to_sec(2, 'hour')) assert_equal(7200.0, utils.to_sec(2, 'hours')) # d assert_equal(172800.0, utils.to_sec(2, 'D')) assert_equal(172800.0, utils.to_sec(2, 'day')) assert_equal(172800.0, utils.to_sec(2, 'days')) # w assert_equal(1209600.0, utils.to_sec(2, 'W')) assert_equal(1209600.0, utils.to_sec(2, 'week')) assert_equal(1209600.0, utils.to_sec(2, 'weeks')) # y assert_equal(63115200.0, utils.to_sec(2, 'Y')) assert_equal(63115200.0, utils.to_sec(2, 'year')) assert_equal(63115200.0, utils.to_sec(2, 'years')) # c assert_equal(6311520000.0, utils.to_sec(2, 'C')) assert_equal(6311520000.0, utils.to_sec(2, 'century')) assert_equal(6311520000.0, utils.to_sec(2, 'centuries')) # undifined unit trigs ValueError assert_raises(ValueError, utils.to_sec, 2, 'month')
def half_life(ensdf): """Grabs the half-lives from an ENSDF file. Parameters ---------- ensdf : str or file-like object ENSDF file to inspect for half-life data Returns ------- data : list of 5-tuples List of tuples where the indices match 1. from_nuclide, int (zzaaam) 2. level, float (MeV) - from_nuc's energy level 3. to_nuclide, int (zzaaam) 4. half_life, float (seconds) 5. branch_ratio, float (frac) """ opened_here = False if isinstance(ensdf, basestring): ensdf = open(ensdf, 'r') opened_here = True data = [] from_nuc = 0 half_life = 0.0 level = 0.0 valid_from_nuc = False # Run through the file lines = ensdf.readlines() for i, line in enumerate(lines): # See if the line matches m = _level_regex.match(line) if m is not None: g = m.groups() # grab the from nuclide try: from_nuc = _to_zzaaam(g[0], g[-2], g[-1]) valid_from_nuc = True except: valid_from_nuc = False continue # parse energy level try: level = float(g[1]) * 1E-3 except ValueError: pass # Grab the half-lives time_info = g[2].replace('?', '').strip() if 0 == len(time_info): valid_from_nuc = False elif time_info == 'STABLE': half_life = np.inf data += [(from_nuc, 0.0, from_nuc, half_life, 1.0)] else: time_unit = [s.strip() for s in time_info.split()] if 2 == len(time_unit): hl, unit = time_unit half_life = to_sec(float(hl), unit) continue m = _level_cont_regex.match(line) if m is not None and valid_from_nuc: g = m.groups() dat = dict([ d.split('=')[:2] for d in g[-1].replace('$', ' ').split() if '=' in d ]) dat = dict([(_decay_to[key](from_nuc), _to_float(val) * 0.01) for key, val in dat.items() if key in _decay_to.keys()]) data += [(from_nuc, level, to_nuc, half_life, br) for to_nuc, br in dat.items() if 0.0 < br] continue if opened_here: ensdf.close() return data
def test_to_sec(): # as assert_equal(2e-18, utils.to_sec(2, "AS")) assert_equal(2e-18, utils.to_sec(2, "attosec")) assert_equal(2e-18, utils.to_sec(2, "attosecond")) assert_equal(2e-18, utils.to_sec(2, "attoseconds")) # fs assert_equal(2e-15, utils.to_sec(2, "FS")) assert_equal(2e-15, utils.to_sec(2, "femtosec")) assert_equal(2e-15, utils.to_sec(2, "femtosecond")) assert_equal(2e-15, utils.to_sec(2, "femtoseconds")) # ps assert_equal(2e-12, utils.to_sec(2, "PS")) assert_equal(2e-12, utils.to_sec(2, "picosec")) assert_equal(2e-12, utils.to_sec(2, "picosecond")) assert_equal(2e-12, utils.to_sec(2, "picoseconds")) # ns assert_equal(2e-9, utils.to_sec(2, "NS")) assert_equal(2e-9, utils.to_sec(2, "nanosec")) assert_equal(2e-9, utils.to_sec(2, "nanosecond")) assert_equal(2e-9, utils.to_sec(2, "nanoseconds")) # us assert_equal(2e-6, utils.to_sec(2, "US")) assert_equal(2e-6, utils.to_sec(2, "microsec")) assert_equal(2e-6, utils.to_sec(2, "microsecond")) assert_equal(2e-6, utils.to_sec(2, "microseconds")) # ms assert_equal(2e-3, utils.to_sec(2, "MS")) assert_equal(2e-3, utils.to_sec(2, "millisec")) assert_equal(2e-3, utils.to_sec(2, "millisecond")) assert_equal(2e-3, utils.to_sec(2, "milliseconds")) # s assert_equal(2.0, utils.to_sec(2, "S")) assert_equal(2.0, utils.to_sec(2, "sec")) assert_equal(2.0, utils.to_sec(2, "second")) assert_equal(2.0, utils.to_sec(2, "seconds")) # m assert_equal(120.0, utils.to_sec(2, "M")) assert_equal(120.0, utils.to_sec(2, "min")) assert_equal(120.0, utils.to_sec(2, "minute")) assert_equal(120.0, utils.to_sec(2, "minutes")) # h assert_equal(7200.0, utils.to_sec(2, "H")) assert_equal(7200.0, utils.to_sec(2, "hour")) assert_equal(7200.0, utils.to_sec(2, "hours")) # d assert_equal(172800.0, utils.to_sec(2, "D")) assert_equal(172800.0, utils.to_sec(2, "day")) assert_equal(172800.0, utils.to_sec(2, "days")) # w assert_equal(1209600.0, utils.to_sec(2, "W")) assert_equal(1209600.0, utils.to_sec(2, "week")) assert_equal(1209600.0, utils.to_sec(2, "weeks")) # y assert_equal(63115200.0, utils.to_sec(2, "Y")) assert_equal(63115200.0, utils.to_sec(2, "year")) assert_equal(63115200.0, utils.to_sec(2, "years")) # c assert_equal(6311520000.0, utils.to_sec(2, "C")) assert_equal(6311520000.0, utils.to_sec(2, "century")) assert_equal(6311520000.0, utils.to_sec(2, "centuries")) # undifined unit trigs ValueError assert_raises(ValueError, utils.to_sec, 2, "month")