浏览我发现一些工具在Python中使用克里格网络是pyKriging和高斯过程回归.但是,我无法使它们中的任何一个工作.第一个对我不起作用(甚至不能导入它):
import pyKriging
File "~/python3.6/site-packages/pyKriging/krige.py", line 142
except Exception, err:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
第二个我不明白如何使用它.我找不到一个简单的工作示例(例如,这个 rroowwllaanndd答案很棒,但遗憾的是数据不再可供下载)
所以我的问题是,如何使用Kriging插入我的数据?我有几个站点数据保存在numpy数组中,如下所示:
2000 1 1 5.0
2000 1 2 3.4
2000 1 3 0.2
Run Code Online (Sandbox Code Playgroud)
列是年 - 月 - 日 - 降水.我有几个这样的数据数组(st1,st2,st3),另一个数组包含每个站的ID和每个站所在的坐标(stid,因此站1位于经度15.6865,北纬62.6420,和等等).
import numpy as np
st1 = np.array([[2000,1,1,5.0],[2000,1,2,3.4],[2000,1,3,0.2]])
st2 = np.array([[2000,1,1,8.2],[2000,1,2,2.5],[2000,1,3,0.0]])
st3 = np.array([[2000,1,1,np.nan],[2000,1,2,4.5],[2000,1,3,1.2]])
stid = np.array([[1,15.6865,62.6420],[2,15.7325,62.1254],[3,16.1035,61.1449]])
Run Code Online (Sandbox Code Playgroud)
我需要的是每天一个数组(或一个3D数组),它包含每天在这样的网格中用Kriging插值的所有站点的数据:
y = np.arange(61,63,0.125)
x = np.arange(14,17,0.125)
X,Y = np.meshgrid(x,y)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
我正在尝试读取一个txt文件,其每行的列数不同。这是我文件的开头:
60381 6
1 0.270 0.30 0.30 0.70 0.70
4.988 4.988 4.988 4.988 4.988 4.988 4.988 4.988 4.988 4.988 4.988 4.988
2 0.078 0.30 0.30 0.70 0.70
5.387 5.312 5.338 4.463 4.675 4.275 4.238 3.562 3.175 3.925 4.950 4.762
6 0.241 0.30 0.60 0.70 0.40
3.700 3.200 2.738 2.325 1.250 0.975 1.175 1.950 2.488 3.613 3.987 3.950
7 0.357 0.30 0.60 0.70 0.40
1.212 1.125 1.050 0.950 0.663 0.488 0.425 0.512 0.637 0.900 1.112 1.188
8 0.031 0.30 0.70 0.70 …Run Code Online (Sandbox Code Playgroud) 我创建了一个随机数据框来模拟来自seaborn的数据集提示:
import numpy as np
import pandas as pd
time = ['day','night']
sex = ['female','male']
smoker = ['yes','no']
for t in range(0,len(time)):
for s in range(0,len(sex)):
for sm in range(0,len(smoker)):
randomarray = np.random.rand(10)*10
if t == 0 and s == 0 and sm == 0:
df = pd.DataFrame(index=np.arange(0,len(randomarray)),columns=["total_bill","time","sex","smoker"])
L = 0
for i in range(0,len(randomarray)):
df.loc[i] = [randomarray[i], time[t], sex[s], smoker[sm]]
L = L + 1
else:
for i in range(0,len(randomarray)):
df.loc[i+L] = [randomarray[i], time[t], sex[s], …Run Code Online (Sandbox Code Playgroud)