Esempio n. 1
0
def phyat2model(phyat_file, model_file):
    """  
    generate a model_file file from a phyat_file, setting all the master lines to I=1.0
    """
    
    list_phyat = read_data(phyat_file)
    with open(model_file, 'w') as f:
        for line in list_phyat:
            if line['ref'] == 999:
                new_num = line['num']-90000000000000
                f.write('{0:14d} {1[id]:9s}      1.000 0.000 1.000e+04  1.000  0000000000000   1   1.00 {1[comment]:>15s}'.format(new_num, line))
Esempio n. 2
0
def get_extra_atoms(extra_file=None, uniq=False):

    if extra_file is None:
        return []
    extra_data = read_data(extra_file)
    atoms = []
    for ID in extra_data.id:
        IDs = split_atom(ID)
        if IDs[0] is None:
            atoms.append('{0[1]}{0[2]}'.format(IDs))
        else:
            atoms.append('{0[0]}{0[1]}{0[2]}'.format(IDs))
    if uniq:
        res = unique(atoms)
    else:
        res = atoms
    return res
Esempio n. 3
0
def get_extra_atoms(extra_file=None,uniq=False):
    
    if extra_file is None:
        return []
    extra_data = read_data(extra_file)
    atoms=[]
    for ID in extra_data.id:
        IDs = split_atom(ID)
        if IDs[0] is None:
            atoms.append('{0[1]}{0[2]}'.format(IDs))
        else:
            atoms.append('{0[0]}{0[1]}{0[2]}'.format(IDs))
    if uniq:
        res = unique(atoms)
    else:
        res = atoms
    return res
Esempio n. 4
0
def phyat2model(phyat_file,
                model_file,
                ion_frac_file,
                norm_hbeta=1e4,
                abund_file='asplund_2009.dat',
                ion_frac_min=1e-4,
                verbose=False):
    """  
    generate a model_file file from a phyat_file, setting all the master lines to I=i_rel/norm
    norm by default corresponds to Hbeta = 1e4
    """

    ab_data = np.genfromtxt(abund_file, dtype='U3, float', names='elem, abund')

    ion_frac_data = np.genfromtxt(ion_frac_file,
                                  dtype='U4,float',
                                  names='ion, ion_frac')
    ion_frac_dic = {}
    for record in ion_frac_data:
        ion_frac_dic[record['ion']] = record['ion_frac']

    list_phyat = read_data(phyat_file)
    Hbeta_num = 90101000000000
    Ibeta = list_phyat[list_phyat['num'] == Hbeta_num]['i_rel'][0]
    norm = Ibeta / norm_hbeta * ion_frac_dic['H1']
    num_tab = []

    with open(model_file, 'w') as f:
        for line in list_phyat:
            if line['ref'] == 999:
                num = line['num']
                new_num = int(str(num)[1::])
                if new_num in num_tab:
                    raise ValueError(
                        'Duplicate reference number {}'.format(new_num))
                else:
                    num_tab.append(new_num)
                Z = int(str(num)[1:3])
                spec = int(str(num)[3:5])
                type_ = int(str(num)[5:6])
                if type_ == 3:  # Collision lines
                    spec -= 1
                elem = Z_inv[Z]
                elem2 = line['id'].split('_')[0]
                coeff_abund = 1.0
                if elem2 == 'D':
                    elem = 'D'
                elif elem2 == '3He':
                    coeff_abund = 1e-3
                ion = elem + str(spec)
                if Z < 90:
                    abund = 10**(ab_data[ab_data['elem'] == elem]['abund'][0] -
                                 12) * coeff_abund
                    ion_frac = 1.0
                    if ion_frac_dic is not None:
                        if ion in ion_frac_dic:
                            ion_frac = ion_frac_dic[ion]
                        else:
                            # TODO we need to look for the available ion with similar structure
                            ionFe = 'Fe' + str(spec)
                            ion_frac = ion_frac_dic[ionFe]
                else:  # No element lines. Absorption. Set to 1.0 by canceling abund / norm
                    abund = norm
                    ion_frac = 1.0
                if ion_frac < ion_frac_min:
                    ion_frac = ion_frac_min
                if verbose:
                    print(line['num'], Z, Z_inv[Z], spec, abund, ion_frac)
                intens = line['i_rel'] / norm * abund * ion_frac
                line['comment'] = line['comment'].strip()
                f.write(
                    '{0:14d} {1[id]:9s}      1.000 0.000{2:10.3e}  1.000  0000000000000   1   1.00 {1[comment]:<100s}\n'
                    .format(new_num, line, intens))