-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
121 lines (107 loc) · 3.59 KB
/
run.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
import gen_dataset as DATASET
from gen_dataset import Dataset
import train as TRAIN
import direction as DIRECTION
import sys
import geninput as INPUT
import naive as NAIVE
import matplotlib.pyplot as plt
import numpy as np
import math
import sklearn.metrics
import scipy.stats
import time
import metrics
def direction_summary(R, Bt, Btnxt, dmaps, chunk_size = 50):
shp = Bt.shape
PX = []
PY = []
DX = []
DY = []
GT = []
DA = []
mean_angle=[]
median_angle = []
mode_angle = []
n_mean_angle = []
n_median_angle = []
time_ugdv = 0
time_naive = 0
for i in range(0, shp[0], chunk_size):
for j in range(0, shp[1], chunk_size):
if(R[0][i][j]!=0):
startx = i
starty = j
endx = min(shp[0],i+chunk_size)
endy = min(shp[1],j+chunk_size)
Rchunk = R[:, startx:endx, starty:endy]
Btchunk = Bt[startx:endx, starty:endy]
Btnxtchunk = Btnxt[startx:endx, starty:endy]
dmapschunk = []
for k in range(0,len(dmaps)):
dmapschunk.append(dmaps[k][startx:endx, starty:endy])
D = Dataset()
X,Y = D.create_dataset(Rchunk,Btchunk,Btnxtchunk,dmapschunk)
w, model = TRAIN.train(X,Y)
P = model.predict(X)
alpha = w[0]+w[1]+w[2]+w[3]+w[4] - 1
beta = w[4]-w[2]
gamma = w[3]-w[1]
PX.append((startx+endx)/2)
PY.append((starty+endy)/2)
DX.append(beta/math.sqrt(beta*beta+gamma*gamma+1))
DY.append(gamma/math.sqrt(beta*beta+gamma*gamma+1))
#window = NAIVE.create_window(Btnxt,(startx+endx)/2,(starty+endy)/2)
#GT.append(NAIVE.get_direction_angle(NAIVE.get_direction(window, Bt[(startx+endx)/2][(starty+endy)/2])))
start_time = time.time()
DA.append(math.atan(gamma/beta))
time_ugdv = max(time.time()-start_time,time_ugdv)
GT = NAIVE.gen_direction_angles(Rchunk, Btchunk, Btnxtchunk)
start_time = time.time()
M,N = NAIVE.eval_naive_mean_median(Rchunk, Btchunk, P)
time_naive = max(time_naive, time.time()-start_time)
n_mean_angle.append(M)
n_median_angle.append(N)
mean_angle.append(np.mean(GT))
median_angle.append(np.median(GT))
#mode_angle.append(scipy.stats.mode(GT))
print metrics.angle_rmse(np.array(DA),np.array(mean_angle))
print metrics.angle_rmse(np.array(DA),np.array(median_angle))
print metrics.angle_rmse(np.array(n_mean_angle),np.array(mean_angle))
print metrics.angle_rmse(np.array(n_median_angle),np.array(median_angle))
print time_ugdv, time_naive
plt.imshow(np.transpose(R[0]))
Q = plt.quiver(np.array(PX),np.array(PY),np.array(DX),np.array(DY))
plt.show()
return
if __name__=="__main__":
data_folder = sys.argv[1]
if(data_folder == ''):
print 'Please enter the name of the data folder'
exit()
#Load Datasets
R = INPUT.give_raster(data_folder+'/1999.tif')
Bt = INPUT.give_raster(data_folder+'/cimg2000.tif')[0]
Btnxt = INPUT.give_raster(data_folder+'/cimg2010.tif')[0]
D_F = INPUT.give_raster(data_folder+'/Distancemaps_F.tif')[0]
D_B = INPUT.give_raster(data_folder+'/Distancemaps_B.tif')[0]
D_W = INPUT.give_raster(data_folder+'/Distancemaps_W.tif')[0]
#E = INPUT.give_raster(data_folder+'/Elevationmap.tif')[0]
D_R = INPUT.give_raster(data_folder+'/Distancemaps_R.tif')[0]
DV_G = NAIVE.gen_direction_angles(R,Bt,Btnxt)
#Create Dataset
Bt = Bt/255
Btnxt = Btnxt/255
Bt,Btnxt = DATASET.ageBuiltUp(R,Bt,Btnxt,0.1)
dmaps = [D_F,D_B,D_W,D_R]
D = Dataset()
X,Y = D.create_dataset(R,Bt,Btnxt,dmaps)
#Direction Summary
direction_summary(R, Bt, Btnxt, dmaps, chunk_size = 300)
exit()
#Training model
params, model = TRAIN.train(X,Y)
#Testing the model
TRAIN.test(X, model, R, Bt, Btnxt, DV_G)
#Generating direction vectors
DIRECTION.visualize3(R,params)