Skip to content

Commit

Permalink
save a copy of original mgra data
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishKuls committed Apr 13, 2023
1 parent 48d92ea commit a72ec2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
21 changes: 9 additions & 12 deletions abm/src/main/emme/toolbox/master_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion scripts/rsm_input_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a72ec2b

Please sign in to comment.