Skip to content

how to use metpy.calc.divergence with chunked Xarray? #2225

Answered by jthielen
QINQINKONG asked this question in Q&A
Discussion options

You must be logged in to vote

A key issue here is the following:

Then I call mpcalc.divergence use xr.apply_ufunc:
div=xr.apply_ufunc(mpcalc.divergence,u10*q,v10*q,dask="parallelized",output_dtypes=[float])

As explained in the documentation, xr.apply_ufunc applies a function for unlabeled arrays. So, when used this way, mpcalc.divergence doesn't see a xarray object, but instead just data inside, which means that none of MetPy's xarray coordinate-aware features will work. Also, you may have noticed that when you tried it this way, the pint.Quantity ended up inside the Dask array rather than the other way around, which comes from a failure of Dask to properly recognize upcast types. All-in-all, this approach won't wor…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@QINQINKONG
Comment options

Answer selected by QINQINKONG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Area: Xarray Pertains to xarray integration
2 participants