Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply_ufunc problem #69

Open
Ex-tranquility opened this issue Jan 22, 2025 · 4 comments
Open

apply_ufunc problem #69

Ex-tranquility opened this issue Jan 22, 2025 · 4 comments

Comments

@Ex-tranquility
Copy link

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.

@jacobtomlinson
Copy link
Collaborator

Could you share a minimal repducible example?

@Ex-tranquility
Copy link
Author

Ex-tranquility commented Jan 22, 2025

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)

@dcherian
Copy link
Contributor

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

@Ex-tranquility
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants