如何插入分散数据常规电网在Python中?- 江南体育网页版- - - - -地球科学堆江南电子竞技平台栈交换 最近30从www.hoelymoley.com 2023 - 07 - 07 - t15:59:56z //www.hoelymoley.com/feeds/question/12057 https://creativecommons.org/licenses/by-sa/4.0/rdf //www.hoelymoley.com/q/12057 20. 如何插入分散数据常规电网在Python中? 达沃Keppas //www.hoelymoley.com/users/10670 2017 - 08 - 11 - t09:43:42z 2018 - 08 - 02 - t19:19:56z < p >我有三个txt文件经度,纬度和温度(或假设三个列表经度,纬度,温度)在英国从分散的气象站。我想首先插入这些数据以得到一个漂亮的彩色地图的温度。然后,我想这个温度插值层只有在土地面具(因此在不列颠群岛和不是在海的那边)。这有可能与Python和如何? < / p > //www.hoelymoley.com/questions/12057/-/12058 # 12058 0 由Communisty回答如何插入分散数据常规电网在Python中? Communisty //www.hoelymoley.com/users/6465 2017 - 08 - 11 - t10:38:46z 2017 - 08 - 11 - t10:38:46z < p >首先你必须读取数据例如在matlab。然后你就可以得到整个领域内插函数griddata matlab。,还存在landmask功能,允许您进一步的情节你喜欢的地图。< / p > < p >是的这是可能的和有必要的功能至少在matlab在其他语言,我猜。< / p > //www.hoelymoley.com/questions/12057/-/12059 # 12059 13 由user2821回答如何插入分散数据常规电网在Python中? user2821 //www.hoelymoley.com/users/2536 2017 - 08 - 11 - t12:35:18z 2017 - 08 - 13 - t15:52:39z < p >你有很多选择。< / p > < p >这个简单任务的最简单的解决方案是使用一个GIS软件,例如自由< a href = " http://www.qgis.org/en/site/ " rel = " noreferrer " > QGIS < / >。添加分隔文本图层栅格插值。下载一个< a href = " http://www.diva-gis.org/gdata " rel = " noreferrer " >自由海岸线向量< / >和剪辑你的光栅与海岸线。一些搜索< A href = " https://gis.stackexchange.com/ " > GIS SE < / >可以帮助你如果你卡住。GIS选项,它也很容易情节如城市或位置提取温度插值。< / p > < p >或者(根据你的更新问题),您可以使用Python。这将在某种程度上给你更多的控制你的工作流。< a href = " https://matplotlib.org/basemap/ " rel = " noreferrer " >基础图< / >是一个有用的包,看到如< a href = " http://earthpy.org/interpolation_between_grids_with_basemap.html " rel = " noreferrer " >开始本教程< / >。Python也是自由和有一个伟大的社区在< a href = " https://stackoverflow.com/questions/tagged/python " > < / >和其他地方。 numpy and scipy are good packages for interpolation and all array processes. For more complicated spatial processes (clip a raster from a vector polygon e.g.) GDAL is a great library.

You can also use R, that might be a smart solution if you intend to do some more demanding statistical analysis later. There are some tutorials that can put you on the right track.

GMT should also able to make what you need and there is a python interface, at least under development.

Probably, you'd like to spend some effort on picking the right interpolation method and make sure that your grid is the best estimate for the actual values.

Enjoy your map-making!


Update:

I think that GIS would be the first approach, but as you asked for some Python commands, here is a sloppy example of how to use Python, basemap and scipy for your application. It can be greatly improved by creating a mask from a shapefile and, as mentioned, a sensitive use of interpolation method.

import numpy as np from scipy.interpolate import griddata from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt #Define mapframe lllon = -11 lllat = 49 urlon = 2 urlat = 61 # Make some toy data, random points + corners n = 10 # no of stations lat = np.random.uniform(low=lllat+2, high=urlat-2, size=n) lat = np.append(lat, [lllat, urlat, urlat, lllat]) lon = np.random.uniform(low=lllon+2, high=urlon-2, size=n) lon = np.append(lon, [lllon, urlon, lllon, urlon]) temp = np.random.randn(n+4) + 8 # British summer? # set up basemap chose projection! m = Basemap(projection = 'merc', resolution='i', llcrnrlon = lllon, llcrnrlat = lllat, urcrnrlon = urlon, urcrnrlat = urlat) # transform coordinates to map projection m m_lon, m_lat = m(*(lon, lat)) # generate grid data numcols, numrows = 240, 240 xi = np.linspace(m_lon.min(), m_lon.max(), numcols) yi = np.linspace(m_lat.min(), m_lat.max(), numrows) xi, yi = np.meshgrid(xi, yi) # interpolate, there are better methods, especially if you have many datapoints zi = griddata((m_lon,m_lat),temp,(xi,yi),method='cubic') fig, ax = plt.subplots(figsize=(12, 12)) # draw map details m.drawmapboundary(fill_color = 'skyblue', zorder = 1) # Plot interpolated temperatures m.contourf(xi, yi, zi, 500, cmap='magma', zorder = 2) m.drawlsmask(ocean_color='skyblue', land_color=(0, 0, 0, 0), lakes=True, zorder = 3) cbar = plt.colorbar() plt.title('Temperature') plt.show() 

(This is modified code, used for something else. For detailed questions, other forums are more suitible. )

enter image description here

//www.hoelymoley.com/questions/12057/-/12061 # 12061 27 由milancurcic回答如何插入分散数据常规电网在Python中? milancurcic //www.hoelymoley.com/users/192 2017 - 08 - 11 - t18:37:51z 2017 - 08 - 11 - t18:37:51z < p >与<代码>这样做很简单numpy < /代码>,<代码> scipy.interpolate.griddata < /代码>,和<代码> matplotlib > < /代码。这是一个例子:< / p > < pre > <代码>进口matplotlib。pyplot as plt import numpy as np from scipy.interpolate import griddata # data coordinates and values x = np.random.random(100) y = np.random.random(100) z = np.random.random(100) # target grid to interpolate to xi = yi = np.arange(0,1.01,0.01) xi,yi = np.meshgrid(xi,yi) # set mask mask = (xi > 0.5) & (xi < 0.6) & (yi > 0.5) & (yi < 0.6) # interpolate zi = griddata((x,y),z,(xi,yi),method='linear') # mask out the field zi[mask] = np.nan # plot fig = plt.figure() ax = fig.add_subplot(111) plt.contourf(xi,yi,zi,np.arange(0,1.01,0.01)) plt.plot(x,y,'k.') plt.xlabel('xi',fontsize=16) plt.ylabel('yi',fontsize=16) plt.savefig('interpolated.png',dpi=100) plt.close(fig)

Result:

enter image description here

How to use this:

  • x and y are locations of points - these correspond to lon and lat values of your stations;
  • z are the values of points - this corresponds to your temperature observations from stations;
  • xi and yi are target grid axes - these will be your target longitude and latitude coordinates, which must match your landmask field;
  • zi is the result;
  • This example includes a simple way to mask the field. You should replace this mask with the landmask on your grid.

Notice also the method argument to griddata. Besides linear, this can also be cubic or nearest. I suggest you play with each to see what yields the best result for your dataset.

Baidu
map