-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathavgOmstare.py
executable file
·163 lines (146 loc) · 4.99 KB
/
avgOmstare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import os
import matplotlib.pyplot as plt
from fieldlib import *
from ParIO import *
from finite_differences import *
import optparse as op
from read_write_geometry import *
#from read_write_geometry_lilo import *
from subprocess import call
import sys
import math
from interp import *
from read_iterdb import *
#from calc_omega_from_field import *
parser=op.OptionParser(description='Plots mode structures and calculates various interesting quantities.')
parser.add_option('--plots','-p', action='store',dest = 'plots', help = 'Plot all plots.',default=False)
parser.add_option('--pfile','-f',type = 'str',action='store',dest="prof_file",help = 'profile file name.',default='empty')
parser.add_option('--w','-w',type = 'str',action='store',dest="weightFunc",help = 'weighting function.',default='empty')
options, args = parser.parse_args()
suffix = args[0]
plots = options.plots
#idb_file = options.idb_file
prof_file = options.prof_file
weightFunc = options.weightFunc
if suffix != '.dat':
suffix = '_'+suffix
par = Parameters()
par.Read_Pars('parameters'+suffix)
pars = par.pardict
field = fieldfile('field'+suffix,pars)
time = np.array(field.tfld)
if 1 == 1:
itime = -1
itime0 = len(time)-1
field.set_time(time[itime])
if 'x_local' in pars:
if pars['x_local']:
x_local = True
else:
x_local = False
else:
x_local = True
if 'lilo' in pars:
if pars['lilo']:
lilo = True
else:
lilo = False
else:
lilo = False
if 1 == 1:
dz = 2.0/field.nz
zgrid = np.arange(field.nz)/float(field.nz-1)*(2.0-dz)-1.0
if 'lx_a' in pars:
xgrid = np.arange(field.nx)/float(field.nx-1)*pars['lx_a']+pars['x0']-pars['lx_a']/2.0
else:
xgrid = np.arange(field.nx)/float(field.nx-1)*pars['lx'] - pars['lx']/2.0
#gpars,geometry = read_geometry_global(pars['magn_geometry'][1:-1]+suffix)
#qmin = np.min(geometry['q'])
#qmax = np.max(geometry['q'])
#mmin = math.ceil(qmin*pars['n0_global'])
#mmax = math.floor(qmax*pars['n0_global'])
#mnums = np.arange(mmin,mmax+1)
#print "mnums",mnums
#qrats = mnums/float(pars['n0_global'])
phi = field.phi()[:,0,:]
apar = field.apar()[:,0,:]
if plots:
plt.figure(figsize=(8.0,9.5))
fig=plt.gcf()
fig.subplots_adjust(right=0.9)
fig.subplots_adjust(left=0.16)
fig.subplots_adjust(hspace=0.35)
plt.subplot(3,1,1)
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.title(r'$|\phi|$')
plt.contourf(xgrid,zgrid,np.abs(phi),70)
#for i in range(len(qrats)):
# ix = np.argmin(abs(geometry['q']-qrats[i]))
# plt.axvline(xgrid[ix],color='white')
cb1=plt.colorbar()
plt.subplot(3,1,2)
plt.title(r'$Re[\phi]$')
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.contourf(xgrid,zgrid,np.real(phi),70)
plt.colorbar()
plt.subplot(3,1,3)
plt.title(r'$Im[\phi]$')
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.contourf(xgrid,zgrid,np.imag(phi),70)
plt.colorbar()
plt.show()
if plots:
plt.figure(figsize=(8.0,9.5))
fig=plt.gcf()
fig.subplots_adjust(right=0.9)
fig.subplots_adjust(left=0.16)
fig.subplots_adjust(hspace=0.35)
plt.subplot(3,1,1)
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.title(r'$|A_{||}|$')
plt.contourf(xgrid,zgrid,np.abs(apar),70)
#for i in range(len(qrats)):
# ix = np.argmin(abs(geometry['q']-qrats[i]))
# plt.axvline(xgrid[ix],color='white')
cb1=plt.colorbar()
plt.subplot(3,1,2)
plt.title(r'$Re[A_{||}]$')
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.contourf(xgrid,zgrid,np.real(apar),70)
plt.colorbar()
plt.subplot(3,1,3)
plt.title(r'$Im[A_{||}]$')
plt.ylabel(r'$z/\pi$',fontsize=13)
plt.xlabel(r'$\rho_{tor}$',fontsize=13)
plt.contourf(xgrid,zgrid,np.imag(apar),70)
plt.colorbar()
plt.show()
if 1 == 1:
if prof_file == 'empty':
prof_file = raw_input("Enter gene output profiles file name:\n")
profData = np.genfromtxt(prof_file)
rho = profData[:,0]
omt = profData[:,4]
omn = profData[:,5]
omstar = pars['kymin'] * (omt + omn)
weight = 0.
norm = 0.
totOmstar = 0.
for i in range(pars['nx0']):
phiX = np.sum(abs(phi[:,i]) ** 2)
aparX = np.sum(abs(apar[:,i]) ** 2)
if weightFunc == 'phi':
weight = phiX
elif weightFunc == 'apar':
weight = aparX
norm = norm + weight
totOmstar = totOmstar + omstar[i] * weight
print 'average Om_star_e = ', totOmstar / norm