diff --git a/modules/util/util.py b/modules/util/util.py index 06f8eb06feb0803c3ddc6b1347da360ad16bf23b..f82694540f0157dbe0c1bd45be82522c87b96e59 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -11,7 +11,7 @@ import h5py import pickle from netCDF4 import Dataset from util.setup import ancillary_path -from scipy.interpolate import RectBivariateSpline +from scipy.interpolate import RectBivariateSpline, interp2d LatLonTuple = namedtuple('LatLonTuple', ['lat', 'lon']) @@ -1397,3 +1397,17 @@ def resample(x, y, z, x_new, y_new): def resample_one(x, y, z, x_new, y_new): f = RectBivariateSpline(x, y, z) return f(x_new, y_new) + + +def resample_2d_linear(x, y, z, x_new, y_new): + z_intrp = [] + for k in range(z.shape[0]): + z_k = z[k, :, :] + f = interp2d(x, y, z_k) + z_intrp.append(f(x_new, y_new)) + return np.stack(z_intrp) + + +def resample_2d_linear_one(x, y, z, x_new, y_new): + f = interp2d(x, y, z) + return f(x_new, y_new) \ No newline at end of file