Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.25k stars 414 forks source link

Issue with calculating CAPE #1146

Closed xebadir closed 5 years ago

xebadir commented 5 years ago

So have been running some tests on a notebook I normally use for class (based on the Workshop ipynb), and ran into a series of issues with the following tuple error:


TypeError Traceback (most recent call last)

in 3 surface_cape, surface_cin = mpcalc.surface_based_cape_cin(sounding['pressure'], 4 sounding['temperature'], ----> 5 sounding['dewpoint']) 6 7 #sounding = sounding.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed', /opt/conda/lib/python3.6/site-packages/metpy/xarray.py in wrapper(*args, **kwargs) 434 kwargs = {name: (v.metpy.unit_array if isinstance(v, xr.DataArray) else v) 435 for name, v in kwargs.items()} --> 436 return func(*args, **kwargs) 437 return wrapper 438 /opt/conda/lib/python3.6/site-packages/metpy/units.py in wrapper(*args, **kwargs) 303 ' x = x * units.meter / units.second') 304 raise ValueError(msg) --> 305 return func(*args, **kwargs) 306 307 return wrapper /opt/conda/lib/python3.6/site-packages/metpy/calc/thermo.py in surface_based_cape_cin(pressure, temperature, dewpoint) 1694 1695 """ -> 1696 p, t, td, profile = parcel_profile_with_lcl(pressure, temperature, dewpoint) 1697 return cape_cin(p, t, td, profile) 1698 /opt/conda/lib/python3.6/site-packages/metpy/xarray.py in wrapper(*args, **kwargs) 434 kwargs = {name: (v.metpy.unit_array if isinstance(v, xr.DataArray) else v) 435 for name, v in kwargs.items()} --> 436 return func(*args, **kwargs) 437 return wrapper 438 /opt/conda/lib/python3.6/site-packages/metpy/units.py in wrapper(*args, **kwargs) 303 ' x = x * units.meter / units.second') 304 raise ValueError(msg) --> 305 return func(*args, **kwargs) 306 307 return wrapper /opt/conda/lib/python3.6/site-packages/metpy/calc/thermo.py in parcel_profile_with_lcl(pressure, temperature, dewpt) 554 new_press = concatenate((p_l, p_lcl, p_u)) 555 prof_temp = concatenate((t_l, t_lcl, t_u)) --> 556 new_temp = _insert_lcl_level(pressure, temperature, p_lcl) 557 new_dewp = _insert_lcl_level(pressure, dewpt, p_lcl) 558 return new_press, new_temp, new_dewp, prof_temp /opt/conda/lib/python3.6/site-packages/metpy/calc/thermo.py in _insert_lcl_level(pressure, temperature, lcl_pressure) 592 def _insert_lcl_level(pressure, temperature, lcl_pressure): 593 """Insert the LCL pressure into the profile.""" --> 594 interp_temp = interpolate_1d(lcl_pressure, pressure, temperature) 595 596 # Pressure needs to be increasing for searchsorted, so flip it and then convert /opt/conda/lib/python3.6/site-packages/metpy/xarray.py in wrapper(*args, **kwargs) 434 kwargs = {name: (v.metpy.unit_array if isinstance(v, xr.DataArray) else v) 435 for name, v in kwargs.items()} --> 436 return func(*args, **kwargs) 437 return wrapper 438 /opt/conda/lib/python3.6/site-packages/pint/registry_helpers.py in wrapper(*values, **kw) 192 new_values, values_by_name = converter(ureg, values, strict) 193 --> 194 result = func(*new_values, **kw) 195 196 if container: /opt/conda/lib/python3.6/site-packages/metpy/interpolate/one_dimension.py in interpolate_1d(x, xp, *args, **kwargs) 117 xp = xp[sorter] 118 # Ensure pressure in increasing order --> 119 variables = [arr[sorter] for arr in args] 120 121 # Make x broadcast with xp /opt/conda/lib/python3.6/site-packages/metpy/interpolate/one_dimension.py in (.0) 117 xp = xp[sorter] 118 # Ensure pressure in increasing order --> 119 variables = [arr[sorter] for arr in args] 120 121 # Make x broadcast with xp TypeError: tuple indices must be integers or slices, not tuple

Its not sounding dependent, and doesn't seem to resolve with simple solutions, so wondering what changed and why. Expected outcome would be there being the calculation working as before. I also get the same error doing this using the example provided on the MetPy site.

import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from datetime import datetime

#Import modules from MetPy-Siphon
import metpy
import metpy.calc as mpcalc
from metpy.cbook import get_test_data
from metpy.plots import Hodograph, SkewT
from metpy.units import pandas_dataframe_to_unit_arrays, units
from metpy.gridding import interpolate
from siphon.simplewebservice.wyoming import WyomingUpperAir

date = datetime(2019, 3, 15, 0)
station = 'DTX'
df = WyomingUpperAir.request_data(date, station)

surface_cape, surface_cin = mpcalc.surface_based_cape_cin(sounding['pressure'],
                                                          sounding['temperature'],
                                                          sounding['dewpoint'])

python -c 'import metpy; print(metpy.version) = 0.10.0

zbruick commented 5 years ago

This was an issue with our dependence on pint, which caused this issue with their release of pint 0.9 (#997). We released a fix in MetPy 0.10.2, so if you update MetPy (and ask students to do the same), then this issue should be resolved: pip install --upgrade metpy or conda update metpy.