Skip to content

Commit

Permalink
Add simple test and fix calling nonzero on
Browse files Browse the repository at this point in the history
0d arrays is deprecated on line:4594, when test
with simple value.
  • Loading branch information
C2oWisComing committed Jun 30, 2024
1 parent 1b00060 commit e23390f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4591,16 +4591,12 @@ def galvez_davison_index(pressure, temperature, mixing_ratio, surface_pressure,
<Quantity(-8.78797532, 'dimensionless')>
"""
if np.any(np.max(pressure, axis=vertical_dim) < 950 * units.hectopascal):
indices_without_950 = np.where(
np.max(pressure, axis=vertical_dim) < 950 * units.hectopascal
)
raise ValueError(
f'Data not provided for 950hPa or higher pressure. '
f'GDI requires 950hPa temperature and dewpoint data, '
f'see referenced paper section 3.d. in docstring for discussion of'
f' extrapolating sounding data below terrain surface in high-'
f'elevation regions.\nIndices without a 950hPa or higher datapoint'
f':\n{indices_without_950}'
f'\nMax provided pressures:'
f'\n{np.max(pressure, axis=0)}'
)
Expand Down
18 changes: 18 additions & 0 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,24 @@ def test_gdi_no_950_raises_valueerror(index_xarray_data):
)


def test_gdi_no_950_by_simplevalue():
"""GDI requires a 950hPa or higher measurement."""
with pytest.raises(ValueError):
pressure = np.array([922., 850., 700., 600., 500., 400., 300., 250.,
200., 150.]) * units.hPa
temperature = np.array([22.6, 18.6, 8.6, 2.8, -4.6, -15.5, -30.6, -40.4,
-52.9, -67.8,]) * units.degC
relative_humidity = np.array([71.12, 71.16, 70.79, 50.33, 28.22, 4.80, 3.68, 5.82,
18.18, 27.33]) * units.percent
mixrat = mixing_ratio_from_relative_humidity(pressure, temperature, relative_humidity)
galvez_davison_index(
pressure,
temperature,
mixrat,
pressure[0]
)


def test_gradient_richardson_number():
"""Test gradient Richardson number calculation."""
theta = units('K') * np.asarray([254.5, 258.3, 262.2])
Expand Down

0 comments on commit e23390f

Please sign in to comment.