-
Notifications
You must be signed in to change notification settings - Fork 2
/
upic-bvp-plot.py
204 lines (157 loc) · 5.37 KB
/
upic-bvp-plot.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# *******************************************************************************
# *******************************************************************************
#
# Making Movies from UPIC data (for spatial Landau Damping)
#
# FST, (c) 2020 Regents of The University of California
#
# *******************************************************************************
# *******************************************************************************
import sys
# change path depending on machine
# the path below is for Frank's Mac
#
sys.path.append('/Users/franktsung/Documents/codes/python-tsung/')
sys.path.append('/Volumes/Lacie-5TB/codes/pyVisOS/')
import osh5io
import osh5def
import osh5vis
import osh5utils
from h5_utilities import *
import matplotlib.pyplot as plt
import sys
import getopt
import glob
import numpy as np
from mpi4py import MPI
def print_help():
print('python upic_bvp_movie.py [options] <InputDir> <OutputDir>')
print('InputDir - Location of the MS folder')
print('OutputDir - Location of the output folder, makes .png files from data')
print('options:')
#2345
import os
import errno
# *******************************************************************************
# this is the subroutine pulled from the Jupyter notebook, replace the plotting
# with file-save
# *******************************************************************************
def something_2(rundir,file_no):
my_path=os.getcwd()
#print(my_path)
working_dir=my_path+'/'+rundir
#print(working_dir)
dir_0=rundir+'/Vx_x/'
dir_1=rundir+'/Ex/'
output_dir = rundir +'/movies/'
try:
os.mkdir(output_dir)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass
quan_0_prefix='vx_x_'
quan_1_prefix='Ex-0_'
output_prefix='frame_'
fig = plt.figure(figsize=(10,8) )
phase_space_filename=dir_0+quan_0_prefix+repr(file_no).zfill(6)+'.h5'
e1_filename=dir_1+quan_1_prefix+repr(file_no).zfill(6)+'.h5'
output_filename=output_dir+'/'+output_prefix+repr(file_no).zfill(6)+'.png'
phase_space_data = osh5io.read_h5(phase_space_filename)
e1_data = np.average(osh5io.read_h5(e1_filename),axis=0)
p1_x1_plot = plt.subplot(221)
osh5vis.osplot(np.log(np.abs(phase_space_data)+1e-10),title='Phase Space',vmax=10,vmin=-2,cmap='Blues')
e1_plot = plt.subplot(222)
osh5vis.osplot(e1_data,title='Electric Field')
e1_plot.set_ylim([-0.1,0.1])
plt.tight_layout()
fv_plot = plt.subplot(223)
# print(hdf5_data)
xmin=phase_space_data.axes[0].min
xmax=phase_space_data.axes[0].max
ymin=phase_space_data.axes[1].min
ymax=phase_space_data.axes[1].max
# dx=(xmax-xmin)/float(nx[0]-1)
# dy=(ymax-ymin)/float(nx[1]-1)
# print(dx)
# print(dy)
# xmax=xmax-dx
# ymax=ymax-dy
# xmin=xmin+10.0*dx
# ymin=ymin-10.0*dy
# print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
nx=phase_space_data.shape
xaxis=np.linspace(xmin,xmax,num=nx[0])
yaxis=np.linspace(ymin,ymax,num=nx[1])
plt.plot(xaxis,np.average(phase_space_data,axis=1))
plt.xlabel('$v/v_{th}$')
plt.ylabel('f(v) [a.u]')
fv_plot.set_ylim([0, 1500])
fv_slices = plt.subplot(224)
# print(hdf5_data)
xmin=phase_space_data.axes[0].min
xmax=phase_space_data.axes[0].max
ymin=phase_space_data.axes[1].min
ymax=phase_space_data.axes[1].max
# dx=(xmax-xmin)/float(nx[0]-1)
# dy=(ymax-ymin)/float(nx[1]-1)
# print(dx)
# print(dy)
# xmax=xmax-dx
# ymax=ymax-dy
# xmin=xmin+10.0*dx
# ymin=ymin-10.0*dy
# print(repr(xmin)+' '+repr(xmax)+' '+repr(ymin)+' '+repr(ymax))
nx=phase_space_data.shape
xaxis=np.linspace(xmin,xmax,num=nx[0])
yaxis=np.linspace(ymin,ymax,num=nx[1])
plt.plot(xaxis,np.average(phase_space_data[:,492:532],axis=1))
plt.plot(xaxis,np.average(phase_space_data[:,352:372],axis=1),'r')
plt.plot(xaxis,np.average(phase_space_data[:,652:672],axis=1),'g')
plt.xlabel('$v/v_{th}$')
plt.ylabel('f(v) [a.u]')
fv_slices.set_ylim([0, 1500])
plt.savefig(output_filename)
# plt.show()
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
argc = len(sys.argv)
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "hxyn:", ['avg', 'env'])
except getopt.GetoptError:
print_help()
sys.exit(2)
if len(args) < 1:
print_help()
sys.exit(2)
dirName = args[0]
# outDir = args[1]
dir_ext = ''
density = 0.1
#2345
# my_path=os.getcwd()
# working_dir=my_path+'/'+rundir
phase_space_dir=dirName+'/Vx_x/'
files=sorted(os.listdir(phase_space_dir))
print(files[1])
start=files[1].find('vx_x_')+5
end=files[1].find('.')
print('file interval = '+files[1][start:end])
## // --> floor division
file_interval=int(files[1][start:end])
file_max=(len(files)-1)*file_interval
total_time = len(files)
my_share = total_time // size
i_begin = rank * my_share
if rank < (size -1):
i_end = (rank + 1) * my_share
else:
i_end = total_time
print(file_max)
# *******************************************************************************
# this line replaces the slider
for file_number in range(i_begin, i_end):
print('file_number = '+repr(file_number))
something_2(rundir=dirName,file_no=file_number*file_interval)
# *******************************************************************************