def trikap(run): # Only execute if plotting if run.no_plot: return print("Plotting scan of triangularity vs elongation...") Nfile = len(run.fnames) # Init arrays of data used in scan. full_lingrowth = [dict() for ifile in range(Nfile)] # Get lingrowth data from .dat file. for ifile in range(Nfile): datfile_name = run.work_dir + run.dirs[ifile] + run.out_dir + run.files[ifile] + '.lingrowth.dat' with open(datfile_name,'rb') as datfile: full_lingrowth[ifile] = pickle.load(datfile) nakx = len(full_lingrowth[0]['kx']) for ifile in range(Nfile): if len(full_lingrowth[ifile]['kx']) != nakx: quit("Error - number of kx values should be constant across all items in the scan - Exiting...") tri,kap = np.zeros(Nfile),np.zeros(Nfile) for ifile in range(Nfile): tri[ifile] = full_lingrowth[ifile]['tri'] kap[ifile] = full_lingrowth[ifile]['kap'] tris = sorted(list(set(tri))) kaps = sorted(list(set(kap))) print("Triangularity values: " + str(tris)) print("Elongation values: " + str(kaps)) if len(tris) * len(kaps) != Nfile: quit("Incorrect number of files added to populate the scan - exiting") gammas = np.zeros((len(tris), len(kaps), nakx)) kymax = np.zeros((len(tris), len(kaps), nakx)) for ifile in range(Nfile): gamma = full_lingrowth[ifile]['gamma'] ky = full_lingrowth[ifile]['ky'] kx = full_lingrowth[ifile]['kx'] # Limits search to ITG. ikymax = int((np.abs(ky-1.0)).argmin()) for itri in range(len(tris)): for ikap in range(len(kaps)): if tri[ifile] == tris[itri] and kap[ifile] == kaps[ikap]: for ikx in range(len(kx)): gammas[itri,ikap,ikx] = np.nanmax(gamma[:ikymax,ikx]) kymax[itri,ikap,ikx] = ky[np.nanargmax(gamma[:ikymax,ikx])] pdflist = [] tmp_pdf_id=0 for ikx in range(nakx): gplot.plot_2d(gammas,tris,kaps,np.min(gammas[:,:,ikx]),np.max(gammas[:,:,ikx]),cmp='Reds',xlab='$\delta$',ylab='$\kappa$',title='$\gamma a/v_t: k_x$ = ' + str(full_lingrowth[0]['kx'][ikx])) tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run) pdflist.append(tmp_pdfname) tmp_pdf_id += 1 merged_pdfname = 'tri_kap_scan' gplot.merge_pdfs(pdflist, merged_pdfname, run)
def my_task_single(ifile, run, myin, myout): # User parameters dump_at_start = 0.3 # fraction of initial time to dump when fitting ikx_list = [-1] # choose which kx to plot, negative means plot all # Compute and save growthrate if not run.only_plot: grid_option = myin['kt_grids_knobs']['grid_option'] t = myout['t'] nt = t.size it_start = round(nt*dump_at_start) kx = myout['kx'] nakx = kx.size ky = myout['ky'] naky = ky.size phi2 = myout['phi2_by_mode'] # modulus squared, avged over theta (indices: [t,ky,kx]) it_end = nt for it in range(nt): for ikx in range(nakx): for iky in range(naky): if it < it_end and not np.isfinite(phi2[it,iky,ikx]): it_end = it - 10 break if grid_option=='range': # In range, plot the only kx ikx_list = [0] elif grid_option=='box': if ikx_list[0]==-1: ikx_list = [i in range(nakx)] # Fit phi to get growthrates gamma = np.zeros([naky,len(ikx_list)]) gamma[0,:]=float('nan') # skip zonal mode for iky in range(1,naky): for ikx in ikx_list: gamma[iky,ikx] = get_growthrate(t,phi2,it_start,it_end,ikx,iky) mydict = {'ikx_list':ikx_list,'kx':kx,'ky':ky,'gamma':gamma,'tri':myin['theta_grid_parameters']['tri'], 'kap':myin['theta_grid_parameters']['akappa']} # Save to .dat file # OB 170918 ~ Changed output to a dict and added kappa, tri datfile_name = run.work_dir + run.dirs[ifile] + run.out_dir + run.files[ifile] + '.lingrowth.dat' with open(datfile_name, 'wb') as datfile: pickle.dump(mydict,datfile) # or read from .dat file else: datfile_name = run.work_dir + run.dirs[ifile] + run.out_dir + run.files[ifile] + '.lingrowth.dat' with open(datfile_name, 'rb') as datfile: mydict = pickle.load(datfile) # Plotting if not run.no_plot: # If we ran for many kx ky, then plot colormap if len(ikx_list) > 3 and ky.size > 3: title = '$\\gamma \\ [v_{thr}/r_r]$' xlab = '$k_{x}\\rho_i$' ylab = '$k_{y}\\rho_i$' cmap = 'RdBu' z = gamma[:,:] z_min, z_max = z.min(), z.max() fig = gplot.plot_2d(z,kx,ky,z_min,z_max,xlab,ylab,title,cmap) # Otherwise plot curves vs ky for each kx else: plt.figure(figsize=(12,8)) plt.xlabel('$k_y\\rho_i$') plt.ylabel('$\\gamma \\ [v_{thr}/r_r]$') plt.title('Linear growthrate') plt.grid(True) my_legend = [] for ikx in ikx_list: plt.plot(ky,gamma[:,ikx]) my_legend.append('$\\rho_i k_x='+str(kx[ikx])+'$') plt.legend(my_legend) pdfname = 'lingrowth' gplot.save_plot(pdfname, run, ifile) print('Maximum linear growthrate: '+str(np.nanmax(gamma)))
def plot(self, ifile, run, myout, mygrids, mytime): print() print("producing time-dependent zonal flow plots...",end='') tmp_pdf_id = 1 pdflist = [] plot_zonal_phi_kx_vs_t(mygrids, mytime, np.real(self.zonal_phi)) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 if (mygrids.nx > 1): # plot flow and flow shear vs (kx,t) and vs (x,t) title='$| J_{0}(k_{x}\\rho)k_{x}\\rho\Phi_{zf}(k_{x},t) |^2$' plot_zonal_vs_kxt(mygrids.kx,mytime.time,self.flow_gyro,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title='$| J_0(k_x\\rho)k_{x}^2\\rho^2\Phi_{zf}(k_{x},t) |^2$' plot_zonal_vs_kxt(mygrids.kx,mytime.time,self.shear_gyro,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title='$\left< \partial_x \Phi_{zf} (x,t) \\right> $' plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.flow_gyro_xt,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title='$\left<\partial_x^2 \Phi_{zf}(x,t)\\right>$' plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.shear_gyro_xt,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 if myout['ntot_igomega_by_mode_present']: for ispec in range(myout['nspec']): stitle=str(ispec+1) + ',zf} (x,t)$' title = '$\delta n_{' + stitle plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.dens_xt[:,ispec,:],title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 if myout['upar_igomega_by_mode_present']: for ispec in range(myout['nspec']): stitle=str(ispec+1) + ',zf} (x,t)$' title = '$\delta u_{\parallel' + stitle plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.upar_xt[:,ispec,:],title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 if myout['tpar_igomega_by_mode_present']: for ispec in range(myout['nspec']): stitle=str(ispec+1) + ',zf} (x,t)$' title = '$\delta T_{\parallel' + stitle plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.tpar_xt[:,ispec,:],title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 if myout['tperp_igomega_by_mode_present']: for ispec in range(myout['nspec']): stitle=str(ispec+1) + ',zf} (x,t)$' title = '$\delta T_{\perp' + stitle plot_zonal_vs_xt(mygrids.xgrid,mytime.time,self.tperp_xt[:,ispec,:],title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) # save plots merged_pdfname = 'zonal_vs_time' gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile) print('complete') if (mygrids.nx > 1): print() print("producing time-averaged zonal flow plots...",end='') tmp_pdf_id = 1 pdflist = [] title = '$| J_{0}(k_{x}\\rho)k_{x}\\rho\Phi_{zf}(k_{x}) |^2$' plot_zonal_vs_kx(mygrids.kx,self.flow_gyro_avg,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title = '$| J_0(k_x\\rho)k_{x}^2\\rho^2\Phi_{zf}(k_{x}) |^2$' plot_zonal_vs_kx(mygrids.kx,self.shear_gyro_avg,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title = '$\left< \partial_x \Phi_{zf} (x) \\right> $' plot_zonal_vs_x(mygrids.xgrid,self.flow_gyro_xt_avg,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 title = '$\left<\partial_x^2 \Phi_{zf}(x)\\right>$' plot_zonal_vs_x(mygrids.xgrid,self.shear_gyro_xt_avg,title) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) # save plots merged_pdfname = 'zonal_steady' gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile) print('complete') print()
def plot_along_tube(ifile,run,mytime,mydict): kperp2_theta_x_y = mydict['kperp2'] gds2 = mydict['gds2' ] gds21 = mydict['gds21'] gds22 = mydict['gds22'] gbdrift = mydict['gbdrift'] gbdrift0 = mydict['gbdrift0'] cvdrift = mydict['cvdrift'] cvdrift0 = mydict['cvdrift0'] bmag = mydict['bmag'] pdflist = [] tmp_pdf_id = 0 write = False if bmag is not None: gplot.plot_1d(mydict['theta'],bmag, '$\\theta$', title = 'bmag', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if gds2 is not None: gplot.plot_1d(mydict['theta'],gds2, '$\\theta$', title = 'gds2', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if gds21 is not None: gplot.plot_1d(mydict['theta'],gds21, '$\\theta$', title = 'gds21', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if gds22 is not None: gplot.plot_1d(mydict['theta'],gds22, '$\\theta$', title = 'gds22', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if kperp2_theta_x_y is not None: # Average over kx,ky. kperp2_theta_x = kperp2_theta_x_y.mean(axis=2) kperp2_theta = kperp2_theta_x.mean(axis=1) gplot.plot_1d(mydict['theta'],kperp2_theta,'$\\theta$', title='$k_\perp^2$', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if gbdrift is not None: gplot.plot_1d(mydict['theta'],gbdrift, '$\\theta$', title = 'gbdrift', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if gbdrift0 is not None: gplot.plot_1d(mydict['theta'],gbdrift0, '$\\theta$', title = 'gbdrift0', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if cvdrift is not None: gplot.plot_1d(mydict['theta'],cvdrift, '$\\theta$', title = 'cvdrift', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if cvdrift0 is not None: gplot.plot_1d(mydict['theta'],cvdrift0, '$\\theta$', title = 'cvdrift0', rads = True, grid="x") tmp_pdfname = 'tmp'+str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id+1 write = True if write: print(run.scan_name) merged_pdfname = 'along_tube' + run.scan_name gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile)
def plot_task_single(ifile, run, my_vars, my_it, my_iky, my_dmid, make_movies): Nf = my_vars['Nf'] t = my_vars['t'] delt = my_vars['delt'] kx = my_vars['kx'] nakx = my_vars['nakx'] kx_bar = my_vars['kx_bar'] dkx = my_vars['dkx'] bloonang_chain = my_vars['bloonang_chain'] phi2 = my_vars['phi2'] phi2bloon_chain = my_vars['phi2bloon_chain'] sum_phi2_chain = my_vars['sum_phi2_chain'] gamma_mid = my_vars['gamma_mid'] gamma_chain = my_vars['gamma_chain'] phi_t_present = my_vars['phi_t_present'] Tf = Nf*delt nt = t.size plt.figure(figsize=(12,8)) # plot sum of phi2 along chain vs time plt.xlabel('$t$') plt.ylabel('$\\ln \\left(\\sum_{K_x}\\vert \\langle \\phi \\rangle_\\theta \\vert ^2\\right)$') plt.title('Sum along a single ballooning mode') plt.grid(True) # NDCTEST: shorten time trace #plt.plot(t[0:600], np.log(sum_phi2_chain[0:600]), color=gplots.myblue, linewidth=3.0) plt.plot(t, np.log(sum_phi2_chain), color=gplots.myblue, linewidth=3.0) # endNDCTEST pdfname = 'floquet_vs_t' pdfname = run.out_dir + pdfname + '_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.pdf' plt.savefig(pdfname) plt.clf() plt.cla() # plot phi2 of chosen chain vs ballooning angle at chosen time if (phi_t_present): for it in my_it: plt.xlabel('$\\theta -\\theta_0$') plt.ylabel('$\\vert \\phi \\vert ^2$') plt.title('$t=$ '+str(t[it])) plt.grid(True) plt.gca().set_xlim(np.min(bloonang_chain[it]),np.max(bloonang_chain[it])) plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E')) plt.plot(bloonang_chain[it], phi2bloon_chain[it], marker='o', \ markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) pdfname = 'balloon_it_' + str(it) pdfname = run.out_dir + pdfname + '_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.pdf' plt.savefig(pdfname) plt.clf() plt.cla() # make movie of phi2 vs ballooning angle over time if (make_movies and phi_t_present): moviename = run.out_dir + 'phi_bloon_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.mp4' images = [] # find global min and max of ballooning angle bloonang_min = 0. bloonang_max = 0. # NDCTEST: to shorten movie #for it in range(401): for it in range(nt): if np.min(bloonang_chain[it]) < bloonang_min: bloonang_min = np.min(bloonang_chain[it]) if np.max(bloonang_chain[it]) > bloonang_max: bloonang_max = np.max(bloonang_chain[it]) print("\ncreating movie of phi vs ballooning angle ...") # NDCTEST: to shorten movie #for it in range(401): for it in range(nt): sys.stdout.write("\r{0}".format("\tFrame : "+str(it)+"/"+str(nt-1))) plt.xlabel('$\\theta -\\theta_0$') plt.ylabel('$\\vert \\phi \\vert ^2$') plt.title('$t=$ '+str(t[it])) plt.grid(True) plt.gca().set_xlim(bloonang_min,bloonang_max) plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E')) plt.plot(bloonang_chain[it], phi2bloon_chain[it], marker='o', \ markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) pngname = run.out_dir + 'tmp_image.png' plt.savefig(pngname) images.append(imageio.imread(pngname)) os.system('rm -rf ' + pngname) plt.clf() plt.cla() sys.stdout.flush() imageio.mimsave(moviename, images, format='FFMPEG') print("\n... movie completed.") # NDCTEST: plotting mutliple times together #plt.xlabel('$\\theta -\\theta_0$') #plt.ylabel('$\\vert \\phi \\vert ^2$') #plt.grid(True) #plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E')) #line2, = plt.plot(bloonang_chain[210], phi2bloon_chain[210], marker='None', linestyle='--', linewidth=4.0, color=gplots.oxbluel) #line3, = plt.plot(bloonang_chain[310], phi2bloon_chain[310], marker='None', linestyle=':', linewidth=3.0, color=gplots.oxbluell) #line1, = plt.plot(bloonang_chain[110], phi2bloon_chain[110], marker='None', linewidth=5.0, color=gplots.oxblue) #plt.legend([line1,line2,line3], ['$t=$ '+"{:.1f}".format(t[110]),'$t=$ '+"{:.1f}".format(t[210]),'$t=$ '+"{:.1f}".format(t[310])]) #plt.savefig('two_times_floquet.pdf') #plt.clf() #plt.cla() # endNDCTEST # plot instantaneous growthrate at mid-plane vs kx pdflist = [] for ifloq in range((nt-1)//Nf): plt.xlabel('$k_x$') plt.ylabel('$\\gamma$') plt.title('Growthrate at $\\theta = 0$ and $t='+str(t[ifloq*Nf])+'$') plt.grid(True) plt.plot(kx[ifloq*Nf,my_iky,:], gamma_mid[ifloq*Nf,:], color=gplots.myblue) pdfname = 'tmp_' + str(ifloq) gplots.save_plot(pdfname, run, ifile) plt.clf() plt.cla() pdflist.append(pdfname) outname = 'growth_mid' outname = outname + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) gplots.merge_pdfs(pdflist,outname,run,ifile) # make movie of growthrate at mid-plane vs kx over time #if (make_movies and phi_t_present): # # moviename = run.out_dir + 'growth_mid_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.mp4' # images = [] # # find global min and max of kx # kx_min = 0. # kx_max = 0. # for it in range(nt): # for ikx in range(nakx): # if np.min(kx[it,my_iky,ikx]) < kx_min: # kx_min = np.min(kx[it,my_iky,ikx]) # if np.max(kx[it,my_iky,ikx]) > kx_max: # kx_max = np.max(kx[it,my_iky,ikx]) # # print("\ncreating movie of growthrate at mid-plane vs kx ...") # for it in range(nt): # # sys.stdout.write("\r{0}".format("\tFrame : "+str(it)+"/"+str(nt-1))) # # plt.xlabel('$k_x$') # plt.ylabel('$\\gamma (\\theta=0)$') # plt.title('$t=$ '+str(t[it])) # plt.grid(True) # plt.gca().set_xlim(kx_min,kx_max) # plt.gca().set_ylim(bottom=-0.5) # plt.gca().set_ylim(top=0.5) # plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E')) # plt.plot(kx[it,my_iky,:], gamma_mid[it,:], marker='o', \ # markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) # pngname = run.out_dir + 'tmp_image.png' # plt.savefig(pngname) # # images.append(imageio.imread(pngname)) # os.system('rm -rf ' + pngname) # plt.clf() # plt.cla() # sys.stdout.flush() # # imageio.mimsave(moviename, images, format='FFMPEG') # print("\n... movie completed.") # plot growthrate vs theta-theta0 at time t[my_it] for it in my_it: plt.xlabel('$\\theta - \\theta_0$') plt.ylabel('$\\gamma$') plt.title('Growthrate at $t='+str(t[it])+'$') plt.grid(True) plt.plot(bloonang_chain[it], gamma_chain[it][:], color=gplots.myblue) pdfname = 'growth_bloon_it_'+str(it) pdfname = run.out_dir + pdfname + '_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.pdf' plt.savefig(pdfname) plt.clf() plt.cla() # make movie of growthrate vs ballooning angle over time #if (make_movies and phi_t_present): # # moviename = run.out_dir + 'growth_bloon_' + run.fnames[ifile] + '_iky_' + str(my_iky) + '_dmid_' + str(my_dmid) + '.mp4' # images = [] # # find global min and max of ballooning angle # bloonang_min = 0. # bloonang_max = 0. # for it in range(nt): # if np.min(bloonang_chain[it]) < bloonang_min: # bloonang_min = np.min(bloonang_chain[it]) # if np.max(bloonang_chain[it]) > bloonang_max: # bloonang_max = np.max(bloonang_chain[it]) # # print("\ncreating movie of growthrate vs ballooning angle ...") # for it in range(nt): # # sys.stdout.write("\r{0}".format("\tFrame : "+str(it)+"/"+str(nt-1))) # # plt.xlabel('$\\theta -\\theta_0$') # plt.ylabel('$\\gamma$') # plt.title('$t=$ '+str(t[it])) # plt.grid(True) # plt.gca().set_xlim(bloonang_min,bloonang_max) # plt.gca().set_ylim(bottom=-0.5) # plt.gca().set_ylim(top=0.5) # plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E')) # plt.plot(bloonang_chain[it], gamma_chain[it], marker='o', \ # markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) # pngname = run.out_dir + 'tmp_image.png' # plt.savefig(pngname) # # images.append(imageio.imread(pngname)) # os.system('rm -rf ' + pngname) # plt.clf() # plt.cla() # sys.stdout.flush() # # imageio.mimsave(moviename, images, format='FFMPEG') # print("\n... movie completed.") # plot phi2 vs t for each kx plt.xlabel('$$t\\ [r_r/v_{thr}]$$') my_ylabel = '$\\ln \\left(\\vert \\langle \\phi \\rangle_\\theta \\vert ^2\\right)$' plt.ylabel(my_ylabel) plt.grid(True) my_colorlist = plt.cm.plasma(np.linspace(0,1,kx_bar.size)) my_legend = [] for ikx in range(kx_bar.size): plt.plot(t, np.log(phi2[:,1,ikx]), color=my_colorlist[ikx]) my_legend.append('$\\rho_i\\bar{k}_x = '+str(kx_bar[ikx])+'$') plt.legend(my_legend) pdfname = 'phi2_by_kx' pdfname = run.out_dir + pdfname + '_' + run.fnames[ifile] + '.pdf' plt.savefig(pdfname) plt.clf() plt.cla() plt.close()
def task_scan(run, full_space): # Start comparing simulations at time-step it_start = N_start*Tfloquet/dt # ie after N_start Floquet oscillations # Normalise sum_phi2 by sum_phi2[it_start] for each run N_start = 2 sum_phi2 = [] t = [] delt = np.zeros(len(run.fnames)) dkx = np.zeros(len(run.fnames)) slope = np.zeros(len(run.fnames)) if not run.no_plot: for ifile in range(len(run.fnames)): Tf = full_space[ifile]['floquet'].Tf delt[ifile] = full_space[ifile]['floquet'].delt dkx[ifile] = full_space[ifile]['floquet'].dkx nwrite = full_space[ifile]['floquet'].nwrite it_start = int(round((N_start*Tf/delt[ifile])/nwrite)) sum_phi2_tmp = np.zeros(len(full_space[ifile]['floquet'].sum_phi2_chain)-it_start) for it in range(sum_phi2_tmp.size): sum_phi2_tmp[it] = full_space[ifile]['floquet'].sum_phi2_chain[it_start+it] sum_phi2_tmp = sum_phi2_tmp/sum_phi2_tmp[0] sum_phi2.append(sum_phi2_tmp) t_tmp = np.zeros(len(full_space[ifile]['floquet'].t)-it_start) for it in range(t_tmp.size): t_tmp[it] = full_space[ifile]['floquet'].t[it_start+it] t.append(t_tmp) [a,dummy] = leastsq_lin(t_tmp,np.log(sum_phi2_tmp)) slope[ifile] = a idxsort = np.argsort(delt) delt = delt[idxsort] dkx = dkx[idxsort] slope = slope[idxsort] pdflist = [] plt.figure(figsize=(12,8)) plt.xlabel('$t$') plt.ylabel('$\\ln \\left(\\sum_{K_x}\\vert \\langle\\phi\\rangle_\\theta \\vert ^2\\right)$') plt.title('Sum along a single ballooning mode') plt.grid(True) my_legend = [] my_colorlist = plt.cm.plasma(np.linspace(0,1,len(run.fnames))) for ifile in range(len(run.fnames)): #my_legend.append('$\\Delta t =$'+str(full_space[ifile]['floquet'].delt)) my_legend.append('$\\Delta k_x =$'+str(full_space[ifile]['floquet'].dkx)) plt.plot(t[ifile], np.log(sum_phi2[ifile]), color=my_colorlist[ifile], linewidth=3.0) plt.legend(my_legend) axes = plt.gca() axes.set_ylim([-0.5, 13.75]) pdfname = 'tmp_1' gplots.save_plot(pdfname, run, ifile) pdflist.append(pdfname) plt.clf() plt.cla() #plt.xlabel('$\\Delta t$') plt.xlabel('$\\Delta k_x$') plt.ylabel('$\\langle \\gamma \\rangle_t$') plt.title('Time averaged growth-rate') plt.grid(True) print('Slopes : ',end='') print(slope) #plt.plot(delt, slope, marker='o', \ # markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) plt.plot(dkx, slope, marker='o', \ markersize=12, markerfacecolor='none', markeredgecolor=gplots.myblue, linewidth=3.0) pdfname = 'tmp_2' gplots.save_plot(pdfname, run, ifile) pdflist.append(pdfname) plt.clf() plt.cla() outname = run.scan_name gplots.merge_pdfs(pdflist,outname,run,ifile) plt.close()
def my_task_single(ifile, run, myin, myout, mygrids): if not run.only_plot: ####################### ### User parameters ### ####################### # Choose which Fourier components to plot it_start_list = [0, 0] ikx_start_list = [3, 4] # ikxmax=126 for nx=192 iky_list = [1, 1] ########################### ### End user parameters ### ########################### # Check parameters make sense size_check = (len(it_start_list) == len(ikx_start_list) == len(iky_list)) if not size_check: print('potential.py: size mismatch in user parameters') sys.exit() # Number of Fourier components to plot Nplot = len(it_start_list) # Copy relevant quantities and make monotonous in kx t = myout['t'] delt = myin['knobs']['delt'] nwrite = myin['gs2_diagnostics_knobs']['nwrite'] kxgrid = mygrids.kx # this version is monotonous dkx = kxgrid[1] - kxgrid[0] kygrid = mygrids.ky g_exb = myin['dist_fn_knobs']['g_exb'] sgn_g = int(np.sign(g_exb)) phi2_by_mode = myout['phi2_by_mode'] phi2_by_mode = np.concatenate( (phi2_by_mode[:, :, mygrids.nxmid:], phi2_by_mode[:, :, :mygrids.nxmid]), axis=2) # Arrays to store values for each (it,ikx,iky) chosen by the user kx_full = [] ky_full = [] t_plot_full = [] t_zero_full = [] t_outgrid_full = [] it_drop_full = [] phi2_kxky_full = [] # Loop over (it,ikx,iky) chosen by the user for iplot in range(Nplot): # Time against which we plot t_plot = [] t_plot.append(t[it_start_list[iplot]]) # My ky iky = iky_list[iplot] ky = kygrid[iky] # Period of ExB remapping Tshift = abs(dkx / (g_exb * ky)) # Time dependent radial wavenumber in lab frame kxstar = [] # Grid point closest to kxstar kxbar = [] # Starting at ... kxbar.append(kxgrid[ikx_start_list[iplot]]) # ... which corresponds to the following wavenumber in shearing frame: kx = kxbar[0] + int( round(g_exb * ky * t[it_start_list[iplot]] / dkx)) * dkx # ... and to the following time dependent wavenumber in lab frame: kxstar.append(kx - g_exb * ky * t[it_start_list[iplot]]) # Mod. sq. of Fourier component phi(kx,ky): phi2_kxky = [] phi2_kxky.append(phi2_by_mode[it_start_list[iplot], iky, ikx_start_list[iplot]]) # At what time was this Fourier coefficient included in the sim ? if kx >= kxgrid.min() and kx <= kxgrid.max( ): # Already in at the start t_ingrid = 0. else: if g_exb > 0.: # Enters from high kx end t_ingrid = (kx - (kxgrid.max() + 0.5 * dkx)) / (g_exb * ky) if g_exb < 0.: # Enters from low ky end t_ingrid = (kx - (kxgrid.min() - 0.5 * dkx)) / (g_exb * ky) # At what time was this Fourier coefficient dropped from the sim ? if g_exb > 0.: # Leaves through low kx end t_outgrid = (kx - (kxgrid.min() - 0.5 * dkx)) / (g_exb * ky) if g_exb < 0.: # Leaves through high ky end t_outgrid = (kx - (kxgrid.max() + 0.5 * dkx)) / (g_exb * ky) # At what time is kxstar=0 ? if kx * g_exb < 0: t_zero = np.nan # will never cross zero else: t_zero = kx / (g_exb * ky) # Compute corresponding it_drop (might be larger than t.size if it does not drop within simulation time) if t_outgrid < t.max(): it_drop = int( np.ceil((t_outgrid + 0.5 * delt) / (nwrite * delt)) ) # add delt/2 because first step in GS2 uses dt/2 else: it_drop = -1 # Continue filling phi2_kxky by following it as it moves across kxgrid ikxgrid = ikx_start_list[iplot] if it_drop > 0: it_max = it_drop else: it_max = t.size for it in range(it_start_list[iplot] + 1, it_max): t_plot.append(t[it]) # Compute new kxstar kxstar.append(kx - g_exb * ky * t[it]) # Check if we now have a new nearest neighbour if abs(kxstar[-1] - kxbar[-1]) > 0.5 * dkx: kxbar.append(kxbar[-1] - sgn_g * dkx) # In GS2, ExB remapping has shifted our Fourier coefficient -> update ikxgrid ikxgrid = int(ikxgrid - sgn_g) else: kxbar.append(kxbar[-1]) phi2_kxky.append(phi2_by_mode[it, iky, ikxgrid]) # End of t loop # Append computed quantities to _full arrays kx_full.append(kx) ky_full.append(ky) t_plot_full.append(t_plot) t_zero_full.append(t_zero) t_outgrid_full.append(t_outgrid) it_drop_full.append(it_drop) phi2_kxky_full.append(phi2_kxky) # End of iplot loop # Save quantities to a dat-file datfile_name = run.work_dir + run.dirs[ ifile] + run.out_dir + run.files[ifile] + '.potential.dat' mydict = { 'g_exb': g_exb, 'kx_full': kx_full, 'ky_full': ky_full, 't_plot_full': t_plot_full, 't_zero_full': t_zero_full, 't_outgrid_full': t_outgrid_full, 'it_drop_full': it_drop_full, 'phi2_kxky_full': phi2_kxky_full } with open(datfile_name, 'wb') as datfile: pickle.dump(mydict, datfile) # End if not only_plot ################ ### Plotting ### ################ if not run.no_plot: # If only plot, read quantities from dat-file if run.only_plot: datfile_name = run.work_dir + run.dirs[ ifile] + run.out_dir + run.files[ifile] + '.potential.dat' with open(datfile_name, 'rb') as datfile: mydict = pickle.load(datfile) g_exb = mydict['g_exb'] kx_full = mydict['kx_full'] ky_full = mydict['ky_full'] t_plot_full = mydict['t_plot_full'] t_zero_full = mydict['t_zero_full'] t_outgrid_full = mydict['t_outgrid_full'] it_drop_full = mydict['it_drop_full'] phi2_kxky_full = mydict['phi2_kxky_full'] Nplot = len(kx_full) # Start pdf list to merge at the end tmp_pdf_id = 1 pdflist = [] for iplot in range(Nplot): # Pick iplot elements from the _full arrays kx = kx_full[iplot] ky = ky_full[iplot] t_plot = t_plot_full[iplot] t_zero = t_zero_full[iplot] t_outgrid = t_outgrid_full[iplot] it_drop = it_drop_full[iplot] phi2_kxky = phi2_kxky_full[iplot] fig = plt.figure(figsize=(12, 8)) # Plot phi_kxky vs t title = '$(k_x=' + '{:4.2f}'.format( kx) + ',k_y=' + '{:4.2f}'.format( ky) + ')$ from $t=' + '{:4.2f}'.format(t_plot[0]) + '$' xlab = '$t (a/v_{t})$' ylab = '$\\langle\\vert\\hat{\\varphi}_{k}\\vert ^2\\rangle_{\\theta}$' plt.semilogy(t_plot, phi2_kxky, linewidth=2) plt.xlabel(xlab) plt.ylabel(ylab) plt.title(title) plt.grid(True) #ax = plt.gca() # NDCDEL #ax.set_ylim([0.01, 1.5]) # NDCDEL # Draw vertical line where kxstar=0 props = dict(boxstyle='square', facecolor='white', edgecolor='white') if t_zero >= min(t_plot) and t_zero <= max(t_plot): plt.axvline(x=t_zero, color='k', linestyle='--', linewidth=2) # Add textbox ax = plt.gca() xmin, xmax = ax.get_xlim() txt_ypos = 0.05 # Place text boxes at bottom txt_xpos = 0.5 * (1. - (max(t_plot) - min(t_plot)) / (xmax - xmin)) + (t_zero - min(t_plot)) / (xmax - xmin) txt_str = '$k_x^*=0$' ax.text(txt_xpos, txt_ypos, txt_str, transform=ax.transAxes, fontsize=20, bbox=props, horizontalalignment='center') # Draw vertical line where kx is dropped from the sim if it_drop > 0: plt.axvline(x=t_outgrid, color='k', linestyle='--', linewidth=2) # Add textbox txt_xpos = 0.5 * (1. - (max(t_plot) - min(t_plot)) / (xmax - xmin)) + (t_outgrid - min(t_plot)) / (xmax - xmin) if g_exb > 0.: txt_str = '$k_x^*=\\min(k_{x,GS2})$' if g_exb < 0.: txt_str = '$k_x^*=\\max(k_{x,GS2})$' ax.text(txt_xpos, txt_ypos, txt_str, transform=ax.transAxes, fontsize=20, bbox=props, horizontalalignment='right') # Save tmp plot and append to list for merge tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 # End of iplot loop # Merge pdfs merged_pdfname = 'potential' gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile)
def plot_fluxes(ifile, run, mytime, mydict): islin = mydict['islin'] has_flowshear = mydict['has_flowshear'] # t grid time = mytime.time time_steady = mytime.time_steady it_min = mytime.it_min it_max = mytime.it_max # k grids nx = mydict['nx'] ny = mydict['ny'] naky = mydict['naky'] nakx = mydict['nakx'] kx = mydict['kx'] ky = mydict['ky'] # species nspec = mydict['nspec'] spec_names = mydict['spec_names'] # fluxes vs t pflx = mydict['pflx'] qflx = mydict['qflx'] vflx = mydict['vflx'] pioq = mydict['pioq'] # fluxes vs (kx,ky) pflx_kxky_tavg = mydict['pflx_kxky_tavg'] qflx_kxky_tavg = mydict['qflx_kxky_tavg'] vflx_kxky_tavg = mydict['vflx_kxky_tavg'] # potential phi2_avg = mydict['phi2_avg'] phi2_by_ky = mydict['phi2_by_ky'] phi2_kxky_tavg = mydict['phi2_kxky_tavg'] print() print(">>> producing plots of fluxes vs time...") print("-- plotting avg(phi2)") write_fluxes_vs_t = False tmp_pdf_id = 1 pdflist = [] if phi2_avg is not None: title = '$\\langle|\phi^{2}|\\rangle_{\\theta,k_x,k_y}$' if islin: title = '$\ln$' + title gplot.plot_1d(time, np.log(phi2_avg), '$t (a/v_{t})$', title) else: gplot.plot_1d(time, phi2_avg, '$t (a/v_{t})$', title) plt.grid(True) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 print("-- plotting particle flux") if pflx is not None: title = '$\Gamma_{GS2}$' plot_flux_vs_t(islin, nspec, spec_names, mytime, pflx, title) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 print("-- plotting heat flux") if qflx is not None: title = '$Q_{GS2}$' plot_flux_vs_t(islin, nspec, spec_names, mytime, qflx, title) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 print("-- plotting momentum flux") if vflx is not None: title = '$\Pi_{GS2}$' plot_flux_vs_t( islin, nspec, spec_names, mytime, vflx, title, ) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 #if myout['es_energy_exchange_present']: # title = 'energy exchange' # gplot.plot_1d(mytime.time,self.xchange,"$t (v_t/a)$",title) # write_fluxes_vs_t = True # tmp_pdfname = 'tmp'+str(tmp_pdf_id) # gplot.save_plot(tmp_pdfname, run, ifile) # pdflist.append(tmp_pdfname) # tmp_pdf_id = tmp_pdf_id+1 print("-- plotting momentum/heat flux ratio") if pioq is not None: title = '$\Pi_{GS2}/Q_{GS2}$' for idx in range(nspec): plt.plot(mytime.time_steady, pioq[it_min:it_max, idx], label=spec_names[idx]) plt.title(title) plt.xlabel('$t (a/v_t)$') plt.legend() plt.grid(True) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 print("-- plotting phi2 by ky") if phi2_by_ky is not None: title = '$\\langle|\phi^{2}|\\rangle_{\\theta,k_x}$' # Create list of colors cmap = plt.get_cmap('nipy_spectral') my_colors = [cmap(i) for i in np.linspace(0, 1, naky - 1)] if islin: title = '$\\ln$' + title plt.semilogy(time, np.log(phi2_by_ky[:, 0]), label='ky = ' + '{:5.3f}'.format(ky[0]), linestyle='dashed', color='black') for iky in range(1, naky): plt.semilogy(time, np.log(phi2_by_ky[:, iky]), label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) else: plt.plot(time, phi2_by_ky[:, 0], label='ky = ' + '{:5.3f}'.format(ky[0]), linestyle='dashed', color='black') for iky in range(1, naky): plt.semilogy(time, phi2_by_ky[:, iky], label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) plt.xlabel('$t (a/v_t)$') plt.title(title) plt.legend(prop={'size': 11}, ncol=6) plt.grid(True) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) if naky > 4: tmp_pdf_id = tmp_pdf_id + 1 title = '$\\langle|\phi^{2}|\\rangle_{\\theta,k_x}$ for low $k_y$' #plt.figure(figsize=(8,8)) # NDCDEL if islin: title = '$\\ln$' + title plt.semilogy(time, np.log(phi2_by_ky[:, 0]), label='ky = ' + '{:5.3f}'.format(ky[0]), linestyle='dashed', color='black') for iky in range(1, 5): plt.semilogy(time, np.log(phi2_by_ky[:, iky]), label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) else: plt.plot(time[:], phi2_by_ky[:, 0], label='ky = ' + '{:5.3f}'.format(ky[0]), linestyle='dashed', color='black') #for iky in range(1,4) :# NDCDEL for iky in range(1, 5): plt.semilogy(time[:], phi2_by_ky[:, iky], label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) #plt.xlabel('$t$') # NDCDEL plt.xlabel('$t (a/v_t)$') #plt.ylabel('$\\langle|\phi^{2}|\\rangle_{\\theta,k_x}$') # NDCDEL plt.title(title) plt.legend() plt.grid(True) # NDCDEL #axes = plt.gca() #axes.set_xlim([0,500]) #plt.savefig('terrific.pdf') # endNDCDEL write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 title = '$\\langle|\phi^{2}|\\rangle_{\\theta,k_x}$ for high $k_y$' if islin: title = '$\\ln$' + title for iky in range(naky - 5, naky): plt.semilogy(time, np.log(phi2_by_ky[:, iky]), label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) else: for iky in range(naky - 5, naky): plt.semilogy(time, phi2_by_ky[:, iky], label='ky = ' + '{:5.3f}'.format(ky[iky]), color=my_colors[iky - 1]) plt.xlabel('$t (a/v_t)$') plt.title(title) plt.legend() plt.grid(True) write_fluxes_vs_t = True tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) if write_fluxes_vs_t: merged_pdfname = 'fluxes_vs_t' if ifile == None: # This is the case when we stitch fluxes together merged_pdfname += '_' + run.scan_name gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile) print('complete') print() print('producing plots of fluxes vs (kx,ky)...', end='') write_fluxes_vs_kxky = False tmp_pdf_id = 1 pdflist = [] # Plot phi2 averaged over t and theta, vs (kx,ky) plot_phi2_vs_kxky(kx, ky, phi2_kxky_tavg, has_flowshear) tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id += 1 if pflx_kxky_tavg is not None: title = '$\Gamma_{GS2}$' for ispec in range(nspec): plot_flux_vs_kxky(ispec, spec_names, kx, ky, pflx_kxky_tavg, title, has_flowshear) tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 write_fluxes_vs_kxky = True if qflx_kxky_tavg is not None: title = '$Q_{GS2}$' for ispec in range(nspec): plot_flux_vs_kxky(ispec, spec_names, kx, ky, qflx_kxky_tavg, title, has_flowshear) tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 write_fluxes_vs_kxky = True if vflx_kxky_tavg is not None: title = '$\Pi_{GS2}$' for ispec in range(nspec): plot_flux_vs_kxky(ispec, spec_names, kx, ky, vflx_kxky_tavg, title, has_flowshear) tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdfname) tmp_pdf_id = tmp_pdf_id + 1 write_fluxes_vs_kxky = True if write_fluxes_vs_kxky: merged_pdfname = 'fluxes_vs_kxky' if ifile == None: # This is the case when we stitch fluxes together merged_pdfname += '_' + run.scan_name gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile) print('complete')
def trikap(run): # Only execute if plotting if run.no_plot: return print("Plotting scan of triangularity vs elongation...") Nfile = len(run.fnames) # Init arrays of data used in scan. full_fluxes = [dict() for ifile in range(Nfile)] full_time = [dict() for ifile in range(Nfile)] # Initialize fluxes and grids from .dat files. for ifile in range(Nfile): datfile_name = run.work_dir + run.dirs[ ifile] + run.out_dir + run.files[ifile] + '.fluxes.dat' with open(datfile_name, 'rb') as datfile: full_fluxes[ifile] = pickle.load(datfile) datfile_name = run.work_dir + run.dirs[ ifile] + run.out_dir + run.files[ifile] + '.time.dat' with open(datfile_name, 'rb') as datfile: full_time[ifile] = pickle.load(datfile) # Uses nspec from first file. Will quit if not constant between files. nspec = full_fluxes[0]['nspec'] print("Number of species " + str(nspec)) tri, kap = np.zeros(Nfile), np.zeros(Nfile) for ifile in range(Nfile): tri[ifile] = full_fluxes[ifile]['tri'] kap[ifile] = full_fluxes[ifile]['kap'] if full_fluxes[ifile]['nspec'] != nspec: quit("Number of species varies between files - exiting") tris = sorted(list(set(tri))) kaps = sorted(list(set(kap))) print("Triangularity values: " + str(tris)) print("Elongation values: " + str(kaps)) if len(tris) * len(kaps) != Nfile: quit("Too few files added to populate the scan - exiting") qflx = np.zeros((len(tris), len(kaps), nspec)) for itri in range(len(tris)): for ikap in range(len(kaps)): for ifile in range(Nfile): if tri[ifile] == tris[itri] and kap[ifile] == kaps[ikap]: for ispec in range(nspec): qflx[itri, ikap, ispec] = full_time[ifile].timeavg( full_fluxes[ifile]['qflx'][:, ispec]) spec_names = full_fluxes[0]['spec_names'] pdflist = [] tmp_pdf_id = 0 for ispec in range(nspec): print("Plotting for species: " + spec_names[ispec]) gplot.plot_2d(qflx[:, :, ispec], tris, kaps, np.min(qflx[:, :, ispec]), np.max(qflx[:, :, ispec]), cmp='Reds', xlab='$\delta$', ylab='$\kappa$', title='$Q_{GS2}$: ' + spec_names[ispec]) tmp_pdfname = 'tmp' + str(tmp_pdf_id) gplot.save_plot(tmp_pdfname, run) pdflist.append(tmp_pdfname) tmp_pdf_id += 1 merged_pdfname = 'tri_kap_scan' gplot.merge_pdfs(pdflist, merged_pdfname, run)
def plot(self, ifile, run, mytime, myfields, mytxt): write_correlation_times(mytxt, self) tmp_pdf_id = 1 pdflist = [] plot_timecorrfnc_nonzonal(self) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 plot_timecorrfnc_zonal(self) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 plot_timecorrfnc_gyrozonal(self) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 plot_nonzonal_freq_spectrum(mytime, myfields) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 plot_zonal_power_spectrum(mytime, myfields, self) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 gfields.plot_power_spectrum(myfields, mytime) tmp_pdfname = 'tmp'+tmp_pdf_id gplot.save_plot(tmp_pdfname, run, ifile) pdflist.append(tmp_pdf_name) tmp_pdf_id = tmp_pdf_id+1 merged_pdfname = 'time_correlation' gplot.merge_pdfs(pdflist, merged_pdfname, run, ifile)
def plot(run, full_space): dt = np.zeros(len(run.fnames)//2) dkx = np.zeros(len(run.fnames)//2) phi2 = np.zeros(len(run.fnames)//2) dt_new = np.zeros(len(run.fnames)//2) dkx_new = np.zeros(len(run.fnames)//2) phi2_new = np.zeros(len(run.fnames)//2) ilast = len(run.fnames) imid = len(run.fnames)//2 ## files with old algorithm for ifile in range(imid): dt[ifile] = full_space[ifile]['flowtest'].dt dkx[ifile] = full_space[ifile]['flowtest'].dkx for ifile in range(imid): #it = int(round(10.*dt[0]/dt[ifile])) - 1 it = -1 phi2[ifile] = full_space[ifile]['flowtest'].phi2[it] ## files with new algorithm for ifile in range(imid, ilast): dt_new[ifile-imid] = full_space[ifile]['flowtest'].dt dkx_new[ifile-imid] = full_space[ifile]['flowtest'].dkx for ifile in range(imid, ilast): #it = int(round(10.*dt[0]/dt_new[ifile-imid])) - 1 it = -1 phi2_new[ifile-imid] = full_space[ifile]['flowtest'].phi2[it] idxsort = np.argsort(dt) dt = dt[idxsort] dt_new = dt_new[idxsort] phi2 = phi2[idxsort] phi2_new = phi2_new[idxsort] plt.rc('text', usetex=True) plt.rc('font', family='serif') plt.rc('font', size=25) plt.figure(figsize=(12,8)) #plt.title('$\\Delta k_x = \\gamma_E\\times\\Delta k_y\\times\\Delta t$') #plt.title('Fixed $\\Delta k_x$') plt.title('Fixed $\\Delta t$') #plt.plot(dt, phi2, marker='o', markersize=12, markerfacecolor='none', markeredgecolor=myblue, color=myblue, linewidth=3.0) #plt.plot(dt_new, phi2_new, marker='s', markersize=8, color=myred, linewidth=3.0) plt.plot(dkx, phi2, marker='o', markersize=12, markerfacecolor='none', markeredgecolor=myblue, color=myblue, linewidth=3.0) plt.plot(dkx_new, phi2_new, marker='s', markersize=8, color=myred, linewidth=3.0) #plt.xlabel('$\\Delta t$') plt.xlabel('$\\Delta k_x$') plt.ylabel('$\\frac{1}{2\\pi}\\int d\\theta\\vert \\phi \\vert ^2(k_x=0)$') plt.legend(['old algo.', 'new algo.'], loc='lower right') plt.gca().set_ylim(bottom = 0.0, top = 1.3e-5) plt.gca().get_yaxis().get_major_formatter().set_powerlimits((0.01,100.)) plt.grid(True) #pdfname = 'get_converged' #pdfname = 'dt_scan' pdfname = 'dkx_scan_kx0' gplot.save_plot(pdfname, run)