def get_ew(path, line_data): """ Get the EW from the moog file output. (just for 1 line in input list for MOOG) Using MOOG 2014... """ create_lines_ew_moog(path+'lines_ew.in', [line_data]) rp.create_ewfind_par(path, 'lines_ew.in') rp.run_MOOG2014(path, 'ewfind.par') loggf_out, ew_calc = np.loadtxt(path+'abund_plan_tspec.test', skiprows=5, usecols=(2, 6), unpack=True) return loggf_out, ew_calc
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+"*")
def run_chain_parameters(): os.system("rm -rf SPECPAR.log") logging.basicConfig(filename='SPECPAR.log', format='%(asctime)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) logging.info('Started') path = './' run_path = 'running_dir/' save_path = 'save_folder/' # CREATE folders # Running ARES linelist_ew = rp.get_install_dir()+rc.read_config_param('linelists', 'iron_parameters').replace("'", "") rp.ares_make_mine_opt(run_path, linelist_ew) logging.info('ARES Started') rp.run_ares(run_path) logging.info('ARES Finished') # Creating moog linelist filename_lines = rp.get_install_dir()+rc.read_config_param('linelists', 'iron_parameters').replace("'", "") filename_ares = rc.read_config_param('ares', 'fileout').replace("'", "") filename_out = 'lines.' + filename_ares isp.ares_to_lines(run_path+filename_ares, filename_lines, run_path+filename_out, 4000, 9999, 5, 150) logging.info('Starting AMEBSA for %s', filename_out) # find_iron_parameters(path,run_path,save_path,filename_out) find_iron_parameters_tmcalc_prior(path, run_path, save_path, filename_out, filename_ares) logging.info('Finished')
def run_chain_tmcalc(): os.system("rm -rf SPECPAR.log") logging.basicConfig(filename='SPECPAR.log', format='%(asctime)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) logging.info('Started') path = './' run_path = 'running_dir/' save_path = 'save_folder/' # CREATE folders # Running ARES linelist_ew = rp.get_install_dir()+rc.read_config_param('linelists', 'tmcalc_linelist').replace("'", "") rp.ares_make_mine_opt(run_path, linelist_ew) logging.info('ARES Started') rp.run_ares(run_path) logging.info('ARES Finished') filename_ares = rc.read_config_param('ares', 'fileout').replace("'", "") logging.info('Getting TMCALC results') print filename_ares teff, feh = rp.get_tmcalc_teff_feh(run_path+filename_ares) print 'Teff:', teff print 'Feh:', feh
def run_moog_kurucz(teff, logg, metal, vtur): rp.create_model_kurucz('./', teff, logg, metal, vtur) rp.run_MOOG('./', 'abfind.par')
def error(filename, fix_logg=False): """ Computes the errors """ # Read the file logout = readmoog(filename) # First determine the set of variables that will be needed to # determine the errors. teff = logout[0] logg = logout[1] vt = logout[2] metal = logout[3] abundfe = logout[5] # abundfe = (logout[5] + logout[8])/2. sigmafe1 = logout[6]/np.sqrt(logout[4]) sigmafe2 = logout[9]/np.sqrt(logout[7]) # Do least squaresfits for FeI vs EW and EP a1, b1, siga1, sigb1 = lsq(logout[19], logout[12]) a2, b2, siga2, sigb2 = lsq(logout[18], logout[12]) # Build new abfind.par file linesfile = filename.replace('Out_moog_', '') linesfile = linesfile.replace('b.', '') rp.create_abfind_par('./', linesfile) ############################## # VT: Run MOOG with +0.1 dex # ############################## # Make intermod and transform file run_moog(teff, logg, metal, vt + 0.10) # Read the results logoutvt = readmoog('abund_plan_tspec.test') # Error on microturbulence if logoutvt[11] == 0: errormicro = abs(siga1/0.001) * 0.10 else: errormicro = abs(siga1/logoutvt[11]) * 0.10 # Determine the variation of FeI deltafe1micro = abs((errormicro/0.10) * (logoutvt[5]-abundfe)) ######### # TEFF: # ######### # With these values, calculate the error on the slope of FeI with # excitation potential addslope = (errormicro/0.10) * logoutvt[10] # Add this quadratically to the error on the original FeI-EP slope errorslopeEP = np.hypot(addslope, siga2) # Run MOOG with teff 100K extra run_moog(teff + 100, logg, metal, vt) # Read the results logoutteff = readmoog('abund_plan_tspec.test') # Error on temperature (assume the variation on the slope is linear # with the error) errorteff = abs(errorslopeEP/logoutteff[10]) * 100 # Determine the variation of FeI deltafe1teff = abs((errorteff/100.) * (logoutteff[5]-abundfe)) ######### # logg: # ######### if not fix_logg: # Calculate the variation that the error in Teff caused in the # abundances of FeII addfe2error = abs((errorteff/100.) * (logoutteff[8]-abundfe)) # Quadratically add it to the original abundance error sigmatotalfe2 = np.hypot(sigmafe2, addfe2error) # Run MOOG with logg minus 0.20 run_moog(teff, logg - 0.20, metal, vt) # Read the results logoutlogg = readmoog('abund_plan_tspec.test') # Error on logg errorlogg = abs(sigmatotalfe2 / (logoutlogg[8]-abundfe) * 0.2) else: errorlogg = 0.0 ########### # [Fe/H]: # ########### # Take into account the dispersion errors on FeI by teff and vt errors # Add them quadratically print sigmafe1, deltafe1teff, deltafe1micro errormetal = math.sqrt(sigmafe1**2 + deltafe1teff**2 + deltafe1micro**2) teff, errorteff = int(teff), int(errorteff) logg, errorlogg = round(logg, 2), round(errorlogg, 2) vt, errorvt = round(vt, 2), round(errormicro, 2) metal, errormetal = round(metal, 2), round(errormetal, 2) logg, errorlogg = round(logg, 2), round(errorlogg, 2) result = (teff, errorteff, logg, errorlogg, vt, errormicro, metal, errormetal, logout[4], logout[7], logout[6], logout[9]) return result
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)
def run_chain_get_element_abund(moogfile, element): run_path = 'running_dir/' save_path = 'save_folder/' teff, logg, feh, vtur = isp.read_parameters_moogfile(moogfile) linelist_element = rp.get_install_dir()+rc.read_config_param('linelists', element+'_abund').replace("'", "") rp.ares_make_mine_opt(run_path, linelist_element) rp.run_ares(run_path) filename_ares = rc.read_config_param('ares', 'fileout').replace("'", "") filename_out = 'lines.' + filename_ares isp.ares_to_lines(run_path+filename_ares, linelist_element, run_path+filename_out, 4000, 9999, 5, 150) rp.create_abfind_par(run_path, filename_out) rp.create_model_kurucz(run_path, teff, logg, feh, vtur) rp.run_MOOG(run_path, 'abfind.par') (ele1, ele1_sig, nele1, ele2, ele2_sig, nele2) = rmoog.read_moog_ele_sigma(run_path+'abund_plan_tspec.test', element, 2.) return (ele1, ele1_sig, nele1, ele2, ele2_sig, nele2)
def recalibrate_loggf_kurucz(path, filein, fileout): """ Differential recalibration of loggf using the KURUCZ models """ rp.create_model_kurucz(path, 5777, 4.44, 0.0, 1.0) recalibrate_loggf(path, filein, fileout)
def recalibrate_loggf_marcs(path, filein, fileout): """ Differential recalibration of loggf using the MARCS models """ rp.create_model_marcs(path, 5777, 4.44, 0.0, 1.0) recalibrate_loggf(path, filein, fileout)