I have two data arrays that are on lat-lon grids. The first one, A, has the shape (89, 180). The second one, B, has the shape (94, 192). A's latitudes are in descending order from 88. to -88. & longitudes are in ascending order from 0. to 358. B's latitudes are in descending order from 88.54199982 to -88.54199982 & longitudes are in ascending order from 0. to 358.125.
I want to regrid/interpolate B's data onto A's coordinate system so that I can get both arrays the same size and calculate the spatial correlation between them. (I can also regrid/interpolate A's data onto B's coordinate system if that's easier.) I tried mpl_toolkits.basemap.interp(datain, xin, yin, xout, yout), but that requires xout & yout to be the same size. I also tried scipy.interpolate.griddata, but I can't figure out how it works and I'm not even sure that'll get me what I'm looking for...
You may want to look at pyresample for this and other similar geographical interpolation problems. It provides multiple methods for interpolation, works well with lat/lon data, and incorporates basemap support. I suggest this package because you can also create AreaDefinition objects that define a domain using Proj4 definitions, then register data to the AreaDefinition.
For your specific problem, I would do the following (note, the interpolation step is not complete, see below):
from pyresample.geometry import SwathDefinition
from pyresample.kd_tree import resample_nearest
def interp_b_to_a(a, b):
'''Take in two dictionaries of arrays and interpolate the second to the first.
The dictionaries must contain the following keys: "data", "lats", "lons"
whose values must be numpy arrays.
'''
def_a = SwathDefinition(lons=a['lons'], lats=a['lats'])
def_b = SwathDefinition(lons=b['lons'], lats=b['lats'])
interp_dat = resample_nearest(def_b, b['data'], def_a, ...)
new_b = {'data':interp_dat,
'lats':copy(a['lats']),
'lons':copy(a['lons'])
}
return new_b
Note that the interpolation step where resample_nearest is called is not complete. You will also need to specify the radius_of_influence which is the search radius to use around each point in meters. This is dependent on the resolution of your data. You may also want to specify nprocs to speed things up and fill_value if you are using masked data.
来源:https://stackoverflow.com/questions/35734070/interpolating-data-from-one-latitude-longitude-grid-onto-a-different-one