Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/elmerice/examples/Inverse_Methods/SCRIPTS/PlotHist.py
3206 views
1
#
2
# Make histogram plots from inverse methods results
3
# Give a file that contains x y uobs vobs umod vmod
4
#
5
#
6
import numpy as np
7
from pylab import genfromtxt;
8
from scipy.stats import norm
9
import matplotlib.pyplot as plt
10
import sys
11
12
try:
13
sys.argv[1]
14
except:
15
print('error: ')
16
print(' provide a file name as argument')
17
print(' must contain x y uobs vobs umod vmod')
18
exit()
19
20
fname=sys.argv[1]
21
try:
22
mat = genfromtxt(fname);
23
except:
24
print('error: ')
25
print(' couldn t open %s'%(fname))
26
27
28
# Get Delta U and Delta V
29
u=mat[:,2]-mat[:,4];
30
v=mat[:,3]-mat[:,5];
31
du=np.sqrt(u*u + v*v)
32
33
# Compute RMS
34
npoints=np.size(mat,0)
35
rms=np.sqrt(np.sum(u*u + v*v )/npoints)
36
print(rms)
37
38
# Fit a normal distribution to the data:
39
mu_u, std_u = norm.fit(u)
40
mu_v, std_v = norm.fit(v)
41
42
plt.subplot(1,3,1)
43
# Plot the histogram.
44
plt.hist(du , bins=25, normed=True, alpha=0.6, color='g')
45
title = "du"
46
plt.title(title)
47
48
plt.subplot(1,3,2)
49
# Plot the histogram.
50
plt.hist(u , bins=25, normed=True, alpha=0.6, color='g')
51
52
# Plot the PDF.
53
xmin, xmax = plt.xlim()
54
x = np.linspace(xmin, xmax, 100)
55
p = norm.pdf(x, mu_u, std_u)
56
plt.plot(x, p, 'k', linewidth=2)
57
title = "u: mu = %.2f, std = %.2f" % (mu_u, std_u)
58
plt.title(title)
59
60
plt.subplot(1,3,3)
61
# Plot the histogram.
62
plt.hist(v , bins=25, normed=True, alpha=0.6, color='g')
63
64
# Plot the PDF.
65
xmin, xmax = plt.xlim()
66
x = np.linspace(xmin, xmax, 100)
67
p = norm.pdf(x, mu_v, std_v)
68
plt.plot(x, p, 'k', linewidth=2)
69
title = "v: mu = %.2f, std = %.2f" % (mu_v, std_v)
70
plt.title(title)
71
72
plt.show()
73
74
75
76
77