Exemplo n.º 1
0
def find_iron_parameters(path, run_path, save_folder, linesin):
    converged = False
    owd = os.getcwd()
    moog_file = moog_file = 'Out_moog_'+linesin
    logging.info('Starting 1st iteration for %s', linesin)
    rp.run_amebsa(path, run_path, linesin, 'KURUCZ')
    # checking convergency:
    if os.path.isfile(run_path+moog_file):
        logging.info('First iteration converged for %s', linesin)
    else:
        logging.warning('First iteration did not converge for %s', linesin)
        moog_file = 'Out_moog_b.'+linesin

    n_removed_lines = isp.remove_outliers_from_linelist(run_path+linesin,run_path+moog_file,run_path+linesin+'_new',3.)
    logging.info('Removed %d outliers lines for %s', n_removed_lines, linesin)
    if n_removed_lines > 1:
        linesin = linesin+'_new'
        moog_file = moog_file = 'Out_moog_'+linesin
        logging.info('Starting 2nd iteration for %s', linesin)
        rp.run_amebsa(path, run_path, linesin, 'KURUCZ')
        if os.path.isfile(run_path+moog_file):
            logging.info('Second iteration converged for %s', linesin)
            converged = True
        else:
            logging.error('Final iteration did not converge for %s', linesin)
            moog_file = 'Out_moog_b.'+linesin
    else:
        logging.info('No need for 2nd iteration for %s', filename_lines)
    os.system("cp "+run_path+linesin+" "+save_folder)
    os.system("cp "+run_path+moog_file+" "+save_folder)

    if converged:
        logging.info('Computing errors for %s', linesin)
    else:
        logging.warning('Computing errors for no convergent result of %s', linesin)

    # Put a try catch here
    moogerr.compute_error(run_path, moog_file, moog_file+'.er', True)
    logging.info('Errors computed for %s', linesin)
    os.system("cp "+run_path+moog_file+'.er'+" "+save_folder)
    os.system("cp "+run_path+moog_file+'.eps'+" "+save_folder)

    os.chdir(owd)
    os.system("rm -rf "+run_path+"*")
Exemplo n.º 2
0
def find_iron_parameters_tmcalc_prior(path, run_path, save_folder,
                                      linesin, filename_ares):
    converged = False
    owd = os.getcwd()
    # Default Starting Values
    teff = 5500
    logg = 4.0
    feh = 0.0
    vtur = 1.0
    teff, feh = rp.get_tmcalc_teff_feh(run_path+filename_ares)
    print teff, feh
    if math.isnan(teff):
        teff = 5500
    if math.isnan(feh):
        feh = 0.0
    # Ramirez 2013
    # vtur = 1.163 + 7.808e-4 * (teff - 5800) - 0.494*(logg - 4.30) - 0.05*feh
    # Tsantaki 2013
    vtur = 6.932e-4*teff - 0.348*logg - 1.437
    logging.info('Using the following parameters as initial: %d %5.2f %5.2f %5.2f', teff, logg, feh, vtur)
    moog_file = moog_file = 'Out_moog_'+linesin
    logging.info('Starting 1st iteration for %s', linesin)
    rp.run_amebsa_prior(path, run_path, linesin, teff, logg, feh, vtur, 'KURUCZ')

    # checking convergency:
    if os.path.isfile(run_path+moog_file):
        logging.info('First iteration converged for %s', linesin)
    else:
        logging.warning('First iteration did not converge for %s', linesin)
        moog_file = 'Out_moog_b.'+linesin
    n_removed_lines = isp.remove_outliers_from_linelist(run_path+linesin,run_path+moog_file,run_path+linesin+'_new',3.)
    logging.info('Removed %d outliers lines for %s', n_removed_lines, linesin)
    if n_removed_lines > 1:
        # NEED TO GET THE LAST VALUES FROM MOOG
        teff, logg, feh, vtur = isp.read_parameters_moogfile(run_path+moog_file)
        linesin = linesin+'_new'
        moog_file = moog_file = 'Out_moog_'+linesin
        logging.info('Starting 2nd iteration for %s', linesin)
        logging.info('Using the following parameters as initial: %d %5.2f %5.2f %5.2f', teff, logg, feh, vtur)
        rp.run_amebsa_prior(path, run_path, linesin, teff, logg, feh, vtur, 'KURUCZ')
        if os.path.isfile(run_path+moog_file):
            logging.info('Second iteration converged for %s', linesin)
            converged = True
        else:
            logging.error('Final iteration did not converge for %s', linesin)
            moog_file = 'Out_moog_b.'+linesin
    else:
        logging.info('No need for 2nd iteration for %s', filename_lines)
        os.system("cp "+run_path+linesin+" "+save_folder)
        os.system("cp "+run_path+moog_file+" "+save_folder)

    if converged:
        logging.info('Computing errors for %s', linesin)
    else:
        logging.warning('Computing errors for no convergent result of %s', linesin)

    # Put a try catch here
    moogerr.compute_error(run_path, moog_file, moog_file+'.er', True)
    logging.info('Errors computed for %s', linesin)
    os.system("cp "+run_path+moog_file+'.er'+" "+save_folder)
    os.system("cp "+run_path+moog_file+'.eps'+" "+save_folder)

    os.chdir(owd)