-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_pressure.py
More file actions
79 lines (66 loc) · 2.03 KB
/
plot_pressure.py
File metadata and controls
79 lines (66 loc) · 2.03 KB
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
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.animation as anim
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.colors import BoundaryNorm
import numpy as np
import os
import sys
from glob import glob
# Enable looped gif by overwriting the PillowWriter class and adding loop=0
class myPillow(anim.PillowWriter):
def finish(self):
self._frames[0].save(
self._outfile, save_all=True, append_images=self._frames[1:],
duration=int(1000 / self.fps), loop=0)
if(len(sys.argv)<2):
print("folder name not Entered")
print("enter Correct Folder name as system arguments")
exit()
home=os.getcwd()
path=home+"/OUTPUT/"+sys.argv[1]
if os.path.exists(path):
os.chdir(path)
print(path)
else:
print("Specified folder doesnt exist")
print("enter Correct Folder name: as system arguments")
exit()
files=sorted(glob("*npz"))
print(len(files))
if(len(files)>3000):
files=files[::10]
data = np.load(files[0])
p=data['pre']
fig = plt.figure(1, [5, 5])
ax = fig.gca()
# Plot colormap.
cmap = mpl.cm.get_cmap('viridis')
norm = BoundaryNorm(np.linspace(-0.2, 0.2, 21), cmap.N);
speed = ax.imshow(p, norm = norm, origin = "lower", cmap=cmap, extent = (0, 1, 0, 1))
# Plot colorbar.
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad=0.05)
bar = fig.colorbar(speed, cax=cax, orientation='vertical')
bar.locator = mpl.ticker.MultipleLocator(0.02)
bar.update_ticks()
plt.tight_layout()
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
def animate(n):
data = np.load(files[n])
p=data['pre']
# print(p[1:-1,1:-1])
speed.set_data(p)
speed.set
t=n/(len(files)-1)
ax.set_title("Pressure at time:{}".format(t))
# plt.savefig("pre{}.png".format(t))
if(n%10==0):
print("Frame " + str(n))
return speed,
writer = myPillow()
writer.fps = 1
animation = anim.FuncAnimation(fig, animate, frames=len(files), interval = 2, blit=True)
file="_{}_pres.gif".format(sys.argv[1])
animation.save(file, writer=writer)