def plot_line_evol(mass,parity,select_modes,sym,lbl_track,xlm,ax): for j in select_modes: mode_fs = [] mode_vels = [] for i in range(10): #print j,i tmpmode = mmod.emode(mass,i,j,par=parity) mode_fs.append(tmpmode.frequency) mode_vels.append(float(tmpmode.eq_vel)) c = int(tmpmode.name.split()[0]) if c!=99: clr = sns.diverging_palette(255, 133, l=60, n=8, center="dark")[c/2] mode_fs = np.array(mode_fs) mode_vels = np.array(mode_vels) plt.plot(mode_fs,(mode_vels/100.)**2,color=clr,marker="o",ms=5) plt.xlabel(r"$\omega/(4\pi G \rho_{\mathrm{ref}})^{1/2}$") plt.ylabel(r"$(V_{\mathrm{eq}} / V_{\mathrm{ref}})^2$") plt.title(r"M="+mass.replace("p",".")+"M$\odot$") curr_ylim = plt.ylim() plt.ylim(-0.5,curr_ylim[1]) plt.xlim(xlm[0],xlm[1]) plt.grid()
mass = "1p875" vel = ocity r_ord = 4 kind = "g" ells = [okc] mds = list_gen(ells, r_ord, r_ord, kind) p_phase = False plog = False col_idx = 4 #f, axarr = plt.subplots(2, sharex=True) yshift = 0.0025 incl = list(np.arange(0, 95, 10)) for mm in mds: em = emode(mass, vel, mm) run_plots(em.mass, em.vel_idx, em.name) # maxl = load_modes() # minl = load_modes("/minL") # maxl = load_modes("/phi_max") # minl = load_modes("/phi_min") wal_max, jh_max = load_mags("", em.mass, em.vel_idx, em.parity, em.index, incl) wal_min, jh_min = load_mags("/minL", em.mass, em.vel_idx, em.parity, em.index, incl) # wal_phi_max,jh_phi_max = load_mags("/phi_max",em.mass,em.vel_idx,em.parity,em.index,incl) # wal_phi_min,jh_phi_min = load_mags("/phi_min",em.mass,em.vel_idx,em.parity,em.index,incl) #
'axes.labelsize': 16, 'ytick.labelsize': 12, 'xtick.labelsize': 12, 'legend.fontsize': 16, 'axes.titlesize': 16, 'font.size': 14 }) r_ord = 4 kind = "p" ells = [0, 1, 2, 3, 4, 5, 6] mds = mmod.list_gen(ells, r_ord, r_ord, kind) mss = "1p875" incl = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] for i in mds: mde = i ll = int(mde.split()[0]) clr = sns.color_palette("Set2", 12)[ll] plt.plot(incl, map(lambda x: x, [mmod.emode(mss, 0, mde).calc_area(incl=i) for i in incl]), label=r"$\ell$=" + str(ll), color=clr) #plt.ylim(0,1.2) plt.xlabel("Inclination") plt.ylabel("(1.0 - Area_Factor)") plt.legend(loc="best") plt.title(r"M=" + mss + "M$\odot$ - V = 0 km s$^{-1}$") plt.grid()
sns.set(style="white",rc={"figure.figsize": (8, 8),'axes.labelsize': 16, 'ytick.labelsize': 12,'xtick.labelsize': 12, 'legend.fontsize': 16,'axes.titlesize':16,'font.size':14}) mname = "0 p4" #mname = "6 g3" lst = ["-","--",":"] inc = [7] vels = [0,2,8,9] clr = sns.color_palette("husl", len(vels)) mode = [] [mode.append(mmod.emode("1p875",i,mname,lpert=True)) for i in vels] #[plt.plot(mode[i].xi_r[:,inc[j]],ls=lst[j],color=clr[i],label=r"V="+mode[i].eq_vel+"km s$^{-1}$") for j in range(len(inc)) for i in range(len(vels))] #plt.grid() #plt.ylabel(r"$\xi_{r}$") #plt.xlabel("R [zone #]") #plt.legend(loc="best") for i in range(len(vels)): if i==9 or i==9: mode[i].plot_dr_r(invert=True) else: mode[i].plot_dr_r()
def plot_point_evol(mass,parity,select_modes,sym,lbl_track,xlm,ax): for i in vels: print i for j in range(90,110): tmpmode = mmod.emode(mass,i,j,par=parity) c = int(tmpmode.name.split()[0]) #clr = cm.viridis((15-c)*255/15) #clr = sns.color_palette("gnuplot", 18)[c] # if tmpmode.frequency>xlm[1]: # #print tmpmode.name, tmpmode.index # break if tmpmode.frequency>xlm[0]: if c!=99: clr = sns.diverging_palette(255, 133, l=60, n=16, center="dark")[c] mkr = sym[c/2] if c==99: clr = "k" mkr = "o" y = (float(tmpmode.eq_vel.replace("p","."))/100.)**2 for t in tag: if t.split()[0]=="0": if (t.find("h")>0 or t.find("H")>0) and (tmpmode.name.find("h")>0 or tmpmode.name.find("H")>0) and (t.split()[0] == tmpmode.name.split()[0]): print t,tmpmode.name,y tags[i,tag.index(t)+1] = tmpmode.frequency tags[i,0] = y elif (t.find("f")>0 or t.find("F")>0) and (tmpmode.name.find("f")>0 or tmpmode.name.find("F")>0) and (t.split()[0] == tmpmode.name.split()[0]): print t,tmpmode.name,y tags[i,tag.index(t)+1] = tmpmode.frequency tags[i,0] = y elif (t.find("f")>0 or t.find("F")>0) and (tmpmode.name.find("f")>0 or tmpmode.name.find("F")>0) and (t.split()[0] == tmpmode.name.split()[0]): print t,tmpmode.name,y tags[i,tag.index(t)+1] = tmpmode.frequency tags[i,0] = y elif t==tmpmode.name: print t,tmpmode.name,y tags[i,tag.index(t)+1] = tmpmode.frequency tags[i,0] = y if len(select_modes)==0: plt.plot(tmpmode.frequency,y,ls="",marker=mkr,color=clr) if i==0: if tmpmode.frequency>xlm[0] and tmpmode.frequency<xlm[1]: #plt.text(tmpmode.frequency,-0.25,str(j),fontsize=10,horizontalalignment='center',color=clr) if c not in lbl_track: lbl_track.append(c) plt.plot([],ls="",marker=mkr,color=clr,label=str(c)) else: if c in select_modes: clr = sns.diverging_palette(255, 133, l=60, n=len(select_modes), center="dark")[select_modes.index(c)] plt.plot(tmpmode.frequency,y,ls="",marker=mkr,color=clr) if i==0: if tmpmode.frequency>xlm[0] and tmpmode.frequency<xlm[1]: #plt.text(tmpmode.frequency,-0.25,str(j),fontsize=10,horizontalalignment='center',color=clr) if c not in lbl_track: lbl_track.append(c) plt.plot([],ls="",marker=mkr,color=clr,label=str(c)) global handles, labels, hl, handles2, labels2 handles, labels = ax.get_legend_handles_labels() labels = [int(i) for i in labels] import operator hl = sorted(zip(handles, labels), key=operator.itemgetter(1)) handles2, labels2 = zip(*hl) labels2 = [r"$\ell$="+str(i) for i in labels2] ax.legend(handles2, labels2,loc='lower center', ncol=8) plt.xlabel(r"$\omega/(4\pi G \rho_{\mathrm{ref}})^{1/2}$") plt.ylabel(r"$(V_{\mathrm{eq}} / V_{\mathrm{ref}})^2$") plt.title(r"M="+mass.replace("p",".")+"M$_{\odot}$") curr_ylim = plt.ylim() plt.ylim(-0.5,curr_ylim[1]+0.5) plt.xlim(xlm[0],xlm[1]) plt.grid() #plt.legend(loc='lower center', ncol=8) if len(tag)>0: for t in tag: plt.plot(tags[:,tag.index(t)+1],tags[:,0],"--",color="k",alpha=0.25)
def run_pipeline(modes,sub_dir="",minL=False,mm="1p875",vv=0,tph=0,drscale=None,tcut=False): global start,model,vel,old_modes,modeloc,pmodels,pmodels_fine,modes_not_found,mds #MODE info: model = [mm] vel = vv #index, not velocity! #modes = list_gen([0,1,2,3,4,5,6,7,8,9,10],5,5,"p") #list_gen([0,1,2,3],1,1,"p") #modes = list_gen([2],8,8,"p") #["1 p1","1 p2","1 p3","1 p4","1 p5", "1 p6", "1 p7", "1 p8", "1 p9"] #["0 1H","0 2H","0 3H","0 4H","0 5H","0 6H","0 7H","0 8H","0 9H","0 10H"] #par = emode(mm,vv,modes[0]).parity clic = False new_mags = False save_perturbation = False only_mags = False incl = list(np.arange(0,95,10)) #incl = [90] reese = False force_f = False f_freq = 1.22 phase = tph ampl = 1./2.2 tlmax = 4.14 #radians (sigma*t of phased Lmax) #### contour plotting option: plot_contour = True excl = 20 #How many core zones to exclude #### freqs = [6.61043] dt_grid = 250 old_modes = list(modes) mode_by_freq = False mode_by_name = False if type(modes[0]) == float: mode_by_freq = True if type(modes[0]) == str: mode_by_name = True if mode_by_freq==True: modes = find_index(freqs,model,vel,par) parity = [] modesx = [] if mode_by_name==True: for i in range(len(modes)): if int(modes[i].split()[0])%2==0: par = "EVEN" else: par = "ODD" parity.append(par) idx_tmp = index_by_name(model,vel,par,modes[i]) print modes[i],"->",idx_tmp modesx.append(idx_tmp) start = timer() klm = 0 rem = 0 modes_not_found = [] for mode in modesx: par = emode(mm,vv,mds[modesx.index(mode)]).parity if mode == 999: modes_not_found.append(old_modes[modes.index(mode)]) continue rem += 1 if mode_by_name == True: par = parity[klm] klm +=1 if force_f==True: sigma=f_freq else: #sigma = find_sigma(model,vel,par,mode) sigma = emode(mm,vv,old_modes[modesx.index(mode)]).frequency #Find the perturbed models! modeloc,pmodels,pmodels_fine = run_visc_pert(model,vel,mode,par,sigma,reese,force_f,minL,phase,ampl,tlmax,tcut) modeloc += sub_dir if not os.path.exists(modeloc): os.makedirs(modeloc) print modeloc print mds[modesx.index(mode)] nrzone = len(dt_t[:,0]) if plot_contour == True: make_contour(r,-zp*cs,model,vel,par,mode,excl) if save_perturbation==True: save_pert(modeloc,model,vel,par,mode,old_modes[modesx.index(mode)]) for i in range(len(pmodels)): np.savetxt(modeloc+"model_MODE_"+str(mode)+"_r"+str(nrzone - i),pmodels[i],'%.16e') np.savetxt(modeloc+"fine_model_MODE_"+str(mode)+"_r"+str(nrzone - i),pmodels_fine[i],'%.16e') rzone = 2 # Radial zone from the surface rzone = 490 print rzone if clic==True: #Ugly way of running pyCLIC: clic_folder = homedir+"pyCLIC/test/" if only_mags==False: subprocess.call(['mkdir',modeloc+'tmp']) os.chdir(modeloc+'tmp') tmpstr = "cp -r "+clic_folder+"* ." subprocess.call(tmpstr,shell=True) for i in incl: if new_mags==True: if (os.path.isfile(modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==True: subprocess.call(['rm',modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) else: print "No mag. file to delete!" if (os.path.isfile(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==True: subprocess.call(['rm',modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) else: print "No walraven_mag. file to delete!" subprocess.call(['cp',modeloc+"model_MODE_"+str(mode)+"_r"+str(rzone),modeloc+'tmp']) subprocess.call(['cp',modeloc+"fine_model_MODE_"+str(mode)+"_r"+str(rzone),modeloc+'tmp']) if (os.path.isfile(modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==False: myfile = open(modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode), "w") myfile.write('#%5s %5s %9s %11s %11s %11s %11s %11s\n' % ("incl","n_r","lum","u","b","v","r","i")) myfile.close() subprocess.call(['cp',modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc+'tmp']) else: subprocess.call(['cp',modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc+'tmp']) if (os.path.isfile(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==False: myfile = open(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode), "w") myfile.write('#%5s %5s %9s %11s %11s %11s %11s %11s\n' % ("incl","n_r","lum","w","u","l","b","v")) myfile.close() subprocess.call(['cp',modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc+'tmp']) else: subprocess.call(['cp',modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc+'tmp']) os.chdir(modeloc+'tmp') #sys.path.append(modeloc+'tmp') #print sys.path import pyCLIC_main as pyclic #sys.path.append(vis_path) os.chdir(vis_path) import color_magnitudes as cmag os.chdir(modeloc+'tmp') pyclic.run_CLIC("model_MODE_"+str(mode)+"_r"+str(rzone),[i],False,3000.,7499.,10.0,par,dt_grid,fine_model=True,savexi=True) cmag.calc_mags('outputflux_i'+str(i)+'.final',[i],mode,rzone) cmag.calc_walraven('outputflux_i'+str(i)+'.final',[i],mode,rzone) subprocess.call(['cp','outputflux_i'+str(i)+'.final',modeloc+"outputflux_i"+str(i)+"_MODE_"+str(mode)+"_r"+str(rzone)]) subprocess.call(['cp',"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc]) subprocess.call(['cp',"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode),modeloc]) subprocess.call(['rm',"model_MODE_"+str(mode)+"_r"+str(rzone)]) subprocess.call(['rm','outputflux_i'+str(i)+'.final']) subprocess.call(['rm',"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) subprocess.call(['rm',"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) os.chdir(vis_path) subprocess.call(['rm',"-r",modeloc+'tmp']) else: os.chdir(vis_path) import color_magnitudes as cmag os.chdir(modeloc) for i in incl: if new_mags==True: if (os.path.isfile(modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==True: subprocess.call(['rm',modeloc+"magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) else: print "No mag. file to delete!" if (os.path.isfile(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==True: subprocess.call(['rm',modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)]) else: print "No walraven_mag. file to delete!" if (os.path.isfile("magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==False: myfile = open("magnitudes_MODE_"+str(mode), "w") myfile.write('#%5s %5s %9s %11s %11s %11s %11s %11s\n' % ("incl","n_r","lum","u","b","v","r","i")) myfile.close() if (os.path.isfile(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode)))==False: myfile = open(modeloc+"walraven_magnitudes"+"_i"+str(i)+"_MODE_"+str(mode), "w") myfile.write('#%5s %5s %9s %11s %11s %11s %11s %11s\n' % ("incl","n_r","lum","w","u","l","b","v")) myfile.close() #cmag.calc_mags("outputflux_i"+str(i)+"_MODE_"+str(mode)+"_r"+str(rzone),[i],mode,rzone) cmag.calc_walraven("outputflux_i"+str(i)+"_MODE_"+str(mode)+"_r"+str(rzone),[i],mode,rzone) os.chdir(vis_path) print mode