0

I am attempting to plot weather variables on a map of Oklahoma using mpl_toolkits.basemap, but am having issues figuring out how to interpolate the data to plot on top of the map.

Here is a general idea of the current code I have:

lons = [-97.9547, -97.9747, -97.4256]
lats = [35.5322, 35.864, 35.4111]
data = [2,2,2]
map = Basemap(llcrnrlon = -103.068237, llcrnrlat = 33.610045, urcrnrlon = -94.359076, urcrnrlat = 37.040928, resolution = 'i')  


CS = map.contour(X, Y, data)
map.drawstates()
plt.show()

What I am attempting to accomplish is to plot the data values on the map based on the related reference index in the lons/lats lists, and then contour the values of the data variable.

Now this obviously won't work, because I need to interpolate the data. Is there a way that I could accomplish this using the griddata function? I am very confused on how I would establish the boundaries of the grid given that latitude and longitude values are not linearly spaced.

Is there an easier way to do this that I am missing?

Any help and/or hints would be greatly appreciated, this is holding me back from moving on to the next major portion of the research project!

4

1 回答 1

0

我没有在这台机器上安装 python,所以无法测试。但是这样的事情应该为您提供计数图所需的输入......

import numpy as np

lons = [-97.9547, -97.9747, -97.4256]
lats = [35.5322, 35.864, 35.4111]
data = [2,2,2]

xs, ys = np.meshgrid(lons, lats)

dataMesh = np.empty_like(xs)
for i, j, d in zip(lons, lats, data):
    dataMesh[lons.index(i), lats.index(j)] = d

map = Basemap(llcrnrlon = -103.068237, llcrnrlat = 33.610045, urcrnrlon = -94.359076, urcrnrlat = 37.040928, resolution = 'i')  


CS = map.contour(xs, ys, dataMesh)
map.drawstates()
plt.show()

就像我说的那样,我还没有测试过这个。我不知道如果您尝试绘制单元化值会发生什么。您可能需要使用不同的 numpy 数组初始化。

于 2013-07-16T00:08:22.320 回答