|
| 1 | +""""Petr Hajduk, based on MAL 2023 Model runs / Johanna Piipponen HSL 2022""" |
| 2 | +import subprocess |
| 3 | + |
| 4 | +HDD_PATH = "XXX" #absoluuttinen polku Helmet kansioon |
| 5 | +MODELSYSTEM = HDD_PATH+'model-systems/helmet-model-system/Scripts' |
| 6 | +RESULTSPATH = "XXX" #absoluuttinen polku tuloskansioon |
| 7 | +EMMEPATH = HDD_PATH+"XXX" #relatiivinen polku projektin .emp tiedostoon |
| 8 | +BASELINEPATH = HDD_PATH+'Lahtodata' |
| 9 | +FORECASTPATH = HDD_PATH+'Ennusteskenaarioiden_syottotiedot' |
| 10 | + |
| 11 | +def run_python_version(): |
| 12 | + """Wrapper around python --version""" |
| 13 | + subprocess.run('python --version', check=True) |
| 14 | + |
| 15 | +def run_input_validation(first_scenario_ids, forecast_data_folders, baselinepath=BASELINEPATH): |
| 16 | + """Wrapper around helmet_validate_inputfiles.py CLI call |
| 17 | +
|
| 18 | + The return code is checked and if errors are found, |
| 19 | + subprocess.CalledProcessError is raised and model runs are stopped. |
| 20 | + """ |
| 21 | + if len(first_scenario_ids) != len(forecast_data_folders): |
| 22 | + raise ValueError |
| 23 | + first_scenario_ids_string = ' '.join([str(id) for id in first_scenario_ids]) |
| 24 | + forecast_data_paths_string = ' '.join([FORECASTPATH + '/' + folder for folder in forecast_data_folders]) |
| 25 | + emme_paths_string = ' '.join([EMMEPATH] * len(first_scenario_ids)) |
| 26 | + subprocess.run('python -u {modelsystem}/helmet_validate_inputfiles.py \ |
| 27 | + --log-level DEBUG \ |
| 28 | + --scenario-name input_file_validation \ |
| 29 | + --results-path {resultspath} \ |
| 30 | + --baseline-data-path {baselinepath} \ |
| 31 | + --emme-paths {emme_paths} \ |
| 32 | + --first-scenario-ids {first_scenario_ids} \ |
| 33 | + --forecast-data-paths {forecast_data_paths}' |
| 34 | + .format(modelsystem=MODELSYSTEM, |
| 35 | + resultspath=RESULTSPATH, |
| 36 | + baselinepath=baselinepath, |
| 37 | + emme_paths=emme_paths_string, |
| 38 | + first_scenario_ids=first_scenario_ids_string, |
| 39 | + forecast_data_paths=forecast_data_paths_string), |
| 40 | + check=True) |
| 41 | + |
| 42 | +def run_helmet(scenario_name, first_scenario_id, forecast_data_folder, modelsystem=MODELSYSTEM, baselinepath=BASELINEPATH, optional_arguments=''): |
| 43 | + """Wrapper around helmet.py CLI call |
| 44 | +
|
| 45 | + Return code is *not* checked so if errors are found, one model run |
| 46 | + will stop but the script resumes.""" |
| 47 | + |
| 48 | + command = f'python {modelsystem}/helmet.py \ |
| 49 | + --log-level DEBUG \ |
| 50 | + --del-strat-files \ |
| 51 | + --scenario-name {scenario_name} \ |
| 52 | + --results-path {RESULTSPATH} \ |
| 53 | + --emme-path {EMMEPATH} \ |
| 54 | + --first-scenario-id {first_scenario_id} \ |
| 55 | + --baseline-data-path {baselinepath} \ |
| 56 | + --forecast-data-path {FORECASTPATH}/{forecast_data_folder} \ |
| 57 | + --iterations 15' |
| 58 | + print(command) |
| 59 | + exit() |
| 60 | + subprocess.run('python {modelsystem}/helmet.py \ |
| 61 | + --log-level DEBUG \ |
| 62 | + --del-strat-files \ |
| 63 | + --scenario-name {scenario_name} \ |
| 64 | + --results-path {resultspath} \ |
| 65 | + --emme-path {emmepath} \ |
| 66 | + --first-scenario-id {first_scenario_id} \ |
| 67 | + --baseline-data-path {baselinepath} \ |
| 68 | + --forecast-data-path {forecastpath}/{forecast_data_folder} \ |
| 69 | + --iterations 15 \ |
| 70 | + {optional_arguments}' |
| 71 | + .format(modelsystem=modelsystem, |
| 72 | + resultspath=RESULTSPATH, |
| 73 | + baselinepath=baselinepath, |
| 74 | + emmepath=EMMEPATH, |
| 75 | + forecastpath=FORECASTPATH, |
| 76 | + scenario_name=scenario_name, |
| 77 | + first_scenario_id=first_scenario_id, |
| 78 | + forecast_data_folder=forecast_data_folder, |
| 79 | + optional_arguments=optional_arguments), |
| 80 | + check=False) |
| 81 | + |
| 82 | +def run_cba(baseline_scenario, projected_scenario, optional_arguments=''): |
| 83 | + """Wrapper around cba.py CLI call |
| 84 | +
|
| 85 | + Return code is *not* checked so if errors are found, one model run |
| 86 | + will stop but the script resumes.""" |
| 87 | + |
| 88 | + subprocess.run('python {modelsystem}/cba.py \ |
| 89 | + {resultspath}/{baseline_scenario} \ |
| 90 | + {resultspath}/{projected_scenario} \ |
| 91 | + --log-level DEBUG \ |
| 92 | + --log-format TEXT \ |
| 93 | + --results-path {resultspath}/{projected_scenario} \ |
| 94 | + {optional_arguments}' |
| 95 | + .format(modelsystem=MODELSYSTEM, |
| 96 | + resultspath=RESULTSPATH, |
| 97 | + baseline_scenario=baseline_scenario, |
| 98 | + projected_scenario=projected_scenario, |
| 99 | + optional_arguments=optional_arguments), |
| 100 | + check=False) |
| 101 | + |
| 102 | + |
| 103 | +def main(): |
| 104 | + """"Handles test model runs""" |
| 105 | + |
| 106 | + |
| 107 | + print('[BATCH] Starting input file validation...') |
| 108 | + # run_input_validation(first_scenario_ids=[100], |
| 109 | + # forecast_data_folders=['2023_Santeri_v2']) |
| 110 | + print('[BATCH] Finished input file validation!') |
| 111 | + |
| 112 | + modelsystem_olusanya = MODELSYSTEM |
| 113 | + |
| 114 | + print('[BATCH] Starting model runs...') |
| 115 | + |
| 116 | + print('[BATCH] Run: 2023') |
| 117 | + run_helmet(scenario_name='2023_pohjaverkko_2024_11_29', modelsystem=modelsystem_olusanya, first_scenario_id=100, forecast_data_folder='2023_Santeri_v2', optional_arguments='-e -s -E') |
| 118 | + |
| 119 | + print('[BATCH] Run: CBA (ve0 -> ve2)') |
| 120 | + #run_cba(baseline_scenario='2040_ve0', projected_scenario='2040_suunnitelmaluonnos_alennus35') |
| 121 | + |
| 122 | + print('[BATCH] Finished model runs!') |
| 123 | + |
| 124 | +if __name__ == "__main__": |
| 125 | + main() |
0 commit comments