@@ -124,12 +124,12 @@ def __call__(
124124 self ._sigmas = self ._compute_sigma (self ._z )
125125
126126 # Compute z3 depths of zco vertical levels
127- zco_z3 = self ._zco_z3
127+ z3t , z3w = self ._zco_z3
128128
129129 # Compute e3 scale factors (cell thicknesses)
130- zco_e3 = self ._compute_e3 (* zco_z3 ) if self ._ln_e3_dep else self ._analyt_e3
130+ e3t , e3w = self ._compute_e3 (z3t , z3w ) if self ._ln_e3_dep else self ._analyt_e3
131131
132- return self ._merge_z3_and_e3 (* zco_z3 , * zco_e3 )
132+ return self ._merge_z3_and_e3 (z3t , z3w , e3t , e3w )
133133
134134 # --------------------------------------------------------------------------
135135 def _compute_pp (
@@ -211,7 +211,7 @@ def _zco_z3(self) -> Tuple[DataArray, ...]:
211211 sigmas = self ._sigmas
212212 sigmas_p1 = self ._compute_sigma (self ._z + 1 )
213213
214- zco_z3 = []
214+ both_z3 = []
215215 for grid , sigma , sigma_p1 in zip (grids , sigmas , sigmas_p1 ):
216216
217217 if self ._is_uniform :
@@ -227,25 +227,21 @@ def _zco_z3(self) -> Tuple[DataArray, ...]:
227227 a1 = self ._ppsur
228228 a2 = self ._ppa0 * (self ._jpk - 1.0 )
229229 a3 = self ._ppa1 * self ._ppacr
230-
231- # Compute z3
232230 z3 = self ._compute_z3 (su , s1 , a1 , a2 , a3 )
233231
234- # Double tanh
235232 if self ._ldbletanh :
236233 # Add double tanh term
237234 ss2 = self ._stretch_zco (- sigma , self ._ldbletanh )
238235 a4 = self ._ppa2 * self ._ppacr2
239236 z3 += ss2 * a4
240237
241- # Force first w-level to be exactly at zero
242238 if grid == "W" :
239+ # Force first w-level to be exactly at zero
243240 z3 [{"z" : 0 }] = 0.0
244241
245- # Append
246- zco_z3 += [z3 ]
242+ both_z3 += [z3 ]
247243
248- return tuple (zco_z3 )
244+ return tuple (both_z3 )
249245
250246 # --------------------------------------------------------------------------
251247 @property
@@ -255,33 +251,29 @@ def _analyt_e3(self) -> Tuple[DataArray, ...]:
255251 Return e3{t,w} as analytical derivative of depth function z3{t,w}.
256252 """
257253
258- # Return here if is uniform
259254 if self ._is_uniform :
260- # 0d DataArray
255+ # Uniform: Return 0d DataArrays
261256 e3 = DataArray ((self ._pphmax / (self ._jpk - 1.0 )))
262257 return tuple ([e3 , e3 ])
263258
264- # Stretched zco grid
265- zco_e3 = []
259+ both_e3 = []
266260 for sigma in self ._sigmas :
261+ # Stretched zco grid
267262 a0 = self ._ppa0
268263 a1 = self ._ppa1
269264 kk = - sigma * (self ._jpk - 1.0 ) + 1.0
270265 tanh1 = np .tanh ((kk - self ._ppkth ) / self ._ppacr )
271-
272- # Compute e3
273266 e3 = a0 + a1 * tanh1
274267
275- # Add double tanh term
276268 if self ._ldbletanh :
269+ # Add double tanh term
277270 a2 = self ._ppa2
278271 tanh2 = np .tanh ((kk - self ._ppkth2 ) / self ._ppacr2 )
279272 e3 += a2 * tanh2
280273
281- # Append
282- zco_e3 += [e3 ]
274+ both_e3 += [e3 ]
283275
284- return tuple (zco_e3 )
276+ return tuple (both_e3 )
285277
286278 def _get_ldbletanh_and_pp2 (
287279 self , ldbletanh : Optional [bool ], pp2 : Tuple [Optional [float ], ...]
@@ -306,16 +298,18 @@ def _get_ldbletanh_and_pp2(
306298 # ldbletanh False and double tanh coefficients specified
307299 warning_msg = f"{ prefix_msg } are ignored when ldbletanh is False"
308300 else :
301+ # All good
309302 warning_msg = ""
310303
311304 if warning_msg :
305+ # Warn and return dummy values
312306 warnings .warn (warning_msg )
313307 return (False , (0 , 0 , 0 ))
314308
315- # Errors: Wrong types
309+ # Errors: pp have inconsistent types
316310 if ldbletanh is True and any (pp_are_none ):
317311 raise ValueError (f"{ prefix_msg } MUST be all float when ldbletanh is True" )
318312 if ldbletanh is None and (any (pp_are_none ) and not all (pp_are_none )):
319- raise ValueError (f"{ prefix_msg } MUST be all None or float" )
313+ raise ValueError (f"{ prefix_msg } MUST be all None or all float" )
320314
321315 return (ldbletanh_out , tuple (pp or 0 for pp in pp2 ))
0 commit comments