-
Notifications
You must be signed in to change notification settings - Fork 0
/
STacf_Form.py
executable file
·173 lines (151 loc) · 5.47 KB
/
STacf_Form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import sys
from UI.stacf import stacf_Form
from PyQt5.QtWidgets import *
import pymysql
from datetime import datetime
import numpy as np
from pySTARMA import stacf_stpacf,starma_model,utils
import pysal
from Acftable_form import *
class Stacf_Form(QWidget, stacf_Form):
def __init__(self):
super(Stacf_Form, self).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.queren)
self.table = Acftable_Form()
# 所有combo初始化
def combo_ini(self):
db = pymysql.connect("localhost", "root", "960609", "biye", charset='utf8')
load_sql = "select * from AOI"
# 使用cursor()方法获取操作游标
cursor = db.cursor()
cursor.execute(load_sql) # 加载表中数据
zd = []
for field_desc in cursor.description:
zd.append(field_desc[0])
self.comboBox.addItems(zd)
self.comboBox.setCurrentIndex(0)
self.comboBox_2.addItems(zd)
self.comboBox_2.setCurrentIndex(0)
self.comboBox_3.addItems(zd)
self.comboBox_3.setCurrentIndex(0)
self.comboBox_4.addItems(zd)
self.comboBox_4.setCurrentIndex(0)
self.comboBox_5.addItems(zd)
self.comboBox_5.setCurrentIndex(0)
db.close()
def queren(self):
time_field=self.comboBox.currentText()
lon_field=self.comboBox_2.currentText()
lat_field=self.comboBox_3.currentText()
val_field=self.comboBox_4.currentText()
location_field=self.comboBox_5.currentText()
K_val=int(self.textEdit.toPlainText())
s_lag=int(self.textEdit_3.toPlainText())
t_lag=int(self.textEdit_4.toPlainText())
diff_val=int(self.textEdit_5.toPlainText())
db = pymysql.connect("localhost", "root", "960609", "biye", charset='utf8')
# 使用cursor()方法获取操作游标
cursor = db.cursor()
#获取地点字段
location_sql='select distinct '+location_field+' from AOI'
cursor.execute(location_sql)
rows=cursor.fetchall()
location_val=[]
for (row,) in rows:
loca=row
location_val.append(loca)
#获取时间字段
time_sql = 'select distinct ' + time_field + ' from AOI'
cursor.execute(time_sql)
rows = cursor.fetchall()
datetime_val = []
for (row,) in rows:
dt = str(row)
datetime_val.append(dt)
data=[]
diff=[diff_val]#差分次数i
#拼接时空数据
for i in range(len(datetime_val)):
locaval_sql = 'select ' + val_field + ' from AOI where ' + time_field + ' = \'' + datetime_val[i
] + '\' order by ' + location_field + ' asc'
cursor.execute(locaval_sql)
rows=cursor.fetchall()
lval=[]
for (row,) in rows:
val=row
lval.append(val)
data.append(lval)
ts=np.array(data)
#计算差分
ts_diff=utils.set_stationary(ts,diff)
#获取点的经纬度坐标
# 点的经度
lon_sql = 'select distinct ' + lon_field + ' from AOI order by '+ location_field + ' asc'
cursor.execute(lon_sql)
rows = cursor.fetchall()
x_val = []
for (row,) in rows:
xval = row
x_val.append(xval)
# 点的纬度
lat_sql = 'select distinct ' + lat_field + ' from AOI order by '+ location_field + ' asc'
cursor.execute(lat_sql)
rows = cursor.fetchall()
y_val = []
for (row,) in rows:
yval = row
y_val.append(yval)
#拼接点
point = []
for i in range(len(x_val)):
coor = []
coor.append(x_val[i])
coor.append(y_val[i])
coortuple = tuple(coor)
point.append(coortuple)
#计算权重
points=np.array(point)
kd = pysal.cg.kdtree.KDTree(points)
# weights
K = int(K_val)
weights = pysal.weights.Distance.KNN(kd, K)
#weights.transform='r'
#计算滞后
w0=[
[1,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1]
]
w=[weights]
for s in range(2,s_lag+1):
w_tmp=pysal.higher_order(weights,s)
w.append(w_tmp)
slw=[w0]
for j in range(len(w)):
w[j].transform='r'
w_f=w[j].full()
slw.append(w_f[0].tolist())
w_slag=np.array(slw)
acf=stacf_stpacf.Stacf(ts_diff,w_slag,t_lag)
acf_val=acf.estimate()
#print(acf_val)
self.table.show_table(acf_val)
def show_form(self):
self.combo_ini()
if not self.isVisible():
self.show()
# 关闭窗口
def close_form(self):
self.close()