-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_analysis_pool.py
179 lines (115 loc) · 5.11 KB
/
run_analysis_pool.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 11 10:40:57 2021
@author: maple
"""
import concurrent.futures
#from multiprocessing import Pool
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from poincare_map import PoincareMapper
import scipy.interpolate
import scipy.signal
import sys
# %% Set up Baseline Poincare Mapper
#pm = PoincareMapper('poincare_input/poincare_config_validation.npz')
#numeigs = len(pm.data['kys'])
#pm.generateFullSection(np.ones(numeigs), np.zeros(numeigs), 'sections/section_validation.npz')
# %% Set up Poincare Mapper
suffix = '_uphavg'
# %% Poincare sections via amplitude of waves
def saveSection(inputdata):
case, ind, ampmult, phaseofs = inputdata
pm = PoincareMapper('/home/nc1472/git/qg-edgeofchaos/poincare_input/case{}_poincare_config_fd_smooth{}.npz'.format(case, suffix))
numeigs = len(pm.data['kys'])
# %% Prepare Poincare section plots
qbar = pm.data['qbar']
uy = pm.data['uy']
nx = 2048
x = np.linspace(-np.pi, np.pi, num=nx, endpoint=False)
# Set up interpolation functions
pad = 4
xp = np.zeros(nx+2*pad)
xp[pad:-pad] = x
xp[:pad] = x[-pad:] - 2*np.pi
xp[-pad:] = x[:pad] + 2*np.pi
def circularInterpolant(vec):
vecp = np.zeros(nx+2*pad)
vecp[pad:-pad] = vec
vecp[:pad] = vec[-pad:]
vecp[-pad:] = vec[:pad]
return scipy.interpolate.interp1d(xp, vecp, kind='quadratic')
uyfft = np.fft.rfft(uy)
hilbuy = np.fft.irfft(1j*uyfft)
hilbuyf = circularInterpolant(hilbuy)
uyf = circularInterpolant(uy)
# Compute regions of zonal flow minima and maxima
uyminxs = x[scipy.signal.argrelextrema(uy, np.less)]
uymaxxs = x[scipy.signal.argrelextrema(uy, np.greater)]
#ampmult = timedata['ampdevs'][:,ind]
#phaseofs = timedata['phasedevs'][:,ind]
pm.generateFullSection(ampmult, phaseofs, '/data/nc1472/qg-edgeofchaos/extra_poincare_sections/case{}_section_ind{:03d}{}.npz'.format(case, ind, suffix), nparticles=193, sections=2039, fancyspacing=True)
data = np.load('/data/nc1472/qg-edgeofchaos/extra_poincare_sections/case{}_section_ind{:03d}{}.npz'.format(case, ind, suffix), 'r')
z0 = data['y'][:,0]
yclip = data['yclip']
nparticles = len(z0)//2
colors = np.zeros((nparticles, yclip.shape[1]))
rotation_number = (data['y'][nparticles:,-1] - data['y'][nparticles:,0]) / data['y'].shape[1] / 2 / np.pi
xavg = np.average(data['y'][:nparticles,:], axis=1)
rotcolors = np.zeros((yclip.shape[0]//2, yclip.shape[1]))
# Compute index of shearless curves
rotmins = np.zeros(uyminxs.shape, dtype=int)
rotmaxs = np.zeros(uymaxxs.shape, dtype=int)
for i in range(len(uyminxs)):
rotmins[i] = np.argmin(rotation_number - (np.abs(xavg - uyminxs[i])<0.2)*1000.0)
rotcolors[rotmins[i]:,:] += 0.5
rotcolors[rotmins[i]+1:,:] += 0.5
for i in range(len(uymaxxs)):
rotmaxs[i] = np.argmax(rotation_number + (np.abs(xavg - uymaxxs[i])<0.2)*1000.0)
rotcolors[rotmaxs[i]:,:] -= 0.5
rotcolors[rotmaxs[i]+1:,:] -= 0.5
# Compute "mixing lengths"
stdresid = np.zeros(nparticles)
for i in range(nparticles):
xall = data['y'][i,:] - xavg[i]
nvar = 9
ymat = np.zeros((nvar, len(xall)-nvar))
xmat = np.zeros((nvar, len(xall)-nvar))
for j in range(nvar):
if j == 0:
ymat[j,:] = xall[nvar-j:]
else:
ymat[j,:] = xall[nvar-j:-j]
xmat[j,:] = xall[nvar-j-1:-(j+1)]
amat = ymat @ np.linalg.pinv(xmat)
residuals = ymat - (amat @ xmat)
stdresid[i] = np.sqrt(np.var(residuals[0,:]))
if np.max(rotcolors) > 0.5:
colors = stdresid[:, np.newaxis] * np.sign(rotcolors-0.5)
else:
colors = stdresid[:, np.newaxis] * np.sign(rotcolors+0.5)
stride = 1
stride2 = 1
fig, ax = plt.subplots(1, 1, figsize=(10.0, 10.0))
ax.set_aspect('equal', adjustable='datalim')
ax.set_xlim([-np.pi,np.pi])
ax.set_ylim([-np.pi,np.pi])
plt.tight_layout()
ax.scatter(yclip[nparticles::stride,::stride2], yclip[:nparticles:stride,::stride2], s=72.0/fig.dpi, marker='o', linewidths=0, c=colors[::stride,::stride2], cmap='Spectral', rasterized=True, vmin=-np.max(np.abs(colors)), vmax=np.max(np.abs(colors)))
plt.savefig('/data/nc1472/qg-edgeofchaos/extra_poincare_sections/case{}_section_ind{:03d}{}.png'.format(case, ind, suffix), dpi=100)
return ind
if __name__ == '__main__':
print(sys.argv)
case = int(sys.argv[1])
with np.load('/home/nc1472/git/qg-edgeofchaos/poincare_input/case{}_eigencomponent_timedata{}.npz'.format(case, suffix), 'r') as timedata:
inds = range(timedata['ampdevs'].shape[1])
cases = [case for i in inds]
ampmults = [timedata['ampdevs'][:,i] for i in inds]
phasedevs = [timedata['phasedevs'][:,i] for i in inds]
allargs = zip(cases, inds, ampmults, phasedevs)
with concurrent.futures.ProcessPoolExecutor(max_workers=16) as executor:
results = executor.map(saveSection, allargs)
for result in results:
print(result)