Skip to content

Commit 8e070a0

Browse files
committed
Test on Quantity arrays and profile
1 parent fbe977e commit 8e070a0

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

tests/calc/test_thermo.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,12 +2476,13 @@ def test_gdi_xarray(index_xarray_data_expanded):
24762476
pressure = index_xarray_data_expanded.isobaric
24772477
temperature = index_xarray_data_expanded.temperature
24782478
dewpoint = index_xarray_data_expanded.dewpoint
2479-
relative_humidity = relative_humidity_from_dewpoint(temperature, dewpoint)
2480-
mixrat = mixing_ratio_from_relative_humidity(pressure, temperature, relative_humidity)
2479+
mixing_ratio = mixing_ratio_from_relative_humidity(
2480+
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))
2481+
24812482
result = galvez_davison_index(
24822483
pressure,
24832484
temperature,
2484-
mixrat,
2485+
mixing_ratio,
24852486
pressure[0]
24862487
)
24872488

@@ -2492,6 +2493,39 @@ def test_gdi_xarray(index_xarray_data_expanded):
24922493
)
24932494

24942495

2496+
def test_gdi_arrays(index_xarray_data_expanded):
2497+
"""Test GDI on 3-D Quantity arrays with an array of surface pressure."""
2498+
ds = index_xarray_data_expanded.isel(time=0).squeeze()
2499+
pressure = ds.isobaric.metpy.unit_array[:, None, None]
2500+
temperature = ds.temperature.metpy.unit_array
2501+
dewpoint = ds.dewpoint.metpy.unit_array
2502+
mixing_ratio = mixing_ratio_from_relative_humidity(
2503+
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))
2504+
surface_pressure = units.Quantity(
2505+
np.broadcast_to(pressure.m, temperature.shape), pressure.units)[0]
2506+
2507+
result = galvez_davison_index(pressure, temperature, mixing_ratio, surface_pressure)
2508+
2509+
assert_array_almost_equal(
2510+
result,
2511+
np.array([[189.5890429, 157.4307982, 129.9739099],
2512+
[106.6763526, 87.0637477, 70.7202505]])
2513+
)
2514+
2515+
2516+
def test_gdi_profile(index_xarray_data_expanded):
2517+
"""Test GDI calculation on an individual profile."""
2518+
ds = index_xarray_data_expanded.isel(time=0, y=0, x=0)
2519+
pressure = ds.isobaric.metpy.unit_array
2520+
temperature = ds.temperature.metpy.unit_array
2521+
dewpoint = ds.dewpoint.metpy.unit_array
2522+
mixing_ratio = mixing_ratio_from_relative_humidity(
2523+
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))
2524+
2525+
assert_almost_equal(galvez_davison_index(pressure, temperature, mixing_ratio, pressure[0]),
2526+
189.5890429, 4)
2527+
2528+
24952529
def test_gdi_no_950_raises_valueerror(index_xarray_data):
24962530
"""GDI requires a 950hPa or higher measurement.
24972531

0 commit comments

Comments
 (0)