用Cartopy插值城市温度数据

时间:2018-02-06 21:58:59

标签: python matplotlib-basemap qgis cartopy metpy

我试图插入在5个地点形成的城市区域观察到的温度数据。我使用cartopy来插值和绘制地图,但是,当我运行脚本时,温度插值没有显示,我只得到带有调色板的市区图层。有人可以帮我解决这个错误吗? shapefile的链接是

https://www.dropbox.com/s/0u76k3yegvr09sx/LimiteAMG.shp?dl=0

https://www.dropbox.com/s/yxsmm3v2ey3ngsp/LimiteAMG.cpg?dl=0

https://www.dropbox.com/s/yx05n31dfkggbb6/LimiteAMG.dbf?dl=0

https://www.dropbox.com/s/a6nk0xczgjeen2d/LimiteAMG.prj?dl=0

https://www.dropbox.com/s/royw7s51n2f0a6x/LimiteAMG.qpj?dl=0

https://www.dropbox.com/s/7k44dcl1k5891qc/LimiteAMG.shx?dl=0

数据

df.groupby(df.index.strftime('%Y%m')).mean()
Out[1199]: 
                Z
201701  49.177419
201702  50.740327
201703  49.954973
201704  48.345833
201705  49.268145
201706  48.943056
201707  49.741263
201708  49.827285
201709  50.442361
201710  48.679435
201711  49.754861
201712  50.173387
201801  94.000000


df.Z.resample('M').mean()
Out[1198]: 
2017-01-31    49.177419
2017-02-28    50.740327
2017-03-31    49.954973
2017-04-30    48.345833
2017-05-31    49.268145
2017-06-30    48.943056
2017-07-31    49.741263
2017-08-31    49.827285
2017-09-30    50.442361
2017-10-31    48.679435
2017-11-30    49.754861
2017-12-31    50.173387
2018-01-31    94.000000
Freq: M, Name: Z, dtype: float64

代码:

        Lat   Lon       tmax
 0   20.8208 -103.4434  22.8
 1   20.7019 -103.4728  17.7
 2   20.6833 -103.3500  24.9
 3   20.6280 -103.4261   NaN
 4   20.7205 -103.3172  26.4
 5   20.7355 -103.3782  25.7
 6   20.6593 -103.4136   NaN
 7   20.6740 -103.3842  25.8
 8   20.7585 -103.3904   NaN
 9   20.6230 -103.4265   NaN
 10  20.6209 -103.5004   NaN
 11  20.6758 -103.6439  24.5
 12  20.7084 -103.3901  24.0
 13  20.6353 -103.3994  23.0
 14  20.5994 -103.4133  25.0
 15  20.6302 -103.3422   NaN
 16  20.7400 -103.3122  23.0
 17  20.6061 -103.3475   NaN
 18  20.6400 -103.2900  23.0
 19  20.7248 -103.5305  24.0
 20  20.6238 -103.2401   NaN
 21  20.4753 -103.4451   NaN

enter image description here

1 个答案:

答案 0 :(得分:1)

问题在于对MetPy interpolate功能的调用。设置hres=35000时,它生成一个间隔为35km的网格。但是,您的数据点似乎间隔得更紧密;这将导致生成的网格只有两个点,如下面的红点所示(黑点是具有非掩码数据的原始站点):

Map with station and grid point locations

结果是它只为网格创建两个点,这两个点都在数据点的边界之外;因此这些点最终被掩盖了。相反,如果我们将hres设置为低得多的东西,比如说5km(即5000),那么就会出现更明智的结果: More sensible interpolation