Got TypeError: got an unexpected keyword argument 'dim_order' when calculating Temperature advection with Metpy?

Viewed 321
1 Answers

The linked example is unfortunately out-of-date with recent versions of MetPy. As noted in this StackOverflow answer, the signature for metpy.calc.advection as of v1.0 has changed to (scalar, u, v), and dim_order is no longer valid as an argument, but instead dimension order is automatically inferred (or manually specified with y_dim and x_dim). In your example, using the updated API could look something like

import metpy.calc as mpcalc
from metpy.units import units
import xarray as xr

data = xr.open_dataset(file).metpy.parse_cf()

level = 850 * units.hPa  # units.Quantity([ 250,  300,  500,  750,  850,
                         # 925, 1000], 'hPa')

temp = data['t'].isel(time=0).metpy.sel(vertical=level)
u_wind = data['u'].isel(time=0).metpy.sel(vertical=level)
v_wind = data['v'].isel(time=0).metpy.sel(vertical=level)

temp_adv = mpcalc.advection(temp, u_wind, v_wind)
Related