Skip to content

Commit 9f4d77a

Browse files
author
Georgia Acton
committed
new diag
1 parent c4844ef commit 9f4d77a

File tree

5 files changed

+269
-181
lines changed

5 files changed

+269
-181
lines changed
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import numpy as np
2-
from stella_plots import movie_2d
2+
from stella_plots import movie_2d, plot_2d
33
from stella_data import gzvs, vpa, zed, ntime, g2nozonal_vs_zvpas, nzed, time
4-
from stella_data import gzvs_zonal
4+
from stella_data import gzvs_zonal, kx_stella
55
from stella_data import outdir
6+
import matplotlib.pyplot as plt
67

78
nvpa = vpa.size
89
print('nvpa', nvpa)
910
gmax = np.arange(ntime,dtype=float)
1011
gmin = np.arange(ntime,dtype=float)
1112

13+
kx_val = 0.05
14+
ikx = next((i for i, value in enumerate(kx_stella) if value >=kx_val), None)
1215
#(t, species, vpa, tube, zed, kx, ri)
13-
g_zonal = np.array(gzvs_zonal[:, 0, :, 0, :, 1, 0] + 1j*gzvs_zonal[:, 0, :, 0, :, 1, 1], dtype=complex)
16+
g_zonal = np.array(gzvs_zonal[:, 0, :, 0, :, ikx, 0] + 1j*gzvs_zonal[:, 0, :, 0, :, ikx, 1], dtype=complex)
1417

1518
for i in range(ntime):
1619
gmax[i] = np.abs(g_zonal[i,:,:]).max()
@@ -19,7 +22,16 @@
1922

2023
ylabel = '$v_{\parallel}$'
2124
xlabel = '$z$'
22-
title = '$\int d\mu \int d^2 \mathbf{R} g^2$'
25+
title = '$\int d\mu \int d^2 \mathbf{R} g$'
2326
movie_file = outdir + 'gzvs.mp4'
2427

25-
movie_2d(g_zonal,zed,vpa,gmin,gmax,ntime-1,movie_file,xlabel,ylabel,title,cmp='RdBu', abs_flag=True)
28+
#movie_2d(g_zonal,zed,vpa,gmin,gmax,ntime-1,movie_file,xlabel,ylabel,title,cmp='RdBu', abs_flag=False)
29+
30+
time_avg = ntime//2
31+
g_zonal_avg = np.sum(g_zonal[time_avg:,:,:],axis=0)
32+
gmax = np.abs(g_zonal_avg).max()
33+
gmin = - gmax
34+
35+
outfile = outdir + 'timeave.pdf'
36+
plot_2d(g_zonal_avg,zed,vpa,gmin,gmax,'zed','vpa',title,cmp='RdBu', outfile=outfile)
37+

POST_PROCESSING/post_processing/kspectra_plots.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,49 +48,7 @@
4848
#f2out.write('#ky0: '+str(ky0)+' ky1: '+str(ky1)+'\n')
4949
f2out.close()
5050

51-
#fig=plt.figure(figsize=(12,8))
52-
fig, axs = plt.subplots(ncols=2, layout='constrained', sharex='col', figsize=(12,8))
53-
54-
# distinguish between zonal
55-
for ikx in range(nakx):
56-
axs[0].semilogy(time,phi2[:,ikx,0])
57-
print('phi2(t=0), kx=', np.sqrt(phi2[0,ikx,0])/kx[ikx]**2 )
58-
axs[1].scatter(kx[ikx], np.sqrt(phi2[-1, ikx,0]/phi2[0,ikx,0]))
59-
print('ratio =', np.sqrt(phi2[-1, ikx,0]/phi2[0,ikx,0]), 'kx=',kx[ikx])
60-
61-
axs[1].set_xscale('log')
62-
axs[0].set_xlabel('$t (v_{t}/a)$')
63-
axs[1].set_label('$k_x \rho_i$')
64-
axs[0].set_xlim([time[0],time[ntime-1]])
65-
axs[1].set_xlim(0,2.1 )
66-
plt.title('$\Phi(k_x,k_y=0)$')
67-
68-
file = outdir+file_prefix+'.stella_kspectra_zonal.pdf'
69-
pdf = PdfPages(file)
70-
for i in plt.get_fignums():
71-
pdf.savefig(i)
72-
pdf.close()
73-
plt.close('all')
74-
75-
7651
fig=plt.figure(figsize=(12,8))
77-
78-
for ikx in range(1, nakx):
79-
plt.semilogy(time, entropy_vs_kx[:,ikx])
80-
81-
plt.semilogy(time, np.sum(entropy_vs_kx[:,:], axis=1), '--')
82-
plt.xlabel('$t (v_{t}/a)$')
83-
plt.ylabel('Free energy')
84-
file = outdir+file_prefix+'.stella_free_energy.pdf'
85-
pdf = PdfPages(file)
86-
for i in plt.get_fignums():
87-
pdf.savefig(i)
88-
pdf.close()
89-
plt.close('all')
90-
91-
92-
fig=plt.figure(figsize=(12,8))
93-
9452
# distinguish between zonal/nonzonal modes
9553
for ikx in range(phi2.shape[1]-1):
9654
plt.semilogy(time,phi2[:,ikx+1,0],'--')

POST_PROCESSING/post_processing/stella_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
####### Import variables from netcdf file #########
1010
#infile = input("Path to netcdf file: ")
11-
input_directory = '/Users/giorgiaacton/Documents/runs/ALL_RH/test_diag/'
11+
#input_directory = '/pitagora_work/FUPA1_STELTURB/gacton00/Paul/linear_60_higherres/'
12+
input_directory = '/pitagora_scratch/userexternal/gacton00/RH_noj0_higherres/'
1213
file_prefix = 'input'
1314
infile = input_directory + file_prefix + '.out.nc'
1415
outdir = input_directory
@@ -193,8 +194,8 @@ def read_stella_float(var):
193194
temperature, temperature_present = \
194195
read_stella_float('temperature')
195196

196-
entropy_vs_kx, entropy_vs_kx_present = \
197-
read_stella_float('entropy_vs_kx')
197+
free_energy_vs_kx, free_energy_vs_kx_present = \
198+
read_stella_float('free_energy_vs_kx')
198199

199200
ncfile.close()
200201

POST_PROCESSING/post_processing/stella_plots.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def logyplot_1d(x,y,xlab,title='',ylab=''):
5151
plt.title(title)
5252
return fig
5353

54-
def plot_2d(z,xin,yin,zmin,zmax,xlab='',ylab='',title='',cmp='RdBu'):
54+
def plot_2d(z,xin,yin,zmin,zmax,xlab='',ylab='',title='',cmp='RdBu', outfile=''):
55+
56+
z = np.real(z)
5557

5658
fig = plt.figure(figsize=(12,8))
5759
x,y = np.meshgrid(xin,yin)
@@ -63,8 +65,9 @@ def plot_2d(z,xin,yin,zmin,zmax,xlab='',ylab='',title='',cmp='RdBu'):
6365
plt.xlabel(xlab)
6466
plt.ylabel(ylab)
6567
plt.title(title)
66-
return fig
67-
68+
plt.savefig(outfile)
69+
plt.close(fig)
70+
6871
def movie_2d(z, xin, yin, zmin, zmax, nframes, outfile,
6972
xlab='', ylab='', title='', step=1, cmp='RdBu',
7073
fps=10, interval=50, abs_flag=True):
@@ -80,8 +83,11 @@ def movie_2d(z, xin, yin, zmin, zmax, nframes, outfile,
8083

8184
if abs_flag == True :
8285
print('abs flag is True')
83-
z_even = np.sign(np.real(z_even_full)) * np.abs(z_even_full)
84-
z_odd = np.sign(np.real(z_odd_full)) * np.abs(z_odd_full)
86+
#z_even = np.sign(np.real(z_even_full)) * np.abs(z_even_full)
87+
#z_odd = np.sign(np.real(z_odd_full)) * np.abs(z_odd_full)
88+
z_even = np.abs(z_even_full)
89+
z_odd = np.abs(z_odd_full)
90+
zmin[:] = 0.0
8591
else:
8692
z_even = np.real(z_even_full)
8793
z_odd = np.real(z_odd_full)
@@ -104,9 +110,9 @@ def movie_2d(z, xin, yin, zmin, zmax, nframes, outfile,
104110
# Create initial images once (frame 0)
105111
i0 = frames[0]
106112
im1 = ax1.imshow(z_even[i0], origin='lower', aspect='auto',
107-
extent=extent, cmap='RdBu', animated=False)
113+
extent=extent, cmap=cmp, animated=False)
108114
im2 = ax2.imshow(z_odd[i0], origin='lower', aspect='auto',
109-
extent=extent, cmap='RdBu', animated=False)
115+
extent=extent, cmap=cmp, animated=False)
110116

111117
# Set initial clim from provided arrays/scalars:
112118
try:

0 commit comments

Comments
 (0)