-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (60 loc) · 3.5 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
import os
import math
import datetime
from src.worker_manager.config_validator import validate_basic_inputs, validate_config_inputs, _verify_processing_config
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)
if processing_option == 'run_pipeline':
precheck_option = 'pre_check'
else:
precheck_option = processing_option
umep_solweig_cell_count, return_code_configs = validate_config_inputs(abs_source_base_path, abs_target_base_path,
city_folder_name, precheck_option)
# Print runtime estimate
if umep_solweig_cell_count is not None:
x = umep_solweig_cell_count
if umep_solweig_cell_count < 1E4:
print(f'\nEstimated runtime for full solweig without intermediate files is a few minutes or less for {x:,} raster cells.\n')
else:
if umep_solweig_cell_count < 4E6:
est_runtime_mins = math.ceil(3.0166957E-5*x +3.2689E1)
else:
est_runtime_mins = math.ceil(6.26228065090E-4*x -2.28907E3)
_print_runtime_estimate(x, 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)
if return_code == 0:
print(return_str)
else:
_highlighted_yellow_print(return_str)
return return_code
def _print_runtime_estimate(cell_count, 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 for full solweig without intermediate files is {est_runtime_hours} hours for {cell_count:,} raster cells.')
print(f'Estimated completion time for processing of tile_001: {est_end_time.strftime('%m/%d/%Y %I:%M %p')}\n')
def _highlighted_yellow_print(msg):
print('\n\x1b[6;30;43m' + 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()
start_processing(args.source_base_path, args.target_base_path, args.city_folder_name, args.processing_option)