apply_ufunc problem
When using apply_ufunc, broadcasting vector functions on several axes will result in the following error:
Implicit conversion to a NumPy array is not allowed. Please use .get() to construct a NumPy array explicitly.
Could you share a minimal repducible example?
ERA5 weather data is a four-dimensional dataset that includes time, altitude (atmospheric pressure layer), longitude, and latitude. When I use the function provided by METPY to calculate divergence. When using vector functions in terms of time and height, the above error will be prompted.But using numpy doesn't have this problem
file=r'C:\Users\Administrator\Desktop\ERA5.nc'
ds=xr.open_dataset(file)[['u','v']]
ds_gpu=ds.cupy.as_cupy()
dx,dy=mcalc.lat_lon_grid_deltas(ds.longitude,ds.latitude)
def divergence(u,v):
div=mcalc.divergence(u,v,dx=dx,dy=dy)
return div
Divergence=xr.apply_ufunc(divergence,
ds_gpu['u'],
ds_gpu['v'],
input_core_dims=[['latitude','longitude'],['latitude','longitude']],
output_core_dims=[['latitude','longitude']],
vectorize=True)
I suspect the issue is in the metpy function which might be converting to numpy. We'll need to see the whole traceback to be sure
thank you. However, when using the decorator to test the vector function of the broadcast, apply_ufunc did not enter the broadcast function stage before jumping out of the error and forcibly terminating. The example provided on the official website of cupy-xarray using apply_ufunc does not use the input_core_dims parameter.So further testing is not possible.