@@ -31,6 +31,7 @@ def uvw_and_known_tke():
3131 e_true = 30
3232 return u , v , w , e_true
3333
34+
3435@pytest .fixture ()
3536def uvw_and_known_tke_xarray ():
3637 """Provide a set of u, v, w with a known tke value as an xarray"""
@@ -39,20 +40,20 @@ def uvw_and_known_tke_xarray():
3940 lat = [10 , 20 ] # degrees North
4041 lon = [30 , 40 ] # degrees East
4142 time = np .array (['2025-01-01T00:00' , '2025-01-01T06:00' ], dtype = 'datetime64' )
42-
43+
4344 # Define dimensions
4445 dims = ("pressure" , "lat" , "lon" , "time" )
45-
46+
4647 # Generate 16 linearly spaced values between -30 and 30
4748 uwind_values = np .linspace (0 , 30 , num = 16 ).reshape (2 , 2 , 2 , 2 )
4849 vwind_values = np .linspace (- 30 , 0 , num = 16 ).reshape (2 , 2 , 2 , 2 )
4950 wwind_values = np .linspace (- 1 , 2 , num = 16 ).reshape (2 , 2 , 2 , 2 )
50-
51+
5152 # Apply units
5253 u = uwind_values * units ('m/s' )
5354 v = vwind_values * units ('m/s' )
5455 w = wwind_values * units ('m/s' )
55-
56+
5657 # Create the Dataset
5758 ds = xr .Dataset (
5859 {
@@ -66,11 +67,12 @@ def uvw_and_known_tke_xarray():
6667 "lon" : lon ,
6768 "time" : time
6869 }
69- )
70-
71- e_true = np .full ((2 , 2 , 2 ), 1.005 ) * units ("m^2/s^2" )
70+ )
71+
72+ e_true = np .full ((2 , 2 , 2 ), 1.005 ) * units ("m^2/s^2" )
7273 return ds , e_true
7374
75+
7476def test_no_tke_1d ():
7577 """Test tke calculation where the expected value is 0."""
7678 observations = 5
@@ -110,8 +112,8 @@ def test_known_tke(uvw_and_known_tke):
110112 """Test basic behavior of tke with known values."""
111113 u , v , w , e_true = uvw_and_known_tke
112114 assert_array_equal (e_true , tke (u , v , w ))
113-
114-
115+
116+
115117def test_known_tke_xarray (uvw_and_known_tke_xarray ):
116118 """Test basic behavior of tke with known xarray values"""
117119 data , e_true = uvw_and_known_tke_xarray
@@ -380,6 +382,7 @@ def uvw_and_known_u_star_zero_mean():
380382 u_star_true = {'uw' : 2.0 , 'uwvw' : 2.3784142300054421 }
381383 return u , v , w , u_star_true
382384
385+
383386@pytest .fixture ()
384387def uvw_and_known_friction_velocity_xarray ():
385388 """Provide a set of u, v, w with a known tke value as an xarray"""
@@ -388,20 +391,20 @@ def uvw_and_known_friction_velocity_xarray():
388391 lat = [10 , 20 ] # degrees North
389392 lon = [30 , 40 ] # degrees East
390393 time = np .array (['2025-01-01T00:00' , '2025-01-01T06:00' ], dtype = 'datetime64' )
391-
394+
392395 # Define dimensions
393396 dims = ("pressure" , "lat" , "lon" , "time" )
394-
397+
395398 # Generate 16 linearly spaced values between -30 and 30
396399 uwind_values = np .linspace (0 , 30 , num = 16 ).reshape (2 , 2 , 2 , 2 )
397400 vwind_values = np .linspace (- 30 , 0 , num = 16 ).reshape (2 , 2 , 2 , 2 )
398401 wwind_values = np .linspace (- 1 , 2 , num = 16 ).reshape (2 , 2 , 2 , 2 )
399-
402+
400403 # Apply units
401404 u = uwind_values * units ('m/s' )
402405 v = vwind_values * units ('m/s' )
403406 w = wwind_values * units ('m/s' )
404-
407+
405408 # Create the Dataset
406409 ds = xr .Dataset (
407410 {
@@ -415,10 +418,11 @@ def uvw_and_known_friction_velocity_xarray():
415418 "lon" : lon ,
416419 "time" : time
417420 }
418- )
421+ )
419422 expected = np .full ((2 , 2 , 2 ), .3760603 ) * units ('meter / second' )
420423 return ds , expected
421424
425+
422426@pytest .fixture ()
423427def uvw_and_known_u_star_nonzero_mean ():
424428 """Return components and friction velocity for a non-zero-mean time series."""
@@ -445,10 +449,11 @@ def test_u_star_1d_nonzero_mean(uvw_and_known_u_star_nonzero_mean):
445449 u_star_true ['uw' ])
446450 assert_almost_equal (friction_velocity (u , w , v = v , perturbation = False ),
447451 u_star_true ['uwvw' ])
448-
452+
453+
449454def test_friction_velocity_nonzero_xarray (uvw_and_known_friction_velocity_xarray ):
450455 """Test friction velocity in 1d with an xarray"""
451- data , expected = uvw_and_known_friction_velocity_xarray ;
456+ data , expected = uvw_and_known_friction_velocity_xarray
452457 assert_array_almost_equal (friction_velocity (data .uwind , data .wwind , data .vwind ), expected )
453458
454459
0 commit comments