@@ -128,7 +128,7 @@ def __init__(
128128 self .diff_style = diff_style
129129 self .orientation = orientation
130130
131- def _diff_func (self , vel , u ):
131+ def _diff_func (self , vel , u , orientation ):
132132 """Applies the chosen style of numerical differentiation to velocity data.
133133
134134 This method calculates the derivative of the velocity data 'vel' with respect to the 'range'
@@ -149,15 +149,23 @@ def _diff_func(self, vel, u):
149149 The calculated derivative of the velocity data.
150150 """
151151
152+ if not orientation :
153+ orientation = self .orientation
154+ sign = 1
155+ if orientation == "down" :
156+ sign *= - 1
157+
152158 if self .diff_style == "first" :
153159 out = _diffz_first (vel [u ].values , vel ["range" ].values )
154- return out , vel .range [1 :]
160+ return sign * out , vel .range [1 :]
161+
155162 elif self .diff_style == "centered" :
156163 out = _diffz_centered (vel [u ].values , vel ["range" ].values )
157- return out , vel .range [1 :- 1 ]
164+ return sign * out , vel .range [1 :- 1 ]
165+
158166 elif self .diff_style == "centered_extended" :
159167 out = _diffz_centered_extended (vel [u ].values , vel ["range" ].values )
160- return out , vel .range
168+ return sign * out , vel .range
161169
162170 def dudz (self , vel , orientation = None ):
163171 """
@@ -182,28 +190,24 @@ def dudz(self, vel, orientation=None):
182190 'true vertical' direction.
183191 """
184192
185- if not orientation :
186- orientation = self .orientation
187- sign = 1
188- if orientation == "down" :
189- sign *= - 1
190-
191- dudz , rng = sign * self ._diff_func (vel , 0 )
193+ dudz , rng = self ._diff_func (vel , 0 , orientation )
192194 return xr .DataArray (
193195 dudz ,
194196 coords = [rng , vel .time ],
195197 dims = ["range" , "time" ],
196198 attrs = {"units" : "s-1" , "long_name" : "Shear in X-direction" },
197199 )
198200
199- def dvdz (self , vel ):
201+ def dvdz (self , vel , orientation = None ):
200202 """
201203 The shear in the second velocity component.
202204
203205 Parameters
204206 ----------
205207 vel : xarray.DataArray
206208 ADCP raw velocity
209+ orientation : str, default=ADPBinner.orientation
210+ Direction ADCP is facing ('up' or 'down')
207211
208212 Returns
209213 -------
@@ -217,22 +221,24 @@ def dvdz(self, vel):
217221 'true vertical' direction.
218222 """
219223
220- dvdz , rng = self ._diff_func (vel , 1 )
224+ dvdz , rng = self ._diff_func (vel , 1 , orientation )
221225 return xr .DataArray (
222226 dvdz ,
223227 coords = [rng , vel .time ],
224228 dims = ["range" , "time" ],
225229 attrs = {"units" : "s-1" , "long_name" : "Shear in Y-direction" },
226230 )
227231
228- def dwdz (self , vel ):
232+ def dwdz (self , vel , orientation = None ):
229233 """
230234 The shear in the third velocity component.
231235
232236 Parameters
233237 ----------
234238 vel : xarray.DataArray
235239 ADCP raw velocity
240+ orientation : str, default=ADPBinner.orientation
241+ Direction ADCP is facing ('up' or 'down')
236242
237243 Returns
238244 -------
@@ -246,7 +252,7 @@ def dwdz(self, vel):
246252 'true vertical' direction.
247253 """
248254
249- dwdz , rng = self ._diff_func (vel , 2 )
255+ dwdz , rng = self ._diff_func (vel , 2 , orientation )
250256 return xr .DataArray (
251257 dwdz ,
252258 coords = [rng , vel .time ],
@@ -537,7 +543,7 @@ def _beam_variance(self, ds, time, noise, beam_order, n_beams):
537543 )
538544
539545 # Calculate along-beam velocity prime squared bar
540- bp2_ = np .empty ((n_beams , len (ds . range ), len (time ))) * np .nan
546+ bp2_ = np .empty ((n_beams , len (ds [ " range" ] ), len (time ))) * np .nan
541547 for i , beam in enumerate (beam_order ):
542548 bp2_ [i ] = np .nanvar (self .reshape (beam_vel [beam ]), axis = - 1 )
543549
@@ -602,7 +608,7 @@ def reynolds_stress_4beam(self, ds, noise=None, orientation=None, beam_angle=Non
602608 np .stack ([upwp_ * np .nan , upwp_ , vpwp_ ]).astype ("float32" ),
603609 coords = {
604610 "tau" : ["upvp_" , "upwp_" , "vpwp_" ],
605- "range" : ds . range ,
611+ "range" : ds [ " range" ] ,
606612 "time" : time ,
607613 },
608614 attrs = {"units" : "m2 s-2" , "long_name" : "Specific Reynolds Stress Vector" },
@@ -646,7 +652,7 @@ def stress_tensor_5beam(
646652 in pitch and roll. u'v'_ cannot be directly calculated by a 5-beam ADCP,
647653 so it is approximated by the covariance of `u` and `v`. The uncertainty
648654 introduced by using this approximation is small if deviations from pitch
649- and roll are small (< 10 degrees).
655+ and roll are small (<= 5 degrees).
650656
651657 Dewey, R., and S. Stringer. "Reynolds stresses and turbulent kinetic
652658 energy estimates from various ADCP beam configurations: Theory." J. of
@@ -663,7 +669,7 @@ def stress_tensor_5beam(
663669
664670 # Run through warnings
665671 b_angle , noise = self ._stress_func_warnings (
666- ds , beam_angle , noise , tilt_thresh = 10
672+ ds , beam_angle , noise , tilt_thresh = 5
667673 )
668674
669675 # Fetch beam order
@@ -713,7 +719,7 @@ def stress_tensor_5beam(
713719 np .stack ([upup_ , vpvp_ , wpwp_ ]).astype ("float32" ),
714720 coords = {
715721 "tke" : ["upup_" , "vpvp_" , "wpwp_" ],
716- "range" : ds . range ,
722+ "range" : ds [ " range" ] ,
717723 "time" : time ,
718724 },
719725 attrs = {
@@ -752,7 +758,7 @@ def stress_tensor_5beam(
752758 np .stack ([upvp_ , upwp_ , vpwp_ ]).astype ("float32" ),
753759 coords = {
754760 "tau" : ["upvp_" , "upwp_" , "vpwp_" ],
755- "range" : ds . range ,
761+ "range" : ds [ " range" ] ,
756762 "time" : time ,
757763 },
758764 attrs = {
@@ -763,49 +769,6 @@ def stress_tensor_5beam(
763769
764770 return tke_vec , stress_vec
765771
766- def total_turbulent_kinetic_energy (
767- self , ds , noise = None , orientation = None , beam_angle = None
768- ):
769- """
770- Calculate magnitude of turbulent kinetic energy from 5-beam ADCP.
771-
772- Parameters
773- ----------
774- ds : xarray.Dataset
775- Raw dataset in beam coordinates
776- noise : int or xarray.DataArray, default=0 (time)
777- Doppler noise level in units of m/s
778- orientation : str, default=ds.attrs['orientation']
779- Direction ADCP is facing ('up' or 'down')
780- beam_angle : int, default=ds.attrs['beam_angle']
781- ADCP beam angle in units of degrees
782-
783- Returns
784- -------
785- tke : xarray.DataArray
786- Turbulent kinetic energy magnitude
787-
788- Notes
789- -----
790- This function is a wrapper around 'calc_stress_5beam' that then
791- combines the TKE components.
792-
793- Warning: the integral length scale of turbulence captured by the
794- ADCP measurements (i.e. the size of turbulent structures) increases
795- with increasing range from the instrument.
796- """
797-
798- tke_vec = self .stress_tensor_5beam (
799- ds , noise , orientation , beam_angle , tke_only = True
800- )
801-
802- tke = tke_vec .sum ("tke" ) / 2
803- tke .attrs ["units" ] = "m2 s-2"
804- tke .attrs ["long_name" ] = ("TKE Magnitude" ,)
805- tke .attrs ["standard_name" ] = "specific_turbulent_kinetic_energy_of_sea_water"
806-
807- return tke .astype ("float32" )
808-
809772 def check_turbulence_cascade_slope (self , psd , freq_range = [0.2 , 0.4 ]):
810773 """
811774 This function calculates the slope of the PSD, the power spectra
@@ -1027,11 +990,11 @@ def dissipation_rate_SF(self, vel_raw, r_range=[1, 5]):
1027990 )
1028991
1029992 if "range_b5" in vel_raw .dims :
1030- rng = vel_raw . range_b5
1031- time = self .mean (vel_raw . time_b5 .values )
993+ rng = vel_raw [ " range_b5" ]
994+ time = self .mean (vel_raw [ " time_b5" ] .values )
1032995 else :
1033- rng = vel_raw . range
1034- time = self .mean (vel_raw . time .values )
996+ rng = vel_raw [ " range" ]
997+ time = self .mean (vel_raw [ " time" ] .values )
1035998
1036999 # bm shape is [range, ensemble time, 'data within ensemble']
10371000 bm = self .demean (vel_raw .values ) # take out the ensemble mean
@@ -1139,7 +1102,7 @@ def friction_velocity(self, ds_avg, upwp_, z_inds=slice(1, 5), H=None):
11391102 raise TypeError ("`z_inds` must be an instance of `slice(int,int)`." )
11401103
11411104 if not H :
1142- H = ds_avg . depth .values
1105+ H = ds_avg [ " depth" ] .values
11431106 z = ds_avg ["range" ].values
11441107 upwp_ = upwp_ .values
11451108
@@ -1151,6 +1114,6 @@ def friction_velocity(self, ds_avg, upwp_, z_inds=slice(1, 5), H=None):
11511114
11521115 return xr .DataArray (
11531116 u_star .astype ("float32" ),
1154- coords = {"time" : ds_avg . time },
1117+ coords = {"time" : ds_avg [ " time" ] },
11551118 attrs = {"units" : "m s-1" , "long_name" : "Friction Velocity" },
11561119 )
0 commit comments