Lost in apply_ufunc land without a map! Trying to find a faster way to apply interp1d. #6286
Unanswered
rodgerduffett
asked this question in
Q&A
Replies: 1 comment 5 replies
-
See https://docs.xarray.dev/en/stable/examples/apply_ufunc_vectorize_1d.html for this exact problem. Let us know if it can be improved in any way |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Dear All,
I'm using xarray and dask to process wind speed data. The dataset has dimensions for time, level and space as a grid. The important variables are wind speed as U and V components and height above ground for each level. I need to interpolate U and V for a target height at each of the grid cells and of course for each time step. I've been able to do this using for loops and a dask delayed function that wraps scipy's interp1d function.
It works reasonably well as long as a small enough subset is selected out in the nested loop structure. But it seems an inefficient way to do things.
I've been trying to understand apply_ufunc and map_blocks in this context without success! The main conceptual issue being that interp1d needs an x and y as equal length vectors. These exist in the data as the 'level' dimension for the height and U/V variables.
Some code may help explain. Simplified data looks like this:
What would be the most efficient way to apply:
at each time step and each grid cell?
At the moment I use something like:
The futures must be computed and the results reshaped back to time,i,j shape before saving to disk.
This works as long as the number of time steps submitted in each pass is kept reasonable and the size of the grid like wise reduced. For bigger datasets it means a lot of looping and selecting. In addition the results come back to the local compute node.
Advice on how to approach this problem in a better way will be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions