1
我使用NumPy的linspace在點之間填充數據。獲取numpy Linspace生成的座標
lats = (-66.44421,-66.57947,-64.81464,-64.69528)
lons = (-73.03290,-72.73904,-64.71657,-65.03036)
NO3 = (33.48,24.01,17.20,20.03)
xi = np.linspace(min(lats),max(lats),360)
yi = np.linspace(min(lons),max(lons),360)
# grid the data.
zi = griddata((lats, lons), NO3, (xi[None,:], yi[:,None]), method='cubic')
# contour the gridded data.
plt.contourf(xi,yi,zi,15,cmap=cMap)
plt.colorbar()
# plot data points.
plt.scatter(lats,lons,facecolors='none', edgecolors='k',s=26)
plt.show()
我想要檢索基於座標從linspace產生對從網格數據的Zi值(丟失的樣本),但座標是不準確的字典查找:
# record index and value of linspace coordinates as key and value
xi_coords = {value: index for index, value in enumerate(xi)}
yi_coords = {value: index for index, value in enumerate(yi)}
# how to retrieve a value inbetween at say... (-65.11018,-67.08512)
zi[xi_coords[-65.11018], yi_coords[-67.08512]]
返回重要錯誤。 有沒有比這個問題更聰明的解決方法?
再次感謝邁克,爲我的問題工作! –