From a72ec2b221c5403252d52e10a91fc9f8a49081eb Mon Sep 17 00:00:00 2001 From: Ashish Kulshrestha Date: Thu, 13 Apr 2023 10:28:59 -0700 Subject: [PATCH] save a copy of original mgra data --- abm/src/main/emme/toolbox/master_run.py | 21 +++++++++------------ scripts/rsm_input_aggregator.py | 6 +++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/abm/src/main/emme/toolbox/master_run.py b/abm/src/main/emme/toolbox/master_run.py index 001b9c0..864ecb1 100644 --- a/abm/src/main/emme/toolbox/master_run.py +++ b/abm/src/main/emme/toolbox/master_run.py @@ -423,12 +423,15 @@ def __call__(self, main_directory, scenario_id, scenario_title, emmebank_title, raise Exception("If Assembler is turned off, default sample rate should be such that 1/(sample rate) is integer value") if run_rsm_setup == 1: - # reset the property 'mgra.socec.file' to use original csv file - self.run_proc( - "runRSMSetProperty.cmd", - [main_directory, rsm_venv_path, rsm_script_path, 'mgra.socec.file', props["mgra.socec.file"].replace("_agg.csv", ".csv")], - "Set Property", capture_output=True) - + # if the orig mgra data file exists (this will be the case when rerunning the RSM from same scenario folder) + # then restore it as the mgra data file + # input aggregator will aggregate the "orig" mgra landuse data to rapid zones landuse data. + mgra_orig_input_file = mgraInputFile.replace(".csv", "_orig.csv") + if(os.path.exists(_join(main_directory, mgra_orig_input_file))): + # copy the _orig as the main mgra file + _shutil.copy(_join(main_directory, mgra_orig_input_file), _join(main_directory, mgraInputFile)) + # delete the _orig file + os.remove(_join(main_directory, mgra_orig_input_file)) if run_zone_aggregator == 1: self.run_proc( @@ -444,12 +447,6 @@ def __call__(self, main_directory, scenario_id, scenario_title, emmebank_title, "runRSMInputAggregator.cmd", [main_directory, rsm_venv_path, rsm_script_path, orig_full_model_dir, num_rsm_zones, num_external_zones], "Input Files Aggregator", capture_output=True) - - # change the property 'mgra.socec.file' to use _agg.csv file - self.run_proc( - "runRSMSetProperty.cmd", - [main_directory, rsm_venv_path, rsm_script_path, 'mgra.socec.file', props["mgra.socec.file"].replace(".csv", "_agg.csv")], - "Set Property", capture_output=True) self.run_proc( "runRSMTripMatrixAggregator.cmd", diff --git a/scripts/rsm_input_aggregator.py b/scripts/rsm_input_aggregator.py index c46f2ba..b858226 100644 --- a/scripts/rsm_input_aggregator.py +++ b/scripts/rsm_input_aggregator.py @@ -15,6 +15,7 @@ import os import logging import pandas as pd +import shutil main_path = os.path.dirname(os.path.realpath(__file__)) + "/../" sys.path.append(main_path) from rsm.data_load.zones import load_mgra_data @@ -42,7 +43,10 @@ RSM_ABM_PROPERTIES = os.path.join(rsm_main_dir, "conf", "sandag_abm.properties") INPUT_RSM_ZONE_FILE = os.path.join(rsm_main_dir, get_property(RSM_ABM_PROPERTIES, "mgra.socec.file")) INPUT_MGRA_CROSSWALK = os.path.join(rsm_main_dir, get_property(RSM_ABM_PROPERTIES, "mgra.to.cluster.crosswalk.file")) -OUTPUT_RSM_ZONE_FILE = INPUT_RSM_ZONE_FILE.replace(".csv", "_agg.csv") +OUTPUT_RSM_ZONE_FILE = os.path.join(rsm_main_dir, get_property(RSM_ABM_PROPERTIES, "mgra.socec.file")) + +# save a copy of the orig mgra landuse data +shutil.copy(INPUT_RSM_ZONE_FILE, INPUT_RSM_ZONE_FILE.replace(".csv", "_orig.csv")) #merge crosswalks with input mgra file mgra = pd.read_csv(INPUT_RSM_ZONE_FILE)