1

I want to regrid georeferenced data to a specific grid with a different resolution on the lat and on the lon dimensions. Before I would use basemap.interp, but this basemap is dead. I am experimenting with the metpy package, and metpy.interpolate_to_points seems the right candidate. Only, from the documentation I can't work out the format of the parameters I should enter. It reads:

points (array_like, shape (n, D)) – Coordinates of the data points. values (array_like, shape (n,)) – Values of the data points. xi (array_like, shape (M, D)) – Points to interpolate the data onto.

Regarding 'points' I have tried providing them as 1-D arrays, as 2-D meshgrids (obtained with np.meshgrid), and in either lon first or lat first fashion. Same for 'xi'. For example:

from metpy.interpolate import interpolate_to_points
out_lons, out_lats = np.meshgrid(out_lons_1Darray, out_lats_1Darray)
downscaled_array = interpolate_to_points( [in_lons, in_lats], input_array, [out_lons, out_lats] )

From whichever attempt I get ValueError: operands could not be broadcast together with shapes (192,) (288,) Any suggestion where I am wrong is greatly appreciated.

Pauli
  • 170
  • 3
  • 9
  • Just to mention, for whomever may still be interested in a quick solution to interpolate as basemap allowed: copying and using the `interp` function from basemap source code works just fine, as it doesn't depend on anything else in basemap itself. – Pauli Sep 24 '19 at 10:59

1 Answers1

1

This function wraps scipy.interpolate.griddata and you can see their documentation here.

Their example shows the following, which works as for the metpy.interpolate.interpolate_to_points function:

def func(x, y):
    return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2

grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])
grid_out = interpolate_to_points(points, values, (grid_x, grid_y))
zbruick
  • 316
  • 1
  • 9
  • Thank you. That it simply wrapped `scipy.interpolate.griddata` escaped my attention. Now it's clear, it just takes some reshuffling and flattening the gridded data. – Pauli Sep 25 '19 at 08:09