diff --git a/Database/Submit_Full_Regional_Model_SOLA.bat b/Database/Submit_Full_Regional_Model_SOLA.bat index 85760a5..efbea88 100644 --- a/Database/Submit_Full_Regional_Model_SOLA.bat +++ b/Database/Submit_Full_Regional_Model_SOLA.bat @@ -33,34 +33,25 @@ for /f "eol=# skip=1 tokens=2 delims=:" %%z in (batch_file.yaml) do (set ver=%%z :break0 for /f "eol=# skip=2 tokens=2 delims=:" %%a in (batch_file.yaml) do (set val=%%a & goto break1) :break1 -for /f "eol=# skip=4 tokens=2 delims=:" %%b in (batch_file.yaml) do (set wfhFile=%%b & goto break2) +for /f "eol=# skip=5 tokens=2 delims=:" %%e in (batch_file.yaml) do (set selLinkFile=%%e & goto break2) :break2 -for /f "eol=# skip=5 tokens=2 delims=:" %%c in (batch_file.yaml) do (set wfh=%%c & goto break3) +for /f "eol=# skip=8 tokens=2* delims=:" %%g in (batch_file.yaml) do (set transactFilePath1=%%g & set transactFilePath2=%%h & goto break3) :break3 -for /f "eol=# skip=6 tokens=2 delims=:" %%d in (batch_file.yaml) do (set tc14=%%d & goto break4) +for /f "eol=# skip=10 tokens=2 delims=:" %%f in (batch_file.yaml) do (set transitAsmt=%%f & goto break4) :break4 -for /f "eol=# skip=9 tokens=2 delims=:" %%e in (batch_file.yaml) do (set selLinkFile=%%e & goto break5) +for /f "eol=# skip=12 tokens=2 delims=:" %%i in (batch_file.yaml) do (set selLineFile=%%i & goto break5) :break5 -for /f "eol=# skip=12 tokens=2* delims=:" %%g in (batch_file.yaml) do (set transactFilePath1=%%g & set transactFilePath2=%%h & goto break6) +for /f "eol=# skip=14 tokens=2 delims=:" %%j in (batch_file.yaml) do (set utilFile=%%j & goto break6) :break6 -for /f "eol=# skip=14 tokens=2 delims=:" %%f in (batch_file.yaml) do (set transitAsmt=%%f & goto break7) +for /f "eol=# skip=16 tokens=2 delims=:" %%k in (batch_file.yaml) do (set UrbansimFile=%%k & goto break7) :break7 -for /f "eol=# skip=16 tokens=2 delims=:" %%i in (batch_file.yaml) do (set selLineFile=%%i & goto break8) +for /f "eol=# skip=18 tokens=2 delims=:" %%l in (batch_file.yaml) do (set RSPrun=%%l & goto break8) :break8 -for /f "eol=# skip=18 tokens=2 delims=:" %%j in (batch_file.yaml) do (set utilFile=%%j & goto break9) +for /f "eol=# skip=21 tokens=2 delims=:" %%m in (batch_file.yaml) do (set srcCode=%%m & goto break9) :break9 -for /f "eol=# skip=20 tokens=2 delims=:" %%k in (batch_file.yaml) do (set UrbansimFile=%%k & goto break10) -:break10 -for /f "eol=# skip=22 tokens=2 delims=:" %%l in (batch_file.yaml) do (set RSPrun=%%l & goto break11) -:break11 -for /f "eol=# skip=25 tokens=2 delims=:" %%m in (batch_file.yaml) do (set srcCode=%%m & goto break12) -:break12 set ver=%ver:~1,5% set val=%val:~1,3% -set wfhFile=%wfhFile:~1% -set wfh=%wfh:~1% -set tc14=%tc14:~1% set selLinkFile=%selLinkFile:~1% set transitAsmt=%transitAsmt:~1,1% rem Construct complete transit file path @@ -96,9 +87,6 @@ cd Database @echo --- Model Run Settings --- @echo Conformity version = %ver% @echo Scenario = %val% -@echo Create WFH validation file = %wfhFile% -@echo Usual WFH share = %wfh% -@echo WFH 1-4 days share = %tc14% @echo Highway assignment select link files = %selLinkFile% @echo Location of network transaction files = %transactFilePath% @echo Run transit assignment = %transitAsmt% diff --git a/Database/Telework.yaml b/Database/Telework.yaml index 9db840c..1adf002 100644 --- a/Database/Telework.yaml +++ b/Database/Telework.yaml @@ -1,5 +1,37 @@ -# ---------------- Work from home module inputs (trip generation) starting year 2025 +# ---------------- Work from home module inputs (trip generation) validationfiles: N +usualwfhpct: 0.0510 +tc14pct: 0.1031 +# ---------------- New Work from home module inputs (trip generation) wfhpctlow: 0.143 wfhpctmedium: 0.232 wfhpcthigh: 0.552 +declinerate: 0.1 +# ---------------- Education portion of WFH workers +# ---------------- Group by high/medium/low WFH rates +# ---------------- 1 for Lower edu level +# ---------------- 2 for Higher edu level +edu: + high: + 1: 0.202 + 2: 0.798 + medium: + 1: 0.268 + 2: 0.732 + low: + 1: 0.305 + 2: 0.695 +# ---------------- Income portion of WFH workers +# ---------------- Group by high/medium/low WFH rates +# ---------------- 1 for Lower income level +# ---------------- 2 for Higher income level +inc: + high: + 1: 0.231 + 2: 0.769 + medium: + 1: 0.418 + 2: 0.582 + low: + 1: 0.353 + 2: 0.647 diff --git a/Database/batch_file.yaml b/Database/batch_file.yaml index 6356971..9e5eafd 100644 --- a/Database/batch_file.yaml +++ b/Database/batch_file.yaml @@ -1,10 +1,6 @@ # Project details model_version: c26q2 scenario_code: 100 -# ---------------- Work from home module inputs (trip generation) -validationfiles: N -usualwfhpct: 0.0510 -tc14pct: 0.1031 # ---------------- Select link analysis files: provide file name (ex: RSP32_links.txt [stored in Database\Select_Link\]) or use None # ---------------- Can submit up to 5, comma-separated, any order, no spaces, (ex: None,test4.txt,test1.txt,None,None) selectLinkFile: None,None,None,None,None @@ -25,4 +21,13 @@ RSP: False # ---------------- Set to False if this is the second of two simultaneous runs being submitted. sourceCode: False # ---------------- PUMA version used in Trip Generation. 2010 is the current option. -pumaVersion: 2010 \ No newline at end of file +pumaVersion: 2010 +# ---------------- Scenario number to year +100: 2019 +200: 2026 +300: 2030 +400: 2032 +500: 2035 +600: 2040 +700: 2045 +800: 2050 diff --git a/Database/build_scenario_networks.bat b/Database/build_scenario_networks.bat index d0d05f6..100f9cf 100644 --- a/Database/build_scenario_networks.bat +++ b/Database/build_scenario_networks.bat @@ -11,7 +11,7 @@ for /f "eol=# skip=1 tokens=2 delims=:" %%z in (batch_file.yaml) do (set ver=%%z :break0 for /f "eol=# skip=2 tokens=2 delims=:" %%a in (batch_file.yaml) do (set val=%%a & goto break1) :break1 -for /f "eol=# skip=12 tokens=2* delims=:" %%g in (batch_file.yaml) do (set transactFilePath1=%%g & set transactFilePath2=%%h & goto break6) +for /f "eol=# skip=8 tokens=2* delims=:" %%g in (batch_file.yaml) do (set transactFilePath1=%%g & set transactFilePath2=%%h & goto break6) :break6 set ver=%ver:~1,5% diff --git a/Database/prep_macros/initialize_scenarios.py b/Database/prep_macros/initialize_scenarios.py index c77a62d..f974be3 100644 --- a/Database/prep_macros/initialize_scenarios.py +++ b/Database/prep_macros/initialize_scenarios.py @@ -54,6 +54,7 @@ config = yaml.safe_load(lines_without_backslashes) scen_yr = config['scenario_code'] # e.g., '200' batchin_path = config['transactionFilePath'] # e.g., M:/catslib/modelprod/c24q2 +real_yr = config[scen_yr] hwy_batchin_dir = os.path.join(batchin_path, 'highway') trn_batchin_dir = os.path.join(batchin_path, 'transit') @@ -392,23 +393,12 @@ ## BUILD TRANSIT ASSIGNMENT SCENARIO NETWORKS ####################### -scen_yr = str(scen_yr) #just to ensure it works here - convert to string -scen3_yr4 = { - '100': 2019, - '200': 2025, - '300': 2030, - '400': 2035, - '500': 2040, - '600': 2045, - '700': 2050 -} - network_batchin_list = [ #[{transit asmt scenario number}, {transaction file time-of-day suffix}, {name of scenario}] - [int(scen_yr)+21, 1, f'{scen3_yr4[scen_yr]} Night (6pm-6am)'], - [int(scen_yr)+23, 2, f'{scen3_yr4[scen_yr]} AM (6am-9am)'], - [int(scen_yr)+25, 3, f'{scen3_yr4[scen_yr]} Midday (9am-4pm)'], - [int(scen_yr)+27, 4, f'{scen3_yr4[scen_yr]} PM (4pm-6pm)'] + [int(scen_yr)+21, 1, f'{real_yr} Night (6pm-6am)'], + [int(scen_yr)+23, 2, f'{real_yr} AM (6am-9am)'], + [int(scen_yr)+25, 3, f'{real_yr} Midday (9am-4pm)'], + [int(scen_yr)+27, 4, f'{real_yr} PM (4pm-6pm)'] ] for asmt_scen in network_batchin_list: @@ -799,14 +789,14 @@ copy_scenario( from_scenario = emmebank.scenario(int(scen_yr)+23), scenario_id = int(scen_yr)+3, - scenario_title = f'{scen3_yr4[scen_yr]} am (6am-9am) transit skim network - {today}', + scenario_title = f'{real_yr} am (6am-9am) transit skim network - {today}', copy_linkshapes=True, overwrite=True ) copy_scenario( from_scenario = emmebank.scenario(int(scen_yr)+25), scenario_id = int(scen_yr)+5, - scenario_title = f'{scen3_yr4[scen_yr]} midday (9am-4pm) transit skim network - {today}', + scenario_title = f'{real_yr} midday (9am-4pm) transit skim network - {today}', copy_linkshapes=True, overwrite=True ) diff --git a/Database/tg/fortran/wfhmodule/incdist.csv b/Database/tg/fortran/wfhmodule/incdist.csv index 501031d..8ac6f97 100644 --- a/Database/tg/fortran/wfhmodule/incdist.csv +++ b/Database/tg/fortran/wfhmodule/incdist.csv @@ -1,7 +1,9 @@ -wfhgroup,hhinc2,pct -high,1,0.231 -high,2,0.769 -medium,1,0.418 -medium,2,0.582 -low,1,0.353 -low,2,0.647 +incdist,hhinc4,pct +high,1,0.038985164 +high,2,0.080435697 +high,3,0.156394004 +high,4,0.724185136 +low,1,0.09287371 +low,2,0.134953622 +low,3,0.238871815 +low,4,0.533300852 diff --git a/Database/tg/fortran/wfhmodule/incdist_base.csv b/Database/tg/fortran/wfhmodule/incdist_base.csv deleted file mode 100644 index 8ac6f97..0000000 --- a/Database/tg/fortran/wfhmodule/incdist_base.csv +++ /dev/null @@ -1,9 +0,0 @@ -incdist,hhinc4,pct -high,1,0.038985164 -high,2,0.080435697 -high,3,0.156394004 -high,4,0.724185136 -low,1,0.09287371 -low,2,0.134953622 -low,3,0.238871815 -low,4,0.533300852 diff --git a/Database/tg/fortran/wfhmodule/wfhflag.py b/Database/tg/fortran/wfhmodule/wfhflag.py index 86c11ff..b4bf4aa 100644 --- a/Database/tg/fortran/wfhmodule/wfhflag.py +++ b/Database/tg/fortran/wfhmodule/wfhflag.py @@ -3,15 +3,11 @@ # this flags tbm people as usualwfh or tc14 import pandas as pd import numpy as np +from pathlib import Path +import yaml import sys import os -# Current trip_gen.bat -# python wfhflag.py %filedir% %savedir% %wfhFile% %wfh% %tc14% - -# Adj trip_gen.bat -# python wfhflag.py %filedir% %savedir% %wfhFile% %wfhl% %wfhm% %wfhh% - # pathways savedir = sys.argv[2] assert os.path.exists(savedir) == True, "savedir not valid" @@ -22,24 +18,39 @@ indpxwalkpath = "indp_naics.csv" geoinpath = savedir + "/GEOG_IN.TXT" -#telework worker distribution by income, edu level and children -incdistpath = "incdist.csv" -edudistpath = "edudist.csv" +db = Path(__file__).resolve().parents[3] # database folder +with open(os.path.join(db, 'Telework.yaml')) as f: + lines_without_backslashes = ''.join([line.replace('\\','/') for line in f]) + wfh_data = yaml.safe_load(lines_without_backslashes) + +with open(os.path.join(db, 'batch_file.yaml')) as f: + lines_without_backslashes = ''.join([line.replace('\\','/') for line in f]) + batch_data = yaml.safe_load(lines_without_backslashes) # save additional output files? savefiles = sys.argv[3] # major parameters - source: mdt + nirpc survey (which is higher than PUMS data...) -# percent of all workers +scen_yr = batch_data['scenario_code'] +real_yr = batch_data[scen_yr] -''' This data will be separated from batch_file.yaml to Telework.yaml including Tuesday-Thursday telework rates''' +# Assume decline_rate from 2026 to 2050, +decline_rate = wfh_data['declinerate'] -wfhl = float(sys.argv[4]) -wfhm = float(sys.argv[5]) -wfhh = float(sys.argv[6]) +# Based on year gap calculate the adjust rate from 2026 to scenaior year +scen_yr_adj_rate = 1 - (real_yr-2026)/(2050-2026) * decline_rate +print('Telework decline rate applied: {0:.4f}'.format(scen_yr_adj_rate)) +wfhl = wfh_data['wfhpctlow'] * scen_yr_adj_rate +wfhm = wfh_data['wfhpctmedium'] * scen_yr_adj_rate +wfhh = wfh_data['wfhpcthigh'] * scen_yr_adj_rate +# Combine to list for easy loop process wfhpctlist = [wfhl, wfhm, wfhh] +# Read income and eduction portion for different WFH rate group from YAML file +incdist_dict = wfh_data['inc'] +edudist_dict = wfh_data['edu'] + # set seedvalue seedvalue = 2 np.random.seed(seed=seedvalue) @@ -49,10 +60,6 @@ dfhh = pd.read_csv(synhhpath, dtype={'MV': object}) indpxwalk = pd.read_csv(indpxwalkpath) -# Need to change if plan to get data from Telework.yaml -incdist = pd.read_csv(incdistpath) -edudist = pd.read_csv(edudistpath) - # merge income2, edu2, trc get workers dfpop = dfpop.merge(indpxwalk, on='INDP', how='left') dfpop = dfpop.merge(dfhh[['household_id', 'HINCP19']], on='household_id', how='left') @@ -69,23 +76,6 @@ workers.loc[:, 'selected'] = 0 workers = workers[workers['ESR'] != '4'] -# telework distribution -inc_values = incdist.iloc[:, 2].astype(float).tolist() -edu_values = edudist.iloc[:, 2].astype(float).tolist() - -# organize into dicts for easier access -incdist_dict = { - "high": {1: inc_values[0], 2: inc_values[1]}, - "medium": {1: inc_values[2], 2: inc_values[3]}, - "low": {1: inc_values[4], 2: inc_values[5]}, -} - -edudist_dict = { - "high": {1: edu_values[0], 2: edu_values[1]}, - "medium": {1: edu_values[2], 2: edu_values[3]}, - "low": {1: edu_values[4], 2: edu_values[5]}, -} - def samplingworkers(df, wfhpctlist): df = df.copy() diff --git a/Database/tg/fortran/wfhmodule/wfhflag_base.py b/Database/tg/fortran/wfhmodule/wfhflag_base.py index 2910822..edb7d40 100644 --- a/Database/tg/fortran/wfhmodule/wfhflag_base.py +++ b/Database/tg/fortran/wfhmodule/wfhflag_base.py @@ -3,6 +3,8 @@ # this flags tbm people as usualwfh or tc14 import pandas as pd import numpy as np +from pathlib import Path +import yaml import sys import os @@ -13,17 +15,20 @@ synpoppath = "synthetic_persons.zip" synhhpath = "synthetic_households.zip" popsynhhpath = savedir + "/POPSYN_HH.csv" -incdistpath = "incdist_base.csv" +incdistpath = "incdist.csv" indmixpath = "indusmix.csv" indpxwalkpath = "indp_naics.csv" - +db = Path(__file__).resolve().parents[3] # database folder +with open(os.path.join(db, 'Telework.yaml')) as f: + lines_without_backslashes = ''.join([line.replace('\\','/') for line in f]) + wfh_data = yaml.safe_load(lines_without_backslashes) # save additional output files? savefiles = sys.argv[3] # major parameters - source: mdt + nirpc survey (which is higher than PUMS data...) -# percent of all workers -usualwfhpct = float(sys.argv[4]) -tc14pct = float(sys.argv[5]) +# Read WFH data from YAML file +usualwfhpct = wfh_data['usualwfhpct'] +tc14pct = wfh_data['tc14pct'] # set seedvalue seedvalue = 2 diff --git a/Database/transit_asmt_macros/create_transit_demand.bat b/Database/transit_asmt_macros/create_transit_demand.bat index a57193e..85cb418 100644 --- a/Database/transit_asmt_macros/create_transit_demand.bat +++ b/Database/transit_asmt_macros/create_transit_demand.bat @@ -29,11 +29,11 @@ cd .. rem -- Read model run settings from batch_file.yaml -- for /f "eol=# skip=2 tokens=2 delims=:" %%a in (batch_file.yaml) do (set val=%%a & goto break1) :break1 -for /f "eol=# skip=14 tokens=2 delims=:" %%f in (batch_file.yaml) do (set transitAsmt=%%f & goto break2) +for /f "eol=# skip=10 tokens=2 delims=:" %%f in (batch_file.yaml) do (set transitAsmt=%%f & goto break2) :break2 -for /f "eol=# skip=16 tokens=2 delims=:" %%h in (batch_file.yaml) do (set selLineFile=%%h & goto break4) +for /f "eol=# skip=12 tokens=2 delims=:" %%h in (batch_file.yaml) do (set selLineFile=%%h & goto break4) :break4 -for /f "eol=# skip=22 tokens=2 delims=:" %%k in (batch_file.yaml) do (set RSPrun=%%k & goto break5) +for /f "eol=# skip=18 tokens=2 delims=:" %%k in (batch_file.yaml) do (set RSPrun=%%k & goto break5) :break5 set val=%val:~1,3% diff --git a/Database/trip_gen.bat b/Database/trip_gen.bat index 8c813ce..4c03dbd 100644 --- a/Database/trip_gen.bat +++ b/Database/trip_gen.bat @@ -39,23 +39,23 @@ rem -------- rem In case CMD.exe is doing stuff in the wrong directory, this command rem changes the directory to where the batch file was called from. cd %~dp0 -rem -- Read model run settings from batch_file.yaml -- +rem -- Read model run settings from Telework.yaml -- for /f "eol=# skip=2 tokens=2 delims=:" %%a in (batch_file.yaml) do (set sc=%%a & goto break1) :break1 -for /f "eol=# skip=4 tokens=2 delims=:" %%b in (batch_file.yaml) do (set wfhFile=%%b & goto break2) +for /f "eol=# skip=1 tokens=2 delims=:" %%b in (Telework.yaml) do (set wfhFile=%%b & goto break2) :break2 -for /f "eol=# skip=5 tokens=2 delims=:" %%c in (batch_file.yaml) do (set wfh=%%c & goto break3) +for /f "eol=# skip=2 tokens=2 delims=:" %%c in (Telework.yaml) do (set wfh=%%c & goto break3) :break3 -for /f "eol=# skip=6 tokens=2 delims=:" %%d in (batch_file.yaml) do (set tc14=%%d & goto break4) +for /f "eol=# skip=3 tokens=2 delims=:" %%d in (Telework.yaml) do (set tc14=%%d & goto break4) :break4 - -rem -- Read model run settings from Telework.yaml -- -for /f "eol=# skip=2 tokens=2 delims=:" %%e in (Telework.yaml) do (set wfhLow=%%e & goto break5) +for /f "eol=# skip=5 tokens=2 delims=:" %%e in (Telework.yaml) do (set wfhLow=%%e & goto break5) :break5 -for /f "eol=# skip=3 tokens=2 delims=:" %%f in (Telework.yaml) do (set wfhMedium=%%f & goto break6) +for /f "eol=# skip=6 tokens=2 delims=:" %%f in (Telework.yaml) do (set wfhMedium=%%f & goto break6) :break6 -for /f "eol=# skip=4 tokens=2 delims=:" %%g in (Telework.yaml) do (set wfhHigh=%%g & goto break7) +for /f "eol=# skip=7 tokens=2 delims=:" %%g in (Telework.yaml) do (set wfhHigh=%%g & goto break7) :break7 +for /f "eol=# skip=8 tokens=2 delims=:" %%g in (Telework.yaml) do (set declineScaled=%%g & goto break8) +:break8 set sc=%sc:~1,3% set wfhFile=%wfhFile:~1% @@ -64,12 +64,7 @@ set tc14=%tc14:~1% set wfhLow=%wfhLow:~1% set wfhMedium=%wfhMedium:~1% set wfhHigh=%wfhHigh:~1% - -for /f %%a in ('powershell -NoProfile -Command "(1000 + (200 - %sc%) * 1000 / 5000)/1000"') do set DeclineScaled=%%a -for /f %%a in ('powershell -NoProfile -Command "%wfhLow% * %DeclineScaled%"') do set wfhLowSc=%%a -for /f %%a in ('powershell -NoProfile -Command "%wfhMedium% * %DeclineScaled%"') do set wfhMediumSc=%%a -for /f %%a in ('powershell -NoProfile -Command "%wfhHigh% * %DeclineScaled%"') do set wfhHighSc=%%a - +set declineScaled=%declineScaled:~1% @echo. @echo ======================================== @@ -83,10 +78,7 @@ if %sc%==100 ( @echo 2025/26 WFH low rate group share= %wfhLow% @echo 2025/26 WFH medium rate group share= %wfhMedium% @echo 2025/26 WFH high rate group share= %wfhHigh% - @echo Decline factor= %DeclineScaled% - @echo Scenario WFH low rate group share= %wfhLowSc% - @echo Scenario WFH medium rate group share= %wfhMediumSc% - @echo Scenario WFH high rate group share= %wfhHighSc% + @echo Decline factor= %declineScaled% ) @echo ======================================== @echo. @@ -191,10 +183,10 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if %val%==100 ( echo Running wfhflag_base.py ... - python wfhflag_base.py %filedir% %savedir% %wfhFile% %wfh% %tc14% + python wfhflag_base.py %filedir% %savedir% %wfhFile% ) else ( echo Running wfhflag.py ... - python wfhflag.py %filedir% %savedir% %wfhFile% %wfhLowSc% %wfhMediumSc% %wfhHighSc% + python wfhflag.py %filedir% %savedir% %wfhFile% ) if %ERRORLEVEL% NEQ 0 (goto wfh_issue)