-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotSeriesNonDim.py
More file actions
176 lines (141 loc) · 7.68 KB
/
Copy pathplotSeriesNonDim.py
File metadata and controls
176 lines (141 loc) · 7.68 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
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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from .uniqueFinder import uniqueFinder
from .velocityProfile import velocityProfile
from .Rxx import Rxx
from .Ryy import Ryy
from .Rxy import Rxy
from .outlierRemove import outlierRemove
from .calcUstar import calcUstar
from .TKE import TKE
import pickle
def plotSeriesNonDim(dataPickle, positionList, function, plotTitle):
'''
Input : dataPickle - a pickle containing different measurement data (.pkl format)
function - function name for required fluid properties
available functions' keywords - "U", "Rxy", "Rxx", "Ryy"
Output: A series of subplots
'''
dataPickle = dataPickle
positionList = positionList
function = function
plotTitle = plotTitle
with open(dataPickle, 'rb') as f:
dataList = pickle.load(f)
yList = [] # a list to store the depth values and finally to pick up the max; depth
# parameter for Subplots #
num_cols = 5
# num_cols = min(len(dataList),5)
num_rows = -(-len(dataList)//num_cols)
fig, axes = plt.subplots(nrows=num_rows, ncols=num_cols, layout='constrained',sharey=True, sharex=True)
axes_flat = axes.flatten()
file = open(plotTitle, 'w') ## Create a file to store results
file.write("Position\tU*\tUavg\tCf\n")
for i, data in reversed(list(enumerate(dataList))):
print('----Program Executing----')
row = i // num_cols ## commented for subplots array
col = i % num_cols
if function == 'Rxy': # Function calling
# if i == len(dataList) - 1: # We want to calculate U* only for free channel section i.e., the first dataset
# Ustar = calcUstar(data) ## Calculate U* by calling calcUstar function
Ustar = calcUstar(data) ## Calculate U* by calling calcUstar function
data = Rxy(data)
# Remove outlier
dataWithoutOutliers = outlierRemove(data,function)
# Fitting line
#slope, intercept = np.polyfit(dataWithoutOutliers['depth[cm]'], dataWithoutOutliers['uv_prime'], 1)
# if i != len(dataList)-1:
# slope, intercept = np.polyfit(dataWithoutOutliers['depth[cm]'], dataWithoutOutliers['uv_prime'], 1)
#
# if i == len(dataList)-1: # to remove the outliers in the data (near the free surface)
# slope, intercept = np.polyfit(dataWithoutOutliers['depth[cm]'][:-1:], dataWithoutOutliers['uv_prime'][:-1:], 1)
y=np.linspace(0,data[-2])
# Ustar = np.sqrt(np.abs(slope)*data[-2])
# print('U* = ', Ustar)
### Plotting
axes[row, col].scatter(dataWithoutOutliers['uv_prime']/Ustar**2, dataWithoutOutliers['depth[cm]']/data[-2], facecolors='None', s=4, color='k')
axes[row, col].ticklabel_format(style='sci',scilimits=(-3,4),axis='both', useLocale=True)
#axes[row, col].tick_params(axis='x', rotation=45)
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
axes[row, col].axline((0, 1), slope=-1, color="gray", ls='-.')
#axes[row, col].set_xlim(right=1)
axes[row, col].set_ylim([0, 1])
#axes[row, col].plot(slope*y+intercept, y, 'k')
fig.supxlabel(r"$\overline{u'v'}/U_{*b}^2$")
#### Storing in a file
Cf = 2*(Ustar/data[-1])**2 # Ref; Wim's lecture notes - data[-1] is depth-averaged velocity
file.write(f"at {positionList[i]}\t{Ustar}\t{data[-1]}\t{Cf}\n")
if function == 'Rxx': # Function calling
Ustar = calcUstar(data) ## Calculate U* by calling calcUstar function
data = Rxx(data)
# Remove outlier
dataWithoutOutliers = outlierRemove(data,function)
# Fitting line
#slope, intercept = np.polyfit(dataWithoutOutliers['depth[cm]'], dataWithoutOutliers['uu_prime'], 1)
#y=np.linspace(0,data[-2])
#Ustar = np.sqrt(np.abs(slope)*data[-2])
#print('U* = ', Ustar)
### Plotting
axes[row, col].scatter(dataWithoutOutliers['uu_prime']/Ustar**2, dataWithoutOutliers['depth[cm]']/data[-2], facecolors='None', s=4, color='k')
axes[row, col].set_ylim([0, 1])
#axes[row, col].plot(slope*y+intercept, y, 'k')
axes[row, col].ticklabel_format(style='sci',scilimits=(-3,4),axis='both', useLocale=True)
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
#### Storing in a file
Cf = 'N/A' # Ref; Wim's lecture notes - data[-1] is depth-averaged velocity
#file.write(f"{positionList[i]}\t{Ustar}\t{data[-1]}\t{Cf}\n")
fig.supxlabel(r"$\overline{u'u'}/U_*^2$")
if function == 'Ryy': # Function calling
Ustar = calcUstar(data) ## Calculate U* by calling calcUstar function
data = Ryy(data)
# Remove outlier
dataWithoutOutliers = outlierRemove(data,function)
# Fitting line
#slope, intercept = np.polyfit(dataWithoutOutliers['depth[cm]'], dataWithoutOutliers['uu_prime'], 1)
#y=np.linspace(0,data[-2])
#Ustar = np.sqrt(np.abs(slope)*data[-2])
#print('U* = ', Ustar)
### Plotting
axes[row, col].scatter(dataWithoutOutliers['vv_prime']/Ustar**2, dataWithoutOutliers['depth[cm]']/data[-2], facecolors='None', s=4, color='k')
axes[row, col].set_ylim([0, 1])
#axes[row, col].plot(slope*y+intercept, y, 'k')
axes[row, col].ticklabel_format(style='sci',scilimits=(-3,4),axis='both', useLocale=True)
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
#### Storing in a file
Cf = 'N/A' # Ref; Wim's lecture notes - data[-1] is depth-averaged velocity
#file.write(f"{positionList[i]}\t{Ustar}\t{data[-1]}\t{Cf}\n")
fig.supxlabel(r"$\overline{v'v'}/U_*^2$")
if function == 'TKE': ## Function calling
Ustar = calcUstar(data) ## Calculate U* by calling calcUstar function
data = TKE(data)
#plotting
axes[row, col].scatter(data[0].reset_index()[0]/Ustar**2, data[0].reset_index()['depth[cm]']/data[1], s=4, facecolors='None', color='k')
axes[row, col].ticklabel_format(style='sci',scilimits=(-3,4),axis='both', useLocale=True)
axes[row, col].set_ylim([0, 1])
axes[row, col].set_xlim(left=0)
axes[row, col].tick_params(axis='x', rotation=45)
axes[row, col].set_title('at '+str(positionList[i])+' m', fontsize=10)
fig.supxlabel('$TKE/U_{*b}^2$')
if function == 'U':
data = velocityProfile(data)
axes[row, col].scatter(data[0].reset_index()['U']/data[-1], data[0].reset_index()['depth[cm]']/data[-2], facecolors='None', s=4, color='k')
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
axes[row, col].set_xlim(left=0)
axes[row, col].set_ylim([0, 1])
fig.supxlabel(r"$U/\overline{U}$")
fig.supylabel('$d/H$')
yList.append(data[-2]) # storing depth values for all positions
#axes[row, col].set_ylim([0, np.max(yList)]) # limiting the y-lim using max; depth
axes[row, col].grid()
axes[row, col].set_box_aspect(2) # aspect ratio for subplot
file.close()
# # Add empty subplots as placeholders for the last row
num_empty = num_cols * num_rows - len(dataList)
for i in range(num_empty):
ax = axes_flat[-1]
ax.axis('off')
axes_flat = axes_flat[:-1]
#plt.tight_layout()
plt.suptitle(function+plotTitle)
plt.savefig(function+plotTitle+'.pdf')