Skip to content

Commit

Permalink
Test on Quantity arrays and profile
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamron committed Dec 26, 2023
1 parent fbe977e commit 8e070a0
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,12 +2476,13 @@ def test_gdi_xarray(index_xarray_data_expanded):
pressure = index_xarray_data_expanded.isobaric
temperature = index_xarray_data_expanded.temperature
dewpoint = index_xarray_data_expanded.dewpoint
relative_humidity = relative_humidity_from_dewpoint(temperature, dewpoint)
mixrat = mixing_ratio_from_relative_humidity(pressure, temperature, relative_humidity)
mixing_ratio = mixing_ratio_from_relative_humidity(
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))

result = galvez_davison_index(
pressure,
temperature,
mixrat,
mixing_ratio,
pressure[0]
)

Expand All @@ -2492,6 +2493,39 @@ def test_gdi_xarray(index_xarray_data_expanded):
)


def test_gdi_arrays(index_xarray_data_expanded):
"""Test GDI on 3-D Quantity arrays with an array of surface pressure."""
ds = index_xarray_data_expanded.isel(time=0).squeeze()
pressure = ds.isobaric.metpy.unit_array[:, None, None]
temperature = ds.temperature.metpy.unit_array
dewpoint = ds.dewpoint.metpy.unit_array
mixing_ratio = mixing_ratio_from_relative_humidity(
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))
surface_pressure = units.Quantity(
np.broadcast_to(pressure.m, temperature.shape), pressure.units)[0]

result = galvez_davison_index(pressure, temperature, mixing_ratio, surface_pressure)

assert_array_almost_equal(
result,
np.array([[189.5890429, 157.4307982, 129.9739099],
[106.6763526, 87.0637477, 70.7202505]])
)


def test_gdi_profile(index_xarray_data_expanded):
"""Test GDI calculation on an individual profile."""
ds = index_xarray_data_expanded.isel(time=0, y=0, x=0)
pressure = ds.isobaric.metpy.unit_array
temperature = ds.temperature.metpy.unit_array
dewpoint = ds.dewpoint.metpy.unit_array
mixing_ratio = mixing_ratio_from_relative_humidity(
pressure, temperature, relative_humidity_from_dewpoint(temperature, dewpoint))

assert_almost_equal(galvez_davison_index(pressure, temperature, mixing_ratio, pressure[0]),
189.5890429, 4)


def test_gdi_no_950_raises_valueerror(index_xarray_data):
"""GDI requires a 950hPa or higher measurement.
Expand Down

0 comments on commit 8e070a0

Please sign in to comment.