-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvelocityProfile.py
More file actions
82 lines (68 loc) · 3.2 KB
/
Copy pathvelocityProfile.py
File metadata and controls
82 lines (68 loc) · 3.2 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
import pandas as pd
import matplotlib.pyplot as plt
import scipy
from scipy import integrate
import numpy as np
from .uniqueFinder import uniqueFinder
def velocityProfile(dataOrig, VelAll=None):
'''
This function is to plot the velocity profile using the measured data from a single file obtained from DasyLAB.
Input:
-----
data : pandas dataframe
VelAll : [optional] if True, it returns instantaneous velocity components.
Return:
------
velocity profiles
Depth-averaged velocity
'''
data = dataOrig.copy()
data = data[data['DisplacementLDA [V]'] != 0.00]
data.reset_index(drop=True, inplace=True)
data = data.sort_values('DisplacementLDA [V]').reset_index(drop=True)
data = uniqueFinder(data)
data['depth[cm]'] = data['uniqueDisplacement'].groupby(data['uniqueDisplacement']).transform(lambda x:np.round(-2.4953*x+25.753,2))
## Velocity components calcuation
data['U'] = data['Vel1 [V]'].groupby(data['depth[cm]']).transform(lambda x: 0.096*(data['Vel2 [V]']-x))
data['V'] = data['Vel1 [V]'].groupby(data['depth[cm]']).transform(lambda x: 0.096*(x+data['Vel2 [V]']))
# ## Scatter plots
# fig, ax = plt.subplots(1,2, figsize=(10,5))
# ax[0].scatter(data['U'].groupby(data['depth[cm]']).mean(), data['depth[cm]'].groupby(data['depth[cm]']).mean(), color='k')
# ax[0].set_xlabel('$U$ [cm/s]')
# ax[0].set_ylabel('$y$ [cm]')
# ax[0].set_xlim([0,np.max(data['U'])])
# ax[0].set_ylim(bottom=0)
# ax[0].grid(True)
# ax[1].scatter(data['V'].groupby(data['depth[cm]']).mean(), data['depth[cm]'].groupby(data['depth[cm]']).mean(), color='r')
# ax[1].set_xlabel('$V$ [cm/s]')
# ax[1].grid(True)
# ax[1].set_xlim([0,np.max(data['U'])])
# ax[1].set_ylim(bottom=0)
'''
To calculate the average velocity
'''
totalDepth = data['depth[cm]'].groupby(data['depth[cm]']).mean().iloc[-1] - data['depth[cm]'].groupby(data['depth[cm]']).mean().iloc[0]
u_avg = scipy.integrate.simps(np.abs(data['U'].groupby(data['depth[cm]']).mean()), data['depth[cm]'].groupby(data['depth[cm]']).mean()) / totalDepth
print('Depth-averaged velocity is = ', np.round(u_avg,3), 'm/sec.')
'''
To calculate friction velocity
'''
upstreamWL = np.mean(38.01-3.76*data['WaterLevel1 [v]'])
#print('upStreamWL', upstreamWL)
downstreamWL = np.mean(36.42-3.8*data['WaterLevel3 [V]'])
#print('downStreamWL', downstreamWL)
diffWL = np.abs(upstreamWL - downstreamWL)
waterDepth = (upstreamWL + downstreamWL)/2
dx = 6 # horizontal length between two water levels
dHdx = (diffWL/100)/dx # energy slope : water level is in centimeter, therefore need to change in meter
#print('energy gradient', dHdx)
R = (waterDepth/100 * 0.4)/(2*waterDepth/100 + 0.04) # hydraulic radius R = Area/Perimeter
Ustar = np.sqrt(9.81*(waterDepth/100)*dHdx)
'''
To insert the line for depth-averaged velocity
'''
#ax[0].axvline(np.round(u_avg,3), color ='k', lw = 4, ls='--', label='$U_{avg}$ = %.3f m/sec' %np.round(u_avg,3))
#ax[0].legend()
if VelAll == True:
return data['U'].groupby(data['depth[cm]'])
return data['U'].groupby(data['depth[cm]']).mean(), upstreamWL, u_avg