diff --git a/Database/Telework.yaml b/Database/Telework.yaml index 9db840c..62f255e 100644 --- a/Database/Telework.yaml +++ b/Database/Telework.yaml @@ -1,5 +1,40 @@ -# ---------------- Work from home module inputs (trip generation) starting year 2025 +# Project details +model_version: c25q4 +scenario_code: 200 +# ---------------- 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 \ No newline at end of file diff --git a/Database/tg/fortran/wfhmodule/edudist.csv b/Database/tg/fortran/wfhmodule/edudist.csv deleted file mode 100644 index 92e43db..0000000 --- a/Database/tg/fortran/wfhmodule/edudist.csv +++ /dev/null @@ -1,7 +0,0 @@ -wfhgroup,hhedu2,pct -high,1,0.202 -high,2,0.798 -medium,1,0.268 -medium,2,0.732 -low,1,0.305 -low,2,0.695 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..b93675f 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,33 @@ 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) # 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 = wfh_data['scenario_code'] -''' This data will be separated from batch_file.yaml to Telework.yaml including Tuesday-Thursday telework rates''' +# Assume decline_rate from 2025 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 2025 to scenaior year +scen_yr_adj_rate = 1 - decline_rate * (scen_yr - 200)/500 +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 +54,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 +70,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/trip_gen.bat b/Database/trip_gen.bat index 8c813ce..e5bd432 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 -- -for /f "eol=# skip=2 tokens=2 delims=:" %%a in (batch_file.yaml) do (set sc=%%a & goto break1) +rem -- Read model run settings from Telework.yaml -- +for /f "eol=# skip=2 tokens=2 delims=:" %%a in (Telework.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=4 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=5 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=6 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=8 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=9 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=10 tokens=2 delims=:" %%g in (Telework.yaml) do (set wfhHigh=%%g & goto break7) :break7 +for /f "eol=# skip=11 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)