Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further updates to pint master branch compatibility #1250

Merged
merged 3 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _lcl_iter(p, p0, w, t):

# np.isclose needed if surface is LCL due to precision error with np.log in dewpoint.
# Causes issues with parcel_profile_with_lcl if removed. Issue #1187
lcl_p = np.where(np.isclose(lcl_p, pressure), pressure, lcl_p) * pressure.units
lcl_p = np.where(np.isclose(lcl_p, pressure.m), pressure.m, lcl_p) * pressure.units

return lcl_p, dewpoint(vapor_pressure(lcl_p, w)).to(temperature.units)

Expand Down Expand Up @@ -1745,7 +1745,7 @@ def _isen_iter(iter_log_p, isentlevs_nd, ka, a, b, pok):
levs = pres[sorter]
tmpk = temperature[sorter]

theta_levels = np.asanyarray(theta_levels.to('kelvin')).reshape(-1)
theta_levels = np.asarray(theta_levels.m_as('kelvin')).reshape(-1)
isentlevels = theta_levels[np.argsort(theta_levels)]

# Make the desired isentropic levels the same shape as temperature
Expand Down
8 changes: 8 additions & 0 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ def lat_lon_grid_deltas(longitude, latitude, **kwargs):
if latitude.ndim < 2:
longitude, latitude = np.meshgrid(longitude, latitude)

# pyproj requires ndarrays, not Quantities
try:
longitude = longitude.m_as('degrees')
latitude = latitude.m_as('degrees')
except AttributeError:
longitude = np.asarray(longitude)
latitude = np.asarray(latitude)

geod_args = {'ellps': 'sphere'}
if kwargs:
geod_args = kwargs
Expand Down
28 changes: 14 additions & 14 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@ def test_multiple_lfs_wide(multiple_intersections):
"""Test 'wide' LFC for sounding with multiple LFCs."""
levels, temperatures, dewpoints = multiple_intersections
lfc_pressure_wide, lfc_temp_wide = lfc(levels, temperatures, dewpoints, which='wide')
assert_almost_equal(lfc_pressure_wide, 705.4346277 * units.hPa, 6)
assert_almost_equal(lfc_temp_wide, 4.8922235 * units.degC, 6)
assert_almost_equal(lfc_pressure_wide, 705.4346277 * units.hPa, 3)
assert_almost_equal(lfc_temp_wide, 4.8922235 * units.degC, 3)


def test_invalid_which(multiple_intersections):
Expand Down Expand Up @@ -1402,24 +1402,24 @@ def test_multiple_el_wide(multiple_intersections):
"""Test 'wide' EL for sounding with multiple ELs."""
levels, temperatures, dewpoints = multiple_intersections
el_pressure_wide, el_temp_wide = el(levels, temperatures, dewpoints, which='wide')
assert_almost_equal(el_pressure_wide, 228.0575059 * units.hPa, 6)
assert_almost_equal(el_temp_wide, -56.8123126 * units.degC, 6)
assert_almost_equal(el_pressure_wide, 228.0575059 * units.hPa, 3)
assert_almost_equal(el_temp_wide, -56.8123126 * units.degC, 3)


def test_muliple_el_most_cape(multiple_intersections):
"""Test 'most_cape' EL for sounding with multiple ELs."""
levels, temperatures, dewpoints = multiple_intersections
el_pressure_wide, el_temp_wide = el(levels, temperatures, dewpoints, which='most_cape')
assert_almost_equal(el_pressure_wide, 228.0575059 * units.hPa, 6)
assert_almost_equal(el_temp_wide, -56.8123126 * units.degC, 6)
assert_almost_equal(el_pressure_wide, 228.0575059 * units.hPa, 3)
assert_almost_equal(el_temp_wide, -56.8123126 * units.degC, 3)


def test_muliple_lfc_most_cape(multiple_intersections):
"""Test 'most_cape' LFC for sounding with multiple LFCs."""
levels, temperatures, dewpoints = multiple_intersections
lfc_pressure_wide, lfc_temp_wide = lfc(levels, temperatures, dewpoints, which='most_cape')
assert_almost_equal(lfc_pressure_wide, 705.4346277 * units.hPa, 6)
assert_almost_equal(lfc_temp_wide, 4.8922235 * units.degC, 6)
assert_almost_equal(lfc_pressure_wide, 705.4346277 * units.hPa, 3)
assert_almost_equal(lfc_temp_wide, 4.8922235 * units.degC, 3)


def test_el_lfc_most_cape_bottom():
Expand All @@ -1432,10 +1432,10 @@ def test_el_lfc_most_cape_bottom():
-6.9, -9.5, -12., -14.6, -15.8]) * units.degC
lfc_pres, lfc_temp = lfc(levels, temperatures, dewpoints, which='most_cape')
el_pres, el_temp = el(levels, temperatures, dewpoints, which='most_cape')
assert_almost_equal(lfc_pres, 900.7395292 * units.hPa, 6)
assert_almost_equal(lfc_temp, 14.672512 * units.degC, 6)
assert_almost_equal(el_pres, 849.7942184 * units.hPa, 6)
assert_almost_equal(el_temp, 12.4233265 * units.degC, 6)
assert_almost_equal(lfc_pres, 900.7395292 * units.hPa, 3)
assert_almost_equal(lfc_temp, 14.672512 * units.degC, 3)
assert_almost_equal(el_pres, 849.7942184 * units.hPa, 3)
assert_almost_equal(el_temp, 12.4233265 * units.degC, 3)


def test_cape_cin_top_el_lfc(multiple_intersections):
Expand Down Expand Up @@ -1573,5 +1573,5 @@ def test_lcl_grid_surface_LCLs():
lcl_pressure, lcl_temperature = lcl(pressure, temperature, dewpoint)
pres_truth = np.array([1000, 932.1515324, 1010]) * units.hPa
temp_truth = np.array([15, 9.10391763, 13]) * units.degC
assert_array_almost_equal(lcl_pressure, pres_truth, 7)
assert_array_almost_equal(lcl_temperature, temp_truth, 7)
assert_array_almost_equal(lcl_pressure, pres_truth, 4)
assert_array_almost_equal(lcl_temperature, temp_truth, 4)