Wboy
Wboy

Reputation: 2552

grid_x and grid_y dimension in natural neighbour to grid?

From the docs https://unidata.github.io/MetPy/latest/api/generated/metpy.interpolate.natural_neighbor_to_grid.html

enter image description here

I have my xp, yp, variable points etc similar to how you would do it in mpl mlab gridder or scipy interpolate, but how is the meshgrid dimension (M,2)?

if i have 1000 columns and 1000 rows, np.meshgrid would return

    
# set up a square grid with the same extents as our measured data
numcols, numrows = 1000, 1000
xi = np.linspace(min_grid_val_x, max_grid_val_x, numcols)
yi = np.linspace(min_grid_val_y, max_grid_val_y, numrows)
x_grid, y_grid = np.meshgrid(xi, yi)

# x_grid and y_grid will have shape 1000x1000 respectively

But metpy seems fixed that the dimension is 2? and why is the output (M,N)? shouldn't it be (M,M)? is there something im missing here?

Upvotes: 1

Views: 176

Answers (1)

Jon Thielen
Jon Thielen

Reputation: 489

This is indeed a mistake in the MetPy documentation! https://github.com/Unidata/MetPy/pull/2216 is a just-opened PR to correct this to indicate that the array shapes for the arguments should be:

  • xp (P, )
  • yp (P, )
  • variable (P, )
  • grid_x (M, N)
  • grid_y (M, N)

Also, a word of warning: natural_neighbor_to_grid is an un-optimized calculation and does not take advantage of the regular structure of the grid (i.e., it treats the target grid points as unstructured points), and so, will likely have very poor performance interpolating on to a domain with ~106 points. I would recommend re-structuring your approach to use smaller domains (e.g., subsets) or use a different interpolation algorithm with better performance.

Upvotes: 1

Related Questions