def _parse_decay_dataset(lines, decay_s): """ This parses a gamma ray dataset. It returns a tuple of the parsed data. Parameters ---------- lines : list of str list containing lines from one dataset of an ensdf file decay_s : str string of the decay type Returns ------- Tuple of decay parameters which is described in detail in gamma_rays docs """ gammarays = [] betas = [] alphas = [] ecbp = [] ident = _ident.match(lines[0]) daughter = ident.group(1) daughter_id = abs(_to_id(daughter)) parent = ident.group(2).split()[0] parent = parent.split('(')[0] parents = parent.split(',') if len(parents) > 1: pfinal = abs(_to_id(parents[0])) else: pfinal = abs(_to_id(parents[0][:5])) tfinal = None tfinalerr = None nrbr = None nbbr = None nrbr_err = None nbbr_err = None nb_err = None br_err = None nb = None br = None level = None special = " " goodgray = False parent2 = None for line in lines: level_l = _level_regex.match(line) if level_l is not None: level, half_lifev, from_nuc, \ state, special = _parse_level_record(level_l) continue b_rec = _beta.match(line) if b_rec is not None: dat = _parse_beta_record(b_rec) if parent2 is None: bparent = pfinal else: bparent = parent2 level = 0.0 if level is None else level bdaughter = abs(data.id_from_level(_to_id(daughter), level)) betas.append([bparent, bdaughter, dat[0], 0.0, dat[2]]) bc_rec = _betac.match(line) if bc_rec is not None: bcdat = _parse_beta_continuation_record(bc_rec) if bcdat[0] is not None: if bc_rec.group(2) == 'B': betas[-1][3] = bcdat[0] else: ecbp[-1][3] = bcdat[0] bggc = _gc.match(line) conv = _parse_gamma_continuation_record(bggc, dat[2], dat[8]) if 'K' in conv: ecbp[-1][-3] = conv['K'][0] if 'L' in conv: ecbp[-1][-2] = conv['L'][0] if 'M' in conv: ecbp[-1][-1] = conv['M'][0] a_rec = _alpha.match(line) if a_rec is not None: dat = _parse_alpha_record(a_rec) if parent2 is None: aparent = pfinal else: aparent = parent2 level = 0.0 if level is None else level adaughter = abs(data.id_from_level(_to_id(daughter), level)) alphas.append([aparent, adaughter, dat[0], dat[2]]) ec_rec = _ec.match(line) if ec_rec is not None: dat = _parse_ec_record(ec_rec) if parent2 is None: ecparent = pfinal else: ecparent = parent2 level = 0.0 if level is None else level ecdaughter = abs(data.id_from_level(_to_id(daughter), level)) ecbp.append([ecparent, ecdaughter, dat[0], 0.0, dat[2], dat[4], 0, 0, 0]) continue g_rec = _g.match(line) if g_rec is not None: dat = _parse_gamma_record(g_rec) if dat[0] is not None: gparent = 0 gdaughter = 0 if level is not None: gparent = abs(data.id_from_level(_to_id(daughter), level, special)) dlevel = level - dat[0] gdaughter = abs(data.id_from_level(_to_id(daughter), dlevel, special)) if parent2 is None: gp2 = pfinal else: gp2 = parent2 dat.insert(0, daughter_id) dat.insert(0, gp2) dat.insert(0, gdaughter) dat.insert(0, gparent) for i in range(3): dat.append(0) gammarays.append(dat) goodgray = True else: goodgray = False continue gc_rec = _gc.match(line) if gc_rec is not None and goodgray is True: conv = _parse_gamma_continuation_record(gc_rec, gammarays[-1][6], gammarays[-1][10]) if 'K' in conv: gammarays[-1][-3] = conv['K'][0] if 'L' in conv: gammarays[-1][-2] = conv['L'][0] if 'M' in conv: gammarays[-1][-1] = conv['M'][0] continue n_rec = _norm.match(line) if n_rec is not None: nr, nr_err, nt, nt_err, br, br_err, nb, nb_err, nrbr, nrbr_err = \ _parse_normalization_record(n_rec) if nb is not None and br is not None: nbbr = nb * br if nb_err is not None and br_err is not None and nb_err != 0: nbbr_err = nbbr*((br_err/br) ** 2 * (nb_err/nb) ** 2) ** 0.5 continue np_rec = _normp.match(line) if np_rec is not None: nrbr2, nrbr_err2, ntbr, ntbr_err, nbbr2, nbbr_err2 = \ _parse_production_normalization_record(np_rec) if nrbr2 is not None and nrbr is None: nrbr = nrbr2 nrbr_err = nrbr_err2 if nbbr2 is not None and nbbr is None: nbbr = nbbr2 nbbr_err = nbbr_err2 continue p_rec = _p.match(line) if p_rec is not None: # only 2 parents are supported so this can be here multi = False if parent2 is not None: multi = True pfinal = [parent2,] tfinal = [t,] tfinalerr = [terr,] parent2, t, terr, e, e_err, special = _parse_parent_record(p_rec) parent2 = abs(data.id_from_level(_to_id(parent2), e, special)) if terr is not None and not isinstance(terr, float): terr = (terr[0] + terr[1])/2.0 if multi: tfinal.append(t) tfinalerr.append(terr) pfinal.append(parent2) else: tfinal = t tfinalerr = terr pfinal = parent2 continue if len(gammarays) > 0 or len(alphas) > 0 or len(betas) > 0 or len(ecbp) > 0: if len(parents) > 1 and parent2 is None: pfinal = [] for item in parents: pfinal.append(_to_id(item)) return pfinal, daughter_id, rxname.id(decay_s.strip().lower()), \ tfinal, tfinalerr, \ br, br_err, nrbr, nrbr_err, nbbr, nbbr_err, gammarays, alphas, \ betas, ecbp return None
def test_id_from_level(): assert_equal(data.id_from_level(811920000, 445, "X"), 811920010) assert_equal(data.id_from_level(561370000, 662), 561370002)
def _parse_decay_dataset(lines, decay_s): """ This parses a gamma ray dataset. It returns a tuple of the parsed data. Parameters ---------- lines : list of str list containing lines from one dataset of an ensdf file decay_s : str string of the decay type Returns ------- Tuple of decay parameters which is described in detail in gamma_rays docs """ gammarays = [] betas = [] alphas = [] ecbp = [] ident = _ident.match(lines[0]) daughter = ident.group(1) daughter_id = _to_id(daughter) parent = ident.group(2).split()[0] parent = parent.split('(')[0] parents = parent.split(',') if len(parents) > 1: pfinal = _to_id(parents[0]) else: pfinal = _to_id(parents[0][:5]) tfinal = None tfinalerr = None nrbr = None nbbr = None nrbr_err = None nbbr_err = None nb_err = None br_err = None nb = None br = None level = None special = " " goodgray = False parent2 = None for line in lines: level_l = _level_regex.match(line) if level_l is not None: level, half_lifev, from_nuc, \ state, special = _parse_level_record(level_l) continue b_rec = _beta.match(line) if b_rec is not None: dat = _parse_beta_record(b_rec) if parent2 is None: bparent = pfinal else: bparent = parent2 level = 0.0 if level is None else level bdaughter = data.id_from_level(_to_id(daughter), level) betas.append([bparent, bdaughter, dat[0], 0.0, dat[2]]) bc_rec = _betac.match(line) if bc_rec is not None: bcdat = _parse_beta_continuation_record(bc_rec) if bcdat[0] is not None: if bc_rec.group(2) == 'B': betas[-1][3] = bcdat[0] else: ecbp[-1][3] = bcdat[0] bggc = _gc.match(line) conv = _parse_gamma_continuation_record(bggc, dat[2], dat[8]) if 'K' in conv: ecbp[-1][-3] = conv['K'][0] if 'L' in conv: ecbp[-1][-2] = conv['L'][0] if 'M' in conv: ecbp[-1][-1] = conv['M'][0] a_rec = _alpha.match(line) if a_rec is not None: dat = _parse_alpha_record(a_rec) if parent2 is None: aparent = pfinal else: aparent = parent2 level = 0.0 if level is None else level adaughter = data.id_from_level(_to_id(daughter), level) alphas.append((aparent, adaughter, dat[0], dat[2])) ec_rec = _ec.match(line) if ec_rec is not None: dat = _parse_ec_record(ec_rec) if parent2 is None: ecparent = pfinal else: ecparent = parent2 level = 0.0 if level is None else level ecdaughter = data.id_from_level(_to_id(daughter), level) ecbp.append([ecparent, ecdaughter, dat[0], 0.0, dat[2], dat[4], 0, 0, 0]) continue g_rec = _g.match(line) if g_rec is not None: dat = _parse_gamma_record(g_rec) if dat[0] is not None: gparent = 0 gdaughter = 0 if level is not None: gparent = data.id_from_level(_to_id(daughter), level, special) dlevel = level - dat[0] gdaughter = data.id_from_level(_to_id(daughter), dlevel, special) if parent2 is None: gp2 = pfinal else: gp2 = parent2 dat.insert(0, daughter_id) dat.insert(0, gp2) dat.insert(0, gdaughter) dat.insert(0, gparent) for i in range(3): dat.append(0) gammarays.append(dat) goodgray = True else: goodgray = False continue gc_rec = _gc.match(line) if gc_rec is not None and goodgray is True: conv = _parse_gamma_continuation_record(gc_rec, gammarays[-1][6], gammarays[-1][10]) if 'K' in conv: gammarays[-1][-3] = conv['K'][0] if 'L' in conv: gammarays[-1][-2] = conv['L'][0] if 'M' in conv: gammarays[-1][-1] = conv['M'][0] continue n_rec = _norm.match(line) if n_rec is not None: nr, nr_err, nt, nt_err, br, br_err, nb, nb_err, nrbr, nrbr_err = \ _parse_normalization_record(n_rec) if nb is not None and br is not None: nbbr = nb * br if nb_err is not None and br_err is not None and nb_err != 0: nbbr_err = nbbr*((br_err/br) ** 2 * (nb_err/nb) ** 2) ** 0.5 continue np_rec = _normp.match(line) if np_rec is not None: nrbr2, nrbr_err2, ntbr, ntbr_err, nbbr2, nbbr_err2 = \ _parse_production_normalization_record(np_rec) if nrbr2 is not None and nrbr is None: nrbr = nrbr2 nrbr_err = nrbr_err2 if nbbr2 is not None and nbbr is None: nbbr = nbbr2 nbbr_err = nbbr_err2 continue p_rec = _p.match(line) if p_rec is not None: # only 2 parents are supported so this can be here multi = False if parent2 is not None: multi = True pfinal = [parent2,] tfinal = [t,] tfinalerr = [terr,] parent2, t, terr, e, e_err, special = _parse_parent_record(p_rec) parent2 = data.id_from_level(_to_id(parent2), e, special) if terr is not None and not isinstance(terr, float): terr = (terr[0] + terr[1])/2.0 if multi: tfinal.append(t) tfinalerr.append(terr) pfinal.append(parent2) else: tfinal = t tfinalerr = terr pfinal = parent2 continue if len(gammarays) > 0 or len(alphas) > 0 or len(betas) > 0 or len(ecbp) > 0: if len(parents) > 1 and parent2 is None: pfinal = [] for item in parents: pfinal.append(_to_id(item)) return pfinal, daughter_id, rxname.id(decay_s.strip().lower()), \ tfinal, tfinalerr, \ br, br_err, nrbr, nrbr_err, nbbr, nbbr_err, gammarays, alphas, \ betas, ecbp return None
def test_id_from_level(): assert_equal(data.id_from_level(811920000, 445, 'X'), 811920010) assert_equal(data.id_from_level(561370000, 662), 561370002)