-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain3.py
129 lines (108 loc) · 6.29 KB
/
main3.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
import os
from test import *
from RoadNetwortLable_by_each_road import *
from concat_all_label_image import *
from GT_post_processing import *
from shp2txt_transform import *
import sys
sys.path.append('topology_construction')
from topology_construction.transform_graph_main import *
from mapcompare import *
import glob
import PIL
from PIL import Image
import pandas as pd
import numpy as np
PIL.Image.MAX_IMAGE_PIXELS = None
import datetime
def main():
print("Hello World")
#test()
with open("time_log.txt","w") as log_f:
for year in [2017,2021]:
for county in ['xixiangxian','shufuxian','guanghexian','danfengxian','jiangzixian','honghexian','liboxian','linquanxian','jingyuxian','lingqiuxian']:
if year ==2017 and county in ['xixiangxian','shufuxian','guanghexian','danfengxian', \
'jiangzixian','honghexian','liboxian','linquanxian','jingyuxian','lingqiuxian']:
continue
elif year ==2021 and county in ['xixiangxian','shufuxian','guanghexian','danfengxian', \
'jiangzixian','honghexian','liboxian']:
if os.path.exists('../output/'+county+'_'+str(year)+'.csv'):
continue
elif year ==2021 and county in ['linquanxian']:
mapcompare('../temp_output/GraphSamplingToolkit-main',county, 'xyx', 'LCR', year)
now_time = datetime.datetime.now()
log_f.write(county+' ' +str(year) +' '+'mapcompare'+ ' '+str(now_time))
log_f.write('\n')
else:
now_time = datetime.datetime.now()
log_f.write(county + ' ' +str(year) + ' ' +str(now_time))
log_f.write('\n')
print(county, ' ', year)
RoadNetwortLable_by_each_road(year,county)
now_time = datetime.datetime.now()
log_f.write(county + ' ' +str(year) +' '+'RoadNetwortLable_by_each_road'+ ' '+str(now_time))
log_f.write('\n')
concat_all_label_image(year,county)
now_time = datetime.datetime.now()
log_f.write(county+ ' ' +str(year) +' '+'concat_all_label_image'+ ' '+str(now_time))
log_f.write('\n')
GT_post_processing(year,county)
now_time = datetime.datetime.now()
log_f.write(county+ ' ' +str(year) + ' '+'GT_post_processing'+ ' '+str(now_time))
log_f.write('\n')
transform_graph_main(year,county)
now_time = datetime.datetime.now()
log_f.write(county+ ' ' +str(year) + ' '+'transform_graph_main'+ ' '+str(now_time))
log_f.write('\n')
shp2txt_transform(year,county)
now_time = datetime.datetime.now()
log_f.write(county+' ' +str(year) +' '+'shp2txt_transform'+ ' '+str(now_time))
log_f.write('\n')
mapcompare('../temp_output/GraphSamplingToolkit-main',county, 'xyx', 'LCR', year)
now_time = datetime.datetime.now()
log_f.write(county+' ' +str(year) +' '+'mapcompare'+ ' '+str(now_time))
log_f.write('\n')
del_list = os.listdir('../temp_output/'+county+'_road_label_by_image_'+str(year)+'/')
for f in del_list:
file_path = os.path.join('../temp_output/'+county+'_road_label_by_image_'+str(year)+'/', f)
if os.path.isfile(file_path):
os.remove(file_path)
del_list = os.listdir('../temp_output/'+county+'_width3_'+str(year)+'/')
for f in del_list:
file_path = os.path.join('../temp_output/'+county+'_width3_'+str(year)+'/', f)
if os.path.isfile(file_path):
os.remove(file_path)
os.removedirs('../temp_output/'+county+'_road_label_by_image_'+str(year))
os.removedirs('../temp_output/'+county+'_width3_'+str(year))
year_list1 = []
county_list1 = []
positive_pixel_list = []
image_weight_list = []
image_height_list = []
for year in [2017,2021]:
for county in ['shufuxian','xixiangxian','guanghexian','danfengxian','jiangzixian','honghexian','liboxian','linquanxian','jingyuxian','lingqiuxian']:
img = Image.open('../temp_output/'+'topology_construction/'+county+'_GT_'+str(year)+'.png')
img_np = np.array(img)
pos_idx = np.where(img_np>0)
year_list1.append(year)
county_list1.append(county)
positive_pixel_list.append(len(pos_idx[0]))
image_weight_list.append(img_np.shape[0])
image_height_list.append(img_np.shape[1])
now_time = datetime.datetime.now()
log_f.write(county + ' ' +str(year) +' '+'GT_statistics'+ ' '+str(now_time))
log_f.write('\n')
pd_statis = pd.DataFrame({'county':county_list1, 'year':year_list1,'pos_pixel':positive_pixel_list, \
'img_weight':image_weight_list,'img_height':image_height_list})
pd_statis.to_csv('GT_statistics.csv', index=False)
df_all = pd.DataFrame({})
for year in [2017,2021]:
for county in ['shufuxian','xixiangxian','guanghexian','danfengxian','jiangzixian','honghexian','liboxian','linquanxian','jingyuxian','lingqiuxian']:
df = pd.read_csv('../output/'+county+'_'+str(year)+'.csv')
df_all = pd.concat([df_all, df])
now_time = datetime.datetime.now()
log_f.write(county + ' ' +str(year) +' '+'validation_statistics_all'+ ' '+str(now_time))
log_f.write('\n')
df_all.to_csv('validation_statistics_all.csv', index=False)
if __name__=="__main__":
main()