I have a set o data (stored in 2D numpy arrays) representing simulations for a same problem. However, each simulation comes from a different model, which results in different resolutions for each of them. For example, these are some of the simulations' sizes:
What I'd like to do is to convert them all to the same resolution, for instance, 144 x 157. I believe I have to perform an interpolation, however, I'm not sure which method to use in Python.
I've been reading about these:
The (3) and (4) seems to fit best the problem, however, I'm unsure about how to make them return a new gridded (2D) data, with an specified resolution.
It turns out that I could solve it using scipy.interpolate.RegularGridInterpolator.html:
import numpy as np
import pylab as plt
from scipy.interpolate import RegularGridInterpolator
def regrid(data, out_x, out_y):
m = max(data.shape[0], data.shape[1])
y = np.linspace(0, 1.0/m, data.shape[0])
x = np.linspace(0, 1.0/m, data.shape[1])
interpolating_function = RegularGridInterpolator((y, x), data)
yv, xv = np.meshgrid(np.linspace(0, 1.0/m, out_y), np.linspace(0, 1.0/m, out_x))
return interpolating_function((xv, yv))
Input:
Output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With