-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (71 loc) · 3.86 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
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
import os
import math
import datetime
from src.worker_manager.config_validator import validate_basic_inputs, validate_config_inputs
from src.worker_manager.graph_builder import build_source_dataframes
from src.worker_manager.job_manager import start_jobs
"""
Guide to creating standalone app for calling QGIS: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/intro.html
https://medium.com/@giovannigallon/how-i-automate-qgis-tasks-using-python-54df35d8d63f
"""
def start_processing(source_base_path, target_base_path, city_folder_name, processing_option):
abs_source_base_path = os.path.abspath(source_base_path)
abs_target_base_path = os.path.abspath(target_base_path)
return_code_basic = validate_basic_inputs(abs_source_base_path, abs_target_base_path, city_folder_name)
processing_config_df = build_source_dataframes(abs_source_base_path, city_folder_name)
if processing_option == 'run_pipeline':
precheck_option = 'pre_check'
else:
precheck_option = processing_option
solweig_full_cell_count, return_code_configs = validate_config_inputs(processing_config_df, abs_source_base_path,
abs_target_base_path, city_folder_name, precheck_option)
# Print runtime estimate
if solweig_full_cell_count is not None:
if solweig_full_cell_count < 2E3:
print('\nEstimated runtime is a few minutes or less.\n')
else:
if solweig_full_cell_count < 1E6:
x = solweig_full_cell_count
est_runtime_mins = math.ceil((7E-5 * x) + 6.9158)
else:
x = pow(solweig_full_cell_count, 6)
est_runtime_mins = math.ceil((8E-79 * x**2) + (4E-38 * x) + 39.571)
_print_runtime_estimate(est_runtime_mins)
if processing_option == 'run_pipeline':
return_code, return_str = start_jobs(abs_source_base_path, abs_target_base_path, city_folder_name, processing_config_df)
if return_code == 0:
print(return_str)
else:
_highlighted_print(return_str)
return return_code
else:
if return_code_basic == 0 and return_code_configs == 0:
print("\nPassed all validation checks")
return 0
else:
_highlighted_print('Pre-check encountered errors.')
return -99
def _print_runtime_estimate(est_runtime_mins):
est_runtime_hours = round(est_runtime_mins / 60, 1)
now = datetime.datetime.now()
time_change = datetime.timedelta(minutes=est_runtime_mins)
est_end_time = now + time_change
print(f'\nEstimated runtime: {est_runtime_hours} hours')
print(f'Estimated completion time for processing of tile_001: {est_end_time.strftime('%m/%d/%Y %I:%M %p')}\n')
def _highlighted_print(msg):
print('\n\x1b[6;30;42m' + msg + '\x1b[0m')
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Run methods in the "UMEP for Processing" QGIS plugin.')
parser.add_argument('--source_base_path', metavar='path', required=True,
help='the path to city-based source data')
parser.add_argument('--target_base_path', metavar='str', required=True,
help='the path to city-based target data')
parser.add_argument('--city_folder_name', metavar='str', required=True,
help='name of source city_folder')
valid_methods = ['run_pipeline', 'pre_check_all', 'pre_check']
parser.add_argument('--processing_option', metavar='str', choices=valid_methods, required=True,
help=f'specifies type of configuration pre-check. Options are: {valid_methods}')
args = parser.parse_args()
return_code = start_processing(args.source_base_path, args.target_base_path, args.city_folder_name, args.processing_option)
print(f'return code: {return_code}')