Skip to content

Commit e518adc

Browse files
committed
Only fixing turbulence function
1 parent 7e0d99e commit e518adc

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/metpy/calc/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def coriolis_parameter(latitude):
631631

632632

633633
@exporter.export
634-
@preprocess_and_wrap()
634+
@preprocess_and_wrap(wrap_like='pressure')
635635
@check_units('[pressure]', '[length]')
636636
def add_height_to_pressure(pressure, height):
637637
r"""Calculate the pressure at a certain height above another pressure level.
@@ -1224,7 +1224,7 @@ def altimeter_to_station_pressure(altimeter_value, height):
12241224

12251225

12261226
@exporter.export
1227-
@preprocess_and_wrap()
1227+
@preprocess_and_wrap(wrap_like='altimeter_value')
12281228
@check_units('[pressure]', '[length]', '[temperature]')
12291229
def altimeter_to_sea_level_pressure(altimeter_value, height, temperature):
12301230
r"""Convert the altimeter setting to sea-level pressure.

src/metpy/calc/thermo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ def dry_lapse(pressure, temperature, reference_pressure=None, vertical_dim=0):
517517

518518

519519
@exporter.export
520-
@preprocess_and_wrap()
520+
@preprocess_and_wrap(
521+
wrap_like='temperature',
522+
broadcast=('pressure', 'temperature', 'reference_pressure')
523+
)
521524
@process_units(
522525
{
523526
'pressure': '[pressure]',

tests/calc/test_turbulence.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
3536
def 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+
7476
def 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+
115117
def 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()
384387
def 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()
423427
def 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+
449454
def 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

Comments
 (0)