-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotSeries.py
More file actions
153 lines (122 loc) · 6.37 KB
/
Copy pathplotSeries.py
File metadata and controls
153 lines (122 loc) · 6.37 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
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 .Rxy import Rxy
from .calcUstar import calcUstar
from .outlierRemove import outlierRemove
from .GuoProfileFunction import GuoProfileFunction
from .TKE import TKE
import pickle
from matplotlib.ticker import LogLocator, LogFormatter
import matplotlib.ticker as ticker
def plotSeries(dataPickle, positionList, function, plotTitle, GuoProfile=False):
'''
Input : dataPickle - a pickle containing different measurement data (.pkl format)
function - function name for required fluid properties
available functions' keywords - "U", "Rxy", "TKE"
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()
# subplotting #
file = open(function+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
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'], dataWithoutOutliers['depth[cm]'], facecolors='None', color='k')
#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)
fig.supxlabel(r"$\overline{u'v'}$ [m$^2$/s$^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"{positionList[i]}\t{Ustar}\t{data[-1]}\t{Cf}\n")
if function == 'Rxx': # Function calling
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'], dataWithoutOutliers['depth[cm]'], facecolors='None', color='k')
#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'}$ [m$^2$/s$^2$]")
if function == 'TKE': ## Function calling
data = TKE(data)
#plotting
axes[row, col].scatter(data[0].reset_index()[0], data[0].reset_index()['depth[cm]'], s=4, facecolors='None', 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('at '+str(positionList[i])+' m', fontsize=10)
fig.supxlabel('$TKE$ [m$^2$/s$^2$]')
if function == 'U' and GuoProfile == False:
data = velocityProfile(data)
axes[row, col].scatter(data[0].reset_index()['U'], data[0].reset_index()['depth[cm]'], s=4, facecolors='None', color='k')
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
axes[row, col].set_xlim(left=0)
fig.supxlabel('$U$ [m/s]')
if function == 'U' and GuoProfile == True:
Ustar = calcUstar(data)
data = velocityProfile(data)
axes[row, col].scatter(data[0].reset_index()['U'], data[0].reset_index()['depth[cm]'], facecolors='None', color='k')
axes[row, col].set_title(str(positionList[i])+' m', fontsize=10)
axes[row, col].set_xlim(left=0)
GuoProfileData = GuoProfileFunction(data,Ustar)
axes[row, col].plot(GuoProfileData[0], GuoProfileData[1],'r')
fig.supxlabel('$U$ [m/s]')
fig.supylabel('$d$ [cm]')
#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')