rbf使用
import numpyas np
import matplotlib.pyplotas plt
from scipy.interpolateimport Rbf
from mpl_toolkits.basemapimport Basemap
import pandasas pd
def leves_colors():# 设置色标方法2
levels = [0, 0.000000001, 1.5, 7, 15, 40, 50]
colors = ['#FFFFFF', '#A6F28F', '#3DBA3D', '#61B8FF', '#0000E1', '#FA00FA', '#800040']
return levels, colors
a= pd.read_csv("http://10.20.76.55/cimiss-web/api?userId=&pwd=&interfaceId=getSurfEleInRectByTime&dataCode=SURF_CHN_MUL_HOR_N&elements=Lon,Lat,PRE_1h×=20200913000000&minLat=31&minLon=104&maxLat=40&maxLon=112&dataFormat=csv")
filename =r'./2020091300.txt'
a.to_csv(filename,index=None,header=None)
file = np.loadtxt(filename, delimiter=',', dtype='str')
file = file[:,:]
# lon = file[:, 0].astype(np.float).reshape(-1, 1)
lon = file[:, 0].astype(np.float)
lat = file[:, 1].astype(np.float)
rain = file[:, 2].astype(np.float)
result = np.ma.masked_greater(rain, 100)
olon = np.linspace(104, 112, 300)
olat = np.linspace(31, 40, 300)
olon, olat = np.meshgrid(olon, olat)
# func = Rbf(lon, lat, result, function='gaussian',epsilon=0.25)
func = Rbf(lon, lat, result, function='linear')
rain_data_new = func(olon, olat)
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111)
m = Basemap(llcrnrlon=105, llcrnrlat=31, urcrnrlon=112, urcrnrlat=40, projection='cyl')
# m.readshapefile('./Map/Shaanxi/Shaanxi_province', 'Shaanxi', default_encoding='utf-8')
xx, yy = m(olon, olat)
levels, colors = leves_colors()
c = m.contourf(xx, yy, rain_data_new, levels=levels, colors=colors, extend='max')
m.colorbar(c)
plt.show()
plt.close()