-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.py
62 lines (51 loc) · 2.13 KB
/
main.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
import os
import glob
import yaml
import time
from distutils.dir_util import copy_tree
from utils.file_io import remove_files, recreate_folder
from utils.find_coordinates import findCoordinates
import segmentation.k_means_segmentation.initial_segmentation_thesis_mh as k_means
import segmentation.merging_algorithm.merger as merging_algorithm
import model.model as md
# Read Config file
config = {}
with open('config.yaml') as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
print("loading config success")
print("cleaning output folders")
print("cleaning k_means_segmentation output files")
remove_files(glob.glob(config['k_means_segmentation']['output']['tables']+"*"))
remove_files(glob.glob(config['k_means_segmentation']['output']['segments']+"*"))
recreate_folder(config['k_means_segmentation']['output']['tables'])
recreate_folder(config['k_means_segmentation']['output']['segments'])
print("cleaning merging algorithm output files")
remove_files(glob.glob(config['mergin_algorithm']['output']['wrong']+"*"))
remove_files(glob.glob(config['mergin_algorithm']['output']['merged']+"*"))
remove_files(glob.glob(config['mergin_algorithm']['output']['regions']+"*"))
recreate_folder(config['mergin_algorithm']['output']['wrong'])
recreate_folder(config['mergin_algorithm']['output']['merged'])
recreate_folder(config['mergin_algorithm']['output']['regions'])
remove_files(glob.glob(config['model']['predictions']+"*"))
recreate_folder(config['model']['predictions'])
print("cleaning output folders success")
# Run k-means
print("1 Running k-means algorithm")
k_means.run(config)
# Run Merging Algorithm
print("2 Running merging algorithm")
merging_algorithm.run(config)
# Run Model
print("3 Searching for landslides")
md.run(config)
print("4 Printing landlines coordinates")
findCoordinates(config)
if config['save_dataset']:
print("Saving dataset")
fromDirectory = "datasets"
toDirectory = "historics/datasets"+ str(int(time.time()))
copy_tree(fromDirectory, toDirectory)
#Remove files
if len([name for name in glob.glob('historics/*')]) == 5:
oldest_file = min('historics/', key=os.path.getctime)
remove_files(oldest_file)