for i in range(len(snaps)): # # Read snapshot specific protostellar properties/SED # fname = run_dir + "/" + snaps[i] + "/dat/stars.inp" f = open(fname, 'r') trash = f.readline() trash = f.readline() r_star.append(float(f.readline().split(' ')[0]) * cs.rsol_per_cm) t_star.append(-float(f.readlines()[-1])) f.close() # fname = run_dir + "/" + snaps[i] + "/dat/spectrum" + str(int( t_star[i])) + ".out" wavs_s[i], flam_s[i], lam_flam, nu, fnu, nu_fnu = fs.SED_read(fname) if sed_norm: fnorm = ( (r_star[i] * cs.cm_per_rsol)**2. * cs.sigma_sb_cgs * \ (t_star[i])**4. ) / (cs.cm_per_pc)**2. for j in range(len(flam_s[i])): flam_s[i][j] /= fnorm else: fnorm = dist**2.0 for j in range(len(flam_s[i])): flam_s[i][j] /= fnorm # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Loop over inclinations, and read in snapshot specific SEDs #
print "\nNow processing cavity-only models\n" for s in range(len(lums)): # for i in range(len(inclins)): # for c in range(len(cavity_theta)): # f_sed_o = dat_dir_o+"/"+r_cores[cut]+"/POST_"+ \ str(lums[s])+"L_cavity"+ str(cavity_theta[c])+ \ "/dat/spectrum"+str(int(temps[s]))+ \ "_ISRF_"+str(inclins[i])+"i.out" wavs_o, flam_o, lam_flam_o, \ nu_o, fnu_o, nu_fnu_o = fs.SED_read(f_sed_o) # f_sed_q = dat_dir_q+"/"+r_cores[cut]+ \ "/POST_cavity"+str(cavity_theta[c])+ \ "/dat/spectrum3974_ISRF_"+str(inclins[i])+"i.out" # wavs_q, flam_q, lam_flam_q, \ nu_q, fnu_q, nu_fnu_q = fs.SED_read(f_sed_q) # flam_int_o = interp1d(wavs_o,flam_o, kind="linear") flam_int_q = interp1d(wavs_q,flam_q, kind="linear") for w in range(len(wavs_compare)): flam_ratio[cut][s][c][0][i][w] = \ flam_int_o(wavs_compare[w]) / flam_int_q(wavs_compare[w])
def sed(arch_dir, dat_dir, sdat_ext, plt_dir, plt_ext, inclin, \ t_star, r_star, t_planet, r_planet, beam_r): # Read in SED, as per sdat_ext, usinf SED_read() function file_read = dat_dir + "/spectrum" + sdat_ext wav, flam, lam_flam, nu, fnu, nu_fnu = fs.SED_read(file_read) # Normalise plotted lam_flam list to user defined distance to source lam_flam /= dist**(2.0) # Do the same, for protostellar SED, as comparison to RT output if incl_star and (mod_inp != "protostar"): shutil.copy2( arch_dir + "/protostar/spectrum" + str(int(t_star)) + ".out", dat_dir + "/") file_read = dat_dir + "/spectrum" + str(int(t_star)) + ".out" wav_star, flam_star, lam_flam_star, \ nu_star, fnu_star, nu_fnu_star = fs.SED_read(file_read) lam_flam_star /= dist**(2.0) # If a planet is present in the SED calculation, apply the same read # and normalisation to the relevant data if incl_planet: shutil.copy2(arch_dir+"/protostar/spectrum"+str(int(t_planet))+ \ ".out", dat_dir+"/") file_read = dat_dir + "/spectrum" + str(int(t_planet)) + ".out" wav_planet, flam_planet, lam_flam_planet, \ nu_planet, fnu_planet, nu_fnu_planet = fs.SED_read(file_read) lam_flam_planet /= dist**(2.0) # Dependent on sed_norm, either set limits, then compute total flux # from central source to normalise SED, or set flam limits based on # absolute values if sed_norm: norm = ( (r_star * cs.cm_per_rsol)**2. * cs.sigma_sb_cgs * \ (t_star)**4. ) / (cs.cm_per_pc)**2. lam_flam /= norm if incl_star and (mod_inp != "protostar"): lam_flam_star /= norm ymax = max(lam_flam) * 10.0 elif not sed_norm: ymax = max(lam_flam) * 10.0 ymin = ymax / 1.0e9 fig = plt.figure(1) ax1 = plt.subplot(111) plt.plot(wav, lam_flam, color="k", linewidth=1, label="Full Model") if incl_star and (mod_inp != "protostar"): plt.plot(wav_star, lam_flam_star, color = "g", linewidth = 1, \ label="Protostar - "+str(int(t_star))+"K") if incl_planet: plt.plot(wav_planet, lam_flam_planet, color = "r", linewidth = 1, \ label = "Planet - "+str(int(t_planet))+"K") plt.legend(loc="upper left", fontsize=10) plt.xlabel("Wavelength (" + (r"$\mu$m") + ")", fontsize=18, labelpad=0.5) plt.xticks(fontsize=15) ax1.set_xscale("log") ax1.set_xlim(5.e-3, 10000.) if sed_norm: plt.ylabel(r"$\lambda$ F$_{\lambda}$ / F", fontsize=18, labelpad=0.5) elif not sed_norm: plt.ylabel(r"$\lambda$ F$_{\lambda}$", fontsize=18, labelpad=0.5) ax1.set_yscale("log") ax1.set_ylim(ymin, ymax) plt.tight_layout() plt.savefig(plt_dir+"/SED_"+plt_ext+"_"+str(inclin)+"i."+plt_form, \ format = plt_form) plt.clf() # Compute flux values for [350, 450, 850, 1300] microns flux_values(wav, fnu, beam_r) # Compute diagnostics for YSO classification from SED data yso_class(nu_star, fnu_star, nu, fnu, nu_fnu, t_star, r_star) return
# leg_names = [r"$\theta_{c} = 10^\circ$", \ r"$\theta_{c} = 20^\circ$", \ r"$\theta_{c} = 30^\circ$"] color = ["r", "g", "b"] linestyle = ["-", "-", "-"] linewidth = [1, 1, 1] for i in range(3): # Read SED data fsed = dat_dir + theta[i] + "/spectrum6L_ISRF_" + str( best_inclin) + "i.out" wav[i], flam[i], lam_flam[i], nu, fnu, nu_fnu = fs.SED_read(fsed) for j in range(len(lam_flam[i])): lam_flam[i][j] /= dist**(2.0) if bolometrics: # Model bolometric luminosity L_bol = fs.Lbol_calc(nu, fnu) # Model bolometric temperature T_bol = fs.Tbol_calc(nu, fnu, nu_fnu) # Model sub-mm to bolometric luminosity ratio
plt_dir = run_dir + "/plots_analysis/POST" elif (restricted[i] == "POST_1000"): dat_dir = run_dir + "/POST_1000/dat" plt_dir = run_dir + "/plots_analysis/POST_1000" if not os.path.isdir(plt_dir): os.system("mkdir {0}".format(plt_dir)) # ### ------------------------------------------------------------------------ ### # Read SED data for t in range(len(temps)): fsed = dat_dir + "/spectrum" + names[t] + "_0i.out" wav[t][i][j], flam[t][i][j], \ lam_flam, nu, fnu, nu_fnu = fs.SED_read(fsed) flam[t][i][j] /= dist**(2.0) ### ------------------------------------------------------------------------ ### # Singular cut method analysis: # # Now plot SED. Zoom into SED in region of interest, using second panel # # SED # color = ["b", "r", "g", "k", "c"] # fig = plt.figure(1) ax1 = plt.subplot(111)
import constants as cs import functions as fs # ------------------------------------------------------------------------------ arch_dir = os.getcwd() + "/../../runs" run_dir = arch_dir + "/OUTBURST/1686/POST" file_read = run_dir + "/dat/spectrum19248_ISRF_0i.out" # ------------------------------------------------------------------------------ # Read SED, using relevant function wav, flam, lam_flam, nu, fnu, nu_fnu = fs.SED_read(file_read) # From SED data, call relevant function to derive bolometric properties L_bol = fs.Lbol_calc(nu, fnu) print("\nBolometric Luminosity is {0} L_sol\n".format(L_bol)) T_bol = fs.Tbol_calc(nu, fnu, nu_fnu) print("\nBolometric Temperature is {0} K\n".format(T_bol)) os.remove("./../constants.pyc") os.remove("./../functions.pyc")
t_star.append(-float(f_star.readlines()[-1])) # l_star.append(round((r_star[s])**2.0 * (t_star[s] / 5780.)**4.0, 3)) round_ind = 2 - int(math.floor(math.log10(l_star[s]))) l_star[s] = round(l_star[s], round_ind) # f_star.close() # # Read protostellar SED data # f_psed = arch_dir + "/protostar/spectrum" + str(int(t_star[s])) + ".out" if not os.path.isfile(f_psed): print("Protostellar SED template not found, exiting...") exit() wavs_s[s], flam_s[s], lam_flam, nu, fnu, nu_fnu = fs.SED_read(f_psed) # Normalise if called for.. if sed_norm: fnorm = ( (r_star[s] * cs.cm_per_rsol)**2. * cs.sigma_sb_cgs * \ (t_star[s])**4. ) / (cs.cm_per_pc)**2. for l in range(len(flam_s[s])): flam_s[s][l] /= fnorm elif not sed_norm: fnorm = dist**2.0 for l in range(len(flam_s[s])): flam_s[s][l] /= fnorm # Now loop over cut, isrf and inclination regimes, reading in and appending # SED data to wavs and flam arrays, and normalising as necessary
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = # # Generate SEDs, comparing unscaled 10 L_sol, i = 30 deg. model with # models where disc mass has been scaled to x0.1, or x2 initial mass runs_dir = cwd + "/../../runs/OUTBURST/1686/1e4AU/POST_10L_cavity10" pstar_dir = cwd + "/../../protostar" plt_dir = cwd + "/../../runs/OUTBURST/plots_analysis" plt_form = "png" file = pstar_dir + "/spectrum5934.out" f = open(file, "r") wav_star, flam_star, lam_flam_star, \ nu_star, fnu_star, nu_fnu_star = fs.SED_read(file) lam_flam_star /= dist**(2.0) labels = ["_disc01", "", "_disc2"] plt_labels = ["Disc x0.1", "Unscaled", "Disc x2"] linestyle = ["--", "-", ":"] wav = [[] for i in range(3)] lam_flam = [[] for i in range(3)] for i in range(3): file = runs_dir + labels[i] + "/dat/spectrum5934_ISRF_30i.out" wav[i], flam_tmp, lam_flam[i], \