DuTianshi / Speedup-Griddata

Speedup the scipy.interpolate.griddata function when employing it on multiple data with the same mapping relations
2 stars 0 forks source link

算法疑问 #1

Open u-fengtao opened 1 week ago

u-fengtao commented 1 week ago

griddata可以基于非grid的数据(irregular)插值出函数,但是你的sample写的是linspace的数据,单调递增,感觉有问题

DuTianshi commented 1 week ago

I’m not sure if you’ve tried this yet, but the code I provided works well for irregular data that doesn't require monotonic increases. Here’s a tested example: ` from speedup_griddata import interp_weights, interpolate import numpy as np

lon = np.random.random(1000) lat = np.random.random(1000) values = np.random.randint(0, 100, lon.shape)

tlon = np.linspace(0, 1, 10) tlat = np.linspace(0, 1, 10) tlon, tlat = np.meshgrid(tlon, tlat)

vts, wts = interp_weights(lon[:, None], lat[:, None], tlon, tlat) new = interpolate(values, vts, wts) ` The only potential issue you might encounter is that the interp_weights function requires 2-dimensional input data. You can either modify the original code in this function to accommodate your irregular (1-D) data, or add an additional dimension to your data as demonstrated above.