Strange error for advection function #2836
-
Hi, I'm using a Metpy to calculate the advection field of Absolute Vorticity using the U, V and W fields passed as Xarray DataArrays as seen in the call below. Given the Xarray requirement in the doc I don't need to pass in the dx, dy, or zx. But I still got this error: adv = mc.advection(av, u=u, v=v, w=w, x_dim=-1, y_dim=-2, vertical_dim=-3)
File ~/anaconda3/envs/contrail/lib/python3.10/site-packages/metpy/calc/tools.py:1312, in _process_deriv_args(f, axis, x, delta)
1310 delta = np.diff(x, axis=axis)
1311 else:
-> 1312 raise ValueError('Must specify either "x" or "delta" for value positions.')
1314 return n, axis, delta
ValueError: Must specify either "x" or "delta" for value positions. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 16 replies
-
Can you change the call to remove the inclusion of |
Beta Was this translation helpful? Give feedback.
-
So the original all NaN result comes from pydata/xarray#7385, coming out of our use of We still need to fix in MetPy the issue with "no units lat/lon" -> "lat/lon in radians". |
Beta Was this translation helpful? Give feedback.
-
Apologies for this late reply. Thank you for support and the solution for vertical advection. Next sprint I'll be integrating |
Beta Was this translation helpful? Give feedback.
So the original all NaN result comes from pydata/xarray#7385, coming out of our use of
xr.broadcast()
, but caused by the way the arrays are constructed in the sample code. When constructing aDataset
of a single variable and then callingto_array()
the returned result isn't a list, but aDataArray
that includes an extravariable
dimension with a single coordinate that seems to correspond to the original variable. That (for reasons unknown at this point) causes broadcast to putnan
in the broadcast field rather than repeating the original values.We still need to fix in MetPy the issue with "no units lat/lon" -> "lat/lon in radians".