Skip to content

Commit

Permalink
Fix shear velocity functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed May 30, 2024
1 parent fa25579 commit d5c8914
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions dolfyn/adp/turbulence.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,24 @@ def __init__(self, n_bin, fs, n_fft=None, n_fft_coh=None,
self.diff_style = diff_style
self.orientation = orientation

def _diff_func(self, vel, u):
def _diff_func(self, vel, u, orientation):
if not orientation:
orientation = self.orientation
sign = 1
if orientation == 'down':
sign *= -1

if self.diff_style == 'first':
out = _diffz_first(vel[u].values, vel['range'].values)
return out, vel.range[1:]
return sign*out, vel.range[1:]

elif self.diff_style == 'centered':
out = _diffz_centered(vel[u].values, vel['range'].values)
return out, vel.range[1:-1]
return sign*out, vel.range[1:-1]

elif self.diff_style == 'centered_extended':
out = _diffz_centered_extended(vel[u].values, vel['range'].values)
return out, vel.range
return sign*out, vel.range

def calc_dudz(self, vel, orientation=None):
"""The shear in the first velocity component.
Expand All @@ -93,21 +101,15 @@ def calc_dudz(self, vel, orientation=None):
'true vertical' direction.
"""

if not orientation:
orientation = self.orientation
sign = 1
if orientation == 'down':
sign *= -1

dudz, rng = sign*self._diff_func(vel, 0)
dudz, rng = self._diff_func(vel, 0, orientation)
return xr.DataArray(dudz,
coords=[rng, vel.time],
dims=['range', 'time'],
attrs={'units': 's-1',
'long_name': 'Shear in X-direction'}
)

def calc_dvdz(self, vel):
def calc_dvdz(self, vel, orientation=None):
"""The shear in the second velocity component.
Parameters
Expand All @@ -122,15 +124,15 @@ def calc_dvdz(self, vel):
'true vertical' direction.
"""

dvdz, rng = self._diff_func(vel, 1)
dvdz, rng = self._diff_func(vel, 1, orientation)
return xr.DataArray(dvdz,
coords=[rng, vel.time],
dims=['range', 'time'],
attrs={'units': 's-1',
'long_name': 'Shear in Y-direction'}
)

def calc_dwdz(self, vel):
def calc_dwdz(self, vel, orientation=None):
"""The shear in the third velocity component.
Parameters
Expand All @@ -144,8 +146,8 @@ def calc_dwdz(self, vel):
coordinate ('dz' is actually diff(self['range'])), not necessarily the
'true vertical' direction.
"""

dwdz, rng = self._diff_func(vel, 2)
dwdz, rng = self._diff_func(vel, 2, orientation)
return xr.DataArray(dwdz,
coords=[rng, vel.time],
dims=['range', 'time'],
Expand Down

0 comments on commit d5c8914

Please sign in to comment.