1

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?

Wboy
  • 2,452
  • 2
  • 24
  • 45

1 Answers1

1

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.

Jon Thielen
  • 479
  • 2
  • 7
  • Ahh okay thanks! Oh man, its so hard to find natural neighbour implentations in python.. i thought this would be it – Wboy Nov 24 '21 at 04:49