Skip to content

Commit

Permalink
Fix galvez_davison_index error: invalid index to scalar variable (#3529)
Browse files Browse the repository at this point in the history
* fix error: invalid index to scalar variable.

* Add simple test and fix calling nonzero on
0d arrays is deprecated on line:4594, when test
with simple value.

* fix comma.
  • Loading branch information
C2oWisComing committed Jul 9, 2024
1 parent 7997bfe commit f7215f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4591,18 +4591,14 @@ 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)[indices_without_950]}'
f'\n{np.max(pressure, axis=0)}'
)

potential_temp = potential_temperature(pressure, temperature)
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 f7215f3

Please sign in to comment.