diff --git a/.gitignore b/.gitignore index ed0389f..06b0a8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,6 @@ # Ignore compiled Python. **/__pycache__ -# Ignore files generated by installing Python eggs. -src/Mode-Dest-TOD/cmap_modedest.egg-info -src/Mode-Dest-TOD/sharrow/sharrow.egg-info - # Ignore large Emme project files. Database/emmemat Database/emmebank @@ -15,7 +11,6 @@ Database/tg/fortran/HH_IN.TXT Database/tg/fortran/POPSYN_HH.CSV Database/tg/fortran/GQ_IN.TXT Database/tg/fortran/ATTR_IN.TXT -Database/tg/fortran/airport_sz.csv Database/tg/fortran/SCHOOL_IN.CSV Database/tg/fortran/wfhmodule/indusmix.csv @@ -39,6 +34,10 @@ Database/tg/fortran/wfhmodule/synthetic_*.zip Database/TG_HHENUM_OUTPUT.TXT Database/tg/fortran/HH_WFH_STATUS.CSV Database/tg/fortran/SIMULATED_HHVEH.TXT +Database/tg/fortran/households_selected_noWFH_enumeration_count.csv +Database/tg/fortran/households_selected_WFH_enumeration_count.csv +Database/tg/fortran/missing_hhtype.csv +Database/tg/fortran/trip_generation_model_log.txt # Ignore files generated by prep macros. Database/*_DISTR.TXT diff --git a/Database/Submit_Full_Regional_Model_SOLA.bat b/Database/Submit_Full_Regional_Model_SOLA.bat index efbea88..370a534 100644 --- a/Database/Submit_Full_Regional_Model_SOLA.bat +++ b/Database/Submit_Full_Regional_Model_SOLA.bat @@ -47,8 +47,6 @@ for /f "eol=# skip=16 tokens=2 delims=:" %%k in (batch_file.yaml) do (set Urbans :break7 for /f "eol=# skip=18 tokens=2 delims=:" %%l in (batch_file.yaml) do (set RSPrun=%%l & goto break8) :break8 -for /f "eol=# skip=21 tokens=2 delims=:" %%m in (batch_file.yaml) do (set srcCode=%%m & goto break9) -:break9 set ver=%ver:~1,5% set val=%val:~1,3% @@ -63,7 +61,6 @@ set selLineFile=%selLineFile:~1% set utilFile=%utilFile:~1,1% set UrbansimFile=%UrbansimFile:~1,1% set RSPrun=%RSPrun:~1,1% -set srcCode=%srcCode:~1,1% REM -- Count number of select link files -- set tempCnt=0 for %%a in (%selLinkFile:None=%) do set /a tempCnt+=1 @@ -94,7 +91,6 @@ if "%transitAsmt%" EQU "T" (@echo Transit assignment select line file = %selLin @echo Save utility files = %utilFile% @echo Create UrbanSim travel time file = %UrbansimFile% @echo RSP evaluation run = %RSPrun% -@echo Have CMAP-TRIP2 use destination-mode choice code in this model setup = %srcCode% @echo ================================================================================== @echo. @@ -107,14 +103,11 @@ set transactFilePath=%transactFilePath:~0,-1% if "%check2%" NEQ "None" ( if not exist Select_Line\%selLineFile% (goto no_select_line_file) ) - -rem Activate Emme Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd emme - @echo -- Verifying select link files -- -call python macros\verify_select_link.py %file1% %selLinkFile% %RSPrun% %trnAsmt% +uv run macros\verify_select_link.py %file1% %selLinkFile% %RSPrun% %trnAsmt% if %ERRORLEVEL% GTR 0 (goto end) + REM Clean up prior to run if exist cache\choice_simulator_trips_out (rmdir /S /Q cache\choice_simulator_trips_out) if exist cache\choice_simulator_trips_out.001 (rmdir /S /Q cache\choice_simulator_trips_out.001) @@ -127,7 +120,6 @@ echo. echo Select Destination Choice-Mode Choice model run mode: echo 1) Minimize run time (default) - resources allocated to support a single model run. echo 2) Balanced - resources allocated to support two simultaneous model runs. -echo [If this is the second of two simultaneous runs: only proceed if srcCode is False (currently set to %srcCode%)] echo. set /a jobs=38 set /a zones=10 @@ -196,19 +188,6 @@ REM PREP WORK CD %~dp0 CD prep_macros -REM Now find R executable -set infile=path.txt -if exist %infile% (del %infile% /Q) -dir "C:\Program Files\R\*R.exe" /s /b >> %infile% 2>nul -set /p path2=<%infile% -set paren=" -set rpath=%paren%%path2%%paren% -echo rpath = %rpath% -call :CheckEmpty2 %infile% -:Rpass -if exist %infile% (del %infile% /Q) -set rfile=create_distr_m01_files - REM -- Start DISTR & M01 Data Processing -- @ECHO. @ECHO Start Time: %date% %time% @@ -222,14 +201,18 @@ if not exist tg\data\m01tg.txt (goto filemiss2) if not exist tg\data\m01type.csv (goto filemiss2) @ECHO. @ECHO -- OBTAINING TRANSIT NETWORK DATA FROM EMME -- -call python prep_macros/distr_m01_data.py %file1% %val% >> prep_macros\report.txt +uv run prep_macros/distr_m01_data.py %file1% %val% >> prep_macros\report.txt if %ERRORLEVEL% GTR 0 (goto issue) cd prep_macros @ECHO. @ECHO -- CREATING FILES FOR SPATIAL ANALYSIS -- @ECHO. -%rpath% CMD BATCH %rfile%.R +rem Activate R env +call %LOCALAPPDATA%\miniconda3\condabin\conda_hook.bat +call conda activate tbm-r +Rscript create_distr_m01_files.R if %ERRORLEVEL% GTR 0 (goto issue) +call conda deactivate @ECHO. @ECHO -- DISTR AND M01 FILES CREATED -- @@ -240,32 +223,21 @@ if exist temp\nul (rmdir temp /S /Q) if exist report.txt (del report.txt /Q) CD .. -rem Activate Python env to build it if necessary -call %~dp0..\Scripts\manage\env\activate_env.cmd -if "%srcCode%" EQU "T" ( - @ECHO -- Ensure CMAP-TRIP2 uses the destination choice-mode choice source code in this model setup -- -python -m pip install -e %~dp0..\src\Mode-Dest-TOD -python -m pip install -e %~dp0..\src\Mode-Dest-TOD\sharrow -) - -rem Activate Emme Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd emme - @ECHO *** Cleaning up databank. *** if exist cleanup.rpt (del cleanup.rpt) -call python useful_macros\cleanup_for_rerun.py %val%>> cleanup.rpt +uv run useful_macros\cleanup_for_rerun.py %val%>> cleanup.rpt if exist reports (del reports) REM RUN FREESKIM TO CREATE TIME, DISTANCE AND TOLL MATRICES @ECHO. @ECHO *** Skimming highway network. *** -call python prep_macros\free.skim.mac.py %file1% %val% +uv run prep_macros\free.skim.mac.py %file1% %val% if %ERRORLEVEL% neq 0 (goto issue) @ECHO. REM IF PRELOAD=1, REPLACE UNCONGESTED TIME AND DISTANCE MATRICES if %preload% EQU 1 (@echo *** Preloading congested times and distances. ***) -if %preload% EQU 1 (call python prep_macros\preload_congested_times_mac.py %file1% %val%) +if %preload% EQU 1 (uv run prep_macros\preload_congested_times_mac.py %file1% %val%) @ECHO ================================================================== REM - LOOP TO RUN MODEL @@ -277,22 +249,22 @@ if %counter% GTR 2 (goto loopend) @ECHO BEGINNING TRANSIT SKIM - FULL MODEL ITERATION %counter% @ECHO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - REM AM Peak Skim -call python macros/skim_transit.py %val% %counter% AM +uv run macros/skim_transit.py %val% %counter% AM if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_triple_indexing.py %val% AM +uv run macros/transit_triple_indexing.py %val% AM if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_skim_final_matrices.py AM +uv run macros/transit_skim_final_matrices.py AM if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_skim_wrapup.py AM +uv run macros/transit_skim_wrapup.py AM if %ERRORLEVEL% neq 0 (goto issue) REM Midday Skim -call python macros/skim_transit.py %val% %counter% MD +uv run macros/skim_transit.py %val% %counter% MD if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_triple_indexing.py %val% MD +uv run macros/transit_triple_indexing.py %val% MD if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_skim_final_matrices.py MD +uv run macros/transit_skim_final_matrices.py MD if %ERRORLEVEL% neq 0 (goto issue) -call python macros/transit_skim_wrapup.py MD +uv run macros/transit_skim_wrapup.py MD if %ERRORLEVEL% neq 0 (goto issue) @ECHO -- End of Transit Skim Procedures: %date% %time% >> model_run_timestamp.txt @@ -300,24 +272,20 @@ if %ERRORLEVEL% neq 0 (goto issue) @ECHO PREPARING EMMEBANK - FULL MODEL ITERATION %counter% @ECHO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem @ECHO on -call python macros\init_HOVsim_databk_mac.py %val% %counter% %file1% +uv run macros\init_HOVsim_databk_mac.py %val% %counter% %file1% if %ERRORLEVEL% neq 0 (goto issue) -rem Activate Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd - @ECHO -- Begin Mode-Destination Choice Procedures: %date% %time% >> model_run_timestamp.txt @ECHO. @ECHO RUN CMAP MODE-DESTINATION CHOICE MODEL - FULL MODEL ITERATION %counter% @ECHO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -call cmap_modedest . --njobs %jobs% --max_zone_chunk %zones% +call conda activate cmap-modedest +cmap_modedest . --njobs %jobs% --max_zone_chunk %zones% if %ERRORLEVEL% NEQ 0 (goto issue) +call conda deactivate @ECHO -- End Mode-Destination Choice Procedures: %date% %time% >> model_run_timestamp.txt @ECHO. -rem Activate Emme Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd emme - @ECHO -- Begin Time-of-Day Procedures: %date% %time% >> model_run_timestamp.txt @ECHO. @ECHO BEGINNING TOD HIGHWAY ASSIGNMENT - FULL MODEL ITERATION %counter% @@ -330,12 +298,12 @@ REM call emme -ng 000 -m macros\ttables.mac %val% %tod_cntr% 92 93 >> blog.txt @ECHO --- End ttables.mac Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- Begin TOD_network_prep.py Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt -call python macros\TOD_network_prep.py %val% %tod_cntr% %counter% >> blog.txt +uv run macros\TOD_network_prep.py %val% %tod_cntr% %counter% >> blog.txt @ECHO --- End TOD_network_prep.py Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- Begin assignment Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- Begin assignment Period %tod_cntr%: %date% %time% --- @ECHO -- Run TOD assignment -- -call python macros/SOLA_assignment.py %tod_cntr% %sola_threads% %counter% %RSPrun% %tempCnt% %selLinkFile% %trnAsmt% +uv run macros/SOLA_assignment.py %tod_cntr% %sola_threads% %counter% %RSPrun% %tempCnt% %selLinkFile% %trnAsmt% if %ERRORLEVEL% NEQ 0 (goto issue) @ECHO --- End assignment Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- End assignment Period %tod_cntr%: %date% %time% --- @@ -345,7 +313,7 @@ call emme -ng 000 -m macros\balance5I_7c.mac %val% >> blog.txt @ECHO --- End balance5I_7c.mac Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- Begin time-of-day skim Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO --- Complete time of day skims --- -call python macros/TOD_skim.py %tod_cntr% %val%%counter%%tod_cntr% %sola_threads% +uv run macros/TOD_skim.py %tod_cntr% %val%%counter%%tod_cntr% %sola_threads% if %ERRORLEVEL% NEQ 0 (goto issue) @ECHO -- End Time-of-Day Procedures Period %tod_cntr%: %date% %time% >> model_run_timestamp.txt @ECHO -- End Time-of-Day Procedures for Period %tod_cntr%: %date% %time% -- @@ -355,9 +323,9 @@ if %tod_cntr% LSS 9 (goto tod_loop) REM -- End time-of-day loop -- @ECHO --- Begin Global Iteration MSA skims: %date% %time% >> model_run_timestamp.txt @ECHO --- Begin Global Iteration MSA skims: %date% %time% --- -call python macros/MSA_iteration_skims.py %file1% 3 %val%%counter%3 %counter% %sola_threads% +uv run macros/MSA_iteration_skims.py %file1% 3 %val%%counter%3 %counter% %sola_threads% if %ERRORLEVEL% NEQ 0 (goto issue) -call python macros/MSA_iteration_skims.py %file1% 5 %val%%counter%5 %counter% %sola_threads% +uv run macros/MSA_iteration_skims.py %file1% 5 %val%%counter%5 %counter% %sola_threads% if %ERRORLEVEL% NEQ 0 (goto issue) @ECHO --- End Global Iteration MSA skims: %date% %time% >> model_run_timestamp.txt @ECHO --- End Global Iteration MSA skims: %date% %time% @@ -380,17 +348,17 @@ REM Run script to complete select link analysis, if necessary set /A counter=counter-1 if %tempCnt% EQU 0 (goto skip_sel_link) if %trnAsmt% EQU 1 (goto skip_sel_link) -call python macros/complete_select_link.py %file1% %val%%counter%9 %val%%counter%0 %tempCnt% %RSPrun% +uv run macros/complete_select_link.py %file1% %val%%counter%9 %val%%counter%0 %tempCnt% %RSPrun% if %ERRORLEVEL% NEQ 0 (goto issue) :skip_sel_link @ECHO End Daily Accumulation Procedures: %date% %time% >> model_run_timestamp.txt REM Run script to write link data for MOVES emissions analysis. -call python post_macros\punchmovesdata.py +uv run post_macros\punchmovesdata.py @ECHO Link Data Written for MOVES Emissions Analysis: %date% %time% >> model_run_timestamp.txt -call python post_macros\final_run_statistics.py +uv run post_macros\final_run_statistics.py rem Run script to create input files for MOVES. -call python post_macros\createMOVESinputfile.py +uv run post_macros\createMOVESinputfile.py if %ERRORLEVEL% NEQ 0 (goto issue) @echo %DATE% %TIME% - INFO - MOVES files created >> model_run_timestamp.txt @@ -403,7 +371,7 @@ if "%utilFile%"=="F" (del cache\choice_simulator_trips_out\choice_simulator_util :USskim if "%UrbansimFile%"=="F" (goto skip_UrbanSim) @ECHO Creating skim file for UrbanSim ... -call python tg\scripts\urbansim_skims.py +uv run tg\scripts\urbansim_skims.py :skip_UrbanSim REM The following lines run transit assignment. @@ -411,31 +379,27 @@ if "%transitAsmt%" EQU "T" ( @ECHO Begin Transit Assignment setup: %date% %time% >> model_run_timestamp.txt REM -- Create matrices to hold TOD transit demand if "%RSPrun%" EQU "T" (@ECHO -- Creating HBW transit demand matrices >> model_run_timestamp.txt) - call python transit_asmt_macros/setup_transit_asmt_2_initialize_matrices.py %file1% %RSPrun% + uv run transit_asmt_macros/setup_transit_asmt_2_initialize_matrices.py %file1% %RSPrun% if %ERRORLEVEL% NEQ 0 (goto issue) REM -- Fill matrices with demand (point to conda environment) - rem Activate Python env - call %~dp0..\Scripts\manage\env\activate_env.cmd - call python transit_asmt_macros\setup_transit_asmt_3_TOD_transit_demand.py %RSPrun% + uv run transit_asmt_macros\setup_transit_asmt_3_TOD_transit_demand.py %RSPrun% if %ERRORLEVEL% NEQ 0 (goto issue) @ECHO End Transit Assignment setup >> model_run_timestamp.txt - rem Activate Emme Python env - call %~dp0..\Scripts\manage\env\activate_env.cmd emme @ECHO Submit Transit Assignment >> model_run_timestamp.txt cd transit_asmt_macros - call python cmap_transit_assignment_runner.py %file1% 1 %val% + uv run cmap_transit_assignment_runner.py %file1% 1 %val% if %ERRORLEVEL% GTR 0 (goto issue) cd .. REM -- Delete transit assignment matrices - call python transit_asmt_macros\delete_transit_skims.py %file1% + uv run transit_asmt_macros\delete_transit_skims.py %file1% if %ERRORLEVEL% GTR 0 (goto issue) if "%check2%" NEQ "None" ( REM -- Run select line analysis - call python transit_asmt_macros\transit_select_line.py %file1% %val% %selLineFile% + uv run transit_asmt_macros\transit_select_line.py %file1% %val% %selLineFile% if %ERRORLEVEL% GTR 0 (goto issue) @ECHO -- Completed Select Line Analysis >> model_run_timestamp.txt REM -- Summarize select line boardings - call python transit_asmt_macros\select_line_boardings.py %file1% %val% %RSPrun% %selLineFile% + uv run transit_asmt_macros\select_line_boardings.py %file1% %val% %RSPrun% %selLineFile% if %ERRORLEVEL% GTR 0 (goto issue) @ECHO -- Completed Select Line Boarding Analysis >> model_run_timestamp.txt ) @@ -459,18 +423,6 @@ goto end pause goto end -:CheckEmpty2 -if %~z1 == 0 (goto badR) -goto Rpass - -:badR -@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@ECHO COULD NOT FIND R INSTALLATION. -@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@ECHO. -pause -goto end - :mcmiss @ECHO @ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Database/batch_file.yaml b/Database/batch_file.yaml index 7454ef1..76ebf8c 100644 --- a/Database/batch_file.yaml +++ b/Database/batch_file.yaml @@ -17,9 +17,6 @@ util_files: False UrbanSim_file: False # ---------------- Is this an RSP evaluation run? Default is False. RSP: False -# ---------------- sourceCode will force CMAP-TRIP2 to use the source code in this model setup if set to True. Default is True. -# ---------------- 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 diff --git a/Database/build_scenario_networks.bat b/Database/build_scenario_networks.bat index 100f9cf..beae1c9 100644 --- a/Database/build_scenario_networks.bat +++ b/Database/build_scenario_networks.bat @@ -39,17 +39,14 @@ set ok=%ok:y=Y% if not "%ok%"=="Y" (goto end) @echo ================================================================== -rem Activate Emme Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd emme - @ECHO --- Cleaning up databank --- if exist cleanup.rpt (del cleanup.rpt) -call python useful_macros\cleanup_for_rerun.py %val%>> cleanup.rpt +uv run useful_macros\cleanup_for_rerun.py %val%>> cleanup.rpt if exist reports (del reports) @ECHO Cleanup complete. @ECHO --- Creating time-of-day highway and transit networks --- -call python prep_macros\initialize_scenarios.py +uv run prep_macros\initialize_scenarios.py if %ERRORLEVEL% GTR 0 (goto end) @ECHO -- Checking for transit network input errors -- @@ -59,7 +56,7 @@ if exist report\build_transit.error (del report\build_transit.error /Q) :while if %trnscen% GTR %maxscen% (goto loopend) -python prep_macros\build_transit_error_check.py %trnscen% +uv run prep_macros\build_transit_error_check.py %trnscen% if exist report\build_transit.error (goto badnet) set /A trnscen=%trnscen%+2 goto while diff --git a/Database/choice_model_params.yaml b/Database/choice_model_params.yaml index f0f2098..3ad2d23 100644 --- a/Database/choice_model_params.yaml +++ b/Database/choice_model_params.yaml @@ -77,7 +77,6 @@ HBWL: intrazonal : 0.02173059479852062 log_attraction : 1.0 metra_longtrip : 5.625 - ovtt_dist : -0.076 ovtt_dist : -0.07639147912439262 samp_af : 1.0 totaltime : -0.014712168298471244 diff --git a/Database/prep_macros/import_tg_results.py b/Database/prep_macros/import_tg_results.py new file mode 100644 index 0000000..e5c7103 --- /dev/null +++ b/Database/prep_macros/import_tg_results.py @@ -0,0 +1,67 @@ +import os +import sys +import re +from pathlib import Path +import inro.modeller as _m +sys.path.append(str(Path(__file__).resolve().parents[2].joinpath('Scripts'))) # Assumes script is in Database/ANOTHERSUBFOLDER; [2] goes up two folders to find cmap_trip-based_model/Scripts +from tbmtools import project as tbm + +def main(): + # Define the path to the Emme project (.emp file) + proj_dir = Path(__file__).resolve().parents[2] + my_modeller = tbm.connect(proj_dir) + + # Connect to the Modeller + delete_matrix = my_modeller.tool('inro.emme.data.matrix.delete_matrix') + matrix_init = my_modeller.tool('inro.emme.data.matrix.create_matrix') + process = my_modeller.tool('inro.emme.data.matrix.matrix_transaction') + my_emmebank = my_modeller.emmebank + + # proceed with all the tools you need + + directory = os.getcwd().replace('\\prep_macros','') + tgdata_path = Path(directory + "\\tg\\data") + for file in tgdata_path.glob("*.in"): + with open(file, "r") as f: + lines = f.readlines() + + third_row = lines[2] + + # Extract matrix_id + match = re.search(r"matrix=(.*?) ", third_row) + matrix_id = match.group(1).strip() + + # Parse the row + parts = third_row.split() + matrix_name = parts[2] + matrix_description = " ".join(parts[4:]) + + matrix_file = os.path.join(tgdata_path, file) + + # Delete old matrix + delete_matrix(matrix=my_emmebank.matrix(matrix_id)) + + # Dynamically name the variable: new_ + var_name = f"new_{matrix_id}" + globals()[var_name] = matrix_init( + matrix_id=matrix_id, + matrix_name=matrix_name, + matrix_description=matrix_description, + overwrite=True, + default_value=0 + ) + + # Process the transaction file + process( + transaction_file=matrix_file, + throw_on_error=True, + scenario=_m.Modeller().scenario + ) + print(f'Successfully process {file}') + + + # END + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Database/tg/fortran/TG_INPUT.TXT b/Database/tg/fortran/TG_INPUT.TXT deleted file mode 100644 index aeed33c..0000000 --- a/Database/tg/fortran/TG_INPUT.TXT +++ /dev/null @@ -1,25 +0,0 @@ - &PARAM - TITLE = 'CMAP Trip Generation' - SUBZONES = 17418 - PUMA5 = 74 - ZONES = 3632 - COUNTIES = 21 - TRIPGEN = .TRUE. - HHENUM = .FALSE. - SAVE_FILE = .TRUE. - EXP_TTYPE = .TRUE. - SYNTH_VEH = .FALSE. - MODE_CHOICE = .TRUE. - IN_EMPFACT = 1.000 - WI_EMPFACT = 1.000 - SWIDX_MAX = 40.0 - REPLICATE_MAX = 1900 - RESAMPLE_MAX = 100 - REGMED_INC = 68300 - GQATT1 = 1.00,2.00,1.00 - GQATT2 = 0.385,0.77,1.00 - GQATT3 = 0.306,0.612,1.00 - GQATT4 = 0.12,0.24,1.00 - RNSEED = 211 - &END - \ No newline at end of file diff --git a/Database/tg/fortran/TG_PopSyn.exe b/Database/tg/fortran/TG_PopSyn.exe deleted file mode 100644 index bd09732..0000000 Binary files a/Database/tg/fortran/TG_PopSyn.exe and /dev/null differ diff --git a/Database/tg/fortran/airport_sz.csv b/Database/tg/fortran/airport_sz.csv new file mode 100644 index 0000000..34d49fd --- /dev/null +++ b/Database/tg/fortran/airport_sz.csv @@ -0,0 +1,68 @@ +subzone,zone,airport,year_open +377,494,MDW,1927 +378,494,MDW,1927 +379,494,MDW,1927 +380,494,MDW,1927 +698,126,ORD,1955 +699,127,ORD,1955 +700,125,ORD,1955 +701,126,ORD,1955 +702,125,ORD,1955 +703,125,ORD,1955 +704,125,ORD,1955 +705,125,ORD,1955 +706,125,ORD,1955 +707,125,ORD,1955 +708,125,ORD,1955 +709,125,ORD,1955 +710,125,ORD,1955 +711,126,ORD,1955 +712,125,ORD,1955 +713,126,ORD,1955 +714,125,ORD,1955 +716,126,ORD,1955 +717,126,ORD,1955 +732,130,ORD,1955 +733,130,ORD,1955 +734,130,ORD,1955 +735,129,ORD,1955 +736,129,ORD,1955 +737,129,ORD,1955 +943,122,ORD,1955 +944,122,ORD,1955 +949,123,ORD,1955 +950,123,ORD,1955 +953,124,ORD,1955 +2586,129,ORD,1955 +3896,1733,ORD,1955 +3897,1733,ORD,1955 +3898,1734,ORD,1955 +3899,1734,ORD,1955 +3900,1734,ORD,1955 +3901,1734,ORD,1955 +3902,1734,ORD,1955 +3903,1734,ORD,1955 +3904,1969,ORD,1955 +5158,1969,ORD,1955 +13907,2907,SSA,2035 +13909,2907,SSA,2035 +13910,2907,SSA,2035 +13913,2907,SSA,2035 +13914,2907,SSA,2035 +13917,2907,SSA,2035 +13918,2907,SSA,2035 +13919,2906,SSA,2035 +13922,2906,SSA,2035 +13925,2906,SSA,2035 +13927,2906,SSA,2035 +13939,2906,SSA,2035 +13940,2906,SSA,2035 +13943,2907,SSA,2035 +13944,2907,SSA,2035 +13947,2907,SSA,2035 +13948,2907,SSA,2035 +13951,2907,SSA,2035 +13952,2907,SSA,2035 +14075,2921,SSA,2035 +14076,2921,SSA,2035 +14077,2921,SSA,2035 diff --git a/Database/tg/fortran/coefficients_attractions.csv b/Database/tg/fortran/coefficients_attractions.csv new file mode 100644 index 0000000..ca53e2f --- /dev/null +++ b/Database/tg/fortran/coefficients_attractions.csv @@ -0,0 +1,197 @@ +trip_type,wfh_flag,cbd,weight_formula +1,0,1,1 * total_employment * low_earner_share +1,0,0,0.755 * total_employment * low_earner_share +1,1,1,1 * total_employment * low_earner_share +1,1,0,0.755 * total_employment * low_earner_share +2,0,1,1 * total_employment * high_earner_share +2,0,0,0.755 * total_employment * high_earner_share +2,1,1,1 * total_employment * high_earner_share +2,1,0,0.755 * total_employment * high_earner_share +3,0,1,1 * retail_employment + 0.241 * nonretail_employment +3,0,0,3.103 * retail_employment + 0.634 * nonretail_employment +3,1,1,1 * retail_employment + 0.241 * nonretail_employment +3,1,0,3.103 * retail_employment + 0.634 * nonretail_employment +4,0,1,1 * enrollment +4,0,0,1 * enrollment * notairport_flag +4,1,1,1 * enrollment +4,1,0,1 * enrollment * notairport_flag +5,0,1,1 * households +5,0,0,1.132 * households * notairport_flag +5,1,1,1 * households +5,1,0,0.057 * households * notairport_flag +6,0,1,1 * retail_employment + 0.042 * nonretail_employment +6,0,0,0.623 * retail_employment + 0.18 * nonretail_employment +6,1,1,1 * retail_employment + 0.024 * nonretail_employment +6,1,0,0.941 * retail_employment + 0.208 * nonretail_employment +7,0,1,1 * retail_employment +7,0,0,1.43 * retail_employment * notairport_flag +7,1,1,1 * retail_employment +7,1,0,0.938 * retail_employment * notairport_flag +8,0,1,1 * households +8,0,0,2.309 * households * notairport_flag +8,1,1,1 * households +8,1,0,0.738 * households * notairport_flag +9,0,1,1 * retail_employment + 0.095 * nonretail_employment +9,0,0,0.383 * retail_employment + 0.106 * nonretail_employment +9,1,1,1 * retail_employment + 0.027 * nonretail_employment +9,1,0,0.641 * retail_employment + 0.158 * nonretail_employment +10,0,1,1 * retail_employment +10,0,0,0.882 * retail_employment * notairport_flag +10,1,1,1 * retail_employment +10,1,0,0.556 * retail_employment * notairport_flag +11,0,1,1 * total_employment +11,0,0,1.55 * total_employment +11,1,1,1 * total_employment +11,1,0,2.722 * total_employment +12,0,1,1 * households +12,0,0,1.414 * households * notairport_flag +12,1,1,1 * households +12,1,0,0.99 * households * notairport_flag +13,0,1,1 * retail_employment + 0.051 * nonretail_employment +13,0,0,0.401 * retail_employment + 0.099 * nonretail_employment +13,1,1,1 * retail_employment + 0.036 * nonretail_employment +13,1,0,0.938 * retail_employment + 0.189 * nonretail_employment +14,0,1,1 * retail_employment +14,0,0,1.106 * retail_employment * notairport_flag +14,1,1,1 * retail_employment +14,1,0,1.217 * retail_employment * notairport_flag +15,0,1,1 * households +15,0,0,1.414 * households * notairport_flag +15,1,1,1 * households +15,1,0,0.99 * households * notairport_flag +16,0,1,1 * retail_employment + 0.051 * nonretail_employment +16,0,0,0.401 * retail_employment + 0.099 * nonretail_employment +16,1,1,1 * retail_employment + 0.036 * nonretail_employment +16,1,0,0.938 * retail_employment + 0.189 * nonretail_employment +17,0,1,1 * retail_employment +17,0,0,1.106 * retail_employment * notairport_flag +17,1,1,1 * retail_employment +17,1,0,1.217 * retail_employment * notairport_flag +18,0,1,1 * households +18,0,0,1.414 * households * notairport_flag +18,1,1,1 * households +18,1,0,0.99 * households * notairport_flag +19,0,1,1 * retail_employment + 0.051 * nonretail_employment +19,0,0,0.401 * retail_employment + 0.099 * nonretail_employment +19,1,1,1 * retail_employment + 0.036 * nonretail_employment +19,1,0,0.938 * retail_employment + 0.189 * nonretail_employment +20,0,1,1 * retail_employment +20,0,0,1.106 * retail_employment * notairport_flag +20,1,1,1 * retail_employment +20,1,0,1.217 * retail_employment * notairport_flag +21,0,1,1 * enrollment +21,0,0,1 * enrollment * notairport_flag +21,1,1,1 * enrollment +21,1,0,1 * enrollment * notairport_flag +22,0,1,1 * households +22,0,0,1.173 * households * notairport_flag +22,1,1,1 * households +22,1,0,1.173 * households * notairport_flag +23,0,1,0.088 * total_employment +23,0,0,1 * retail_employment + 0.263 * nonretail_employment +23,1,1,0.088 * total_employment +23,1,0,1 * retail_employment + 0.263 * nonretail_employment +24,0,1,1 * retail_employment +24,0,0,1.634 * retail_employment * notairport_flag +24,1,1,1 * retail_employment +24,1,0,1.634 * retail_employment * notairport_flag +25,0,1,1 * households +25,0,0,0.985 * households * notairport_flag +25,1,1,1 * households +25,1,0,0.985 * households * notairport_flag +26,0,1,1 * retail_employment + 0.047 * nonretail_employment +26,0,0,0.754 * retail_employment + 0.18 * nonretail_employment +26,1,1,1 * retail_employment + 0.047 * nonretail_employment +26,1,0,0.754 * retail_employment + 0.18 * nonretail_employment +27,0,1,1 * retail_employment +27,0,0,1.53 * retail_employment * notairport_flag +27,1,1,1 * retail_employment +27,1,0,1.53 * retail_employment * notairport_flag +28,0,1,1 * households +28,0,0,0.985 * households * notairport_flag +28,1,1,1 * households +28,1,0,0.985 * households * notairport_flag +29,0,1,1 * retail_employment + 0.047 * nonretail_employment +29,0,0,0.754 * retail_employment + 0.18 * nonretail_employment +29,1,1,1 * retail_employment + 0.047 * nonretail_employment +29,1,0,0.754 * retail_employment + 0.18 * nonretail_employment +30,0,1,1 * retail_employment +30,0,0,1.53 * retail_employment * notairport_flag +30,1,1,1 * retail_employment +30,1,0,1.53 * retail_employment * notairport_flag +31,0,1,1 * households +31,0,0,0.985 * households * notairport_flag +31,1,1,1 * households +31,1,0,0.985 * households * notairport_flag +32,0,1,1 * retail_employment + 0.047 * nonretail_employment +32,0,0,0.754 * retail_employment + 0.18 * nonretail_employment +32,1,1,1 * retail_employment + 0.047 * nonretail_employment +32,1,0,0.754 * retail_employment + 0.18 * nonretail_employment +33,0,1,1 * retail_employment +33,0,0,1.53 * retail_employment * notairport_flag +33,1,1,1 * retail_employment +33,1,0,1.53 * retail_employment * notairport_flag +34,0,1,1 * households +34,0,0,1.511 * households * notairport_flag +34,1,1,1 * households +34,1,0,1.511 * households * notairport_flag +35,0,1,1 * households +35,0,0,36.326 * households * notairport_flag +35,1,1,1 * households +35,1,0,36.326 * households * notairport_flag +36,0,1,1 * retail_employment + 0.031 * nonretail_employment +36,0,0,2.51 * retail_employment + 0.324 * nonretail_employment +36,1,1,1 * retail_employment + 0.031 * nonretail_employment +36,1,0,2.51 * retail_employment + 0.324 * nonretail_employment +37,0,1,1 * retail_employment +37,0,0,1 * retail_employment * notairport_flag +37,1,1,1 * retail_employment +37,1,0,1 * retail_employment * notairport_flag +38,0,1,1 * households +38,0,0,16.44 * households * notairport_flag +38,1,1,1 * households +38,1,0,16.44 * households * notairport_flag +39,0,1,0.058 * total_employment +39,0,0,1 * retail_employment + 0.922 * nonretail_employment +39,1,1,0.058 * total_employment +39,1,0,1 * retail_employment + 0.922 * nonretail_employment +40,0,1,1 * retail_employment +40,0,0,1 * retail_employment * notairport_flag +40,1,1,1 * retail_employment +40,1,0,1 * retail_employment * notairport_flag +41,0,1,1 * households +41,0,0,16.44 * households * notairport_flag +41,1,1,1 * households +41,1,0,16.44 * households * notairport_flag +42,0,1,0.058 * total_employment +42,0,0,1 * retail_employment + 0.922 * nonretail_employment +42,1,1,0.058 * total_employment +42,1,0,1 * retail_employment + 0.922 * nonretail_employment +43,0,1,1 * retail_employment +43,0,0,1 * retail_employment * notairport_flag +43,1,1,1 * retail_employment +43,1,0,1 * retail_employment * notairport_flag +44,0,1,1 * households +44,0,0,16.44 * households * notairport_flag +44,1,1,1 * households +44,1,0,16.44 * households * notairport_flag +45,0,1,0.058 * total_employment +45,0,0,1 * retail_employment + 0.922 * nonretail_employment +45,1,1,0.058 * total_employment +45,1,0,1 * retail_employment + 0.922 * nonretail_employment +46,0,1,1 * retail_employment +46,0,0,1 * retail_employment * notairport_flag +46,1,1,1 * retail_employment +46,1,0,1 * retail_employment * notairport_flag +47,0,1,1 * households +47,0,0,16.44 * households * notairport_flag +47,1,1,1 * households +47,1,0,16.44 * households * notairport_flag +48,0,1,0.058 * total_employment +48,0,0,1 * retail_employment + 0.922 * nonretail_employment +48,1,1,0.058 * total_employment +48,1,0,1 * retail_employment + 0.922 * nonretail_employment +49,0,1,1 * retail_employment +49,0,0,1 * retail_employment * notairport_flag +49,1,1,1 * retail_employment +49,1,0,1 * retail_employment * notairport_flag diff --git a/Database/tg/fortran/coefficients_nonhome_productions.csv b/Database/tg/fortran/coefficients_nonhome_productions.csv new file mode 100644 index 0000000..22482ab --- /dev/null +++ b/Database/tg/fortran/coefficients_nonhome_productions.csv @@ -0,0 +1,197 @@ +trip_type,wfh_flag,cbd,weight_formula +1,0,1,0 +1,0,0,0 +1,1,1,0 +1,1,0,0 +2,0,1,0 +2,0,0,0 +2,1,1,0 +2,1,0,0 +3,0,1,0 +3,0,0,0 +3,1,1,0 +3,1,0,0 +4,0,1,0 +4,0,0,0 +4,1,1,0 +4,1,0,0 +5,0,1,0 +5,0,0,0 +5,1,1,0 +5,1,0,0 +6,0,1,0 +6,0,0,0 +6,1,1,0 +6,1,0,0 +7,0,1,0 +7,0,0,0 +7,1,1,0 +7,1,0,0 +8,0,1,1 * total_employment +8,0,0,3.048 * total_employment +8,1,1,1 * total_employment +8,1,0,6.545 * total_employment +9,0,1,1 * total_employment +9,0,0,0.765 * total_employment +9,1,1,1 * total_employment +9,1,0,2.525 * total_employment +10,0,1,1 * total_employment +10,0,0,1.901 * total_employment +10,1,1,1 * total_employment +10,1,0,4.9 * total_employment +11,0,1,1 * total_employment +11,0,0,1.837 * total_employment +11,1,1,1 * total_employment +11,1,0,2.059 * total_employment +12,0,1,1 * households +12,0,0,1.401 * households * notairport_flag +12,1,1,1 * households +12,1,0,1.01 * households * notairport_flag +13,0,1,1 * households +13,0,0,1.401 * households * notairport_flag +13,1,1,1 * households +13,1,0,1.01 * households * notairport_flag +14,0,1,1 * households +14,0,0,1.401 * households * notairport_flag +14,1,1,1 * households +14,1,0,1.01 * households * notairport_flag +15,0,1,1 * retail_employment + 0.05 * nonretail_employment +15,0,0,0.401 * retail_employment + 0.097 * nonretail_employment +15,1,1,1 * retail_employment + 0.038 * nonretail_employment +15,1,0,0.963 * retail_employment + 0.195 * nonretail_employment +16,0,1,1 * retail_employment + 0.05 * nonretail_employment +16,0,0,0.401 * retail_employment + 0.097 * nonretail_employment +16,1,1,1 * retail_employment + 0.038 * nonretail_employment +16,1,0,0.963 * retail_employment + 0.195 * nonretail_employment +17,0,1,1 * retail_employment + 0.05 * nonretail_employment +17,0,0,0.401 * retail_employment + 0.097 * nonretail_employment +17,1,1,1 * retail_employment + 0.038 * nonretail_employment +17,1,0,0.963 * retail_employment + 0.195 * nonretail_employment +18,0,1,1 * retail_employment +18,0,0,1.129 * retail_employment * notairport_flag +18,1,1,1 * retail_employment +18,1,0,1.227 * retail_employment * notairport_flag +19,0,1,1 * retail_employment +19,0,0,1.129 * retail_employment * notairport_flag +19,1,1,1 * retail_employment +19,1,0,1.227 * retail_employment * notairport_flag +20,0,1,1 * retail_employment +20,0,0,1.129 * retail_employment * notairport_flag +20,1,1,1 * retail_employment +20,1,0,1.227 * retail_employment * notairport_flag +21,0,1,0 +21,0,0,0 +21,1,1,0 +21,1,0,0 +22,0,1,0 +22,0,0,0 +22,1,1,0 +22,1,0,0 +23,0,1,0 +23,0,0,0 +23,1,1,0 +23,1,0,0 +24,0,1,0 +24,0,0,0 +24,1,1,0 +24,1,0,0 +25,0,1,1 * households +25,0,0,1.281 * households * notairport_flag +25,1,1,1 * households +25,1,0,1.281 * households * notairport_flag +26,0,1,1 * households +26,0,0,1.281 * households * notairport_flag +26,1,1,1 * households +26,1,0,1.281 * households * notairport_flag +27,0,1,1 * households +27,0,0,1.281 * households * notairport_flag +27,1,1,1 * households +27,1,0,1.281 * households * notairport_flag +28,0,1,1 * retail_employment + 0.046 * nonretail_employment +28,0,0,0.734 * retail_employment + 0.176 * nonretail_employment +28,1,1,1 * retail_employment + 0.046 * nonretail_employment +28,1,0,0.734 * retail_employment + 0.176 * nonretail_employment +29,0,1,1 * retail_employment + 0.046 * nonretail_employment +29,0,0,0.734 * retail_employment + 0.176 * nonretail_employment +29,1,1,1 * retail_employment + 0.046 * nonretail_employment +29,1,0,0.734 * retail_employment + 0.176 * nonretail_employment +30,0,1,1 * retail_employment + 0.046 * nonretail_employment +30,0,0,0.734 * retail_employment + 0.176 * nonretail_employment +30,1,1,1 * retail_employment + 0.046 * nonretail_employment +30,1,0,0.734 * retail_employment + 0.176 * nonretail_employment +31,0,1,1 * retail_employment +31,0,0,1.441 * retail_employment * notairport_flag +31,1,1,1 * retail_employment +31,1,0,1.441 * retail_employment * notairport_flag +32,0,1,1 * retail_employment +32,0,0,1.441 * retail_employment * notairport_flag +32,1,1,1 * retail_employment +32,1,0,1.441 * retail_employment * notairport_flag +33,0,1,1 * retail_employment +33,0,0,1.441 * retail_employment * notairport_flag +33,1,1,1 * retail_employment +33,1,0,1.441 * retail_employment * notairport_flag +34,0,1,0 +34,0,0,0 +34,1,1,0 +34,1,0,0 +35,0,1,0 +35,0,0,0 +35,1,1,0 +35,1,0,0 +36,0,1,0 +36,0,0,0 +36,1,1,0 +36,1,0,0 +37,0,1,0 +37,0,0,0 +37,1,1,0 +37,1,0,0 +38,0,1,1 * households +38,0,0,2.599 * households * notairport_flag +38,1,1,1 * households +38,1,0,2.599 * households * notairport_flag +39,0,1,1 * households +39,0,0,2.599 * households * notairport_flag +39,1,1,1 * households +39,1,0,2.599 * households * notairport_flag +40,0,1,1 * households +40,0,0,2.599 * households * notairport_flag +40,1,1,1 * households +40,1,0,2.599 * households * notairport_flag +41,0,1,1 * households +41,0,0,22 * households * notairport_flag +41,1,1,1 * households +41,1,0,22 * households * notairport_flag +42,0,1,1 * households +42,0,0,22 * households * notairport_flag +42,1,1,1 * households +42,1,0,22 * households * notairport_flag +43,0,1,1 * households +43,0,0,22 * households * notairport_flag +43,1,1,1 * households +43,1,0,22 * households * notairport_flag +44,0,1,0.065 * total_employment +44,0,0,1 * retail_employment + 0.137 * nonretail_employment +44,1,1,0.065 * total_employment +44,1,0,1 * retail_employment + 0.137 * nonretail_employment +45,0,1,0.065 * total_employment +45,0,0,1 * retail_employment + 0.137 * nonretail_employment +45,1,1,0.065 * total_employment +45,1,0,1 * retail_employment + 0.137 * nonretail_employment +46,0,1,0.065 * total_employment +46,0,0,1 * retail_employment + 0.137 * nonretail_employment +46,1,1,0.065 * total_employment +46,1,0,1 * retail_employment + 0.137 * nonretail_employment +47,0,1,1 * retail_employment +47,0,0,1 * retail_employment * notairport_flag +47,1,1,1 * retail_employment +47,1,0,1 * retail_employment * notairport_flag +48,0,1,1 * retail_employment +48,0,0,1 * retail_employment * notairport_flag +48,1,1,1 * retail_employment +48,1,0,1 * retail_employment * notairport_flag +49,0,1,1 * retail_employment +49,0,0,1 * retail_employment * notairport_flag +49,1,1,1 * retail_employment +49,1,0,1 * retail_employment * notairport_flag diff --git a/Database/tg/fortran/create_HHvtype_file.py b/Database/tg/fortran/create_HHvtype_file.py deleted file mode 100644 index 18e1126..0000000 --- a/Database/tg/fortran/create_HHvtype_file.py +++ /dev/null @@ -1,45 +0,0 @@ -''' -##################################################################################### -CREATE_HHVYTPE_FILE.PY - Craig Heither, rev. 04-15-2021 - - Script reads enumerated household file created by TG (HI_HHENUM_TRIP_OUT.TXT) - and geography correspondence file (GEOG_IN.TXT) to create the file - Database\TG_HHENUM_OUTPUT.TXT required by the non-work vehicle occupancy - procedures. The file has the following fields: - subzone, zone, household type (vehicle definition) - -##################################################################################### -''' -import os -import pandas as pd - -geog_input = os.getcwd() + "\\tg\\fortran\\GEOG_IN.TXT" ### subzone-zone correspondence file -hh_input = os.getcwd() + "\\tg\\fortran\\HI_HHENUM_TRIP_OUT.TXT" ### enumerated HH file -hh_output = os.getcwd() + "\\tg\\fortran\\TG_HHENUM_OUTPUT.TXT" - -if os.path.exists(hh_output): - os.remove(hh_output) - -print("Creating File of Household Types by Subzone ...") - -# ---------------------------------------------------------------------------- -# Read in Geography file. -# ---------------------------------------------------------------------------- -geo=pd.read_csv(geog_input, sep=',', header=None) -geo.columns=['subzone','county','name','state','puma','zone','chicago','cbd','rc','area','cmap'] -geo.drop(columns=['county','name','state','puma','chicago','cbd','rc','area','cmap'], axis=1, inplace=True) ### drop unnecessary columns - -# ---------------------------------------------------------------------------- -# Read in Trip Enumeration file. -# ---------------------------------------------------------------------------- -hh=pd.read_fwf(hh_input, widths=[5,7,4,4], header=None) -hh.columns=['subzone','puma','hhtype','hhvtype'] -hh.drop(columns=['puma','hhtype'], axis=1, inplace=True) ### drop unnecessary columns - -# ---------------------------------------------------------------------------- -# Merge dataframes, sort data and write file. -# ---------------------------------------------------------------------------- -hh1 = hh.merge(geo, how='left', on='subzone', copy=False) -hh1.sort_values(by=['zone', 'subzone'], inplace=True) -hh1.to_csv(hh_output, columns=['subzone','zone','hhvtype'], header=False, index=False) diff --git a/Database/tg/fortran/highinc_workers.csv b/Database/tg/fortran/highinc_workers.csv deleted file mode 100644 index dc147d4..0000000 --- a/Database/tg/fortran/highinc_workers.csv +++ /dev/null @@ -1,4 +0,0 @@ -0.0,0.0,0.0,0.0,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000 -0.0,0.0,0.0,0.0,0.538,0.318,0.217,0.164,0.065,0.061,0.045,0.013,0.013 -0.0,0.0,0.0,0.0,1.000,0.821,0.624,0.589,0.429,0.352,0.288,0.179,0.117 -0.0,0.0,0.0,0.0,1.000,0.953,0.842,0.813,0.836,0.713,0.617,0.545,0.410 diff --git a/Database/tg/scripts/summarize_tg_results.py b/Database/tg/scripts/summarize_tg_results.py index f810273..5bbdce7 100644 --- a/Database/tg/scripts/summarize_tg_results.py +++ b/Database/tg/scripts/summarize_tg_results.py @@ -180,7 +180,7 @@ widths=[6, 6, 2, 9, 9], names=['subzone17', 'zone17', 'trip_type', 'hh_prods', 'hh_attrs'] ) -trip = not_wfh_trip.append(wfh_trip) +trip = pd.concat([not_wfh_trip, wfh_trip], ignore_index=True) trip = trip.groupby(['subzone17', 'zone17', 'trip_type']).sum().reset_index() # Calculate TAZ median household income diff --git a/Database/transit_asmt_macros/run_transit_assignment.bat b/Database/transit_asmt_macros/run_transit_assignment.bat index 434dae4..f143a5a 100644 --- a/Database/transit_asmt_macros/run_transit_assignment.bat +++ b/Database/transit_asmt_macros/run_transit_assignment.bat @@ -21,11 +21,11 @@ echo. 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 4c03dbd..5190bd4 100644 --- a/Database/trip_gen.bat +++ b/Database/trip_gen.bat @@ -152,23 +152,19 @@ if "%run%" == "" ( echo =================================================================== echo. -rem Activate Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd -if %ERRORLEVEL% NEQ 0 (goto end) - cd tg\scripts echo. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo Updating Trip Generation inputs with UrbanSim data ... echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -python urbansim_update_tg_input_files.py +uv run urbansim_update_tg_input_files.py if %ERRORLEVEL% NEQ 0 (goto urbansim_issue) @echo. echo. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo Updating Heavy Truck Trip allocation weights with UrbanSim data ... echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -python urbansim_hcv_allocation.py +uv run urbansim_hcv_allocation.py if %ERRORLEVEL% NEQ 0 (goto hcv_issue) cd ..\fortran @@ -183,10 +179,10 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if %val%==100 ( echo Running wfhflag_base.py ... - python wfhflag_base.py %filedir% %savedir% %wfhFile% + uv run wfhflag_base.py %filedir% %savedir% %wfhFile% ) else ( echo Running wfhflag.py ... - python wfhflag.py %filedir% %savedir% %wfhFile% + uv run wfhflag.py %filedir% %savedir% %wfhFile% ) if %ERRORLEVEL% NEQ 0 (goto wfh_issue) @@ -198,17 +194,24 @@ if not exist GQ_IN.TXT (goto socec_data_error) if not exist ATTR_IN.TXT (goto socec_data_error) if not exist POPSYN_HH.CSV (goto socec_data_error) -rem Delete old output files. +rem Delete old output files and deprecated files. if exist *OUT.TXT (del *OUT.TXT) if exist *OUTPUT.TXT (del *OUTPUT.TXT) if exist MCHW_HH.TXT (del MCHW_HH.TXT) - -TG_PopSyn.exe -cd ..\scripts +if exist TG_PopSyn.exe (del TG_PopSyn.exe) +if exist TG_INPUT.TXT (del TG_INPUT.TXT) +if exist highinc_workers.csv (del highinc_workers.csv) + +cd ..\.. +@echo ============================================================= +@echo BEGIN CMAP TRIP GENERATION MODEL +@echo ============================================================= +uv run trip_generation\trip_generation_model.py +cd tg\scripts echo Creating summary files ... -python summarize_tg_results.py %project% %run% -python prepare_iom_inputs.py %project% %run% +uv run summarize_tg_results.py %project% %run% +uv run prepare_iom_inputs.py %project% %run% echo. cd ..\data @@ -226,8 +229,6 @@ if not exist m01type.csv (goto m01_data_error) cd %~dp0 -python tg\fortran\create_HHvtype_file.py - echo Module 1 finished. echo. echo =================================================================== @@ -278,20 +279,16 @@ call :CheckEmpty %infile% if exist %infile% (del %infile% /Q) cd Database -rem Activate Emme Python env -call %~dp0..\Scripts\manage\env\activate_env.cmd emme -if %ERRORLEVEL% NEQ 0 (goto end) - echo Preparing emmebank for model run... -call python useful_macros\cleanup_for_rerun.py %val%>> tg.rpt +uv run useful_macros\cleanup_for_rerun.py %val%>> tg.rpt echo. echo Importing production and attraction matrices (used only for b/l/m truck distribution)... -call emme -ng 000 -m prep_macros\import.tg.results 1 >> tg.rpt +call python prep_macros\import_tg_results.py >> tg.rpt echo. echo Skimming highway network... -call python prep_macros\free.skim.mac.py %file1% %val% +uv run prep_macros\free.skim.mac.py %file1% %val% echo. echo Distributing trucks... diff --git a/Database/trip_generation/household_trip_enumeration.py b/Database/trip_generation/household_trip_enumeration.py new file mode 100644 index 0000000..ed7574b --- /dev/null +++ b/Database/trip_generation/household_trip_enumeration.py @@ -0,0 +1,115 @@ +""" +Filename: household_trip_enumeration.py +Author: Craig Heither +Description: This function completes the household trip enumeration process + for trip generation. +""" + +import numpy as np + +def tripEnumeration(starts, ends, selection_array, probability_array, + rng=None, households_chosen=None, replicateMax=3000, + resampleMax=200): + """ + Select travel survey households to attach daily trips to synthetic households. + + Parameters + ---------- + starts : array_like + 0-based inclusive start indices (length N) + ends : array_like + 0-based inclusive end indices (length N) + selection_array : ndarray + 1D array of survey identifiers (length M) + probability_array : ndarray + 1D array of probabilities for each survey (length M) + rng : numpy.random.Generator, optional + NumPy Generator instance for reproducible draws. If None, uses + np.random.default_rng(). + households_chosen : dict, optional + Dictionary to track selected households and their replication counts. + If None, no resampling occurs when thresholds are reached. + replicateMax : int, optional + Maximum times a specific survey household can be matched to synthetic + households before resampling occurs. Default is 3000. + resampleMax : int, optional + Maximum times resampling will occur once replicateMax has been reached. + Default is 200. + + Returns + ------- + ndarray + Integer array (dtype int64) of length N with selected survey identifiers. + """ + # Use provided generator or default + if rng is None: + rng = np.random.default_rng() + + # Read inputs into numpy arrays, + 1 to ends to be inclusive of selection + # Example: array = [1,2,3,4,5,6,7] + # the slice for (1,2,3) is [0:3], slice for (4,5,6,7) is [3:7] + starts = np.asarray(starts, dtype=np.int64) + ends = np.asarray(ends + 1, dtype=np.int64) + selection_array = np.asarray(selection_array).astype(np.int64) + probability_array = np.asarray(probability_array).astype(float) + + # Cumulative probabilities with a leading zero for easy slice arithmetic + cumul_prob = np.concatenate(([0.0], np.cumsum(probability_array))) + + # Compute total mass for each slice + masses = cumul_prob[ends] - cumul_prob[starts] + + # Draw uniform random values within each slice's mass using RNG + u = rng.random(size=masses.shape) * masses + cumul_prob[starts] + # Map cumulative draws to travel survey household index + idx = np.searchsorted(cumul_prob, u, side='right') - 1 + selected_households = selection_array[idx].astype(np.int64) + + # Place current selections into output + keep_output = selected_households + + # Update counts and resample if threshold reached + if households_chosen is not None: + for survey_id in selected_households: + households_chosen[survey_id] = households_chosen.get(survey_id, 0) + 1 + ### households_chosen[survey_id] += 1 + + # Identify households needing resample + needs_resample = np.array( + [households_chosen.get(int(survey_id), 0) > replicateMax for + survey_id in selected_households], dtype=bool, + ) + if np.any(needs_resample): + # Iterate only on houseohlds above threshold + for i, need in enumerate(needs_resample): + if not need: + continue + + start_i = int(starts[i]) + end_i = int(ends[i]) + choices = selection_array[start_i : end_i] + probs = probability_array[start_i : end_i] + total_p = np.nansum(probs) + + if not np.isfinite(total_p) or total_p <= 0: + # Uniform if invalid probabilities + new_sel = int(rng.choice(choices)) + else: + probs = probs / total_p + new_sel = int(selected_households[i]) # default to current + for _ in range(resampleMax): + candidate = int(rng.choice(choices, p=probs)) + if households_chosen.get(candidate, 0) < replicateMax: + # Roll back previous count of selected[i] + households_chosen[int(selected_households[i])] -= 1 + # Use the candidate and increment its count + new_sel = candidate + households_chosen[new_sel] = households_chosen.get(new_sel, 0) + 1 + break + # If we never found below-threshold, keep the last selection (new_sel) + selected_households[i] = new_sel + + # Write back selections to out for the resampled subset + keep_output = selected_households + + return keep_output.astype(np.int64) \ No newline at end of file diff --git a/Database/trip_generation/trip_generation.yaml b/Database/trip_generation/trip_generation.yaml new file mode 100644 index 0000000..738087e --- /dev/null +++ b/Database/trip_generation/trip_generation.yaml @@ -0,0 +1,39 @@ +## -- Name identifying the model run +rtpVersion: '2026 LRTP' +## -- Number of trip generation subzones in the modeling area +subzones: 17418 +## -- Number of Census 2010 five percent sample PUMAs in the modeling area +puma5: 74 +## -- Zones used for trip distribution, mode choice, and assignment +## -- (excluding Points of entry) +zones: 3632 +## -- Number of counties in the modeling area +counties: 21 +## -- Maximum value used by the vehicle availability submodel for subzone +## -- sidewalk density (miles of sidewalk per square mile) +sidewalkMaxDensity: 40.0 +## -- Regional median household income, in 2019 dollars +incomeRegMed: 72800 +## -- Seed for random number generator +randomSeed: 211 +## -- Maximum times a specific survey household can be matched to synthetic +## -- households before resampling occurs +replicateMax: 1900 +## -- Maximum times resampling will occur once replicateMax has been reached +resampleMax: 100 +## -- Group quarters trip information +### --- Workers per person by GQ type +militaryWorkersPerPerson: 1.00 +univWorkersPerPerson: 0.385 +other1664WorkersPerPerson: 0.306 +other65WorkersPerPerson: 0.12 +### --- Person work trip rates by GQ type +militaryWorkTrips: 2.00 +univWorkTrips: 0.77 +other1664WorkTrips: 0.612 +other65WorkTrips: 0.24 +## -- Flag to write optional files (HI_HHENUM_TRIP_OUT.CSV, PRODS_HH_OUT.CSV, +## -- PRODS_GQ_OUT.CSV, FIRST_PA_OUT.CSV, EXTERNAL_PA_OUT.CSV). These are +## -- useful for debugging and model validation, but are not required for +## -- production model runs. +writeOptionalFiles: False diff --git a/Database/trip_generation/trip_generation_model.py b/Database/trip_generation/trip_generation_model.py new file mode 100644 index 0000000..9bda35c --- /dev/null +++ b/Database/trip_generation/trip_generation_model.py @@ -0,0 +1,987 @@ +""" +Filename: trip_generation_model.py +Author: Craig Heither +Description: This is the Python translation of CMAP's Trip Generation model, + originally written by Ronald W. Eash. It creates the subzone- + level trip productions and attractions by trip type used in the + trip-based model. Trip generation has seven major steps: + 1. Load the input files + 2. Run the vehicle availability model to estimate the number + of vehicles for each synthetic household + 3. Run the household trip enumeration process to create + productions for each synthetic household + 4. Calculate non-institutional group quarters trip productions + 5. Allocate trip productions and attractions for non-home trip + ends + 6. Factor external home-based productions and attractions + 7. Finalize productions and attractions +Input files: + - POPSYN_HH.CSV: contains information about each synthetic household + - GEOG_IN.TXT: defines various geographies for each zone and subzone + - HH_IN.TXT: contains subzone totals of household and person level attributes + - HH_WFH_STATUS.CSV: contains the telework status for each synthetic household + - tg_hhvtype_lookup.csv: defines the attributes in household vehicle type categories + - HHID_choices1.csv: defines the range of survey households available for trip + enumeration for non-telework households based on synthetic household attributes + - HHID_choices2.csv: lists the survey households in each group defined in HHID_choices1.csv + - HHID_wfh1.csv: defines the range of survey households available for trip + enumeration for telework households based on synthetic household attributes + - HHID_wfh2.csv: lists the survey households in each group defined in HHID_wfh1.csv + - HI_HHENUM_IN.TXT: contains travel survey households including the number of weekday + household trips by purpose + - GQ_IN.TXT: contains the number of workers and nonworking adults in non-institutionalized + group quarters for each subzone + - GQ_TRIPRATES.csv: contains group quarters trip rates for non-work trips developed from + the household travel survey + - airport_sz.csv: contains subzones representing airports + - SCHOOL_IN.CSV: lists high school and college enrollment values for subzones containing + these institutions + - ATTR_IN.TXT: contains subzone-level employment information + - coefficients_attractions.csv: contains the trip type coefficients used to allocate + attractions + - coefficients_nonhome_productions.csv: contains the trip type coefficients used to + allocate non-home productions + - EXT_IN.TXT: PUMA-level adjustment factors to modify workplace trips from internal + households to external workplaces and vice-versa +Output files: + - SIMULATED_HHVEH.TXT: stores the category of simulated vehicles available for each + household following the vehicle availability model + - TRIP49_PA_OUT.TXT: contains subzone-level productions and attractions by trip type + for non-telework households + - TRIP49_PA_WFH_OUT.TXT: contains subzone-level productions and attractions by trip type + for telework households + - TG_HHENUM_OUTPUT.TXT: lists the subzone, zone and household vehicle type of each + enumerated household + - households_selected_noWFH_enumeration_count.csv: lists the number of times each survey + household was selected during trip enumeration for non-telework households + - households_selected_WFH_enumeration_count.csv: lists the number of times each survey + household was selected during trip enumeration for telework households + - trip_generation_model_log.txt: trip generation model log file + - HI_HHENUM_TRIP_OUT.CSV (optional): contains the number of trips by type for each + synthetic household + - PRODS_HH_OUT.CSV (optional): contains a subzone-level summary of trip productions + by trip type within four categories of households + - PRODS_GQ_OUT.CSV (optional): contains a subzone-level summary of trip productions for + workers and nonworking adults within each group quarters resident category + - FIRST_PA_OUT.CSV (optional): contains preliminary subzone-level productions and + attractions by trip type prior to external adjustments + - EXTERNAL_PA_OUT.CSV (optional): contains subzone-level external productions and + attractions by trip type +""" + +# ---------------------------------------------------------------------------- +# Import packages, set paths and variables. +# ---------------------------------------------------------------------------- +import os +import pandas as pd +import numpy as np +from pathlib import Path +import numexpr as ne +import yaml +import timeit +import logging +import vehicle_availability as veh +import household_trip_enumeration as enumer + +t_alpha = timeit.default_timer() + +# Input Files +baseDir = Path(__file__).resolve().parents[1] +fileDir = Path(__file__).resolve().parents[1].joinpath('tg', 'fortran') +yamlDir = Path(__file__).resolve().parent +configDir = Path(__file__).resolve().parents[2].joinpath('Scripts', + 'prepare', + 'conformity_scenario', + 'hand') +popSynFile = fileDir / 'POPSYN_HH.CSV' +geoFile = fileDir / 'GEOG_IN.TXT' +szAttributesFile = fileDir / 'HH_IN.TXT' +wfhFile = fileDir / 'HH_WFH_STATUS.CSV' +hhvtypeFile = fileDir / 'tg_hhvtype_lookup.csv' +enumerateNoWfhDataFile1 = fileDir / 'HHID_choices1.csv' +enumerateNoWfhDataFile2 = fileDir / 'HHID_choices2.csv' +enumerateWfhDataFile1 = fileDir / 'HHID_wfh1.csv' +enumerateWfhDataFile2 = fileDir / 'HHID_wfh2.csv' +travelSurveyFile = fileDir / 'HI_HHENUM_IN.TXT' +groupQuartersFile = fileDir / 'GQ_IN.TXT' +groupQuartersTripsFile = fileDir / 'GQ_TRIPRATES.csv' +airportFile = fileDir / 'airport_sz.csv' +enrollmentFile = fileDir / 'SCHOOL_IN.CSV' +attractionsFile = fileDir / 'ATTR_IN.TXT' +coeffsAttractFile = fileDir / 'coefficients_attractions.csv' +coeffsProdsFile = fileDir / 'coefficients_nonhome_productions.csv' +externalShares = fileDir / 'EXT_IN.TXT' +yamlBatchin = baseDir / 'batch_file.yaml' +yamlTg = yamlDir / 'trip_generation.yaml' +yamlConfig = configDir / 'config.yaml' + +# Output Files +simVehicles = fileDir / 'SIMULATED_HHVEH.TXT' +nowfhEnumCount = fileDir / 'households_selected_noWFH_enumeration_count.csv' +wfhEnumCount = fileDir / 'households_selected_WFH_enumeration_count.csv' +finalProdsAttrs = fileDir / 'TRIP49_PA_OUT.TXT' +finalWfhProdsAttrs = fileDir / 'TRIP49_PA_WFH_OUT.TXT' +logFile = fileDir / 'trip_generation_model_log.txt' +hhVehtypeFile = fileDir / 'TG_HHENUM_OUTPUT.TXT' +syntheticHHTrips = fileDir / 'HI_HHENUM_TRIP_OUT.CSV' +householdProductions = fileDir / 'PRODS_HH_OUT.CSV' +groupQuartersProductions = fileDir / 'PRODS_GQ_OUT.CSV' +firstProdsAttrs = fileDir / 'FIRST_PA_OUT.CSV' +extrnlProdsAttrs = fileDir / 'EXTERNAL_PA_OUT.CSV' + +for fl1 in [syntheticHHTrips, householdProductions, groupQuartersProductions, + firstProdsAttrs, extrnlProdsAttrs]: + if os.path.exists(fl1): + os.remove(fl1) + +# Configure the logging +handlers = [logging.FileHandler(logFile, mode='w'), + logging.StreamHandler()] +logging.basicConfig(level=logging.DEBUG, handlers = handlers, + format='%(asctime)s - %(levelname)s - %(message)s') +logger = logging.getLogger() + +# Read configuration file attributes +with open(yamlTg, 'r') as file: + tgConfig = yaml.safe_load(file) + +with open(yamlBatchin, 'r') as file: + batchConfig = yaml.safe_load(file) + +with open(yamlConfig, 'r') as file: + config = yaml.safe_load(file) + +# Create a NumPy Generator seeded from config to pass to functions +rng = np.random.default_rng(tgConfig['randomSeed']) +# Model version +modelVersion = tgConfig['rtpVersion'] +# Set maximum sidewalk density value +sidewalkMax = float(tgConfig['sidewalkMaxDensity']) +# Set threshold for enumeration replicates to trigger resampling +replicateMax = int(tgConfig['replicateMax']) +# Set replicate resampling maximum +resampleMax = int(tgConfig['resampleMax']) +# Get regional median household income +regionalMedianIncome = int(tgConfig['incomeRegMed']) +# Get military group quarters workers per person +militaryWorkers = float(tgConfig['militaryWorkersPerPerson']) +# Get dormitory group quarters workers per person +univWorkers = float(tgConfig['univWorkersPerPerson']) +# Get other 16-64 group quarters workers per person +other1664Workers = float(tgConfig['other1664WorkersPerPerson']) +# Get other 65+ group quarters workers per person +other65Workers = float(tgConfig['other65WorkersPerPerson']) +# Get military group quarters worker trip rates +militaryWorkTrips = float(tgConfig['militaryWorkTrips']) +# Get dormitory group quarters worker trip ratesn +univWorkTrips = float(tgConfig['univWorkTrips']) +# Get other 16-64 group quarters worker trip rates +other1664WorkTrips = float(tgConfig['other1664WorkTrips']) +# Get other 65+ group quarters worker trip rates +other65WorkTrips = float(tgConfig['other65WorkTrips']) +# Write optional files +writeOptional = bool(tgConfig['writeOptionalFiles']) + +scen_code = batchConfig['scenario_code'] +real_year = int(config['scenario_years'][scen_code]) + +pdVersion = pd.__version__ +if float(pdVersion[:3]) >= 1.5: + pdEngine = 'pyarrow' +else: + pdEngine = 'c' + +# ---------------------------------------------------------------------------- +# Functions. +# ---------------------------------------------------------------------------- +def run_formula(df): + """ + Evaluate weight formulas from a DataFrame column using numexpr to calculate + non-home trip production weights or trip allocation weights. + + For each unique formula in the 'weight_formula' column, evaluates the + formula expression using numexpr on the subset of rows with that formula. + Results are aggregated into a single output array. + + Parameters + ---------- + df : DataFrame + Input DataFrame containing a 'weight_formula' column with formula + expressions and numeric columns referenced in those formulas. + + Returns + ------- + ndarray + Numeric array (float64) of evaluated results with length equal to + the number of rows in df. NaN values are returned for rows where + formula evaluation fails. + """ + result = np.zeros(len(df)) + for formula in df['weight_formula'].unique(): + mask = df['weight_formula'] == formula + subset = df[mask] + # Filter the data to only needed columns for this formula + local_dict = {col: subset[col].values for col in df.columns} + try: + result[mask.values] = ne.evaluate(formula, local_dict) + except Exception as e: + logging.error(f"Error evaluating formula '{formula}': {e}") + result[mask.values] = np.nan + return result + +def fixed_width(outfile, df): + """ + Write DataFrame to fixed-width format file. + + Extracts specified columns from the input DataFrame and writes them + to a file with right-justified fields of fixed widths. Suitable for + output compatibility with legacy fixed-format data files. + + Parameters + ---------- + outfile : str or Path + Path where the fixed-width file will be written. + df : DataFrame + Input DataFrame containing at least the columns: 'subzone', 'zone', + 'trip_type', 'sz_prods', 'sz_attrs'. + + Returns + ------- + None + Writes data directly to outfile. + + Notes + ----- + Field widths are: subzone (6), zone (6), trip_type (2), sz_prods (9), + sz_attrs (9). All numeric values are right-justified. sz_prods and + sz_attrs are formatted with 1 decimal place. + """ + data = df[['subzone', 'zone', 'trip_type', 'sz_prods', 'sz_attrs']].values + with open(outfile, 'w') as f: + for row in data: + # write right-justified fields of specified width + f.write('{:>6.0f}{:>6.0f}{:>2.0f}{:>9.1f}{:>9.1f}\n'.format(*row)) + +# ---------------------------------------------------------------------------- +# Step 1. Load data files and prepare data. +# ---------------------------------------------------------------------------- +logging.info("Beginning CMAP Trip Generation model: {0} Scenario {1}" + .format(modelVersion, batchConfig['scenario_code'])) +logging.info("Loading data files") + +# Load synthetic households +popSynCols = ['subzone','hh_type','vehicles','serial_number','state_puma', + 'row_column','adults','workers','children','income_category', + 'age_category','hh_veh_type','income'] +popSynDrop = ['vehicles','hh_veh_type'] +hh = pd.read_csv(popSynFile, names=popSynCols, dtype='Int64', engine=pdEngine) +hh['household_record'] = hh.index + 1 +hh.drop(popSynDrop, axis=1, inplace=True) +numberHouseholds = len(hh) + +# Load geography file +geogCols = ['subzone','county','county_name','state','puma','zone','chicago', + 'cbd','row_column','area','cmap'] +geogDrop = ['state','puma','row_column','state_puma'] +geog = pd.read_csv(geoFile, names=geogCols, engine=pdEngine) +geog.loc[geog.state.eq('IL'), 'state_puma'] = 1700000 + geog['puma'] +geog.loc[geog.state.eq('IN'), 'state_puma'] = 1800000 + geog['puma'] +geog.loc[geog.state.eq('WI'), 'state_puma'] = 5500000 + geog['puma'] +pumas = geog[['subzone','state_puma']].copy().reset_index(drop=True) +geog.drop(geogDrop, axis=1, inplace=True) + +# Load subzone summary data file +szCols = ['subzone','households','adults','workers','children', + 'income_category1','income_category2','income_category3', + 'income_category4','age_category1','age_category2','age_category3', + 'auto_commute_share','sidewalk_density'] +szDrop = ['adults','workers','children','income_category1', + 'income_category2','income_category3','income_category4', + 'age_category1','age_category2','age_category3'] +sz = pd.read_csv(szAttributesFile, names=szCols, engine=pdEngine) +totalHHs = sz['households'].sum() +sz.drop(szDrop, axis=1, inplace=True) + +# Load household work from home flag file +wfhCols = ['serial_number','wfh_flag','number_WFH_workers','tc14_not_working'] +wfhDrop = ['number_WFH_workers','tc14_not_working'] +wfh = pd.read_csv(wfhFile, names=wfhCols, engine=pdEngine) +wfh['household_record'] = wfh.index + 1 +wfh['wfh_flag'] = wfh['wfh_flag'].clip(upper=1) +wfh.drop(wfhDrop, axis=1, inplace=True) + +# Load household vehicle type category file +hhvtype = pd.read_csv(hhvtypeFile, dtype='Int64', engine=pdEngine) +hhvtype.rename(columns={'ADULT': 'adults', 'WORKER': 'workers', 'CHILD': + 'children', 'VEH': 'vehicles', 'AGE_INDEX': + 'age_category', 'HHVTYPE': 'hh_veh_type'}, + inplace=True) + +# Load trip enumeration data for non-Work From Home households +# This identifies the set of survey households that will be sampled +enumNoWfhData1Cols = ['state_puma','hh_veh_type','match_category', + 'choice_start','choice_end'] +enumData1 = pd.read_csv(enumerateNoWfhDataFile1, names=enumNoWfhData1Cols, + dtype='Int64', engine=pdEngine) + +# Load trip enumeration choices data for non-Work From Home households +# This identifies the survey household numbers and probability of selection +enumNoWfhData2Cols = ['survey_number','cumul_probability'] +enumData2 = pd.read_csv(enumerateNoWfhDataFile2, names=enumNoWfhData2Cols, + engine=pdEngine) + +# Load trip enumeration data for Work From Home households +# This identifies the set of survey households that will be sampled +enumWfhData1Cols = ['state_puma','hh_type','match_category','choice_start', + 'choice_end'] +enumWfhData1 = pd.read_csv(enumerateWfhDataFile1, names=enumWfhData1Cols, + dtype='Int64', engine=pdEngine) + +# Load trip enumeration choices data for Work From Home households +# This identifies the survey household numbers and probability of selection +enumWfhData2 = pd.read_csv(enumerateWfhDataFile2, names=enumNoWfhData2Cols, + engine=pdEngine) + +# convert enumeration selection boundaries from FORTRAN index to Python index +# (1-based to 0-based) +enumData1['choice_start'] = enumData1['choice_start'] - 1 +enumWfhData1['choice_start'] = enumWfhData1['choice_start'] - 1 +enumData1['choice_end'] = enumData1['choice_end'] - 1 +enumWfhData1['choice_end'] = enumWfhData1['choice_end'] - 1 + +# Convert Lee County state_puma to match GEOG_IN.TXT values, if needed +enumData1.loc[enumData1['state_puma'] == 1700104, 'state_puma'] = 1717104 +enumWfhData1.loc[enumWfhData1['state_puma'] == 1700104, 'state_puma'] = 1717104 + +# Convert from cumulative probability to individual probabilities +enumData2['p'] = enumData2['cumul_probability'].shift(1).fillna(0) +enumData2['probability'] = np.where(enumData2['p'] < 1, + enumData2['cumul_probability'] + - enumData2['p'], + enumData2['cumul_probability']) +enumWfhData2['p'] = enumWfhData2['cumul_probability'].shift(1).fillna(0) +enumWfhData2['probability'] = np.where(enumWfhData2['p'] < 1, + enumWfhData2['cumul_probability'] + - enumWfhData2['p'], + enumWfhData2['cumul_probability']) + +# Load file of household travel survey data +surveyCols = ['state_puma','hh_veh_type','survey_number','adults_survey', + 'workers_survey','nonworkers_survey','children_survey', + 'children12-15_survey','vehicles_survey'] +for i in range(1,50): + fieldName = f"trips{i}" + surveyCols.append(fieldName) +surveyDrop = ['state_puma','hh_veh_type','adults_survey','workers_survey', + 'nonworkers_survey','children_survey','children12-15_survey', + 'vehicles_survey'] +surveyHouseholds = pd.read_csv(travelSurveyFile, names=surveyCols, + engine=pdEngine) +surveyHouseholds.drop(surveyDrop, axis=1, inplace=True) + +# Load file of group quarters residents +gqCols = ['subzone','military','college','other16-64','other65'] +gq = pd.read_csv(groupQuartersFile, names=gqCols, dtype='Int64', + engine=pdEngine) +groupQuarters = pd.melt(gq, id_vars='subzone', var_name='gq_type', + value_name='gq_persons') +groupQuarters['gq_persons'] = groupQuarters['gq_persons'].astype(int) +numberGqHousholds = groupQuarters['gq_persons'].sum() + +# Load file of group quarters trip rates 3-33, add trip type 1 placeholder +gqTripRates = pd.read_csv(groupQuartersTripsFile, names=['trip_type', + 'trip_production_rate'], + engine=pdEngine) +new_row = {'trip_type': 1, 'trip_production_rate': 0.0} +gqTripRates.loc[len(gqTripRates)] = new_row +gqTripRates.sort_values('trip_type', inplace=True) + +# Load airport subzone file +airports = pd.read_csv(airportFile, usecols=['subzone','year_open'], + engine=pdEngine) +airports['notairport_flag'] = np.where(real_year >= airports['year_open'], 0, 1) +airports.drop('year_open', axis=1, inplace=True) + +# Load subzone high school and college enrollment file +schools = pd.read_csv(enrollmentFile, names=['subzone','enrollment'], + engine=pdEngine) + +# Load subzone attractions file +attrCols = ['subzone','retail_employment','total_employment', + 'high_earner_share'] +attractions = pd.read_csv(attractionsFile, names=attrCols, engine=pdEngine) +attractions['high_earner_share'] = attractions['high_earner_share'].round(3) +attractions['nonretail_employment'] = (attractions['total_employment'] + - attractions['retail_employment']) +attractions['low_earner_share'] = (1.0 - attractions['high_earner_share'] + ).round(3) + +# Load file of coefficients for attractions allocation +coeffsAttr = pd.read_csv(coeffsAttractFile) + +# Load file of coefficients for nonhome productions allocation +coeffsProd = pd.read_csv(coeffsProdsFile) + +# Load file of external home-workplace production and attraction shares +extCols = ['state_puma','ext_prod_factor','ext_attr_factor'] +extrnShare = pd.read_csv(externalShares, names=extCols, engine=pdEngine) +# Convert Lee County state_puma to match GEOG_IN.TXT values, if needed +extrnShare.loc[extrnShare['state_puma'] == 1700104, 'state_puma'] = 1717104 + +# Attach data to synthetic households +hh = hh.merge(geog, how='left', on='subzone', copy=False) +hh = hh.merge(sz, how='left', on='subzone', copy=False) +hh = hh.merge(wfh, how='left', on=['household_record','serial_number'], + copy=False) + +# Prepare variables +# Set household category attributes to maximum values for HHTYPE and HHVTYPE +hh['adults'] = hh['adults'].clip(upper=4) +hh['workers'] = hh['workers'].clip(upper=3) +hh['children'] = hh['children'].clip(upper=3) +hh['nonworkers'] = hh['adults'] - hh['workers'] +# Set sidewalk density to maximum subzone value +hh['sidewalk_density'] = hh['sidewalk_density'].clip(upper=sidewalkMax) + +# ---------------------------------------------------------------------------- +# Verify values are within acceptable ranges. +# ---------------------------------------------------------------------------- +assert totalHHs == len(hh), "Number of households is not consistent" +assert hh['adults'].min() == 1, "Minimum number of adults for HHTYPE is " \ + "below 1" +assert hh['adults'].max() == 4, "Maximum number of adults for HHTYPE is not 4" +assert hh['workers'].min() == 0, "Minimum number of workers for HHTYPE is" \ + "not 0" +assert hh['workers'].max() == 3, "Maximum number of workers for HHTYPE is " \ + "not 3" +assert hh['children'].min() == 0, "Minimum number of children for HHTYPE is" \ + "not 0" +assert hh['children'].max() == 3, "Maximum number of children for HHTYPE is" \ + "not 3" +assert hh['age_category'].min() == 1, "Minimum age of head of householder " \ + "category for HHTYPE is not 1" +assert hh['age_category'].max() == 3, "Maximum age of head of householder" \ + "category for HHTYPE is not 3" +assert hh['income_category'].min() == 1, "Minimum income category for HHTYPE" \ + "is not 1" +assert hh['income_category'].max() == 4, "Maximum income category for HHTYPE" \ + "is not 4" +assert hh['sidewalk_density'].max() == tgConfig['sidewalkMaxDensity'], "Maximum" \ + "sidewalk density does not match yaml file " \ + "parameter" +assert hh['nonworkers'].min() == 0, "Minimum number of nonworkers is not 0" +assert hh['wfh_flag'].min() == 0, "Minimum WFH flag is not 0" +assert hh['wfh_flag'].max() == 1, "Maximum WFH flag is not 1" +logging.info(' -- Number of households to process: {0:,}'.format(len(hh))) + +# ---------------------------------------------------------------------------- +# Step 2. Run the vehicle availability model for each household. +# ---------------------------------------------------------------------------- +logging.info("Running the Vehicle Availability model") + +# Separate households by number of adults to apply the appropriate model +adult1 = hh[hh.adults.eq(1)].copy().reset_index() +adult2 = hh[hh.adults.eq(2)].copy().reset_index() +adult3 = hh[hh.adults.gt(2)].copy().reset_index() + +# Apply vehicle availability model +adult1['vehicles'] = veh.vehOwnOneAdult(adult1[['sidewalk_density', + 'row_column', 'age_category', + 'workers', 'income_category', + 'auto_commute_share'] + ].to_numpy(), rng=rng + ).astype(int) +adult2['vehicles'] = veh.vehOwnTwoAdult(adult2[['sidewalk_density', + 'row_column', 'age_category', + 'workers', 'income_category', + 'auto_commute_share', + 'children']].to_numpy(), + rng=rng).astype(int) +adult3['vehicles'] = veh.vehOwnThreeAdult(adult3[['sidewalk_density', + 'row_column', 'age_category', + 'workers', 'income_category', + 'auto_commute_share', + 'nonworkers']].to_numpy(), + rng=rng).astype(int) + +# Re-combine the households and write simulated vehicles file +hh = pd.concat([adult1, adult2, adult3], ignore_index=True, sort=False) +hh.sort_values('household_record', inplace=True) +logging.info(' - 0-vehicle households: {0:>10,}'.format((hh['vehicles'] + == 0).sum())) +logging.info(' - 1-vehicle households: {0:>10,}'.format((hh['vehicles'] + == 1).sum())) +logging.info(' - 2-vehicle households: {0:>10,}'.format((hh['vehicles'] + == 2).sum())) +logging.info(' - 3+-vehicle households: {0:>9,}'.format((hh['vehicles'] + == 3).sum())) +logging.info(' --> Writing {0:,} records to {1}'.format(len(hh), + Path(simVehicles).name)) +hh.to_csv(simVehicles, columns=['serial_number','vehicles', + 'household_record'], index=False) + +# Apply household vehicle type category (HHVTYPE) +hh = hh.merge(hhvtype, how='left', on=['adults','workers','children', + 'vehicles','age_category'], + copy=False) +assert hh['vehicles'].min() == 0, "Minimum household vehicles is not 0" +assert hh['vehicles'].max() < 4, "Maximum household vehicles is not within " \ + "range" +assert hh['hh_veh_type'].min() > 0, "Minimum household vehicle type code " \ + "is not greater than 0" +assert hh['hh_veh_type'].max() < 625, "Maximum household vehicle type code " \ + "is not within range" + +# Write household vehicle type file +veh = hh[['subzone','zone','hh_veh_type']].reset_index(drop=True) +veh.sort_values(by=['zone', 'subzone'], inplace=True) +logging.info(' --> Writing {0:,} records to {1}'.format( + len(veh), Path(hhVehtypeFile).name)) +veh.to_csv(hhVehtypeFile, header=False, index=False) + +# ---------------------------------------------------------------------------- +# Step 3. Run the household trip enumeration process. +# ---------------------------------------------------------------------------- +logging.info('Running the Household Trip Enumeration Process') +logging.info(' -- Non-Work From Home households') +logging.info(' -- Preparing the data') + +# Attach trip enumeration data to households +nowfh = hh[hh.wfh_flag.eq(0)].reset_index(drop=True) +nowfh = nowfh.merge(enumData1, how='left', on=['state_puma','hh_veh_type'], + copy=False) +assert nowfh.isnull().any().sum() == 0, "Non-work from home data have" \ + "missing values" +# Create data arrays +selection_array = enumData2['survey_number'].to_numpy().astype(np.int64) +probability_array = enumData2['probability'].to_numpy() + +# Create a dictionary of survey household ids to track how many times each is +# selected during the trip enumeration process +households_chosen = {key: 0 for key in enumData2['survey_number'].unique()} + +# Implement household trip enumeration +logging.info(' -- Running trip enumeration') +nowfh['survey_number'] = enumer.tripEnumeration( + nowfh['choice_start'].to_numpy(), + nowfh['choice_end'].to_numpy(), + selection_array, + probability_array, + rng=rng, + households_chosen=households_chosen, + replicateMax=replicateMax, + resampleMax=resampleMax +) + +assert nowfh['survey_number'].min() >= enumData2['survey_number'].min(), \ + "Invalid non-work from home survey household selected during enumeration" +assert nowfh['survey_number'].max() <= enumData2['survey_number'].max(), \ + "Invalid non-work from home survey household selected during enumeration" + +# Output dictionary of households selected during trip enumeration +dictList = [[key, value] for key, value in households_chosen.items()] +nowfhCount = pd.DataFrame(dictList, columns=['survey_household', + 'selection_count']) +nowfhCount.sort_values(['selection_count'], ascending=False, inplace=True) +nowfhCount.to_csv(nowfhEnumCount, index=False) +# ---------------------------------------------------------------------------- +logging.info(' -- Work From Home households') +logging.info(' -- Preparing the data') + +# Attach trip enumeration data to households +wfh = hh[hh.wfh_flag.eq(1)].reset_index(drop=True) +wfh = wfh.merge(enumWfhData1, how='left', on=['state_puma','hh_type'], + copy=False) +assert wfh.isnull().any().sum() == 0, "Work from home data have" \ + "missing values" +# Create data arrays +selection_array = enumWfhData2['survey_number'].to_numpy() +probability_array = enumWfhData2['probability'].to_numpy() + +# Create a dictionary of survey household ids to track selections +wfh_households_chosen = {key: 0 for key in enumWfhData2['survey_number']. + unique()} + +# Implement household trip enumeration +logging.info(' -- Running trip enumeration') +wfh['survey_number'] = enumer.tripEnumeration( + wfh['choice_start'].to_numpy(), + wfh['choice_end'].to_numpy(), + selection_array, + probability_array, + rng=rng, + households_chosen=wfh_households_chosen, + replicateMax=replicateMax, + resampleMax=resampleMax +) +assert wfh['survey_number'].min() >= enumWfhData2['survey_number'].min(), \ + "Invalid work from home survey household selected during enumeration" +assert wfh['survey_number'].max() <= enumWfhData2['survey_number'].max(), \ + "Invalid work from home survey household selected during enumeration" + +# Output dictionary of households selected during trip enumeration +dictList = [[key, value] for key, value in wfh_households_chosen.items()] +wfhCount = pd.DataFrame(dictList, columns=['survey_household', + 'selection_count']) +wfhCount.sort_values(['selection_count'], ascending=False, inplace=True) +wfhCount.to_csv(wfhEnumCount, index=False) + +# recombine the household data +households = pd.concat([nowfh, wfh], ignore_index=True, sort=False) +households.sort_values('household_record', inplace=True) + +# split out fields for HI_HHENUM_TRIP_OUT.CSV +housholds_out = households[['household_record', 'subzone', 'survey_number', + 'state_puma', 'hh_type', 'hh_veh_type', + 'vehicles', 'row_column', 'serial_number', + 'match_category', 'wfh_flag', 'income', + 'children']].copy().reset_index(drop=True) +householdEnum = housholds_out.merge(surveyHouseholds, how='left', + on='survey_number', copy=True + ).reset_index(drop=True) + +# Redefine work trips for high income households +householdEnum['trips2'] = np.where(householdEnum['income'] >= regionalMedianIncome, + householdEnum['trips1'], + 0) +householdEnum['trips1'] = np.where(householdEnum['income'] >= regionalMedianIncome, + 0, + householdEnum['trips1']) +householdEnum.sort_values('household_record', inplace=True) + +if writeOptional: + logging.info(' --> Writing {0:,} records to {1}'.format( + len(householdEnum), Path(syntheticHHTrips).name)) + householdEnum.to_csv(syntheticHHTrips, index=False) + +# prepare data for PRODS_HH_OUT.CSV +# Summarize household productions by subzone, trip type and four household +# categories: +# 1 = 0 children and 0 vehicles +# 2 = 1 or more children and 0 vehicles +# 3 = 0 children and 1 or more vehicles +# 4 = 1 or more children and 1 or more vehicles +householdEnum.loc[householdEnum.children.eq(0) & householdEnum.vehicles.eq(0), + 'household_category'] = 1 +householdEnum.loc[householdEnum.children.ge(1) & householdEnum.vehicles.eq(0), + 'household_category'] = 2 +householdEnum.loc[householdEnum.children.eq(0) & householdEnum.vehicles.ge(1), + 'household_category'] = 3 +householdEnum.loc[householdEnum.children.ge(1) & householdEnum.vehicles.ge(1), + 'household_category'] = 4 +dropCols = ['children','vehicles','survey_number','household_record', + 'state_puma','hh_type','hh_veh_type','vehicles', 'row_column', + 'serial_number', 'match_category', 'income'] +householdEnum.drop(dropCols, axis=1, inplace=True) +hhProds = pd.melt(householdEnum, id_vars=['subzone','wfh_flag', + 'household_category'], + var_name='trip_type', + value_name='productions') +prods = hhProds.groupby(['subzone','wfh_flag','household_category', + 'trip_type']).agg({'productions': 'sum'} + ).reset_index() +prods['trip_type'] = prods['trip_type'].str.replace('trips', '', + regex=False).astype(int) +prods.sort_values(['subzone','wfh_flag','household_category','trip_type'], + inplace=True) + +if writeOptional: + logging.info(' --> Writing {0:,} records to {1}'.format( + len(prods), Path(householdProductions).name)) + prods.to_csv(householdProductions, index=False) + +# Prepare household data for production and attraction allocations +# Summarize household productions by trip type, subzone and WFH flag +# Summarize household productions by trip type and WFH flag +householdTrips = prods.groupby(['subzone','trip_type','wfh_flag']).agg({ + 'productions': 'sum'}).reset_index() +householdTrips.rename(columns={'productions':'hh_productions'}, + inplace=True) +tripWfh = prods.groupby(['trip_type','wfh_flag']).agg({'productions': 'sum'} + ).reset_index() +tripWfh.rename(columns={'productions':'trip_hh_productions'}, inplace=True) + +# ---------------------------------------------------------------------------- +# Step 4. Calculate group quarters trip productions +# ---------------------------------------------------------------------------- +logging.info('Calculating Group Quarters Trip Productions') + +# Determine workers and nonworkers +groupQuarters['workers'] = 0.0 +groupQuarters.loc[groupQuarters.gq_type.eq('military'), 'workers'] = ( + groupQuarters['gq_persons'] * militaryWorkers) +groupQuarters.loc[groupQuarters.gq_type.eq('college'), 'workers'] = ( + groupQuarters['gq_persons'] * univWorkers) +groupQuarters.loc[groupQuarters.gq_type.eq('other16-64'), 'workers'] = ( + groupQuarters['gq_persons'] * other1664Workers) +groupQuarters.loc[groupQuarters.gq_type.eq('other65'), 'workers'] = ( + groupQuarters['gq_persons'] * other65Workers) +groupQuarters['workers'] = groupQuarters['workers'].round(3) +groupQuarters['nonworkers'] = 0.0 +groupQuarters['nonworkers'] = (groupQuarters['gq_persons'] + - groupQuarters['workers']).round(3) +groupQuarters = groupQuarters.merge(gqTripRates, how='cross', copy=False) + +# Calculate Worker trip productions +# 1 - Home-work low income household +groupQuarters.loc[groupQuarters.gq_type.eq('military') & + groupQuarters.trip_type.eq(1), 'productions'] = ( + groupQuarters['workers'] * militaryWorkTrips) +groupQuarters.loc[groupQuarters.gq_type.eq('college') & + groupQuarters.trip_type.eq(1), 'productions'] = ( + groupQuarters['workers'] * univWorkTrips) +groupQuarters.loc[groupQuarters.gq_type.eq('other16-64') & + groupQuarters.trip_type.eq(1), 'productions'] = ( + groupQuarters['workers'] * other1664WorkTrips) +groupQuarters.loc[groupQuarters.gq_type.eq('other65') & + groupQuarters.trip_type.eq(1), 'productions'] = ( + groupQuarters['workers'] * other65WorkTrips) +# 4 - Home-school (only for 16-64) +groupQuarters.loc[groupQuarters.gq_type.eq('other16-64') & + groupQuarters.trip_type.eq(4), 'productions'] = ( + groupQuarters['workers'] + * groupQuarters['trip_production_rate']) +# Remaining Worker trip types applied to all GQ persons +workTypes = [3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] +groupQuarters.loc[groupQuarters['trip_type'].isin(workTypes), 'productions'] = ( + groupQuarters['workers'] + * groupQuarters['trip_production_rate']) + +# Calculate Nonworker trip productions +# 21 - Home-school (only for 16-64) +groupQuarters.loc[groupQuarters.gq_type.eq('other16-64') & + groupQuarters.trip_type.eq(21), 'productions'] = ( + groupQuarters['nonworkers'] + * groupQuarters['trip_production_rate']) +# Remaining Nonworker trip types applied to all GQ persons except military +skipType = ['military'] +nonworkTypes = [22,23,24,25,26,27,28,29,30,31,32,33] +groupQuarters.loc[groupQuarters['trip_type'].isin(nonworkTypes) & + ~groupQuarters['gq_type'].isin(skipType), 'productions'] = ( + groupQuarters['nonworkers'] + * groupQuarters['trip_production_rate']) + +groupQuarters.fillna(0, inplace=True) +groupQuarters['productions'] = groupQuarters['productions'].round(3) +groupQuarters.drop('trip_production_rate', axis=1, inplace=True) + +if writeOptional: + logging.info(' --> Writing {0:,} records to {1}'.format(len(groupQuarters), + Path(groupQuartersProductions).name)) + groupQuarters.to_csv(groupQuartersProductions, index=False) + +# Prepare GQ data for production and attraction allocations +# Summarize GQ productions by trip type and subzone +# Summarize GQ productions by trip type +groupQuartersTrips = groupQuarters.groupby(['subzone','trip_type']).agg( + {'productions': 'sum'}).reset_index() +groupQuartersTrips['wfh_flag'] = 0 +groupQuartersTrips.rename(columns={'productions':'gq_productions'}, + inplace=True) +gqTripTypeTrips = groupQuarters.groupby(['trip_type']).agg( + {'productions': 'sum'}).reset_index() +gqTripTypeTrips.rename(columns={'productions':'trip_gq_productions'}, + inplace=True) +groupQuartersTrips = groupQuartersTrips.merge(gqTripTypeTrips, how='left', + on='trip_type', copy=False) +gq1Sum = int(groupQuarters['productions'].sum()) +gq2Sum = int(groupQuartersTrips['gq_productions'].sum()) +assert gq1Sum == gq2Sum, "Mismatch in GQ productions" + +# ---------------------------------------------------------------------------- +# Step 5. Allocate trip productions and attractions for non-home trip ends +# ---------------------------------------------------------------------------- +logging.info('Allocating Productions and Attractions for Non-Home Trip Ends') +logging.info(' -- Preparing the data') + +totalHouseholds = numberGqHousholds + numberHouseholds + +# Create complete template of subzone-trip type-wfh flag options +prodTemplate = geog[['subzone', 'zone', 'cbd']].copy().reset_index(drop=True) +hhPart = sz[['subzone', 'households']].copy().reset_index(drop=True) +tripTypes = coeffsAttr[['trip_type']].copy().reset_index(drop=True) +tripTypes.drop_duplicates(subset=['trip_type'], keep='first', inplace=True) +prodTemplate = prodTemplate.merge(hhPart, how='left', on='subzone', + copy=False) +prodTemplate = prodTemplate.merge(attractions, how='left', on='subzone', + copy=False) +prodTemplate = prodTemplate.merge(airports, how='left', on='subzone', + copy=False) +prodTemplate = prodTemplate.merge(schools, how='left', on='subzone', + copy=False) +prodTemplate = prodTemplate.merge(tripTypes, how='cross', copy=False) +prodTemplate['notairport_flag'] = prodTemplate['notairport_flag'].fillna(1) +prodTemplate['wfh_flag'] = 0 +prodWFH = prodTemplate.copy() +prodWFH['wfh_flag'] = 1 +prodTemplate = pd.concat([prodTemplate, prodWFH], ignore_index=True, + sort=False) +assert len(prodTemplate) == (17418 * 49 * 2), "prodTemplate is not complete" + +logging.info(' -- Allocating non-home productions') +# Attach household and group quarters productions +prodTemplate = prodTemplate.merge(householdTrips, how='left', + on=['subzone','trip_type','wfh_flag'], + copy=False) +prodTemplate = prodTemplate.merge(tripWfh, how='left', on=['trip_type', + 'wfh_flag'], + copy=False) +prodTemplate = prodTemplate.merge(groupQuartersTrips, how='left', + on=['subzone','trip_type','wfh_flag'], + copy=False) +prodTemplate.fillna(0, inplace=True) + +# Attach nonhome production coefficients and calculate shares +prodTemplate = prodTemplate.merge(coeffsProd, how='left', + on=['cbd','trip_type','wfh_flag'], + copy=False) +prodTemplate['sz_share'] = run_formula(prodTemplate) +prodTemplate.drop('weight_formula', axis=1, inplace=True) + +logging.info(' -- Allocating attractions') +# Attach attraction coefficients and calculate shares +prodTemplate = prodTemplate.merge(coeffsAttr, how='left', + on=['cbd','trip_type','wfh_flag'], + copy=False) +prodTemplate['sz_share_attr'] = run_formula(prodTemplate) + +# Sum subzone shares to determine trip type totals +tripTotals = prodTemplate.groupby(['trip_type','wfh_flag']).agg( + {'sz_share': 'sum', + 'sz_share_attr': 'sum'} + ).round(3).reset_index() +tripTotals.rename(columns={'sz_share':'tripShare', + 'sz_share_attr':'tripShareAttr'}, inplace=True) +prodTemplate = prodTemplate.merge(tripTotals, how='left', + on=['trip_type','wfh_flag'], copy=False) + +logging.info(' -- Updating productions') +homeTypes = [1,2,3,4,5,6,7,21,22,23,24,34,35,36,37] +prodTemplate['sz_prods'] = np.where(prodTemplate['trip_type'].isin(homeTypes), + prodTemplate['hh_productions'], + prodTemplate['sz_share'] + / prodTemplate['tripShare'] + * prodTemplate['trip_hh_productions'] + ).round(1) + +prodTemplate['sz_gq_prods'] = np.where(prodTemplate['trip_type'].isin(homeTypes), + prodTemplate['gq_productions'], + prodTemplate['sz_share'] + / prodTemplate['tripShare'] + * prodTemplate['trip_gq_productions'] + ).round(1) + +logging.info(' -- Updating attractions') +notUsed = [2,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49] +prodTemplate['sz_attrs'] = (prodTemplate['sz_share_attr'] + / prodTemplate['tripShareAttr'] + * prodTemplate['trip_hh_productions']).round(1) +prodTemplate['sz_gq_attrs'] = np.where(prodTemplate['trip_type'].isin(notUsed), + prodTemplate['gq_productions'], + prodTemplate['sz_share_attr'] + / prodTemplate['tripShareAttr'] + * prodTemplate['trip_gq_productions'] + ).round(1) + +firstPass = prodTemplate[['subzone', 'zone', 'wfh_flag', 'trip_type', + 'sz_prods', 'sz_attrs', 'sz_gq_prods', + 'sz_gq_attrs']].copy().reset_index(drop=True) + +if writeOptional: + logging.info(' --> Writing {0:,} records to {1}'.format(len(firstPass), + Path(firstProdsAttrs).name)) + firstPass.to_csv(firstProdsAttrs, index=False) + +# ---------------------------------------------------------------------------- +# Step 6. Factor external home-based productions and attractions +# ---------------------------------------------------------------------------- +logging.info('Factoring External Home-Workplace Productions and Attractions') + +# Apply external factors to trip type 1 and 2 +adjusted = firstPass[firstPass.trip_type.le(2)].copy().reset_index(drop=True) +unadjusted = firstPass[firstPass.trip_type.gt(2)].copy().reset_index(drop=True) +adjusted = adjusted.merge(pumas, how='left', on='subzone', copy=False) +adjusted = adjusted.merge(extrnShare, how='left', on='state_puma', + copy=False) +adjusted['sz_ext_prods'] = (adjusted['sz_prods'] * adjusted['ext_prod_factor'] + ).round(1) +adjusted['sz_ext_attrs'] = adjusted['sz_attrs'] * adjusted['ext_attr_factor'] + +# Balance external attractions to productions +extTotals = adjusted.groupby(['wfh_flag','trip_type']).agg( + {'sz_ext_prods': 'sum', + 'sz_ext_attrs': 'sum'} + ).reset_index() + +extTotals.rename(columns={'sz_ext_prods':'total_ext_prods', + 'sz_ext_attrs':'total_ext_attrs'}, inplace=True) +adjusted = adjusted.merge(extTotals, how='left', on=['wfh_flag', 'trip_type'], + copy=True) +adjusted['sz_ext_attrs'] = (adjusted['sz_ext_attrs'] + * adjusted['total_ext_prods'] + / adjusted['total_ext_attrs']) + +# Update productions and attractions, adjust external attractions if needed +adjusted['sz_ext_attrs'] = np.where(adjusted['sz_ext_attrs'] + > adjusted['sz_attrs'], + adjusted['sz_attrs'], + adjusted['sz_ext_attrs']).round(1) +adjusted['sz_prods'] = (adjusted['sz_prods'] - adjusted['sz_ext_prods'] + ).round(1) +adjusted['sz_attrs'] = (adjusted['sz_attrs'] - adjusted['sz_ext_attrs'] + ).round(1) + +if writeOptional: + logging.info(' --> Writing {0:,} records to {1}'.format(len(adjusted), + Path(extrnlProdsAttrs).name)) + writeCols = ['subzone', 'zone', 'wfh_flag', 'trip_type', 'sz_ext_prods', + 'sz_ext_attrs'] + adjusted.to_csv(extrnlProdsAttrs, columns=writeCols, index=False) + +# ---------------------------------------------------------------------------- +# Step 7. Finalize productions and attractions +# ---------------------------------------------------------------------------- +logging.info('Finalizing Productions and Attractions') + +dropCols = ['state_puma', 'ext_prod_factor', 'ext_attr_factor', 'sz_ext_prods', + 'sz_ext_attrs', 'total_ext_prods', 'total_ext_attrs'] +adjusted.drop(dropCols, axis=1, inplace=True) +prodsAttrs = pd.concat([adjusted, unadjusted], ignore_index=True, sort=False) +prodsAttrs.sort_values(['trip_type','subzone'], inplace=True) +prodsAttrs['sz_prods'] = prodsAttrs['sz_prods'] + prodsAttrs['sz_gq_prods'] +prodsAttrs['sz_attrs'] = prodsAttrs['sz_attrs'] + prodsAttrs['sz_gq_attrs'] + +# Write final productions and attractions +noWfhPA = prodsAttrs[prodsAttrs.wfh_flag.eq(0)].copy().reset_index(drop=True) +fixed_width(finalProdsAttrs, noWfhPA) +logging.info(' --> Writing {0:,} records to {1}'.format(len(noWfhPA), + Path(finalProdsAttrs).name)) +# +wfhPA = prodsAttrs[prodsAttrs.wfh_flag.eq(1)].copy().reset_index(drop=True) +fixed_width(finalWfhProdsAttrs, wfhPA) +logging.info(' --> Writing {0:,} records to {1}'.format(len(wfhPA), + Path(finalWfhProdsAttrs).name)) + +# Final summary +workers = prodsAttrs[prodsAttrs.trip_type.le(20)].copy() +nonworkers = prodsAttrs[prodsAttrs.trip_type.ge(21) & + prodsAttrs.trip_type.le(33)].copy() +children = prodsAttrs[prodsAttrs.trip_type.ge(34)].copy() +logging.info('Final Results') +logging.info(' - Workers') +logging.info(' - Productions: {0:>12,.1f}'.format(workers['sz_prods'].sum())) +logging.info(' - Attractions: {0:>12,.1f}'.format(workers['sz_attrs'].sum())) +logging.info(' - Nonworking Adults') +logging.info(' - Productions: {0:>12,.1f}'.format(nonworkers['sz_prods'].sum())) +logging.info(' - Attractions: {0:>12,.1f}'.format(nonworkers['sz_attrs'].sum())) +logging.info(' - Children 12-15') +logging.info(' - Productions: {0:>12,.1f}'.format(children['sz_prods'].sum())) +logging.info(' - Attractions: {0:>12,.1f}'.format(children['sz_attrs'].sum())) +logging.info(' - Total') +logging.info(' - Productions: {0:>12,.1f}'.format(prodsAttrs['sz_prods'].sum())) +logging.info(' - Attractions: {0:>12,.1f}'.format(prodsAttrs['sz_attrs'].sum())) + +t_omega = timeit.default_timer() +logging.info('Trip Generation model took {0:.2f} minutes for {1:,} households' + .format((t_omega-t_alpha)/60, len(hh))) +logging.info('Trip Generation model finished') \ No newline at end of file diff --git a/Database/trip_generation/vehicle_availability.py b/Database/trip_generation/vehicle_availability.py new file mode 100644 index 0000000..3349c74 --- /dev/null +++ b/Database/trip_generation/vehicle_availability.py @@ -0,0 +1,326 @@ +""" +Filename: vehicle_availability.py +Author: Craig Heither +Description: These functions are the household vehicle availability model + for trip generation. +""" + +import numpy as np + +def vehOwnOneAdult(rows, rng=None): + """ + Vehicle ownership model for 1-adult households. + + Parameters + ---------- + rows : array_like + Six inputs: [sidewalk_density, row_column, age_category, workers, + income_category, auto_commute_share] + rng : numpy.random.Generator, optional + A Numpy Generator instance for reproducible results. If None, uses + np.random.default_rng(). + + Returns + ------- + ndarray + Integer array of vehicle counts (0..2). + """ + + # Read household parameters + rows = np.asarray(rows) + if rows.ndim == 1: + rows = rows.reshape(1, -1) + sidewalk = rows[:, 0].astype(float) + rowcol = rows[:, 1] + age = rows[:, 2] + workers = rows[:, 3] + income = rows[:, 4] + auto_comm = rows[:, 5].astype(float) + if rng is None: + rng = np.random.default_rng() + + # Lookup tables + bias1_lookup = np.array([-2.600, -2.676, -2.869, -3.082]) + bias2_lookup = np.array([-5.077, -4.823, -4.914, -4.984]) + hh_lookup = np.array([0.392, 0.401, 0.249]) + hh2_lookup = np.array([0.394, 0.465, 0.218]) + + # Safe indexing (rowcol and age are 1-based) + rowcol_idx = np.clip(rowcol.astype(int) - 1, 0, 3) + age_idx = np.clip(age.astype(int) - 1, 0, 2) + + # Utility for zero vehicles + COEF_PEF0 = 0.06165 + UTIL0 = COEF_PEF0 * sidewalk + + # Utility for one vehicle + COEF_WORKER = 0.4731 + COEF_HINC2 = 1.182 + COEF_HINC3 = 0.9910 + COEF_AUTOMS = 4.677 + COEF_PEF1 = 0.03188 + + bias1 = bias1_lookup[rowcol_idx] + hh_bias = hh_lookup[age_idx] + temp1 = (workers.astype(int) == 1).astype(int) + temp2 = (income.astype(int) != 1).astype(int) + temp3 = (income.astype(int) >= 3).astype(int) + + UTIL1 = (COEF_WORKER * temp1 + COEF_HINC2 * temp2 + COEF_HINC3 * temp3 + + COEF_AUTOMS * auto_comm + COEF_PEF1 * sidewalk + bias1 + hh_bias) + + # Utility for two or more vehicles + COEF_WORKER = 0.4731 + COEF_HINC2 = 1.766 + COEF_HINC3 = 1.690 + COEF_HINC4 = 0.4668 + COEF_AUTOMS = 4.677 + + bias2 = bias2_lookup[rowcol_idx] + hh_bias2 = hh2_lookup[age_idx] + temp1 = (workers.astype(int) == 1).astype(int) + temp2 = (income.astype(int) != 1).astype(int) + temp3 = (income.astype(int) >= 3).astype(int) + temp4 = (income.astype(int) == 4).astype(int) + + UTIL2 = (COEF_WORKER * temp1 + COEF_HINC2 * temp2 + COEF_HINC3 * temp3 + + COEF_HINC4 * temp4 + COEF_AUTOMS * auto_comm + bias2 + hh_bias2) + + # Vehicle ownership probabilities + expU = np.exp(np.vstack([UTIL0, UTIL1, UTIL2]).T) + denom = expU.sum(axis=1, keepdims=True) + probs = expU / denom + cumul_probs = probs.cumsum(axis=1) + + # Determine vehicle ownership level + u = rng.random(size=cumul_probs.shape[0]) + # Vectorized row-wise mapping: count how many cumulative probs are < u + idx = np.sum(u[:, None] > cumul_probs, axis=1) + # idx maps to 0->0 vehicles, 1->1, 2->2+ + return idx.astype(int) + +def vehOwnTwoAdult(rows, rng=None): + """ + Vehicle ownership model for 2-adult households. + + Parameters + ---------- + rows : array_like + Seven inputs: [sidewalk_density, row_column, age_category, workers, + income_category, auto_commute_share, children] + rng : numpy.random.Generator, optional + A Numpy Generator instance for reproducible results. If None, uses + np.random.default_rng(). + + Returns + ------- + ndarray + Integer array of vehicle counts (0..3). + """ + rows = np.asarray(rows) + if rows.ndim == 1: + rows = rows.reshape(1, -1) + sidewalk = rows[:, 0].astype(float) + rowcol = rows[:, 1] + age = rows[:, 2] + workers = rows[:, 3].astype(int) + income = rows[:, 4].astype(int) + auto_comm = rows[:, 5].astype(float) + children = rows[:, 6].astype(float) + if rng is None: + rng = np.random.default_rng() + + # Lookup tables + bias1_lookup = np.array([2.018, 2.259, 2.151, 1.925]) + bias2_lookup = np.array([-2.827, -2.637, -2.728, -3.144]) + bias3_lookup = np.array([-4.393, -3.944, -4.126, -4.302]) + hh_lookup = np.array([0.392, 0.401, 0.249]) + hh2_lookup = np.array([0.394, 0.465, 0.218]) + hh3_lookup = np.array([0.403, 0.574, 0.007]) + + # Safe indexing (rowcol and age are 1-based) + rowcol_idx = np.clip(rowcol.astype(int) - 1, 0, 3) + age_idx = np.clip(age.astype(int) - 1, 0, 2) + + # Utility for zero vehicles + COEF_PEF = 0.1280 + UTIL0 = COEF_PEF * sidewalk + + # Utility for one vehicle + COEF_HINC2 = 1.702 + COEF_PEF = 0.06309 + bias1 = bias1_lookup[rowcol_idx] + hh_bias = hh_lookup[age_idx] + temp1 = (income != 1).astype(int) + + UTIL1 = COEF_HINC2 * temp1 + COEF_PEF * sidewalk + bias1 + hh_bias + + # Utility for two vehicles + COEF_WORK1 = 0.6940 + COEF_WORK2 = 0.5198 + COEF_HINC2 = 2.466 + COEF_HINC3 = 0.8650 + COEF_HINC4 = 0.4517 + COEF_AUTOMS = 5.284 + COEF_CHILD = 0.2218 + COEF_PEF = 0.03359 + + bias2 = bias2_lookup[rowcol_idx] + hh_bias2 = hh2_lookup[age_idx] + temp1 = (workers > 0).astype(int) + temp2 = (workers > 1).astype(int) + temp3 = (income > 1).astype(int) + temp4 = (income > 2).astype(int) + temp5 = (income == 4).astype(int) + + UTIL2 = (COEF_WORK1 * temp1 + COEF_WORK2 * temp2 + COEF_HINC2 * temp3 + + COEF_HINC3 * temp4 + COEF_HINC4 * temp5 + COEF_AUTOMS * auto_comm + + COEF_CHILD * children + COEF_PEF * sidewalk + bias2 + hh_bias2) + + # Utility for three plus vehicles + COEF_WORK1 = 0.6940 + COEF_WORK2 = 0.5198 + COEF_HINC2 = 2.466 + COEF_HINC3 = 0.8650 + COEF_HINC4 = 0.8827 + COEF_AUTOMS = 5.284 + + bias3 = bias3_lookup[rowcol_idx] + hh_bias3 = hh3_lookup[age_idx] + temp1 = (workers > 0).astype(int) + temp2 = (workers > 1).astype(int) + temp3 = (income > 1).astype(int) + temp4 = (income > 2).astype(int) + temp5 = (income == 4).astype(int) + + UTIL3 = (COEF_WORK1 * temp1 + COEF_WORK2 * temp2 + COEF_HINC2 * temp3 + + COEF_HINC3 * temp4 + COEF_HINC4 * temp5 + COEF_AUTOMS * auto_comm + + bias3 + hh_bias3) + + # Vehicle ownership probabilities + expU = np.exp(np.vstack([UTIL0, UTIL1, UTIL2, UTIL3]).T) + denom = expU.sum(axis=1, keepdims=True) + probs = expU / denom + cumul_probs = probs.cumsum(axis=1) + + # Determine vehicle ownership level + u = rng.random(size=cumul_probs.shape[0]) + # Vectorized row-wise mapping: count how many cumulative probs are < u + idx = np.sum(u[:, None] > cumul_probs, axis=1) + return idx.astype(int) + +def vehOwnThreeAdult(rows, rng=None): + """ + Vehicle ownership model for 3-or-more-adult households. + + Parameters + ---------- + rows : array_like + Seven inputs: [sidewalk_density, row_column, age_category, workers, + income_category, auto_commute_share, nonworkers] + rng : numpy.random.Generator, optional + A Numpy Generator instance for reproducible results. If None, uses + np.random.default_rng(). + + Returns + ------- + ndarray + Integer array of vehicle counts (0..3). + """ + rows = np.asarray(rows) + if rows.ndim == 1: + rows = rows.reshape(1, -1) + sidewalk = rows[:, 0].astype(float) + rowcol = rows[:, 1] + age = rows[:, 2] + workers = rows[:, 3].astype(int) + income = rows[:, 4].astype(int) + auto_comm = rows[:, 5].astype(float) + nonworkers = rows[:, 6].astype(float) + if rng is None: + rng = np.random.default_rng() + + # Lookup tables + bias1_lookup = np.array([2.806, 2.552, 1.547, 2.272]) + bias2_lookup = np.array([-1.836, -2.139, -2.783, -2.430]) + bias3_lookup = np.array([-1.631, -1.789, -2.668, -2.278]) + hh_lookup = np.array([0.392, 0.401, 0.249]) + hh2_lookup = np.array([0.394, 0.465, 0.218]) + hh3_lookup = np.array([0.403, 0.574, 0.007]) + + # Safe indexing (rowcol and age are 1-based) + rowcol_idx = np.clip(rowcol.astype(int) - 1, 0, 3) + age_idx = np.clip(age.astype(int) - 1, 0, 2) + + # Utility for zero vehicles + COEF_PEF = 0.1703 + UTIL0 = COEF_PEF * sidewalk + + # Utility for one vehicle + COEF_WORK1 = 1.114 + COEF_HINC2 = 0.9492 + COEF_PEF = 0.06586 + + bias1 = bias1_lookup[rowcol_idx] + hh_bias = hh_lookup[age_idx] + temp1 = (workers > 0).astype(int) + temp2 = (income > 1).astype(int) + + UTIL1 = (COEF_WORK1 * temp1 + COEF_HINC2 * temp2 + COEF_PEF * sidewalk + + bias1 + hh_bias) + + # Utility for two vehicles + COEF_WORK1 = 1.114 + COEF_WORK2 = 0.7934 + COEF_HINC2 = 1.487 + COEF_HINC3 = 0.8723 + COEF_HINC4 = 1.390 + COEF_AUTOMS = 4.959 + COEF_PEF2 = 0.06586 + + bias2 = bias2_lookup[rowcol_idx] + hh_bias2 = hh2_lookup[age_idx] + temp1 = (workers > 0).astype(int) + temp2 = (workers > 1).astype(int) + temp3 = (income > 1).astype(int) + temp4 = (income > 2).astype(int) + temp5 = (income == 4).astype(int) + + UTIL2 = (COEF_WORK1 * temp1 + COEF_WORK2 * temp2 + COEF_HINC2 * temp3 + + COEF_HINC3 * temp4 + COEF_HINC4 * temp5 + COEF_AUTOMS * auto_comm + + COEF_PEF2 * sidewalk + bias2 + hh_bias2) + + # Utility for three plus vehicles + COEF_WORK1 = 1.114 + COEF_WORK2 = 0.7934 + COEF_WORK3 = 1.389 + COEF_HINC2 = 1.487 + COEF_HINC3 = 1.571 + COEF_HINC4 = 1.834 + COEF_ADULT = 0.1491 + COEF_AUTOMS = 4.959 + + bias3 = bias3_lookup[rowcol_idx] + hh_bias3 = hh3_lookup[age_idx] + temp1 = (workers > 0).astype(int) + temp2 = (workers > 1).astype(int) + temp3 = (workers > 2).astype(int) + temp4 = (income > 1).astype(int) + temp5 = (income > 2).astype(int) + temp6 = (income == 4).astype(int) + + UTIL3 = (COEF_WORK1 * temp1 + COEF_WORK2 * temp2 + COEF_WORK3 * temp3 + + COEF_HINC2 * temp4 + COEF_HINC3 * temp5 + COEF_HINC4 * temp6 + + COEF_ADULT * nonworkers + COEF_AUTOMS * auto_comm + bias3 + hh_bias3) + + # Vehicle ownership probabilities + expU = np.exp(np.vstack([UTIL0, UTIL1, UTIL2, UTIL3]).T) + denom = expU.sum(axis=1, keepdims=True) + probs = expU / denom + cumul_probs = probs.cumsum(axis=1) + + # Determine vehicle ownership level + u = rng.random(size=cumul_probs.shape[0]) + # Vectorized row-wise mapping: count how many cumulative probs are < u + idx = np.sum(u[:, None] > cumul_probs, axis=1) + return idx.astype(int) \ No newline at end of file diff --git a/Scripts/manage/env/CMAP-TRIP2.yml b/Scripts/manage/env/CMAP-TRIP2.yml deleted file mode 100644 index 674f2a1..0000000 --- a/Scripts/manage/env/CMAP-TRIP2.yml +++ /dev/null @@ -1,57 +0,0 @@ -# To use this file: -# conda env create -f CMAP-TRIP2.yml -name: CMAP-TRIP2 -channels: - - conda-forge -dependencies: - - altair=4.1 - - appdirs=1.4 - - cloudpickle=2.0 - - dask=2021.12 - - datashader=0.13 - - distributed=2021.12 - - fiona=1.8 - - geopandas=0.10 - - gh=2.4 - - git=2.34 - - graphviz=2.50 - - ipykernel=6.6 - - ipyparallel=8.1 - - ipywidgets=7.6 - - joblib=1.1 - - jupyter=1.0 - - jupyter_contrib_nbextensions=0.5 # On conda-forge only - - larch=5.5.9 - - matplotlib=3.5 - - nb_conda=2.2 - - notebook=6.4 - - numba=0.53 - - numpy=1.21 - - numexpr=2.7 - - pandas=1.3 - - pip=21.3 - - platypus-opt=1.0 - - plotly=5.5 - - pyarrow=6.0 - - pydot=1.4 - - pyscaffold=4.1 - - pytest=6.2 - - python=3.9 - - python-kaleido=0.2 # Plotly Static Image Export - - pyzmq=22.3 - - salib=1.4 - - scikit-learn=1.0 - - scipy=1.7 - - seaborn=0.11 - - shortuuid=1.0 - - sqlalchemy=1.4 - - statsmodels=0.13 - - tbb=2021.4 - - tbb4py=2021.4 - - xarray=0.20 - - zarr=2.10 - - pip: - - emat - # Uses relative paths to local packages - - -e ../../../src/Mode-Dest-TOD - - -e ../../../src/Mode-Dest-TOD/sharrow \ No newline at end of file diff --git a/Scripts/manage/env/activate_env.cmd b/Scripts/manage/env/activate_env.cmd deleted file mode 100644 index 7b67d2f..0000000 --- a/Scripts/manage/env/activate_env.cmd +++ /dev/null @@ -1,64 +0,0 @@ -@echo off - -rem activate_env.cmd [1] - -rem Activates an existing conda environment or, if it does not exist, -rem creates the environment before activating it. - -rem Parameters: -rem 1 : emme -rem Activate the custom Emme environment instead of the TBM -rem environment (default). - -if [%~1] == [emme] (set EMME_ENV=y) else (set EMME_ENV=n) -set PDIR=%~dp0 - -rem Define here the name of the TBM environment to be used. -set TBM_ENVNAME=CMAP-TRIP2 -rem Define here the name of the custom Emme environment to be used. -set EMME_ENVNAME=emme-plus - -call "%PDIR%set_condapath.cmd" -if %ERRORLEVEL% neq 0 (goto end) - -if %EMME_ENV%==y (set ENVNAME=%EMME_ENVNAME%) else (set ENVNAME=%TBM_ENVNAME%) -set ENVPATH=%CONDAPATH%\envs\%ENVNAME% - -rem Create it if it doesn't exist. -if not exist "%ENVPATH%\python.exe" ( - echo Python not found at "%ENVPATH%" - echo. - rem Activate the conda base environment. - rem Using call is required here, see: - rem https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files - call "%CONDAPATH%\Scripts\activate.bat" - if %ERRORLEVEL% neq 0 ( - echo Error in activating conda - goto end - ) - rem Create it from a file. - echo Creating %ENVNAME% environment - echo. - call conda env create -f "%PDIR%%ENVNAME%.yml" - - if %EMME_ENV%==y ( - rem Add the path configuration file to include Emme Python libraries. - copy "%PDIR%emme.pth" "%ENVPATH%\Lib\site-packages" - ) -) - -rem Activate it. -call "%CONDAPATH%\Scripts\activate.bat" "%ENVPATH%" -if %ERRORLEVEL% neq 0 ( - echo Error in activating %ENVNAME% - goto end -) else (goto activated) - -:end -echo. -pause -exit - -:activated -echo Active conda environment is %ENVNAME% -echo. \ No newline at end of file diff --git a/Scripts/manage/env/emme-plus.yml b/Scripts/manage/env/emme-plus.yml deleted file mode 100644 index e9cb7f3..0000000 --- a/Scripts/manage/env/emme-plus.yml +++ /dev/null @@ -1,16 +0,0 @@ -# To use this file: -# conda env create -f emme-plus_environment.yml -name: emme-plus -channels: - - conda-forge -dependencies: - - jinja2 - - markdown - - myst-parser - - openpyxl - - pyarrow - - python=3.11.6 - - pyyaml - - sphinx - - sphinx_rtd_theme - - tqdm \ No newline at end of file diff --git a/Scripts/manage/env/set_condapath.cmd b/Scripts/manage/env/set_condapath.cmd deleted file mode 100644 index cc8d49e..0000000 --- a/Scripts/manage/env/set_condapath.cmd +++ /dev/null @@ -1,46 +0,0 @@ -@echo off - -rem The `CONDAPATH` environment variable should be set before running this .cmd -rem It points to the place where conda is installed -rem Alternatively, if running in a conda prompt itself then CONDA_PREFIX will be set -if defined CONDAPATH ( - goto condafound -) -if defined CONDA_PREFIX ( - set CONDAPATH=%CONDA_PREFIX% - echo CONDA_PREFIX is "%CONDAPATH%" - goto condafound -) -rem Define here all the places where we might find the conda installation -rem If you try to run the model, you know that conda is installed, and the -rem model fails with "cannot find conda", then visit a conda prompt, -rem run `where conda`, and add the resulting path to this list. -for %%x in ( - %CONDAPATH% - %CONDA_PREFIX% - %LOCALAPPDATA%\mambaforge - %LOCALAPPDATA%\miniforge - %LOCALAPPDATA%\miniconda - %LOCALAPPDATA%\miniconda3 - %LOCALAPPDATA%\Anaconda3 - %USERPROFILE%\Anaconda3 - %USERPROFILE%\Anaconda - %USERPROFILE%\Anaconda2 - %USERPROFILE%\miniconda3 - %USERPROFILE%\miniconda - %USERPROFILE%\miniconda2 -) do ( - if exist "%%x\Scripts\activate.bat" ( - set CONDAPATH=%%x - goto condafound - ) -) -echo Cannot find conda in any of the usual places. -echo CONDAPATH is not defined, first run set CONDAPATH=C:\... to point to the conda installation. -echo. -pause -exit - -:condafound -echo CONDAPATH is "%CONDAPATH%" -echo. \ No newline at end of file diff --git a/Scripts/manage_envs/cmap-modedest/cmap-modedest.yml b/Scripts/manage_envs/cmap-modedest/cmap-modedest.yml new file mode 100644 index 0000000..d44d1a7 --- /dev/null +++ b/Scripts/manage_envs/cmap-modedest/cmap-modedest.yml @@ -0,0 +1,7 @@ +name: cmap-modedest +channels: + - conda-forge +dependencies: + - larch=5.5.9 + - python=3.9 + - uv \ No newline at end of file diff --git a/Scripts/manage_envs/cmap-modedest/requirements.txt b/Scripts/manage_envs/cmap-modedest/requirements.txt new file mode 100644 index 0000000..4b2351e --- /dev/null +++ b/Scripts/manage_envs/cmap-modedest/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/CMAP-REPOS/cmap_modedest@v24.4.1 \ No newline at end of file diff --git a/Scripts/manage/env/emme.pth b/Scripts/manage_envs/emme.pth similarity index 100% rename from Scripts/manage/env/emme.pth rename to Scripts/manage_envs/emme.pth diff --git a/Scripts/manage_envs/install_envs.ps1 b/Scripts/manage_envs/install_envs.ps1 new file mode 100644 index 0000000..4fa4c9c --- /dev/null +++ b/Scripts/manage_envs/install_envs.ps1 @@ -0,0 +1,49 @@ +# Install miniconda. +$condaPath = "$env:LOCALAPPDATA\miniconda3" +if (-not (Test-Path -Path "$condaPath\python.exe")) { + Invoke-WebRequest -Uri "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" -OutFile "$env:USERPROFILE\Downloads\Miniconda3-latest-Windows-x86_64.exe" + Start-Process -FilePath "$env:USERPROFILE\Downloads\Miniconda3-latest-Windows-x86_64.exe" -ArgumentList "/S", "/D=$condaPath" -Wait +} +# Install uv. +$uvPath = "$env:USERPROFILE\.local\bin" +if (-not (Test-Path -Path "$uvPath\uv.exe")) { + # Run the installer. Please review the printed message after installation. + powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" + # Add uv to Path + $env:Path = "$uvPath;$env:Path" +} +.$condaPath\shell\condabin\conda-hook.ps1 +# Create the R conda environment for running R scripts. +if (-not (conda env list | Select-String -Pattern "tbm-r" -Quiet)) { + conda env create --file "$PSScriptRoot\tbm-r\tbm-r.yml" --yes + if ($LastExitCode -ne 0) { + Write-Error "conda env create tbm-r failed" + exit $LastExitCode + } +} +# Create the Python conda environment for running cmap_modedest. +if (-not (conda env list | Select-String -Pattern "cmap-modedest" -Quiet)) { + conda env create --file "$PSScriptRoot\cmap-modedest\cmap-modedest.yml" --yes + if ($LastExitCode -ne 0) { + Write-Error "conda env create cmap-modedest failed" + exit $LastExitCode + } + conda activate cmap-modedest + uv pip install --requirements "$PSScriptRoot\cmap-modedest\requirements.txt" + if ($LastExitCode -ne 0) { + Write-Error "(cmap-modedest) uv pip install failed" + exit $LastExitCode + } + conda deactivate +} +# Sync the base uv environment for running the model. +if (-not (Test-Path -Path "$PSScriptRoot\..\..\uv.lock")) { + uv lock +} +uv sync --locked +if ($LastExitCode -ne 0) { + Write-Error "uv sync failed" + exit $LastExitCode +} +# Extend the base environment to include Emme packages. +Copy-Item -Path "$PSScriptRoot\emme.pth" -Destination "$PSScriptRoot\..\..\.venv\Lib\site-packages" \ No newline at end of file diff --git a/Scripts/manage_envs/tbm-r/tbm-r.yml b/Scripts/manage_envs/tbm-r/tbm-r.yml new file mode 100644 index 0000000..6cc3d50 --- /dev/null +++ b/Scripts/manage_envs/tbm-r/tbm-r.yml @@ -0,0 +1,8 @@ +name: tbm-r +channels: + - conda-forge +dependencies: + - r-base=4.3 + - r-foreign + - r-tidyverse + - r-sf \ No newline at end of file diff --git a/Scripts/manage_envs/uninstall_envs.ps1 b/Scripts/manage_envs/uninstall_envs.ps1 new file mode 100644 index 0000000..8bac98a --- /dev/null +++ b/Scripts/manage_envs/uninstall_envs.ps1 @@ -0,0 +1,4 @@ +$condaPath = "$env:LOCALAPPDATA\miniconda3" +.$condaPath\shell\condabin\conda-hook.ps1 +conda remove --name tbm-r --yes --all +conda remove --name cmap-modedest --yes --all \ No newline at end of file diff --git a/Scripts/prepare/conformity_scenario/run.cmd b/Scripts/prepare/conformity_scenario/run.cmd index 8bc1d72..0d93afa 100644 --- a/Scripts/prepare/conformity_scenario/run.cmd +++ b/Scripts/prepare/conformity_scenario/run.cmd @@ -2,7 +2,6 @@ cd %~dp0 -call "..\..\manage\env\activate_env.cmd" "emme" -python ".\src\prepare_conformity_scenario.py" +uv run ".\src\prepare_conformity_scenario.py" pause \ No newline at end of file diff --git a/Scripts/share/standard_data/src/standard_data.py b/Scripts/share/standard_data/src/standard_data.py index 50ea576..edaf8c9 100644 --- a/Scripts/share/standard_data/src/standard_data.py +++ b/Scripts/share/standard_data/src/standard_data.py @@ -182,7 +182,11 @@ def export(project_file_name, trip_roster_file_name, tg_data_file_name, scenario # Copy TG results to output directory. logging.info('Copying TG results') tg_dir = _proj_dir.joinpath('Database/tg') - file = sorted(tg_dir.joinpath('data').glob('tg_results*.csv'))[0] + tg_results_file = sorted(tg_dir.joinpath('data').glob('tg_results*.csv')) + if len(tg_results_file) > 1: + raise FileNotFoundError(f'Multiple TG results files exist in {tg_dir}.') + else: + file = tg_results_file[0] shutil.copy(file, _out_dir) file_copy = _out_dir.joinpath(file.name) renamed_copy = file_copy.with_name(tg_data_file_name) diff --git a/copy_scenario_data.ps1 b/copy_scenario_data.ps1 index fdd0ca8..b6a6b43 100644 --- a/copy_scenario_data.ps1 +++ b/copy_scenario_data.ps1 @@ -8,11 +8,6 @@ $destination_db = "$destination_dir\Database\" $items = @("emmebank" "emmemat" "tg\UrbanSim_inputs" - "tg\fortran\ATTR_IN.TXT" - "tg\fortran\HH_IN.TXT" - "tg\fortran\GQ_IN.TXT" - "tg\fortran\POPSYN_HH.CSV" - "tg\fortran\airport_sz.csv" "tg\fortran\SCHOOL_IN.CSV" "tg\fortran\wfhmodule\indusmix.csv") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8f914ca --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[project] +name = "cmap_trip-based_model" +version = "26.4.22" +requires-python = "==3.11.6" +dependencies = [ + "jinja2", + "markdown", + "myst-parser", + "numpy~=1.0", + "numexpr>=2.8.0,<2.8.5", + "openpyxl", + "pandas~=2.0", + "pyarrow", + "pyyaml", + "sphinx", + "sphinx_rtd_theme", + "tqdm" +] + +[tool.uv] +package = false \ No newline at end of file diff --git a/src/Mode-Dest-TOD/.gitignore b/src/Mode-Dest-TOD/.gitignore deleted file mode 100644 index bee8a64..0000000 --- a/src/Mode-Dest-TOD/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/src/Mode-Dest-TOD/README.md b/src/Mode-Dest-TOD/README.md deleted file mode 100644 index 82de4bf..0000000 --- a/src/Mode-Dest-TOD/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# CMAP Trip-based Model - -This directory contains the code needed to run the CMAP trip-based model's -mode, destination and time-of-day model components. - -## Installation Instructions - -- First, if "conda" is not already installed and accessible by the current user - on the target development machine, install it. An easy installation solution - is using the "Mambaforge" installer, which can be downloaded for windows here: - - > https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe - - Once downloaded, double-click and run the installer. Mamba is a somewhat faster - implementation of the conda package installer, and can be used interchangably - with conda - nearly any command you might run as `conda foo` can also be run as - `mamba foo`. - -- Then if needed also install git and (optionally) the GitHub command line interface. - From either the Anaconda Prompt or the Miniforge Prompt, run: - - > mamba install git gh -c conda-forge - -- Now clone the CMAP trip-based model code from GitHub, and checkout the CS2021 branch. - - > gh repo clone camsys/cmap_trip-based_model - > cd cmap_trip-based_model - > git checkout CS2021 - - To clone into a different directory than the current directory (probably the - user's home directory) change to that directory using `cd` first. - -- Next, create a conda environment to use for the mode, destination and - time-of-day model components, which are written in Python. - Creating a unique environment will ensure that all the necessary computational - libraries are installed, and no conflicts are introduced with other tools - (including Emme). A conda environment file is included in the GitHub repository, - which installs everything you need into an environment called "CMAP-TRIP". - - > conda env create --file src/Mode-Dest-TOD/conda-environment.yml - - All the necessary files for a basic run of the model using the default base year - inputs are already in the `Database` folder of this repository, except for the - skim data, which is quite large. - -- Skim data can be accessed by the mode, destination and time-of-day model - components in one of two formats: either as uncompressed raw "emx" files stored - in the `Database/emmemat` directory, or as compressed and chunked files stored - in the `Database/emmemat.zarr` directory. A base year set of skims in zarr - format is available here: - - > https://camsys-my.sharepoint.com/:u:/p/jeffnewman/Eckzo0ouKfpKkpfiGtsLJBYB4zUQt6dZ5eloVisGIJV9gg?e=CNsW0M - -## Execution Instructions - -- To run the mode, destination, and time-of-day components for the CMAP Trip-based - model, first activate the correct conda environment. From either the Anaconda Prompt - or the Miniforge Prompt, run: - - > conda activate CMAP-TRIP - - (If you created an environment with some other name, activate that other environment instead.) - -- Then, you can run the model by calling its executable version right from that - same command prompt, pointing at the correct `Database` directory: - - > cmap_modedest .\path\to\Database - -- The `cmap_modedest` command line tool has a number of available options. The most important - of these include the number of jobs and maximum number of origin zones processed per chunk, - each of which needs to be set appropriately for the computer running the model to maximize - resource usage (CPU's, RAM) without exceeding available resources, which can cause - out-of-memory errors or processor thrashing that can slow the overall runtime. - These options can be reviewed in the online help: - - > cmap_modedest --help - - - - -cmap_modedest Database --njobs 12 --max_zone_chunk 5 \ No newline at end of file diff --git a/src/Mode-Dest-TOD/TECHNICALGUIDE.md b/src/Mode-Dest-TOD/TECHNICALGUIDE.md deleted file mode 100644 index 6ec0825..0000000 --- a/src/Mode-Dest-TOD/TECHNICALGUIDE.md +++ /dev/null @@ -1,66 +0,0 @@ -# Mode, Destination, and Time of Day Technical Guide - -## Functional Flow - -When you invoke the `cmap_modedest` tool on the command line, a Python session -is started and the `run` function (see `cmap_modedest/__main__.py`) is called. - -- `run()` in `cmap_modedest/__main__.py` - - This is the main control loop function. It processes command line arguments - and then launches `choice_simulator_trips_many` as configured. - -- `choice_simulator_trips_many()` in `cmap_modedest/application.py` - - This is the workhorse function, it breaks TAZ's into batches, starts multiple - parallel processes to handle trip simulation on the batches, and aggregates - the results. The other principal functions that this function calls include - `choice_simulator_trips`, `compute_deadhead_trip_table`, and `assemble_trips`. - -- `choice_simulator_trips()` in `cmap_modedest/application.py` - - This is the single-process function to model trips by mode/dest/time, called - once for each job started by `choice_simulator_trips_many`. - -- `compute_deadhead_trip_table()` in `cmap_modedest/application.py` - - This is where deadhead trips are created. - -- `assemble_trips()` in `cmap_modedest/application.py` - - This is where all the various parquet trip-list files are assembled into - a common dask DataFrame for processing. - -- `choice_simulator_initialize` in `cmap_modedest/application.py` - - This function checks if the mode+destination choice models have already been - loaded into memory for this process. If they have not, it then checks if - a pickled version of the choice models has been saved to disk, and loads that - if it is available. Otherwise, it initializes the choice models from scratch - using the `model_builder` function. - -- `model_builder` in `cmap_modedest/choice_model.py` - - This function creates the structure of the model and sets parameter - values within that structure if given. - -- `choice_simulator_prob` in `cmap_modedest/application.py` - - Here, the choice model is used to compute the probabilities for the mode and - destintion choices. - - - - -## Statefulness - -The program avoids creating a global "state" to facilitate passing the state to -subprocesses that actually execute jobs. Instead, a common DataHandler object -is used to pass state (i.e. the names of the input files, configuration options, -etc) from the main process to subprocessed. - -The main state object is a `DataHandler` object. This class is defined in -`cmap_modedest/data_handlers/__init__.py`. An instance of the DataHandler is passed -around between functions, generally as the first argument to each function that -needs it, as an argument named `dh`. - diff --git a/src/Mode-Dest-TOD/USERGUIDE.md b/src/Mode-Dest-TOD/USERGUIDE.md deleted file mode 100644 index 07a1111..0000000 --- a/src/Mode-Dest-TOD/USERGUIDE.md +++ /dev/null @@ -1,495 +0,0 @@ -# Mode, Destination, and Time of Day User Guide - -This document describes the Mode, Destination, and Time of Day (MDT) models, -including the basic conceptual structure, input files used, output files -generated, and method of operation. - -## Model Structure - -The CMAP trip-based model's MDT models are implemented in Python, using modern -multiprocessing techniques to greatly enhance the sensitivity and detail of the -model, without significantly increasing the overall model runtime. - -### Joint Mode and Destination - -The model includes an integrated mode and destination choice model. The mode and -destination choice model was estimated as a single model using full-information -maximum likelihood methods, which represents a significant theoretical enhancement -over two-step models (i.e. models where mode choice logsums are computed based on -the estimated mode choice model, and those logsums are used as static input values -when estimating parameters for a destination choice model). - -The integrated mode and destination choice model is represented as a hierarchical -nested logit model. The top of the nesting hierarchy represents the attraction -zone for each trip. For all home-based trips the attraction end is the non-home, -while for non-home-based trips it is modeled as the actual destination of the -trip in the normal sense. Below the attraction nest, the mode choice is further -sub-nested, with all private auto modes (SOV, HOV2, HOV3) grouped in one nest, -and all public auto modes (Taxi, TNC1, TNC2) grouped in a different nest. - -![](nesting-tree.png) - -For application, as this is a semi-aggregate model, there is no sampling of -alternatives. Thus, for each trip, the number of mode and destination alternatives -is 3632 zones times 9 modes = 32,688 alternatives. - -### Mode Choices - -The set of alternatives included explicitly in the mode choice level of the model -includes 9 discrete alternatives: - -1. SOV: Single occupant private vehicle (driving alone) -2. HOV2: 2-person trip in a private vehicle -3. HOV3: 3 or more persons sharing a private vehicle -4. Taxi -5. TNC1: Regular ride hail (e.g. Uber or Lyft) -6. TNC2: Shared ride hail (e.g. Uber Pool or Lyft Line) -7. Transit -8. Bike -9. Walk - - -### Transit Access and Egress - -To facilitate the implementation for these models, the calculation of transit -access and egress levels of service has been ported from Fortran to Python. -The actual mathematical logic underpinning these level of service calculations -is unchanged from the previous model, and is still based on a random distribution -of transit access characteristics computed based on the geography of each zone. - -### Work from Home Segmentation - -The unfolding pandemic has introduced a new wrinkle in travel demand forecasting: -unexpectedly large and deep uncertainty about the future of “work from home” -(WFH) behaviors. - -A fundamental challenge in modeling changing WFH behavior is that it impacts not -just the presence or absence of work trips, but also the number and temporal and -geographic distribution of non-work trips. A remote worker has much more limited -opportunity to undertake non-home-based trips in the middle of the day around the -workplace (e.g. going out for lunch in the loop) and much greater opportunity to -make home-based trips. - -The trip-based model has been built to include sensitivity to changes -in WFH, by bifurcating the regional population into two groups: households -that have at least one worker who works from home at least sometimes, and -households that have no WFH activity. Athough the parameters of the mode and -destination choice models are the same for both groups, the trip productions and -attractions by zone for these two groups differ, resulting in unique utility -functions and different behavior patterns for each. - -### Time of Day Models - -Although the mode and destination models are fully integrated, the time of day -models are estimated and applied separately as an independent step. These models, -which are applied only to automobile based modes (of both private and hired car -varieties), are sensitive to changes in congested travel times over the course -of the day. They are structured as a simple multinomial logit model, despite the -fact that the 8 modeled time periods are heterogeneously sized. This is not -problematic, as these models all include a complete set of alternative specific -constants, which represent not only behavioral preferences but also the aggregate -size (i.e. duration) of each time period. - -The utility functions for the time of day models are relatively simple compared -to the mode and destination models, as the differentiation available across the -alternatives is limited. Nevertheless, the models are structured to be sensitive -to congested travel times, as well as mode choice, as TNC usage exhibits a vastly -different temporal pattern than private auto usage, with many TNC rides clustered -in the evening and overnight hours. - - -## Input Files - -The descriptions here are focused on technical implementation, -i.e. what appears in these files, not where these values should come from. - -In most cases, there are several possible locations for each input file, which -are identified as "alternative file search locations"`under each heading. In -each case, the model checks each location in the order shown to find the file, -and the first location where a file exists is the location actually used. -Typically, files stored directly in the "Database" directory are preferred, but -fallback files from other locations can also used. This allows the MDT models to -run even if, for example, EMME has not been used to prepare a scenario specific -input file. - -In addition to the files below, the MDT models also read a wide variety of skim -data from various EMME matrix files found in the `emmemat` directory. - - -### HW_CBDPARK.TXT - -Alternative file search locations: -- HW_CBDPARK.TXT -- defaults_base_year/HW_CBDPARK.TXT - -This file contains CBD parking cost inputs. Two different sets of records are -included in the file. The first set identifies the parking supply characteristics -of each CBD zone that contains parking. Each zone in this set has five records -with the following information: - -- CBD parking zone number. -- The probability of finding parking within the zone at the threshold parking - cost (this value must be 100 percent in each zone’s fifth record). -- The threshold parking cost in cents per hour. -- The savings in parking costs in cents per hour determined by subtracting the - threshold parking cost from the maximum parking cost in the zone. -- The amount of time needed to walk one block in the CBD (180 seconds). - -Parking user characteristics are included in the second set of records in the -CBD parking file – these correspond to the final five records in the file. These -records are ordered by household income ranges and include the following variables -for CBD commuters: - -- The upper value of the household income quintile range (last record is the - lower bound of the highest quintile). -- The percentage of CBD auto commuters with free parking. -- The percentage of all CBD workers taking transit to CBD. -- The percentage of CBD auto commuters in single occupant vehicles. -- The percentage of CBD auto commuters ridesharing in two person vehicles -- The percentage of CBD auto commuters carpooling in three person vehicles. -- The percentage of CBD auto commuters carpooling in four or more person vehicles. - - -### ALLPURPOSE_M01.TXT - -Alternative file search locations: -- ALLPURPOSE_M01.TXT -- defaults_base_year/ALLPURPOSE_M01.TXT - -The M01 file stores several variables to provide the mode choice and distribution -models with zonal transit availability and park and ride characteristic parameters. -Some of the parameters are calculated using transit network characteristics and -are specific to each scenario network. The contents of the M01 file are summarized: - -1. Zone Number -2. Zone Type - - 1=Chicago downtown - - 2=Rest of Chicago - - 3=dense suburban CBD - - 4=all other zones -3. Park and Ride Cost - The cost of parking at the park and ride lot closest to the zone’s geographic - centroid. This represents the lowest rate of either the daily parking rate or the cost of a monthly parking pass divided by twenty work days. -4. Median zone household income - The median household income in the zone (in $100s) -5. Park and ride availability - A binary value indicating that the zone has park and ride access if - there is a park and ride location within ten miles of the zone’s - geographic centroid. -6. Average waiting time for bus service in zone for home-work trips -7. Average waiting time for bus service in zone for non-work trips -8. Average waiting time for feeder bus service in zone for home-work trips -9. Average waiting time for feeder bus service in zone for non-work trips -10. Home-work trip auto work end auto occupancy - -> Note: In prior version of the CMAP trip-based model, separate nearly identical copies -> of the M01 files were needed to support pre-distribution and mode choice -> components, e.g. PDHW_M01 and MCHW_M01. The current model does not require -> separate files, so the model reads only a common file with an ALLPURPOSE prefix. - - -### ALLPURPOSE_M023.TXT - -Alternative file search locations: -- ALLPURPOSE_M023.TXT -- defaults_base_year/ALLPURPOSE_M023.TXT - -The M023 file contains transit fare and auto operating cost data used by the -distribution and mode choice models. The file is composed of six records: - -1. CTA fares; -2. Pace feeder bus fares; -3. Pace regional bus fares; -4. Auto operating costs in 5 mile per hour increments for speeds - between 0-40 miles per hour; -5. Auto operating costs in 5 mile per hour increments for speeds - between 40-80 miles per hour; -6. Average auto operating costs per mile by zone type used to estimate - transit access/egress costs. - -The last record in the file contains the average per mile auto operating cost -for each of the four zone types (defined in the M01 file). The M023 data is -collapsed into six records. All values are reported in cents. - -> Note: In prior version of the CMAP trip-based model, separate identical copies -> of the M023 files were needed to support pre-distribution and mode choice -> components, e.g. PDHW_M023 and MCHW_M023. The current model does not require -> separate files, so the model reads only a common file with an ALLPURPOSE prefix. - - -### ??_DISTR.TXT - -Variants: -- HW_DISTR.TXT -- HO_DISTR.TXT -- NH_DISTR.TXT - -Alternative file search locations: -- ??_DISTR.TXT -- defaults_base_year/??_DISTR.TXT - -The DISTR files contain zonal transit approach distribution parameters. The -parameters are calculated using transit network characteristics and are thus -specific to each scenario network. The following describes the DISTR file fields. - -1. CMAP modeling zone number -2. Commuter Rail: Mean distance in miles to station -3. Commuter Rail: Standard deviation of distance to station -4. Commuter Rail: Type of Mode Choice distribution, with - - 101 = normal distribution. - - 102 = exponential distribution. -5. CTA Rail: Mean distance in miles to station -6. CTA Rail: Standard deviation of distance to station -7. CTA Rail: Type of Mode Choice distribution, with - - 101 = normal distribution. - - 102 = exponential distribution. -8. Regular Bus: Minimum bus stop distance -9. Regular Bus: Maximum bus stop distance -10. Regular Bus: Proportion of the zone within minimum walking distance -11. Feeder Bus: Minimum bus stop distance -12. Feeder Bus: Maximum bus stop distance -13. Feeder Bus: Proportion of the zone within minimum walking distance -14. Park and Ride: Mean distance in miles to lot -15. Park and Ride: Standard deviation of distance to lot -16. Park and Ride: Type of Mode Choice distribution, with - - 101 = normal distribution. - - 102 = exponential distribution. - -> Note: In prior version of the CMAP trip-based model, separate identical copies -> of the DISTR files were needed to support pre-distribution and mode choice -> components, e.g. PDHW_DISTR and MCHW_DISTR. The current model does not require -> separate files by component, so the model reads only a common file without the component- -> specific prefix. The purpose-specific prefix is still required, as the data in -> these files can vary by purpose. - - -### cmap_trip_config.yaml - -This yaml file contains a variety of model configurations, including: -- Taxi and TNC fare parameters -- Parking costs for zones other than those enumerated explicitly in `CBD_PARK` -- Intrazonal auto speeds by area type -- The regional income distribution across 5 income buckets -- Average occupancy of HOV3+ vehicles by trip purpose -- Activity durations by purpose (used to compute total parking costs) -- The number of replications used to simulate transit access and egress factors -- Factors by purpose to split trips into production-attraction and attraction-production -- Superdistrict codes for geographic validation summaries - - -### choice_model_params.yaml - -Alternative file search locations: -- choice_model_params.yaml -- cache/choice_model_params.yaml - -This file contains the choice model parameters used in the mode and destination -model. Mode and destination are modeled simultaneously in a single multi-level -nested logit structure. - - -### tod_model_params.yaml - -Alternative file search locations: -- tod_model_params.yaml -- cache/tod_model_params.yaml - -This file contains the choice model parameters used in the time-of-day model. -This model is only applied to auto trips, both private auto (sov, hov) and -hired-car (taxi, tnc) modes. - - -### CMAP_Zone_Districts.csv.gz - -Alternative file search locations: -- CMAP_Zone_Districts.csv.gz -- cache/CMAP_Zone_Districts.csv.gz - -This file is used to attach district and super-district codes to the resulting -trip tables, primarily for validation purposes. - - -### TG_HHENUM_OUTPUT.TXT.gz - -Alternative file search locations: -- TG_HHENUM_OUTPUT.TXT.gz -- cache/TG_HHENUM_OUTPUT.TXT.gz -- TG_HHENUM_OUTPUT.TXT -- cache/TG_HHENUM_OUTPUT.TXT -- defaults_base_year/TG_HHENUM_OUTPUT.TXT.gz - -This file, which is created as an output of the trip generation model, lists the -subzone and zone of each enumerated household, as well as the HHVTYPE. - - -### value_of_time_buckets.csv - -Alternative file search locations: -- value_of_time_buckets.csv -- cache/value_of_time_buckets.csv - -This file describes the share of single occupant vehicles to put into each of the -value of time buckets, based on trip purpose and household income group. If a -row does not sum to 1.0, the values will be scaled linearly so that the totals -are 1 and all trips are assigned to a bucket. - - -### CMAP_TripTable_VisitorsWeekday.csv.gz - -Alternative file search locations: -- cache/CMAP_TripTable_VisitorsWeekday.csv.gz -- CMAP_TripTable_VisitorsWeekday.csv.gz -- defaults_base_year/CMAP_TripTable_VisitorsWeekday.csv.gz - -This file contains a pre-computed trip table for weekday visitors (i.e. non-CMAP -region residents). It is used to replace the destination choice component for -visitor trips, although a mode choice model is still applied to distribute -visitor trips across modes. - - -### default_auto_propensity.csv.gz - -Alternative file search locations: -- cache/computed_auto_propensity.csv -- computed_auto_propensity.csv -- defaults_base_year/default_auto_propensity.csv -- defaults_base_year/default_auto_propensity.csv.gz - -This file contains the propensity of home-based trips to be attracted to a given -zone using a private auto mode (SOV or HOV). It is used to adjust the probability -that non-home-based trips produced in this zone will also use a private auto mode. - -To aid in computational efficiency, the model implementation uses computed auto -propensity lagged by one feedback iteration. That is, the computed auto propensity -from the prior global iteration is used at each iteration. When there is no prior -iteration (i.e. on the first iteration) then the default auto propensity is used. - - -## Output Files - -### cache/choice_simulator_trips_out/choice_simulator_trips_*.pq - -The primary output of the MDT models is a roster of trips. When the model is -run in multiprocessing/parallel mode, which is the default, individual trip -roster files are written out for each "job", so there will be numerous individual -trip roster files, which should be considered as different parts that can be -concatenated into one master trip roster table. The overall computational work is -split into numerous independent jobs, where just a few trip production/origin -zones are processed together in a batch. Moreover, the trips made by -work-from-home (WFH) households are modeled independently from trips made by -"typical" households that do not include a WFH person, so these trips are -seperated into two computational jobs even for the same zones. - -Each *.pq file is a [parquet format](https://parquet.apache.org/) file containing -a roster of trips, segmented on the following dimensions: - -- Trip Purpose - - HBWH: Home-based work trips by high-income households - - HBWL: Home-based work trips by low-income households - - HBS: Home-based shopping trips - - HBO: Home-based other purpose trips - - NHB: Non-home based trips - - VISIT: Trips made by visitors to the region - - DEAD: Deadhead trips made taxis and rideshare vehicles between revenue trips -- Mode - - 1: SOV - - 2: HOV2 - - 3: HOV3+ - - 4: TAXI - - 5: TNC Private / Regular - - 6: TNC Shared / Pooled - - 7: TRANSIT - - 8: WALK - - 9: BIKE -- Origin Zone - - TAZ number for the trip origin. Note this is always the beginning of the - actual trip, and not necessarily the home/production zone, e.g. for trips - returning home from a workplace, the origin zone is the workplace. -- Destination Zone - - TAZ number for the trip destination. Note this is always the end of the - actual trip, and not necessarily the attraction zone, e.g. for trips - returning home from a workplace, the destination zone is home. -- Attraction Zone - - TAZ number for the trip attraction zone. This can be either the production - or attraction zone, depending on directionality of the trip. For trips modeled - as O-D instead of P-A, the attraction zone is always the destination. -- Number of Autos Owned by Household - - The number of automobiles (0, 1, or 2) owned by the household of the person - making the trip. This is only applicable for home-based trips, as consistent - tours are not maintained and the model cannot use auto ownership for - anything other than home-based trips. -- Household Income Category - - The household income category (1 through 5 inclusive) of the person - making the trip. This is computed based on the income profile of zone households - for home-based trips, and based on the regional average income profile for - non-home-based trips, as consistent tours are not maintained. -- Time Period - - One of 9 time periods {EA, AM1, AM2, AM3, MD, PM1, PM2, PM3} is assigned for - all public and hired auto trips. No time period is actually assigned for - transit or non-motorized trips, trips by these modes are marked with 'NA'. - -Each new run of the MDT model generates a new `choice_simulator_trips_out` -directory in the `Database\cache` folder. Previous output directories are -rotated with a dot-number extensions, so that the un-numbered output directory is -the most recent output. - -### emmemat/mf*.emx - -Unless the "--no-aggregate" option is set, the trip roster is also aggregated -into Emme matrix files of vehicle trips for automobile modes, and person trips -for transit. In contrast to the trip roster files, which are written to a -rotated directory that prevents data loss, new EMX files will overwrite any -existing data stored with the same filename. - -For all automobile modes, trips are aggregated from person trips to vehicle -trips. SOV trips are split into three value of time categories according to the -ratios given in the `value_of_time_buckets.csv` input file. HOV2 and HOV3+ modes -are each in a single bucket, but are converted from person trips to vehicle trips -based on auto occupancy, which is 2 for HOV2 and slightly over 3 for HOV3+, the -exact value varies by purpose and is given by the `hov3_occupancy` key in the -`cmap_trip_config.yaml` input file. - -The time of day dimension for auto trips is preserved, along with origin and -destination, yielding 8 full matrix tables per bucket, organized as follows: - -- SOV low value of time – mf411-mf418 -- SOV med value of time – mf421-mf428 -- SOV high value of time – mf431-mf438 -- HOV2 not diff'd by vot – mf441-mf448 -- HOV3 not diff'd by vot – mf451-mf458 - -In each group, the time of day ordering is the same, with the last digit of the -file name representing the time period: - -- 1: EA -- 2: AM1 -- 3: AM2 -- 4: AM3 -- 5: MD -- 6: PM1 -- 7: PM2 -- 8: PM3 - -Unlike auto trips, transit person trips are not aggregated to vehicles nor -segmented by time period. Instead, transit person trips are segmented only by -trip purpose, yielding just 5 full matrix tables: - -- home-based work low income - mf40 -- home-based work high income - mf41 -- home-based shopping - mf39 -- home-based other - mf42 -- non-home-based - mf43 - - -### cache/choice_simulator_trips_out/validation_data.xlsx - -This excel file contains some extra validation output of the MDT models. -The file contains the following worksheets of partially aggregated data, -consistent with the format of the validation template: - -- Autos: Regional trips aggregated by purpose, mode, and auto ownership. -- Incomes: Regional trips aggregated by purpose, mode, and household income category. -- TimePeriod: Regional trips aggregated by purpose, mode, and time period. -- FlowsByPurp&Mode: Selected superdistrict-to-superdistrict trip flows by mode and purpose. -- FlowsByPurp&Mode%: Selected superdistrict-to-superdistrict mode shares by purpose. - diff --git a/src/Mode-Dest-TOD/cmap_modedest/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/__init__.py deleted file mode 100644 index ba3e4a8..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# CMAP Trip-based model tools - -__version__ = '21.01.1' - -from .cmap_logging import * -from .numexpr_patch import CacheDictSafe diff --git a/src/Mode-Dest-TOD/cmap_modedest/__main__.py b/src/Mode-Dest-TOD/cmap_modedest/__main__.py deleted file mode 100644 index e1c0832..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/__main__.py +++ /dev/null @@ -1,274 +0,0 @@ -import sys -import os -import shutil -import time -import datetime - -import numpy as np -import pandas as pd -import argparse -import cmap_modedest - -def main(*args): - - parser = argparse.ArgumentParser( - prog='cmap_modedest', - description='Mode, destination, and time-of-day for CMAP trip-based model.', - ) - parser.add_argument( - 'database_dir', - type=str, - help='The path of the current database directory, which is used as the ' - 'base location for loading all input files.', - ) - parser.add_argument( - '-l', '--loglevel', - type=int, - help='The logging level, or how verbose the log output should be. Set to ' - '10 or less for debug-level output.', - default=20, - ) - parser.add_argument( - '--max_zone_chunk', - type=int, - help='Maximum number of zones to process in one chunk. Each job can ' - 'process a few zones at once, but trying to run too many can ' - 'trigger out-of-memory problems.', - default=4, - ) - parser.add_argument( - '--njobs', - type=int, - help=""" - Number of jobs to process in parallel. Larger computers with more CPUs - can handle more jobs at the same time.""", - default=10, - ) - parser.add_argument( - '--stagger', - type=int, - help=""" - Number of seconds to pause between initial parallel starts. - This can stagger storage-heavy and cpu-heavy sections of code to - better distribute workload.""", - default=5, - ) - parser.add_argument( - '--short', - type=float, - help=""" - Whether to shorten runtime by processing only a subset of origin zones. - Give a fraction less than one to run that fraction of zones spread over - the entire region, or an integer 1 or more to run in a single process - that number of zones starting from the first zone. This feature is - primarily for testing and quick validation. - """, - ) - parser.add_argument( - '--no-aggregate', - action="store_true", - help=""" - Disable vehicle trip table aggregation. If not set, the vehicle trip - tables in Database/emmemat will be overwritten. - """, - ) - parser.add_argument( - '--subdir', - type=str, - help="""cache subdirectory into which results are saved""", - default="choice_simulator_trips_out", - ) - parser.add_argument( - '--check', - help='Check input arguments to this command (including default arguments) ' - 'and the exit without processing anything.', - action="store_true", - ) - parser.add_argument( - '--rebuild', - help='Rebuild all numba caches. Try setting this argument in the model is ' - 'crashing unexpectedly. Rebuilding caches takes a little time but is ' - 'potentially necessary when switching the code to a new computer.', - action="store_true", - ) - parser.add_argument( - '--profile', - help='Run in profiler mode. This will slow down the model run somewhat, ' - 'but provide a profiling report for code optization. This features ' - 'requires that the pyinstrument library is installed.', - action="store_true", - ) - parser.add_argument( - '--tbb', - help='Use the TBB backend for numba. Experimental', - action="store_true", - ) - parser.add_argument( - '--zarr-to-emmemat', - help='Convert all matrix files that are only found in the emmemat.zarr ' - 'format into standard emmemat .EMX files, and then quit. Note that ' - 'EMME may not recognize these files as included in the model data ' - 'unless they were previously initialized.', - action="store_true", - ) - - args = parser.parse_args() - return run(args) - - -def run(args): - if args.tbb or os.environ.get("NUMBA_THREADING_LAYER", None) in ("safe", "tbb"): - from numba import config, njit, threading_layer - # set the threading layer before any parallel target compilation - config.THREADING_LAYER = 'tbb' - - @njit(parallel=True) - def foo(a, b): - return a + b - - x = np.arange(10.) - y = x.copy() - - # this will force the compilation of the function, select a threading layer - # and then execute in parallel - foo(x, y) - - # demonstrate the threading layer chosen - print("Threading layer chosen: %s" % threading_layer()) - os.environ["NUMBA_THREADING_LAYER"] = "tbb" - - - log_dir = os.path.join(args.database_dir, "cache", "logs") - os.makedirs(log_dir, exist_ok=True) - log = cmap_modedest.log_to_stderr( - level=args.loglevel, - log_dir=log_dir, - ) - - if args.profile: - from pyinstrument import Profiler - profiler = Profiler() - profiler.start() - - from cmap_modedest.runtime import working_dir, log_info - log.info(time.strftime("RUN STARTED %A, %d %B %Y, %I:%M:%S %p")) - start_time = time.time() - try: - log_info("###################################################################") - log_info("## CMAP TRIP-BASED MODEL: MODE, DESTINATION, AND TIME OF DAY ##") - log_info("###################################################################") - if not os.path.isdir(args.database_dir): - raise NotADirectoryError(args.database_dir) - log_info(f"# database_dir = {args.database_dir}") - log_info(f"# (full path) = {os.path.abspath(args.database_dir)}") - log_info(f"# --max_zone_chunk = {args.max_zone_chunk}") - log_info(f"# --njobs = {args.njobs}") - if args.short is not None and args.short >= 1.0 and args.njobs > 1: - log_info(f"# -> n_jobs is set to 1 when running in sequential short mode") - log_info(f"# --stagger = {args.stagger}") - log_info(f"# --short = {args.short}") - log_info(f"# --subdir = {args.subdir}") - log_info(f"# --check = {args.check}") - log_info(f"# --rebuild = {args.rebuild}") - log_info(f"# --tbb = {args.tbb}") - log_info(f"# --zarr-to-emmemat = {args.zarr_to_emmemat}") - log_info("###################################################################") - - if args.check: return # early exit if only checking arguments - - if args.rebuild: - import pathlib - here = os.path.dirname(__file__) - for p in pathlib.Path(here).rglob('*.py[co]'): - p.unlink() - for p in pathlib.Path(here).rglob('*.nb[ci]'): - p.unlink() - - - from cmap_modedest.application import choice_simulator_trips_many, choice_simulator_trips, assemble_trips - - if args.zarr_to_emmemat: - working_dir(args.database_dir, backfill_uncompressed_skims=True) - return - - dh = working_dir(args.database_dir) - - ## Rename subdir folder if it already exists. - cache_subdir = dh.filenames.cache_dir / args.subdir - if os.path.exists(cache_subdir): - n = 1 - while os.path.exists(cache_subdir.with_suffix(f".{n:03d}")): - n += 1 - shutil.move(cache_subdir, cache_subdir.with_suffix(f".{n:03d}")) - - - if args.short is None: - otaz = None - n_jobs = args.njobs - elif args.short < 1.0: - otaz = np.linspace(1, 3632, int(np.round(3632 * args.short)), dtype=int) - n_jobs = args.njobs - else: # args.short >= 1.0: - otaz = np.arange(0, int(args.short)) + 1 - n_jobs = 1 - - choice_simulator_trips_many( - dh, - otaz=otaz, - max_chunk_size=args.max_zone_chunk, - n_jobs=n_jobs, - cache_subdir=args.subdir, - with_wfh=True, - staggertime=args.stagger, - ) - - sim_trips_many = assemble_trips( - dh, - from_dir=dh.filenames.cache_dir / args.subdir, - pattern="choice_simulator_trips_*.pq", - compute_auto_propensity=False, - ) - - if True: - from cmap_modedest.validation import validation_aggregation - validation_aggregation(dh, sim_trips_many, to_dir=dh.filenames.cache_dir / args.subdir) - - if sim_trips_many is not None and not args.no_aggregate: - log.info("Aggregating trips to vehicle trip tables by value of time and time of day") - from cmap_modedest.application import aggregate_to_vehicle_matrixes - aggregate_to_vehicle_matrixes(dh, sim_trips_many) - - if sim_trips_many is not None: - s = str( - sim_trips_many - .groupby(["mode", "purpose"])['trips'] - .sum() - .compute() - .unstack(0) - .fillna(0) - ) - log_info(f"Trip Summary by Mode and Purpose ------\n{s}") - - s = str( - sim_trips_many - .groupby(["hh_inc5", "purpose"])['trips'] - .sum() - .compute() - .unstack(0) - .fillna(0) - ) - log_info(f"Trip Summary by Income and Purpose ------\n{s}") - - log_info("#### COMPLETED: MODE, DESTINATION, AND TIME OF DAY ####") - finally: - log.info(time.strftime("RUN ENDED %A, %d %B %Y, %I:%M:%S %p")) - end_time = time.time() - log.info(f"ELAPSED TIME {datetime.timedelta(seconds=end_time-start_time)}") - - if args.profile: - profiler.stop() - print(profiler.output_text(unicode=True, color=True)) - - -if __name__ == "__main__": - sys.exit(main()) \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/addict.py b/src/Mode-Dest-TOD/cmap_modedest/addict.py deleted file mode 100644 index 734665a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/addict.py +++ /dev/null @@ -1,203 +0,0 @@ -# - from https://github.com/mewwts/addict -# - edited to allow pickling -# -# The MIT License (MIT) -# -# Copyright (c) 2014 Mats Julian Olsen -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - - -import copy - - -class Dict(dict): - - def __init__(__self, *args, **kwargs): - object.__setattr__(__self, '__parent', kwargs.pop('__parent', None)) - object.__setattr__(__self, '__key', kwargs.pop('__key', None)) - object.__setattr__(__self, '__frozen', False) - for arg in args: - if not arg: - continue - elif isinstance(arg, dict): - for key, val in arg.items(): - __self[key] = __self._hook(val) - elif isinstance(arg, tuple) and (not isinstance(arg[0], tuple)): - __self[arg[0]] = __self._hook(arg[1]) - else: - for key, val in iter(arg): - __self[key] = __self._hook(val) - - for key, val in kwargs.items(): - __self[key] = __self._hook(val) - - def __setattr__(self, name, value): - if hasattr(self.__class__, name): - raise AttributeError("'Dict' object attribute " - "'{0}' is read-only".format(name)) - else: - self[name] = value - - def __setitem__(self, name, value): - isFrozen = (hasattr(self, '__frozen') and - object.__getattribute__(self, '__frozen')) - if isFrozen and name not in super(Dict, self).keys(): - raise KeyError(name) - super(Dict, self).__setitem__(name, value) - try: - p = object.__getattribute__(self, '__parent') - key = object.__getattribute__(self, '__key') - except AttributeError: - p = None - key = None - if p is not None: - p[key] = self - object.__delattr__(self, '__parent') - object.__delattr__(self, '__key') - - def __add__(self, other): - if not self.keys(): - return other - else: - self_type = type(self).__name__ - other_type = type(other).__name__ - msg = "unsupported operand type(s) for +: '{}' and '{}'" - raise TypeError(msg.format(self_type, other_type)) - - @classmethod - def _hook(cls, item): - if isinstance(item, dict): - return cls(item) - elif isinstance(item, (list, tuple)): - try: - return type(item)(cls._hook(elem) for elem in item) - except TypeError: - # some subclasses don't implement a constructor that - # accepts a generator, e.g. namedtuple - return type(item)(*(cls._hook(elem) for elem in item)) - return item - - def __getattr__(self, item): - return self.__getitem__(item) - - def __missing__(self, name): - if object.__getattribute__(self, '__frozen'): - raise KeyError(name) - return self.__class__(__parent=self, __key=name) - - def __delattr__(self, name): - del self[name] - - def to_dict(self): - base = {} - for key, value in self.items(): - if isinstance(value, type(self)): - base[key] = value.to_dict() - elif isinstance(value, (list, tuple)): - try: - base[key] = type(value)( - item.to_dict() if isinstance(item, type(self)) else - item for item in value) - except TypeError: - # some subclasses don't implement a constructor that - # accepts a generator, e.g. namedtuple - base[key] = type(value)(*( - item.to_dict() if isinstance(item, type(self)) else - item for item in value)) - else: - base[key] = value - return base - - def copy(self): - return copy.copy(self) - - def deepcopy(self): - return copy.deepcopy(self) - - def __deepcopy__(self, memo): - other = self.__class__() - memo[id(self)] = other - for key, value in self.items(): - other[copy.deepcopy(key, memo)] = copy.deepcopy(value, memo) - return other - - def update(self, *args, **kwargs): - other = {} - if args: - if len(args) > 1: - raise TypeError() - other.update(args[0]) - other.update(kwargs) - for k, v in other.items(): - if ((k not in self) or - (not isinstance(self[k], dict)) or - (not isinstance(v, dict))): - self[k] = v - else: - self[k].update(v) - - def __getnewargs__(self): - return tuple(self.items()) - - def __getstate__(self): - state = self.to_dict() - isFrozen = (hasattr(self, '__frozen') and - object.__getattribute__(self, '__frozen')) - state['__addict__frozen__'] = isFrozen - return state - - def __setstate__(self, state): - shouldFreeze = state.pop('__addict__frozen__', False) - self.update(state) - self.freeze(shouldFreeze) - - def __or__(self, other): - if not isinstance(other, (Dict, dict)): - return NotImplemented - new = Dict(self) - new.update(other) - return new - - def __ror__(self, other): - if not isinstance(other, (Dict, dict)): - return NotImplemented - new = Dict(other) - new.update(self) - return new - - def __ior__(self, other): - self.update(other) - return self - - def setdefault(self, key, default=None): - if key in self: - return self[key] - else: - self[key] = default - return default - - def freeze(self, shouldFreeze=True): - object.__setattr__(self, '__frozen', shouldFreeze) - for key, val in self.items(): - if isinstance(val, Dict): - val.freeze(shouldFreeze) - - def unfreeze(self): - self.freeze(False) diff --git a/src/Mode-Dest-TOD/cmap_modedest/ae_distance_sim.py b/src/Mode-Dest-TOD/cmap_modedest/ae_distance_sim.py deleted file mode 100644 index b24f9fd..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/ae_distance_sim.py +++ /dev/null @@ -1,80 +0,0 @@ -import numpy as np -import pandas as pd -from scipy import stats -import logging -log = logging.getLogger('CMAP') - -def sloped_linear(x_min, x_max, ratio=1.0, random_state=None, replication=1): - if isinstance(replication, int): - replication = [replication] - x_max = np.asarray(x_max) - x_min = np.asarray(x_min) - reps = list(x_min.shape)+replication - if isinstance(ratio, float) and ratio == 1.0: - return stats.uniform(x_min, x_max).rvs(reps, random_state=random_state) - else: - span = x_max - x_min - slope = (1.0-ratio)/np.where(span!=0, span, 1.0) - area =.5*(1+ratio)*span - if len(replication) == 1: - y = stats.uniform().rvs(reps, random_state=random_state)*area[:,None] - zp = np.sqrt(ratio[:,None] ** 2 + 2 * slope[:,None] * y) - return (zp - ratio[:,None]) / np.where(slope != 0, slope, 1.0)[:,None] + x_min[:,None] - elif len(replication) == 2: - y = stats.uniform().rvs(reps, random_state=random_state)*area[:,None,None] - zp = np.sqrt(ratio[:,None,None] ** 2 + 2 * slope[:,None,None] * y) - return (zp - ratio[:,None,None]) / np.where(slope != 0, slope, 1.0)[:,None,None] + x_min[:,None,None] - else: - raise ValueError('too many dims') - - -def trunc_normal(*arg, random_state=None, replication=1): - if isinstance(replication, int): - replication = [replication] - rv = stats.norm(*(np.asarray(j) for j in arg)) - reps = replication+list(rv.args[0].shape) - return np.fmax(rv.rvs(reps, random_state=random_state), 0.06) - - -def simulate_ae_dist(p1,p2,p3, random_state=None, replication=1): - p1 = np.asarray(p1).reshape(-1) - p2 = np.asarray(p2).reshape(-1) - p3 = np.asarray(p3).reshape(-1) - if isinstance(replication, int): - replication = [replication] - reps = list(p1.shape)+replication - result = np.full(reps, np.nan, dtype=np.float32) - - use_normal = (p3 == 101) - if use_normal.any(): - result[use_normal,...] = trunc_normal( - p1[use_normal], - p2[use_normal], - random_state=random_state, - replication=replication, - ).T - - use_slopey = (p3 < 101) - n = use_slopey.sum() - if n: - result[use_slopey,...] = sloped_linear( - p1[use_slopey], - p2[use_slopey], - p3[use_slopey], - random_state=random_state, - replication=replication, - ) - - use_nan = (p3 == 999) - result[use_nan,...] = 255.0 - return result - - -ae_mode_speeds = { # minutes per mile - 1: 20, # walk - 2: 20, # bus - 3: 2, # pnr - 4: 2, # knr - 5: 20, # feeder - 999: 1, # not available -} \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/application.py b/src/Mode-Dest-TOD/cmap_modedest/application.py deleted file mode 100644 index 1de062a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/application.py +++ /dev/null @@ -1,1495 +0,0 @@ -import pickle - -import numpy as np -import pandas as pd -import xarray as xr -import os -import time -import larch -from larch.util import piece -from larch.util.dataframe import columnize -import re -from .addict import Dict -import pyarrow as pa -import pyarrow.feather as pf -import pyarrow.compute as pc -import sharrow as sh -from scipy.stats import binom -from pathlib import Path - -from .tnc_costs import taxi_cost, tnc_solo_cost, tnc_pool_cost -from .transit_approach import transit_approach -from .modecodes import mode9codes -from .choice_model import model_builder, alt_codes_and_names -from .random_states import check_random_generator -from .data_handlers import DataHandler -from .data_handlers.tabler import Table -from .data_handlers.m01_handler import attach_areatypes, sample_hh_income_cats -from .hh_sampling import sample_hh_from_zone -from .fast.random_generator import multichoices -from .deadheading import compute_deadhead_trip_table -from .purposes import purposesA, purposes_to_5, purposes_to_3 -from .time_of_day_model import time_of_day_simulator_initialize - -from .cmap_logging import getSubLogger, get_worker_log, LOGGER_NAME - -app_floatdtype = np.float32 - - -n_modes = len(mode9codes) - -av = {} - - -def _data_for_application_1(dh, otaz=1, replication=None): - """ - - Parameters - ---------- - dh : DataHandler - otaz : int - peak : bool - replication : int, optional - - Returns - ------- - pd.DataFrame - """ - global av - log = getSubLogger("application.DATA1") - log.info(f"prepare tier 1 data for otaz {otaz}") - - try: - fast_application_data = dh.fast_application_data - except AttributeError: - from .fast.application_data import application_data - fast_application_data = dh.fast_application_data = application_data(dh) - - from .purposes import purposes5 - purposes = purposes5 - - log.debug("prepare availability") - n_zones = dh.n_internal_zones - for purpose in purposes: - av_purpose = av.get(purpose, {}) - if len(av_purpose) != n_zones * n_modes: - av_purpose = {} - num = n_modes - for i in range(n_zones): - av_purpose[num + mode9codes.AUTO] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.HOV2] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.HOV3] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.TNC1] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.TNC2] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.TAXI] = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av_purpose[num + mode9codes.TRANSIT] = f"altdest{i + 1:04d}_transit_avail_{purpose}" - av_purpose[num + mode9codes.WALK] = f"altdest{i + 1:04d}_walk_avail_{purpose}" - av_purpose[num + mode9codes.BIKE] = f"altdest{i + 1:04d}_bike_avail_{purpose}" - num += n_modes - av[purpose] = av_purpose - - if replication is None: - replication = dh.cfg.get('n_replications', 50) - - log.debug("initialize dtaz and tbl") - dtaz = pd.Index(np.arange(n_zones) + 1) - otaz_series = pd.Series(otaz, index=dtaz) - - tbl = pa.table({ - 'otaz_idx': np.full_like(dtaz, otaz) - 1, - 'dtaz_idx': dtaz - 1, - 'otaz': np.full_like(dtaz, otaz), - 'dtaz': dtaz, - }) - - log.debug("load t1") - t1 = fast_application_data.load(tbl, as_table=True) - - log.debug("concat_tables t2") - t2 = sh.concat_tables([t1] * replication) - - log.debug("prepare transit approach function") - from .fast.transit.approach import compile_transit_approach, transit_approach_wrap, transit_approach_distances - if not dh.cfg.transit_approach_func: - trapp_struct = compile_transit_approach(dh) - dh.cfg.transit_approach_struct = trapp_struct - - oz = np.full(3632, otaz) - dz = np.arange(3632) + 1 - - random_generator = np.random.default_rng([otaz, 1234]) - - log.debug("run trapp_dist_HW") - trapp_dist_HW = transit_approach_distances(dh.cfg.transit_approach_struct, oz, dz, 'HW', random_seed=random_generator)[0] - log.debug("run trapp_HW") - trapp_HW = transit_approach_wrap(dh.cfg.transit_approach_struct, oz, dz, 'HW', trapp_dist_HW, ) - - log.debug("run trapp_dist_HO") - trapp_dist_HO = transit_approach_distances(dh.cfg.transit_approach_struct, oz, dz, 'HO', random_seed=random_generator)[0] - log.debug("run trapp_HO") - trapp_HO = transit_approach_wrap(dh.cfg.transit_approach_struct, oz, dz, 'HO', trapp_dist_HO, ) - - log.debug("run add peak transit approach columns on t2") - t2['transit_approach_drivetime_PEAK'] = trapp_HW['drivetime'].T.reshape(-1) - t2['transit_approach_waittime_PEAK'] = trapp_HW['waittime'].T.reshape(-1) - t2['transit_approach_walktime_PEAK'] = trapp_HW['walktime'].T.reshape(-1) - t2['transit_approach_cost_PEAK'] = trapp_HW['cost'].T.reshape(-1) - ##-- Heither, flag KnR-PnR approaches for HBW trips -- ## - t2['M_drive_PEAK'] = np.where((trapp_HW['drivetime']>0) & (trapp_HW['drivetime']=hhadults'] = (hh_data['N_VEHICLES'] >= hh_data['N_ADULTS']).astype(app_floatdtype) - - df2 = t2.to_pandas() - - # This can be fairly fast because we're not adding new columns, just overwriting dummy columns. - # parking cost - from .parking_costs import parking_cost_v3, parking_is_free - dtazs = sh.concat_tables([tbl.select(['dtaz'])] * replication).to_pandas().values - hhincs = hh_data['hhinc5'].repeat(len(tbl)).values - - # Whether a trip gets free parking is a function of income but not destination or purpose - paid_parking = parking_is_free( - dh, - hhincs, - random_state=random_generator, - ) - - for purp in purposesA: - temp_parking_cost = parking_cost_v3( - dh, - dtazs, - dh.cfg.default_activity_durations[purposes_to_3[purp]], - purposes_to_3[purp], - random_state=random_generator, - ).values - temp_parking_cost *= paid_parking.astype(temp_parking_cost.dtype).values - df2[f'auto_parking_cost_{purp}'] = temp_parking_cost - - df2_array = df2.to_numpy(dtype=app_floatdtype).reshape(replication, -1) - - col_names = getattr(dh, 'column_2_replacement', []) - try: - df3 = pd.DataFrame( - df2_array, - columns=col_names, - ) - except ValueError: - df3 = pd.DataFrame( - df2.to_numpy(dtype=app_floatdtype).reshape(replication, -1), - columns=pd.MultiIndex.from_product([ - [f"altdest{x:04d}" for x in range(1, n_zones + 1)], - df2.columns, - ]) - ) - need_to_fix_column_names = True - else: - need_to_fix_column_names = False - hh_data.index = df3.index - - addon = hh_data[[ - 'o_zone', 'ozone_autopropensity', 'hhveh==0', 'hhveh>=hhadults', - 'hhinc5', 'hhinc5g', - 'hhinc5==1', 'hhinc5==2', 'hhinc5==3', 'hhinc5==4', 'hhinc5==5', - 'hhinc5l', 'hhinc5l==1', 'hhinc5l==2', - 'hhinc5h', 'hhinc5h==3', 'hhinc5h==4', 'hhinc5h==5', - ]] - df3 = pd.concat([df3, addon], axis=1) - if need_to_fix_column_names: - _fix_column_names(dh, df3) - return df3 - - -def _fix_column_names(dh, dfx): - column_2_replacement = getattr(dh, 'column_2_replacement', []) - if len(dfx.columns) != len(column_2_replacement): - columns = [(f"{j[0]}_{j[1]}" if isinstance(j, tuple) else j) for j in dfx.columns] - if columns[-1] == '_o_zone': - columns[-1] = 'o_zone' - s0f = lambda c: c.replace("_dtaz", "") - - s1 = re.compile("(altdest[0-9]+)_o_zone == dtaz") - s1f = lambda c: s1.sub("o_zone == \g<1>", c) - - s2 = re.compile("(altdest[0-9]+_)piece\((.*)\)") - s2f = lambda c: s2.sub(r"piece(\g<1>\g<2>)", c) - - s3 = re.compile(r"(altdest[0-9]+_)log\(attractions\)") - s3f = lambda c: s3.sub(r"log(\g<1>attractions)", c) - - s4 = re.compile(r"(altdest[0-9]+_)log\(1/samp_wgt\)") - s4f = lambda c: s4.sub(r"log(1/\g<1>samp_wgt)", c) - - s5 = re.compile("(altdest[0-9]+_)1-(.*)") - s5f = lambda c: s5.sub(r"1-\g<1>\g<2>", c) - - s6 = re.compile(r"(altdest[0-9]+_)(.*)(time|ovtt)(.*)/auto_dist_(.*)") - s6f = lambda c: s6.sub(r"\g<1>\g<2>\g<3>\g<4>/\g<1>auto_dist_\g<5>", c) - - s7 = re.compile("(altdest[0-9]+_)(fm..)\(ozone_areatype, areatype\)==(.*)") - s7f = lambda c: s7.sub(r"\g<2>(ozone_areatype, \g<1>areatype)==\g<3>", c) - - s8 = re.compile("(altdest[0-9]+_)hard_sigmoid\((.*)\)") - s8f = lambda c: s8.sub(r"hard_sigmoid(\g<1>\g<2>)", c) - - column_2_replacement = [s8f(s7f(s6f(s5f(s4f(s3f(s2f(s1f(s0f(j))))))))) for j in columns] - dh.column_2_replacement = column_2_replacement - - dfx.columns = column_2_replacement - - -to_disk = False - - -def _data_for_application_2(dh, df2, filename): - # _fix_column_names(dh, df2) - log = getSubLogger("DATA2") - - n_zones = dh.n_internal_zones - alt_codes, alt_names = alt_codes_and_names( - n_sampled_dests=n_zones, - include_actual_dest=False, - ) - - log.debug("initialize dataframes") - dfas = larch.DataFrames( - co=df2.astype(app_floatdtype), - alt_codes=alt_codes, - av=True, - ) - - if to_disk: - log.debug("writing dataframes to disk") - dfas.to_feathers(filename) - return _reload_data_for_application_2(dh, filename) - - log.debug("completed _data_for_application_2") - return dfas - - -def _reload_data_for_application_2(dh, filename): - return larch.DataFrames.from_feathers(filename) - - -def data_for_application(dh, otaz=1, replication=None): - """ - - Parameters - ---------- - otaz : int or array-like - peak : bool - purpose : str - replication : int, optional - - Returns - ------- - - """ - log = getSubLogger("DATA") - if replication is None: - replication = dh.cfg.get('n_replications', 50) - - if isinstance(otaz, int): - df2 = _data_for_application_1(dh, otaz=otaz, replication=replication) - filename = dh.filenames.cache_dir / f"data_for_application_{otaz}" - else: - log.debug("data_for_application::_data_for_application_1") - df2_list = [ - _data_for_application_1(dh, otaz=z, replication=replication) - for z in otaz - ] - log.debug("data_for_application::concat") - df2 = pd.concat(df2_list) - log.debug("data_for_application::filename") - filename = dh.filenames.cache_dir / f"data_for_application_{otaz[0]}_{otaz[-1]}" - return _data_for_application_2(dh, df2.reset_index(drop=True), filename) - - -def blockwise_mean(a, blocksize): - """ - - Parameters - ---------- - a : array-like - blocksize : int - - Returns - ------- - array - """ - n_blocks = a.shape[0] // blocksize + (1 if a.shape[0] % blocksize else 0) - mean = np.zeros([n_blocks, *a.shape[1:]]) - for j in range(n_blocks): - mean[j] = a[j * blocksize:(j + 1) * blocksize].mean(0) - return mean - - -choice_simulator_global = Dict() - - -def choice_simulator_initialize(dh, n_threads=1, cache=True): - """ - Load or create the choice models. - - This function checks if the mode+destination choice models have already been - loaded into memory for this process. If they have not, it then checks if - a pickled version of the choice models has been saved to disk, and loads that - if it is available. Otherwise, it initializes the choice models from scratch - using the `model_builder` function. - - Not coincidentally, these three ways of making the choice model available in - the current process are ordered from fastest to slowest. - - Parameters - ---------- - dh : DataHandler - n_threads : int - How many threads each model should use in computation. - cache : bool - Whether to write pickles to disk. - - Returns - ------- - Dict - """ - global choice_simulator_global - log = getSubLogger("SIM_INIT") - - get_worker_log( - os.path.join(dh.filenames.cache_dir, 'logs'), - level=10, - ) - - log.debug(f"choice_simulator_initialize(n_threads={n_threads}), cache={cache}") - n_zones = dh.n_internal_zones - choice_model_params = dh.choice_model_params - - if len(choice_model_params) == 0: - raise ValueError("no choice_model_params") - - pickle_name = dh.filenames.cache_dir / f"choice_models_{n_zones}.pkl" - - if n_zones not in choice_simulator_global: - log.debug("choice_simulator_initialize: preloaded choice_simulator not available") - if os.path.exists(pickle_name): - import cloudpickle - with open(pickle_name, 'rb') as pkl_f: - log.debug("loading pickled choice_simulator") - choice_simulator_global[n_zones] = cloudpickle.load(pkl_f) - if n_zones in choice_simulator_global: - cache = False - else: - log.debug("pickled choice_simulator not available") - - if n_zones in choice_simulator_global: - log.info("using existing choice_simulator") - choice_simulator = choice_simulator_global[n_zones] - for purpose in purposesA: - choice_simulator[purpose].set_values(choice_model_params[purpose]) - else: - log.info("creating fresh choice_simulator") - choice_simulator = Dict() - for purpose in purposesA: - choice_simulator[purpose] = model_builder( - purpose=purpose, - include_actual_dest=False, - n_sampled_dests=n_zones, # 3632, - parameter_values=choice_model_params[purpose], - constraints=False, - n_threads=n_threads, - explicit_av=False, - ) - choice_simulator_global[n_zones] = choice_simulator - - if cache and not os.path.exists(pickle_name): - import cloudpickle - with open(pickle_name, 'wb') as pkl_f: - log.debug("pickling choice_simulator for future reload") - cloudpickle.dump( - choice_simulator_global[n_zones], - pkl_f, - ) - - return choice_simulator - - -def attach_dataframes(sim, purpose, dfa): - log = getSubLogger("ATTACH_DFS") - if sim.dataframes is None: - log.debug(f"attach_dataframes {purpose} attach dataframes new") - sim.dataframes = dfa - else: - log.debug(f"attach_dataframes {purpose} attach dataframes direct injection") - sim.set_dataframes(dfa, False) - # TODO: explore using inject_feathers instead - - -def _sim_prob(purpose, sim): - sim_pr = sim.probability() - return sim_pr - - -def choice_simulator_prob( - dh, - otaz, - n_threads=1, - temp_dir=None, - purposes=None, -): - """ - Compute probabilities for mode and destination choice. - - Parameters - ---------- - dh : DataHandler - otaz : int or array-like - n_threads : int - temp_dir : Path-like, optional - purposes : Collection, optional - Only compute probabilities for these purposes. - - Returns - ------- - simulated_probability : dict - By purpose, the average choice probabilities. Averages are computed by - simulation of a number of random households and transit accessibility - in the zone, and averaging over the simulation. - simulated_probability_disagg : dict - By purpose, the simulated disaggregated choice probabilities. - validation_useful_data : DataFrame - Validation data extracted from the simulation. - simulated_utility : DataFrame - By purpose, the simulated utilities for auto and transit - """ - if purposes is None: - purposes = purposesA - get_worker_log( - os.path.join(dh.filenames.cache_dir, 'logs'), - level=10, - ) - - data_cache_file = None - if temp_dir: - os.makedirs(temp_dir, exist_ok=True) - if isinstance(otaz, int): - data_cache_file = os.path.join(temp_dir, f"cached_data_for_application_{otaz}.feathers") - else: - data_cache_file = os.path.join(temp_dir, f"cached_data_for_application_{otaz[0]}_{otaz[-1]}.feathers") - - log = getSubLogger("CHOICE_SIM") - - log.debug("data_for_application") - if data_cache_file and os.path.exists(data_cache_file+".data_co"): - log.debug("data_for_application load") - dfa = larch.DataFrames.from_feathers(data_cache_file) - else: - log.debug("data_for_application make") - dfa = data_for_application(dh, otaz=otaz) - if data_cache_file: - dfa.to_feathers(data_cache_file) - - log.debug("settings") - replication = dh.cfg.get('n_replications', 50) - - choice_simulator = choice_simulator_initialize(dh, n_threads=n_threads) - simulated_utility = {} - simulated_probability = {} - simulated_probability_disagg = {} - - for purpose in purposes: - sim = choice_simulator[purpose] - attach_dataframes(sim, purpose, dfa) - log.critical("--- GENERATING SIMULATED UTILITY ---") - sim_u = sim.utility() - sim_u_auto = sim_u[:,mode9codes.AUTO-1:dh.n_internal_zones*9:9] - sim_u_transit = sim_u[:,mode9codes.TRANSIT-1:dh.n_internal_zones*9:9] - simulated_utility[purpose] = pd.concat([ - pd.DataFrame(blockwise_mean(sim_u_auto, replication), index=otaz).rename_axis('otaz', axis=0), - pd.DataFrame(blockwise_mean(sim_u_transit, replication), index=otaz).rename_axis('otaz', axis=0), - ], keys=['AUTO', 'TRANSIT'], names=['MODE']) - sim_pr = _sim_prob(purpose, sim) - simulated_probability_disagg[purpose] = sim_pr - simulated_probability[purpose] = blockwise_mean(sim_pr, replication) - if np.any(np.isnan(simulated_probability[purpose])): - raise ValueError(f"nan in simulated_probability[{purpose}]") - - simulated_utility = pd.concat( - objs=simulated_utility.values(), - keys=simulated_utility.keys(), - names=['PURPOSE'] - ) - - #transit_approach_walktime_cols = [i for i in dfa.data_co.columns if 'transit_approach_walktime' in i and 'auto' not in i and 'sigmoid' not in i] - validation_useful_data = pd.DataFrame(data=np.int8(0), index=dfa.data_co.index, columns=["hh_auto_own", 'hhinc5', 'hhinc5l', 'hhinc5h', 'hhinc5g']) - validation_useful_data.loc[dfa.data_co['hhveh==0'] == 0, "hh_auto_own"] = 1 - validation_useful_data.loc[dfa.data_co['hhveh==0'] > 0, "hh_auto_own"] = 0 - validation_useful_data.loc[dfa.data_co['hhveh>=hhadults'] > 0, "hh_auto_own"] = 2 - validation_useful_data['hhinc5'] = dfa.data_co['hhinc5'] - validation_useful_data['hhinc5g'] = dfa.data_co['hhinc5g'] - validation_useful_data['hhinc5l'] = dfa.data_co['hhinc5l'] - validation_useful_data['hhinc5h'] = dfa.data_co['hhinc5h'] - log.debug("complete") - return simulated_probability, simulated_probability_disagg, validation_useful_data, simulated_utility - - -def choice_simulator_trips( - dh, - otaz, - purposes=None, - random_state=None, - n_threads=1, - save_dir=None, - delay=0, - temp_dir=None, - disagg_choices=True, - use_wfh_pa=False, -): - """ - The single-process function to model trips by mode/dest/time. - - Parameters - ---------- - otaz : int or array-like - purposes : Collection, optional - - Returns - ------- - - """ - get_worker_log( - os.path.join(dh.filenames.cache_dir, 'logs'), - level=10, - ) - log = getSubLogger("TRIP_SIM") - try: - if delay: - log.debug(f"DELAY choice_simulator_trips {delay})") - time.sleep(delay) - - if use_wfh_pa: - dh['tripclass'] = 'wfh' - else: - dh['tripclass'] = 'typical' - - if purposes is None: - purposes = purposesA - - if isinstance(otaz, int): - otaz = [otaz] - - log.debug(f"CALL choice_simulator_trips({len(otaz)} OTAZ's starting from {otaz[0]})") - - simulated_probability, simulated_probability_disagg, validation_data, simulated_utility = choice_simulator_prob( - dh, - otaz=otaz, - n_threads=n_threads, - temp_dir=temp_dir, - ) - simulated_choices = {} - - tod_models = time_of_day_simulator_initialize(dh, cache=True) - - for purpose in purposes: - log.debug(f" choice_simulator_trips processing time-of-day for purpose {purpose})") - choices_data = {} - n = 0 - - for _o in otaz: - random_state = check_random_generator([_o, 534]) - - num_productions = dh.zone_productions5.loc[_o, purpose] - log.debug(f" {purpose} productions for {_o} = {num_productions}") - - if disagg_choices: - c = np.empty(num_productions, dtype=np.int32) - hh_autos = np.zeros(num_productions, dtype=np.int8) - hh_inc5 = np.zeros(num_productions, dtype=np.int8) - c_position = 0 - num_reps = 50 - for _rep in range(num_reps): - num_productions_rep = (num_productions // num_reps) + (1 if (num_productions % num_reps)>_rep else 0) - p = simulated_probability_disagg[purpose][n] - try: - c_ = random_state.choice(p.size, size=num_productions_rep, p=p) - except ValueError as err: - if 'probabilities do not sum to 1' in str(err): - log.error(f"probabilities sum to {np.sum(p)}, correcting") - p /= np.sum(p) - c_ = random_state.choice(p.size, size=num_productions, p=p) - else: - raise - c[c_position:c_position+c_.size] = c_ - hh_autos[c_position:c_position+c_.size] = validation_data["hh_auto_own"][n] - if purpose == 'HBWH': - hh_inc5[c_position:c_position+c_.size] = validation_data["hhinc5h"][n] - elif purpose == 'HBWL': - hh_inc5[c_position:c_position + c_.size] = validation_data["hhinc5l"][n] - elif purpose == 'NHB': - hh_inc5[c_position:c_position + c_.size] = validation_data["hhinc5g"][n] - hh_autos[c_position:c_position + c_.size] = 0 - else: - hh_inc5[c_position:c_position+c_.size] = validation_data["hhinc5"][n] - c_position += c_.size - n += 1 - - else: - p = simulated_probability[purpose][n] - try: - c = random_state.choice(p.size, size=num_productions, p=p) - except ValueError as err: - if 'probabilities do not sum to 1' in str(err): - log.error(f"probabilities sum to {np.sum(p)}, correcting") - p /= np.sum(p) - c = random_state.choice(p.size, size=num_productions, p=p) - else: - raise - n += 1 - hh_autos = np.zeros_like(c) - hh_inc5 = np.zeros_like(c) - - choices_data[_o] = pd.DataFrame(dict( - mode=(c % n_modes) + 1, - zone=(c // n_modes) + 1, - - # other things to track for calibration / validation - hh_autos=hh_autos, - hh_inc5=hh_inc5, - - )).value_counts().sort_index().rename(_o).astype(np.int16) - - full_index = pd.MultiIndex.from_product( - [ - np.arange(n_modes) + 1, - np.arange(dh.n_internal_zones) + 1, - np.arange(3), - np.arange(5) + 1, - ], - names=[ - 'mode', - 'a_zone', - 'hh_autos', - 'hh_inc5', - ], - ) - - simulated_choices_purpose = pd.concat( - choices_data, - axis=1, - ).reindex(full_index).fillna(0).astype(np.int16) - simulated_choices_purpose.columns.name = 'p_zone' - - # simulated_choices_purpose is now a dataframe, with columns giving - # the production zones (by batch) and a dense 2-level index (mode, a_zone) - - simtrips = simulated_choices_purpose.stack().rename("trips").reset_index() - - reg_auto_trips = simtrips.query("(mode in (1,2,3)) and (trips > 0)") - - def apply_tod(base_trips, is_hired_car=0.0, random_gen=123): - - time_data = dh.skims.raw[[f'mf46{j}' for j in range(1, 9)]].iat_df( - base_trips.rename(columns={'a_zone': 'dtaz', 'p_zone': 'otaz'})[['otaz', 'dtaz']] - 1 - ) - time_data["mode9 in ('TAXI','TNC1','TNC2')"] = is_hired_car - time_data["paFlip"] = 0.0 - time_data["(mode9 in ('TAXI','TNC1','TNC2'))*paFlip"] = 0.0 - time_dfs = larch.DataFrames( - co=time_data.astype(np.float64), - av=1, - alt_codes=[1, 2, 3, 4, 5, 6, 7, 8], - alt_names=['EA', 'AM1', 'AM2', 'AM3', 'MD', 'PM1', 'PM2', 'PM3'], - ) - tod_model = tod_models[purposes_to_5[purpose]] - tod_model.dataframes = time_dfs - tod_model_pr = tod_model.probability().copy() - tod_model.dataframes.data_co["paFlip"] = 1.0 - tod_model.dataframes.data_co["(mode9 in ('TAXI','TNC1','TNC2'))*paFlip"] = is_hired_car - tod_model_pr_flip = tod_model.probability().copy() - n_flipped_trips = binom.rvs( - n=base_trips["trips"].values, - p=dh.cfg.time_of_day.pa_split.get(purpose, 0.0 if purpose=='NHB' else 0.5), - random_state=random_gen, - ) - n_unflipped_trips = base_trips["trips"].values - n_flipped_trips - - # forward trips, which go from production to attraction (PA = OD) - reg_auto_trips_tod = pd.DataFrame( - multichoices( - tod_model_pr, - n_unflipped_trips, - seeds=base_trips.index.values+base_trips["p_zone"].values<<16, - ), - index=base_trips.index, - columns=['EA', 'AM1', 'AM2', 'AM3', 'MD', 'PM1', 'PM2', 'PM3'], - ) - reg_auto_trips_fwd = pd.concat([base_trips.drop(columns=['trips']), reg_auto_trips_tod], axis=1) - reg_auto_trips_fwd_= reg_auto_trips_fwd.rename(columns={'p_zone': 'o_zone', 'a_zone': 'd_zone'}) - reg_auto_trips_fwd_['a_zone'] = reg_auto_trips_fwd['a_zone'] - reg_auto_trips_fwd = reg_auto_trips_fwd_.set_index(['mode', 'o_zone', 'd_zone', 'a_zone', 'hh_autos', 'hh_inc5']) - reg_auto_trips_fwd.columns.name = "timeperiod" - reg_auto_trips_fwd = reg_auto_trips_fwd.stack().rename("trips") - - # flipped trips, which go from attraction to production - if isinstance(n_flipped_trips, int): - n_flipped_trips = np.asarray([n_flipped_trips]) - try: - reg_auto_trips_tod_r = pd.DataFrame( - multichoices( - tod_model_pr_flip, - n_flipped_trips, - seeds=base_trips.index.values+base_trips["p_zone"].values<<18, - ), - index=base_trips.index, - columns=['EA', 'AM1', 'AM2', 'AM3', 'MD', 'PM1', 'PM2', 'PM3'], - ) - except: - log.error(f"{tod_model_pr_flip=}") - log.error(f"{n_flipped_trips=}") - log.exception("error in reg_auto_trips_tod_r") - raise - reg_auto_trips_bwd = pd.concat([base_trips.drop(columns=['trips']), reg_auto_trips_tod_r], axis=1) - reg_auto_trips_bwd_ = reg_auto_trips_bwd.rename(columns={'p_zone': 'd_zone', 'a_zone': 'o_zone'}) - reg_auto_trips_bwd_['a_zone'] = reg_auto_trips_bwd['a_zone'] - reg_auto_trips_bwd = reg_auto_trips_bwd_.set_index(['mode', 'o_zone', 'd_zone', 'a_zone', 'hh_autos', 'hh_inc5']) - reg_auto_trips_bwd.columns.name = "timeperiod" - reg_auto_trips_bwd = reg_auto_trips_bwd.stack().rename("trips") - - return pd.concat([ - reg_auto_trips_fwd[reg_auto_trips_fwd > 0], - reg_auto_trips_bwd[reg_auto_trips_bwd > 0], - ]) - - - hired_auto_trips = simtrips.query("(mode in (4,5,6)) and (trips > 0)") - - log.debug(f" applying TOD to reg_auto_trips") - reg_auto_trips = apply_tod(reg_auto_trips, 0.0, random_state) - log.debug(f" applying TOD to hired_auto_trips") - hired_auto_trips = apply_tod(hired_auto_trips, 1.0, random_state) - - log.debug(f" applying directionality to non-auto trips") - # non-auto trips - non_auto_trips = simtrips.query("(mode in (7,8,9)) and (trips > 0)") - non_auto_trips = non_auto_trips.reset_index(drop=True) - non_auto_trips["timeperiod"] = "NA" - n_flipped_trips = binom.rvs( - n=non_auto_trips["trips"].values, - p=dh.cfg.time_of_day.pa_split.get(purpose, 0.5), - random_state=random_state, - ) - n_unflipped_trips = non_auto_trips["trips"].values - n_flipped_trips - - non_auto_trips_attractions = non_auto_trips['a_zone'] - - non_auto_trips_r = non_auto_trips.copy(deep=True) - non_auto_trips_r["trips"] = n_flipped_trips - non_auto_trips_r = non_auto_trips_r.rename(columns={'p_zone': 'o_zone', 'a_zone': 'd_zone'}) - non_auto_trips_r['a_zone'] = non_auto_trips_attractions - non_auto_trips_r = non_auto_trips_r.set_index(['mode', 'o_zone', 'd_zone', 'a_zone', 'hh_autos', 'hh_inc5', 'timeperiod'])["trips"] - - non_auto_trips["trips"] = n_unflipped_trips - non_auto_trips = non_auto_trips.rename(columns={'p_zone': 'd_zone', 'a_zone': 'o_zone'}) - non_auto_trips['a_zone'] = non_auto_trips_attractions - non_auto_trips = non_auto_trips.set_index(['mode', 'o_zone', 'd_zone', 'a_zone', 'hh_autos', 'hh_inc5', 'timeperiod'])["trips"] - - non_auto_trips = pd.concat([non_auto_trips[non_auto_trips>0], non_auto_trips_r[non_auto_trips_r>0]]) - #non_auto_trips = non_auto_trips.reset_index() - - sim_mode_dest_tod = pd.concat([reg_auto_trips, hired_auto_trips, non_auto_trips]) - if isinstance(sim_mode_dest_tod, pd.Series): - sim_mode_dest_tod = pd.DataFrame(sim_mode_dest_tod) - # if save_dir is not None: - # sim_mode_dest_tod.to_parquet(os.path.join(save_dir, f"choice_simulator_trips_{purpose}_{otaz[0]}_{otaz[-1]}.pq")) - simulated_choices[purpose] = sim_mode_dest_tod - - if purpose == 'NHB': - - # Visitor trips - visitor_choices_data = [] - for otaz_n, otaz_ in enumerate(otaz): - - visitor_pr = simulated_probability['NHB'][otaz_n] - k = 0 - for dtaz_ in range(1, dh.n_internal_zones+1): - n_visitor_trips_here = dh.visitor_trips.iloc[otaz_-1, dtaz_-1] - if n_visitor_trips_here == 0: - k += 9 - continue - else: - visitor_mode_pr = np.nan_to_num(visitor_pr[k:k+9]) - visitor_mode_pr[mode9codes.TAXI-1] *= dh.cfg.get('visitor_taxi_multiple', 5.0) - visitor_mode_pr[mode9codes.TNC1-1] *= dh.cfg.get('visitor_tnc1_multiple', 5.0) - visitor_mode_pr[mode9codes.TNC2-1] *= dh.cfg.get('visitor_tnc2_multiple', 5.0) - k += 9 - visitor_mode_pr_sum = visitor_mode_pr.sum() - if visitor_mode_pr_sum == 0: continue # this OD pair is not valid - visitor_mode_pr /= visitor_mode_pr_sum - c = random_state.choice( - 9, - size=n_visitor_trips_here, - p=visitor_mode_pr, - ) - visitor_choices_data.append(pd.DataFrame(dict( - mode=c+1, - p_zone=otaz_, - a_zone=dtaz_, - hh_autos=-1, - hh_inc5=-1, - )).value_counts().sort_index().rename('trips').astype(np.int16)) - - visitor_choices = pd.concat(visitor_choices_data).reset_index() - visitor_reg_auto_trips = apply_tod(visitor_choices.query("(mode in (1,2,3)) and (trips > 0)"), 0.0) - visitor_hired_auto_trips = apply_tod(visitor_choices.query("(mode in (4,5,6)) and (trips > 0)"), 1.0) - visitor_nonauto_trips = visitor_choices.query("(mode in (7,8,9)) and (trips > 0)").copy() - visitor_nonauto_trips['timeperiod'] = 'NA' - visitor_nonauto_trips = visitor_nonauto_trips.rename(columns={'p_zone': 'o_zone', 'a_zone': 'd_zone'}) - visitor_nonauto_trips['a_zone'] = visitor_nonauto_trips['d_zone'] - visitor_choices_with_time = pd.concat([ - visitor_reg_auto_trips.reset_index(), - visitor_hired_auto_trips.reset_index(), - visitor_nonauto_trips, - ], ignore_index=True).set_index(['mode','o_zone','d_zone','a_zone','hh_autos','hh_inc5','timeperiod']) - simulated_choices['VISIT'] = visitor_choices_with_time - - concatd = pd.concat(simulated_choices) - concatd.index.set_names('purpose', level=0, inplace=True) - if save_dir is not None: - os.makedirs(save_dir, exist_ok=True) - concise = pd.DataFrame(concatd) - concise.to_parquet(os.path.join( - save_dir, - f"choice_simulator_trips_{otaz[0]}_{otaz[-1]}_{'_'.join(purposes)}_{dh['tripclass']}.pq" - )) - log.critical(f"--- SAVING SIMULATED UTILITY to {save_dir} ---") - simulated_utility.columns = [f'dest{i+1}' for i in range(dh.n_internal_zones)] - simulated_utility.to_parquet(os.path.join( - save_dir, - f"choice_simulator_util_{otaz[0]}_{otaz[-1]}_{'_'.join(purposes)}_{dh['tripclass']}.pq" - )) - else: - log.critical(f"--- NOT SAVING SIMULATED UTILITY (save_dir is None) ---") - log.debug(f"COMPLETED choice_simulator_trips({len(otaz)} OTAZ's starting from {otaz[0]})") - - return concatd - except: - log.exception(f"error in choice_simulator_trips for otaz={otaz}") - raise - -def stagger_starts(iterable, delay=3, n_jobs=4): - pause = 0 - for n, i in enumerate(iterable, start=1): - yield (pause, i) - if n >= n_jobs: - pause = 0 - else: - pause += delay - - -def choice_simulator_trips_many( - dh, - otaz=None, - max_chunk_size=20, - n_jobs=5, - thread_saturation=1, - cache_subdir="choice_simulator_trips", - temp_dir=None, - with_nonhome_auto=False, - disagg_choices=True, - with_wfh=True, - staggertime=15, -): - """ - Run the choice simulators, batching a few TAZ's at at time in parallel jobs. - - Parameters - ---------- - dh : DataHandler - otaz : array-like, optional - The OTAZ's to process. Defaults to generating trips originating from - all internal zones. - max_chunk_size : int, default 20 - The number of OTAZ's to group together in each chunk. Larger chunks - run faster but require more RAM. - n_jobs : int, default 5 - Number of parallel jobs to start. - thread_saturation : int, default 1 - Number of threads per job to allow. Some parts of some computations are - multi-threaded, and can run faster if multiple threads are allowed. - However, if enough RAM is available, it is more efficent to have more - jobs than use more threads per job. - cache_subdir : Path-like, default "choice_simulator_trips" - Relative path, within the cache directory, in which partial results are - stored from each job. - temp_dir : Path-like, optional - A temporary directory used to store processed data during a job. This - feature is made available to handle the case where non-home-based trips - need to be processed separately from home-based trips, so that auto - propensity can be used from the current iteration. The model as - implemented (October 2021) uses lagged auto propensity from the prior - global iteration, so storing this data is not necessary. - with_nonhome_auto : bool, default False - Set to True to use auto propensity from the current home-based trips in - the current global iteration. Warning: This massively increases model - runtime. - disagg_choices : bool, default True - Keep a record of trip choices by disaggregate validation categories - (income, auto ownership, etc). The computed behavioral choices are the - same, but the output files are generated with more detail suitable for - validation (but they are also much larger). - with_wfh : bool, default True - Run the entire model a second time, using the WFH production and - attractions. - staggertime : int, default 15 - Number of seconds to stagger the initial launch of jobs. Staggering - helps prevent resource contention across jobs (i.e. trying to read - inputs from disk at the same time, which can saturate the bandwidth for - disk reading and cause slowdowns in processes). - - Returns - ------- - dask dataframe - The modeled trips - """ - log = getSubLogger("TRIP_SIM_MULTI") - - if otaz is None: - otaz = np.arange(dh.n_internal_zones) + 1 - - # auto chunk size calculation - n_chunks_per_job = 0 - chunk_size = np.inf - while chunk_size > max_chunk_size: - n_chunks_per_job += 1 - chunk_size = int(np.ceil(len(otaz) / n_jobs / n_chunks_per_job)) - if chunk_size == 1: - break - - log.info(f"using chunk_size={chunk_size} to process {len(otaz)} otazs across {n_jobs} jobs") - - otaz_chunks = [otaz[i:i + chunk_size] for i in range(0, len(otaz), chunk_size)] - # inits = [None for _ in range(0, min(len(otaz), n_jobs))] - - import joblib - save_dir = dh.filenames.cache_dir / cache_subdir - os.makedirs(save_dir, exist_ok=True) - n_threads = max(int(thread_saturation * joblib.cpu_count() // n_jobs), 1) - log.info(f"using n_threads={n_threads} (per job)") - - # if temp_dir is None: - # temp_dir = save_dir/"temp" - if temp_dir is not None: - os.makedirs(temp_dir, exist_ok=True) - - # The model allows for using auto propensity for non-home trips - # that is lagged by one global iteration. This allows all trip purposes - # to be processed together, greating improving runtime. - if with_nonhome_auto: - first_purposes = tuple(j for j in purposesA if 'NHB' not in j) - second_purposes = tuple(j for j in purposesA if j not in first_purposes) - else: - first_purposes = purposesA - second_purposes = () - - with joblib.Parallel(n_jobs=n_jobs, verbose=100) as parallel: - # IMPORTANT: Do not run the initialize step as show below - # the memory usage of the worker will be much smaller - # than for a real step, and loky will think there is - # a memory leak and kill the worker. - # if init_step: - # log.info("joblib model init starting") - # _ = parallel( - # joblib.delayed(choice_simulator_initialize)(dh, False) - # for _ in inits - # ) - # log.info("joblib model init complete") - # else: - log.info("joblib model body starting") - parallel( - joblib.delayed(choice_simulator_trips)( - dh, - otaz_chunk, - purposes=first_purposes, - save_dir=save_dir, - n_threads=n_threads, - delay=delay, - temp_dir=temp_dir, - disagg_choices=disagg_choices, - ) - for delay, otaz_chunk in stagger_starts(otaz_chunks, delay=staggertime, n_jobs=n_jobs) - ) - if with_wfh: - log.info("joblib model WFH starting") - parallel( - joblib.delayed(choice_simulator_trips)( - dh, - otaz_chunk, - purposes=first_purposes, - save_dir=save_dir, - n_threads=n_threads, - delay=delay, - temp_dir=temp_dir, - disagg_choices=disagg_choices, - use_wfh_pa=True, - ) - for delay, otaz_chunk in stagger_starts(otaz_chunks, delay=staggertime, n_jobs=n_jobs) - ) - log.info("joblib first purposes complete") - - log.info("computing auto propensity by zone") - trips = assemble_trips( - dh, - from_dir=save_dir, - pattern="choice_simulator_trips_*.pq", - compute_auto_propensity=True, - ) - if second_purposes: - with joblib.Parallel(n_jobs=n_jobs, verbose=100) as parallel: - log.info("joblib model second purposes starting") - parallel( - joblib.delayed(choice_simulator_trips)( - dh, - otaz_chunk, - purposes=second_purposes, - save_dir=save_dir, - n_threads=n_threads, - delay=delay, - temp_dir=temp_dir, - disagg_choices=disagg_choices, - ) - for delay, otaz_chunk in stagger_starts(otaz_chunks, delay=staggertime, n_jobs=n_jobs) - ) - if with_wfh: - log.info("joblib model second purposes WFH starting") - parallel( - joblib.delayed(choice_simulator_trips)( - dh, - otaz_chunk, - purposes=second_purposes, - save_dir=save_dir, - n_threads=n_threads, - delay=delay, - temp_dir=temp_dir, - disagg_choices=disagg_choices, - use_wfh_pa=True, - ) - for delay, otaz_chunk in stagger_starts(otaz_chunks, delay=staggertime, n_jobs=n_jobs) - ) - - log.info("joblib second purposes complete") - trips = assemble_trips( - dh, - from_dir=save_dir, - pattern="choice_simulator_trips_*.pq", - compute_auto_propensity=False, - ) - - log.info("computing deadhead trips by hired cars") - try: - deadheads = compute_deadhead_trip_table( - dh, - trips, - ) - except KeyError: - import numexpr as ne - ne.necompiler._numexpr_cache.clear() - deadheads = compute_deadhead_trip_table( - dh, - trips, - ) - if disagg_choices: - deadheads['hh_autos'] = -1 - deadheads['hh_inc5'] = -1 - deadheads.to_parquet(os.path.join(save_dir, "choice_simulator_trips_deadhead.pq")) - - return assemble_trips( - dh, - from_dir=save_dir, - pattern="choice_simulator_trips_*.pq", - compute_auto_propensity=False, - ) - - - -def assemble_trips( - dh, - from_dir, - pattern="choice_simulator_trips_*.pq", - compute_auto_propensity=False, - validation_dump=None, -): - """ - Assemble trip list files into a single dask DataFrame for processing. - - Parameters - ---------- - dh - from_dir - pattern - compute_auto_propensity - validation_dump - - Returns - ------- - - """ - from_dir = Path(from_dir) - - import dask.dataframe as ddf - import glob - - trips = ddf.read_parquet(glob.glob(os.fspath(from_dir/pattern))) - - if compute_auto_propensity: - homebased_trips_by_mode = ( - trips - .query("purpose not in ('NHB', 'NHBR', 'NHBS')") - .groupby(["mode", "a_zone"])['trips'] - .sum() - .compute() - .unstack(0) - .fillna(0) - ) - auto_propensity = ( - homebased_trips_by_mode.loc[:, [1, 2, 3]].sum(1) / homebased_trips_by_mode.sum(1) - ) - auto_propensity = auto_propensity.reindex(pd.RangeIndex(1, 3632 + 1)).fillna(0.95).rename("auto_propensity") - auto_propensity.index.name = "TAZ" - auto_propensity.to_csv(dh.filenames.emme_database_dir / "computed_auto_propensity.csv") - - if validation_dump is not None: - trips.to_csv( - os.fspath(from_dir/validation_dump), - single_file=True, - compression='gzip' if validation_dump.endswith(".gz") else None, - ) - - return trips - - -def aggregate_to_vehicle_matrixes( - dh, - trips, -): - """ - Aggregate person trips into emme matrix vehicle trips. - - This function writes vehicle trip tables to mfNNN.emx files in the - `Database/emmemat` directory, according to the following guide: - - Automobile Vehicle Trips (by 8 time of day periods EA AM1 AM2 AM3 MD PM1 PM2 PM3) - - SOV low value of time – mf411-mf418 - - SOV med value of time – mf421-mf428 - - SOV high value of time – mf431-mf438 - - HOV2 not diff'd by vot – mf441-mf448 - - HOV3 not diff'd by vot – mf451-mf458 - - Transit Person Trips (not by time of day) - - home-based work low income - mf40 - - home-based work high income - mf41 - - home-based shopping - mf39 - - home-based other - mf42 - - non-home-based - mf43 - - Parameters - ---------- - dh : DataHandler - trips : DataFrame - The output trip table from the mode/dest/time-of-day models - - Returns - ------- - vehicle_trips : xarray.DataArray - """ - - log = getSubLogger("application.ToMatrix") - log.info(f"running aggregate_to_vehicle_matrixes") - - # If we receive a dask dataframe, load it into a pandas dataframe now - import dask.dataframe as ddf - if isinstance(trips, ddf.DataFrame): - log.debug(f"converting trips from dask.dataframe to pandas.dataframe") - trips = trips.compute() - - # hov3_occupancy = { - # 'HBW': 3.36, - # 'HBO': 3.31, - # 'NHB': 3.39, - # } - - from .modecodes import mode9codes - from .time_of_day_model import time_period_names - n_timeperiods = len(time_period_names) - n_zones = dh.skims.raw.dims['otaz'] - z_range = pd.RangeIndex(1, n_zones + 1) - vot_names = ['sovL', 'sovM', 'sovH', 'hov2', 'hov3'] - - votb = pd.read_csv( - dh.filenames.value_of_time_buckets, - comment="#", - skipinitialspace=True, - ) - votb = votb.set_index(["Purpose", "Income Group"]) - votb = votb.div(votb.sum(1), axis=0) - - vehicle_trips = xr.DataArray( - data=np.float32(0.0), - dims=['vot', 'timeperiod', 'o_zone', 'd_zone'], - coords={ - 'vot': vot_names, - 'timeperiod': time_period_names, - 'o_zone': z_range, - 'd_zone': z_range, - } - ) - - for purpose, income in votb.index: - log.info(f" sov for purpose {purpose} income {income}") - - sov_array = xr.DataArray.from_series( - trips - .query(f"purpose == '{purpose}' and mode == {1} and hh_inc5 == {income}") - .groupby(["timeperiod", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - timeperiod=time_period_names, o_zone=z_range, d_zone=z_range, - ).fillna(0).values - - log.info(f" sov for purpose {purpose} income {income} total={np.sum(sov_array)}") - - for vot_bucket in range(3): - vehicle_trips[vot_bucket] += sov_array * votb.loc[(purpose, income)].iloc[vot_bucket] - - # count up all HOV2 person trips, divide by 2 - #for modecode, vot_bucket in zip([mode9codes.HOV2, mode9codes.HOV3], [3,4]): - log.info(f" hov2") - vehicle_trips[3, ...] = xr.DataArray.from_series( - trips - .query(f"mode in ({mode9codes.HOV2},{mode9codes.TAXI},{mode9codes.TNC1})") ##-- Heither .query(f"mode == {mode9codes.HOV2}") - .groupby(["timeperiod", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - timeperiod=time_period_names, o_zone=z_range, d_zone=z_range, - ).fillna(0).values / 2 - - log.info(f" hov3") - # count up all HOV3 person trips, divide by occupancy - vehicle_trips[4, ...] += xr.DataArray.from_series( - trips - .query(f"purpose in ('HBWH', 'HBWL') and mode in ({mode9codes.HOV3},{mode9codes.TNC2})") ##-- Heither .query(f"purpose in ('HBWH', 'HBWL') and mode == {mode9codes.HOV3}") - .groupby(["timeperiod", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - timeperiod=time_period_names, o_zone=z_range, d_zone=z_range, - ).fillna(0).values / dh.cfg.hov3_occupancy['HBW'] - vehicle_trips[4, ...] += xr.DataArray.from_series( - trips - .query(f"purpose in ('HBO', 'HBS') and mode in ({mode9codes.HOV3},{mode9codes.TNC2})") ##-- Heither .query(f"purpose in ('HBO', 'HBS') and mode == {mode9codes.HOV3}") - .groupby(["timeperiod", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - timeperiod=time_period_names, o_zone=z_range, d_zone=z_range, - ).fillna(0).values / dh.cfg.hov3_occupancy['HBO'] - vehicle_trips[4, ...] += xr.DataArray.from_series( - trips - .query(f"purpose in ('NHB', 'VISIT') and mode in ({mode9codes.HOV3},{mode9codes.TNC2})") ##-- Heither .query(f"purpose in ('NHB', 'VISIT') and mode == {mode9codes.HOV3}") - .groupby(["timeperiod", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - timeperiod=time_period_names, o_zone=z_range, d_zone=z_range, - ).fillna(0).values / dh.cfg.hov3_occupancy['NHB'] - - output_mf_numbers = { - 'sovL': 411, # SOV low value of time – mf411-mf418 - 'sovM': 421, # SOV med value of time – mf421-mf428 - 'sovH': 431, # SOV high value of time – mf431-mf438 - 'hov2': 441, # HOV2 not diff'd by vot – mf441-mf448 - 'hov3': 451, # HOV3 not diff'd by vot – mf451-mf458 - } - - for vot in vot_names: - for t, time_period_name in enumerate(time_period_names): - n = output_mf_numbers[vot] + t - mtx_filename = os.fspath(dh.filenames.emme_database_dir / f"emmemat/mf{n}.emx") - write_out = vehicle_trips \ - .sel(vot=vot, timeperiod=time_period_name) \ - .transpose("o_zone", "d_zone") \ - .values - if os.path.exists(mtx_filename): - mmap_mode = 'r+' - else: - mmap_mode = 'w+' - # We write into the existing file instead of deleting and rewriting the file - # emme may be happier this way if the file handle was previously held open - mmap = np.memmap( - mtx_filename, - dtype=np.float32, - mode=mmap_mode, - shape=write_out.shape, - ) - mmap[:,:] = write_out - mmap.flush() - - # transit person trips - - purposes6 = np.asarray(( - 'HBWH', # Home-based Work, High Income - 'HBWL', # Home-based Work, Low Income - 'HBS', # Home-based Shopping - 'HBO', # Home-based Other Purpose Not Enumerated - 'NHB', # Non-home-based - 'VISIT', - ),) - - transit_trips = xr.DataArray.from_series( - trips - .query(f"mode == {mode9codes.TRANSIT}") - .groupby(["purpose", "o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - purpose=purposes6, o_zone=z_range, d_zone=z_range, - ).astype(np.float32).fillna(0) - - transit_trip_mtx_numbers = { - 'HBWL': 'mf40', - 'HBWH': 'mf41', - 'HBS': 'mf39', - 'HBO': 'mf42', - 'NHB': 'mf43', - 'VISIT': 'mf38', - } - - for purpose, purp_mtx in transit_trip_mtx_numbers.items(): - mtx_filename = os.fspath(dh.filenames.emme_database_dir / f"emmemat/{purp_mtx}.emx") - write_out = transit_trips.sel(purpose=purpose).transpose("o_zone", "d_zone").values #.tofile(mtx_filename) - if os.path.exists(mtx_filename): - mmap_mode = 'r+' - else: - mmap_mode = 'w+' - # We write into the existing file instead of deleting and rewriting the file - # emme may be happier this way if the file handle was previously held open - mmap = np.memmap( - mtx_filename, - dtype=np.float32, - mode=mmap_mode, - shape=write_out.shape, - ) - mmap[:, :] = write_out - mmap.flush() - - # Example: home-based work high and low income auto person-trips - if False: - custom_person_trips = xr.DataArray.from_series( - trips - .query(f"purpose in ('HBWH', 'HBWL') and mode in ({mode9codes.AUTO},{mode9codes.HOV2},{mode9codes.HOV3})") - .groupby(["o_zone", "d_zone"])['trips'] - .sum() - ).reindex( - o_zone=z_range, d_zone=z_range, - ).astype(np.float32).fillna(0) - - custom_matrix_number = 1234 - mtx_filename = os.fspath(dh.filenames.emme_database_dir / f"emmemat/{custom_matrix_number}.emx") - write_out = custom_person_trips.transpose("o_zone", "d_zone").values # use "transpose" to ensure ozone is rows and dzone is cols - if os.path.exists(mtx_filename): - mmap_mode = 'r+' - else: - mmap_mode = 'w+' - # We write into the existing file instead of deleting and rewriting the file - # emme may be happier this way if the file handle was previously held open - mmap = np.memmap( - mtx_filename, - dtype=np.float32, - mode=mmap_mode, - shape=write_out.shape, - ) - mmap[:, :] = write_out - mmap.flush() - - return vehicle_trips \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/choice_model.py b/src/Mode-Dest-TOD/cmap_modedest/choice_model.py deleted file mode 100755 index 165c1f5..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/choice_model.py +++ /dev/null @@ -1,544 +0,0 @@ -import numpy as np -import pandas as pd -import larch -from larch import P,X -from larch.util.data_expansion import piecewise_linear -from .addict import Dict -from .cmap_logging import getLogger -from .modecodes import mode5codes, mode9codes, mode9names - -log = getLogger() - - - -def alt_codes_and_names( - n_sampled_dests=5, - include_actual_dest=True, -): - """ - Generate alternative names and codes for mode-destination model. - - Parameters - ---------- - n_sampled_dests : int - The number of destinations that will be used. In estimation, this - is the number of destinations to be sampled. In application, this - is the total number of destinations, as sampling is not used. - include_actual_dest : bool - Whether to include the "actual" destination. This destination is - included in estimation, where it is used to populate the actually - chosen alternative. In appplication, the "actual" destination is - not applicable and should be turned off. - - Returns - ------- - alt_codes : ndarray - alt_names : list - """ - n_modes = len(mode9names) - alt_codes = np.arange(n_modes * (n_sampled_dests + 1)) + 1 - alt_names = [i for i in mode9names] - for i in range(n_sampled_dests): - alt_names.extend([(j + f"d{i + 1:04d}") for j in mode9names]) - if not include_actual_dest: - alt_codes = alt_codes[n_modes:] - alt_names = alt_names[n_modes:] - return alt_codes, alt_names - - -def model_utility_for_dest( - m, - dest_number, - purpose, - n_modes, -): - """ - Construct some utility functions for the mode and destination model. - - This method constructs the utility functions for all of the modes, for - a single destination. It is called multiple times to build the complete - set of utility functions across all destinations. - - Parameters - ---------- - m : larch.Model - dest_number : int - The number of the destination. In application, this is - the TAZ index (TAZ ID minus 1). In estimation, this is - the sampling slot, or for actual destination, give -1. - purpose : str - n_modes : int - - Returns - ------- - - """ - if dest_number == -1: - dest_label = "actualdest" - else: - dest_label = f'altdest{dest_number + 1:04d}' - - alts_per_dest = n_modes - utility_destination = ( - + P("samp_af") * X(f"log(1/{dest_label}_samp_wgt)") - + P("log_attraction") * X(f"{dest_label}_log_attractions_{purpose}") - + P("intrazonal") * X(f"o_zone == {dest_label}") - + piecewise_linear(f"{dest_label}_auto_dist_OFFPEAK", "distance", breaks=[5, 10]) - ) - shift = (dest_number+1) * alts_per_dest - jAUTO = mode9codes.AUTO + shift - jHOV2 = mode9codes.HOV2 + shift - jHOV3 = mode9codes.HOV3 + shift - jTNC1 = mode9codes.TNC1 + shift - jTNC2 = mode9codes.TNC2 + shift - jTAXI = mode9codes.TAXI + shift - jTRANSIT = mode9codes.TRANSIT + shift - jWALK = mode9codes.WALK + shift - jBIKE = mode9codes.BIKE + shift - peaky = 'PEAK' if 'W' in purpose else 'OFFPEAK' - peaky_hov = 'hov_PEAK' if 'W' in purpose else 'OFFPEAK' - - - m.utility_co[jAUTO] = ( - + P("cost") * X(f"{dest_label}_auto_opcost_{peaky}") / 100 # cost in dollars - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("cost") * X(f"{dest_label}_auto_parking_cost_{purpose}") / 100 # cost in dollars - # TODO add walk terminal time cost - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - ) + utility_destination - if purpose.upper()[-1] == 'H': - m.utility_co[jAUTO] += P("cost") * X(f"{dest_label}_auto_toll_hiinc_PEAK") / 100 # cost in dollars - elif purpose.upper()[-1] == 'L': - m.utility_co[jAUTO] += P("cost") * X(f"{dest_label}_auto_toll_loinc_PEAK") / 100 # cost in dollars - else: - m.utility_co[jAUTO] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 100 # cost in dollars - if purpose.upper() in {'NH', 'NHB'}: - m.utility_co[jAUTO] += ( - + P("AUTO_ozone_autopropensity") * X(f"ozone_autopropensity") - + P("AUTO_dzone_autopropensity") * X(f"{dest_label}_autopropensity") - ) - else: - m.utility_co[jAUTO] += ( - + P("AUTO_no_veh") * X("hhveh==0") - + P("AUTO_sufficient_veh") * X("hhveh>=hhadults") - ) - - - m.utility_co[jHOV2] = ( - P.Const_HOV2 - + P("cost") * X(f"{dest_label}_auto_opcost_{peaky_hov}") * 0.5 / 100 # cost in dollars - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("cost") * 0.5 * X(f"{dest_label}_auto_parking_cost_{purpose}") / 100 # cost in dollars - # TODO add walk terminal time cost - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - + piecewise_linear(f"{dest_label}_auto_dist_OFFPEAK", "HOV2_distance", breaks=[5, 10]) - ) + utility_destination - if purpose.upper()[-1] == 'H': - m.utility_co[jHOV2] += P("cost") * X(f"{dest_label}_auto_toll_hov_hiinc_PEAK") / 2 / 100 # cost in dollars - elif purpose.upper()[-1] == 'L': - m.utility_co[jHOV2] += P("cost") * X(f"{dest_label}_auto_toll_hov_loinc_PEAK") / 2 / 100 # cost in dollars - else: - m.utility_co[jHOV2] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 2 / 100 # cost in dollars - if purpose.upper() in {'NH', 'NHB'}: - m.utility_co[jHOV2] += ( - + P("HOV_ozone_autopropensity") * X(f"ozone_autopropensity") - + P("HOV_dzone_autopropensity") * X(f"{dest_label}_autopropensity") - ) - else: - m.utility_co[jHOV2] += ( - + P("HOV_no_veh") * X("hhveh==0") - + P("HOV_sufficient_veh") * X("hhveh>=hhadults") - ) - - - - - m.utility_co[jHOV3] = ( - P.Const_HOV3 - + P("cost") * X(f"{dest_label}_auto_opcost_{peaky_hov}") * 0.33 / 100 # cost in dollars - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("cost") * 0.33 * X(f"{dest_label}_auto_parking_cost_{purpose}") / 100 # cost in dollars - # TODO add walk terminal time cost - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - + piecewise_linear(f"{dest_label}_auto_dist_OFFPEAK", "HOV3_distance", breaks=[5, 10]) - ) + utility_destination - if purpose.upper()[-1] == 'H': - m.utility_co[jHOV3] += P("cost") * X(f"{dest_label}_auto_toll_hov_hiinc_PEAK") / 3 / 100 # cost in dollars - elif purpose.upper()[-1] == 'L': - m.utility_co[jHOV3] += P("cost") * X(f"{dest_label}_auto_toll_hov_loinc_PEAK") / 3 / 100 # cost in dollars - else: - m.utility_co[jHOV3] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 3 / 100 # cost in dollars - if purpose.upper() in {'NH', 'NHB'}: - m.utility_co[jHOV3] += ( - + P("HOV_ozone_autopropensity") * X(f"ozone_autopropensity") - + P("HOV_dzone_autopropensity") * X(f"{dest_label}_autopropensity") - ) - else: - m.utility_co[jHOV3] += ( - + P("HOV_no_veh") * X("hhveh==0") - + P("HOV_sufficient_veh") * X("hhveh>=hhadults") - ) - m.utility_co[jTNC1] = ( - P.Const_TNC1 - + P("cost") * X(f"{dest_label}_tnc_solo_fare_{peaky}") / 100 # cost in dollars - + P("ovtt_dist") * X(f"{dest_label}_tnc_solo_wait_time_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("totaltime") * X(f"{dest_label}_tnc_solo_wait_time_{peaky}") - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - ) + utility_destination - m.utility_co[jTNC2] = ( - P.Const_TNC2 - + P("cost") * X(f"{dest_label}_tnc_pool_fare_{peaky}") / 100 # cost in dollars - + P("ovtt_dist") * X(f"{dest_label}_tnc_pool_wait_time_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("totaltime") * X(f"{dest_label}_tnc_pool_wait_time_{peaky}") - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - ) + utility_destination - m.utility_co[jTAXI] = ( - P.Const_TAXI - + P("cost") * X(f"{dest_label}_taxi_fare_{peaky}") / 100 # cost in dollars - + P("ovtt_dist") * X(f"{dest_label}_taxi_wait_time_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("totaltime") * X(f"{dest_label}_taxi_wait_time_{peaky}") - + P("totaltime") * X(f"{dest_label}_auto_time_{peaky}") - + P("unavail") * X(f"1-{dest_label}_auto_avail_{purpose}") - ) + utility_destination - - if purpose.upper()[-1] == 'H': - m.utility_co[jTNC1] += P("cost") * X(f"{dest_label}_auto_toll_hiinc_PEAK") / 100 # cost in dollars - m.utility_co[jTNC2] += P("cost") * X(f"{dest_label}_auto_toll_hiinc_PEAK") / 2 / 100 # cost in dollars - m.utility_co[jTAXI] += P("cost") * X(f"{dest_label}_auto_toll_hiinc_PEAK") / 100 # cost in dollars - elif purpose.upper()[-1] == 'L': - m.utility_co[jTNC1] += P("cost") * X(f"{dest_label}_auto_toll_loinc_PEAK") / 100 # cost in dollars - m.utility_co[jTNC2] += P("cost") * X(f"{dest_label}_auto_toll_loinc_PEAK") / 2 / 100 # cost in dollars - m.utility_co[jTAXI] += P("cost") * X(f"{dest_label}_auto_toll_loinc_PEAK") / 100 # cost in dollars - else: - m.utility_co[jTNC1] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 100 # cost in dollars - m.utility_co[jTNC2] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 2 / 100 # cost in dollars - m.utility_co[jTAXI] += P("cost") * X(f"{dest_label}_auto_toll_OFFPEAK") / 100 # cost in dollars - - - m.utility_co[jWALK] = ( - P.Const_WALK - #+ P("walk_time") * X(f"{dest_label}_auto_dist_OFFPEAK") * 20 # minutes per mile - + piecewise_linear(f"{dest_label}_auto_dist_OFFPEAK", "walk_time", breaks = [0.5,1.0]) * 20 # minutes per mile - + P("walk_intrazonal") * X(f"o_zone == {dest_label}") - + P("walk_areatype2") * X(f"fmax(ozone_areatype, {dest_label}_areatype)==2") - + P("walk_areatype3") * X(f"fmax(ozone_areatype, {dest_label}_areatype)==3") - + P("walk_areatype4") * X(f"fmax(ozone_areatype, {dest_label}_areatype)==4") - ) + utility_destination - m.utility_co[jBIKE] = ( - P.Const_BIKE - + P("bike_time") * X(f"{dest_label}_auto_dist_OFFPEAK") * 5 # minutes per mile - + P("bike_intrazonal") * X(f"o_zone == {dest_label}") - ) + utility_destination - m.utility_co[jTRANSIT] = ( - P.Const_Transit - + P("cost") * X(f"{dest_label}_transit_fare_{peaky}") / 100 # cost in dollars - + P("totaltime") * X(f"{dest_label}_transit_ovtt_{peaky}") - + P("cost") * X(f"{dest_label}_transit_approach_cost_{peaky}") / 100 # cost in dollars - + P("totaltime") * X(f"{dest_label}_transit_approach_drivetime_{peaky}") - + P("totaltime") * X(f"{dest_label}_transit_approach_walktime_{peaky}") - + P("totaltime") * X(f"{dest_label}_transit_approach_waittime_{peaky}") - + P("unavail") * X(f"1-{dest_label}_transit_avail_{purpose}") - + P("ovtt_dist") * X(f"{dest_label}_transit_ovtt_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("ovtt_dist") * X(f"{dest_label}_transit_approach_walktime_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("ovtt_dist") * X(f"{dest_label}_transit_approach_waittime_{peaky}")/X(f"{dest_label}_auto_dist_{peaky}") - + P("transit_intrazonal") * X(f"o_zone == {dest_label}") - - ) + utility_destination - if 'W' not in purpose.upper(): - m.utility_co[jTRANSIT] += ( - + P("transit_walk_is_short") * X(f"hard_sigmoid({dest_label}_transit_approach_walktime_{peaky}, 4.0, 2.0)") - + P("transit_areatype3") * X(f"fmax(ozone_areatype, {dest_label}_areatype)==3") - ) - else: - m.utility_co[jTRANSIT] += ( - + P("transit_areatype2") * X(f"fmin(ozone_areatype, {dest_label}_areatype)==2") - + P("transit_areatype3") * X(f"fmin(ozone_areatype, {dest_label}_areatype)==3") - + P("transit_areatype4") * X(f"fmin(ozone_areatype, {dest_label}_areatype)==4") - + P("metra_longtrip") * X(f"{dest_label}_Metra_drive_{peaky}") - ) - - if purpose.upper() in {'NH', 'NHB'}: - m.utility_co[jTRANSIT] += ( - + P("totaltime") * X(f"piece({dest_label}_transit_ivtt_{peaky}, None, 20)") - + P("ivtt_longtransit") * X(f"piece({dest_label}_transit_ivtt_{peaky}, 20, None)") - ) - else: - m.utility_co[jTRANSIT] += ( - + P("totaltime") * X(f"{dest_label}_transit_ivtt_{peaky}") - ) - - ## IMPORTANT be sure to change `nests_per_dest` elsewhere (i.e. estimation code) - # if/when the number of nests per destination is altered here - - private_car = m.graph.new_node( - parameter="Mu-PrivateCar", - children=[jAUTO, jHOV2, jHOV3], - name=f"privatecar-{dest_label}", - ) - hired_car = m.graph.new_node( - parameter="Mu-HiredCar", - children=[jTAXI, jTNC1, jTNC2], - name=f"hiredcar-{dest_label}", - ) - m.graph.new_node( - parameter="Mu-Dest", - children=[private_car, hired_car, jTRANSIT, jWALK, jBIKE], - name=f"{dest_label}", - ) - - -def _lock_value(self, name, value, note=None, change_check=True): - """ - Set a fixed value for a model parameter. - - Parameters with a fixed value (i.e., with "holdfast" set to 1) - will not be changed during estimation by the likelihood - maximization algorithm. - - Parameters - ---------- - name : str - The name of the parameter to set to a fixed value. - value : float - The numerical value to set for the parameter. - note : str, optional - A note as to why this parameter is set to a fixed value. - This will not affect the mathematical treatment of the - parameter in any way, but may be useful for reporting. - change_check : bool, default True - Whether to trigger a check to see if any parameter frame - values have changed. Can be set to false to skip this - check if you know that the values have not changed or want - to delay this check for later, but this may result in - problems if the check is needed but not triggered before - certain other modeling tasks are performed. - - """ - name = str(name) - if value == 'null': - value = self.pf.loc[name, 'nullvalue'] - self.set_value(name, value, holdfast=1, initvalue=value, nullvalue=value, minimum=value, maximum=value) - if note is not None: - self._frame.loc[name, 'note'] = note - if change_check: - self._check_if_frame_values_changed() - - -def purpose_peakiness(purpose): - from .purposes import purposes_to_peaky - if purposes_to_peaky[purpose]: - return 'PEAK' - else: - return 'OFFPEAK' - - -def model_choice_availability(purpose, n_sampled_dests, include_actual_dest=False): - """ - Build a dictionary that has expressions for availability of each mode to each destination. - - Parameters - ---------- - purpose : str - The trip purpose, which in turn determines the available skims used. - n_sampled_dests : int - The number of destinations that will be used. In estimation, this - is the number of destinations to be sampled. In application, this - is the total number of destinations, as sampling is not used. - include_actual_dest : bool - Whether to include the "actual" destination. This destination is - included in estimation, where it is used to populate the actually - chosen alternative. In appplication, the "actual" destination is - not applicable and should be turned off. - - Returns - ------- - Dict[int, str] - """ - - peaky = purpose_peakiness(purpose) - n_modes = len(mode9codes) - - # Define the alternative availability for each alternative in this model. - av = {} - dzone_has_nonzero_attractions = f"actualdest_log_attractions_{purpose} > -666" - if include_actual_dest: - av[mode9codes.AUTO] = dzone_has_nonzero_attractions - av[mode9codes.HOV2] = dzone_has_nonzero_attractions - av[mode9codes.HOV3] = dzone_has_nonzero_attractions - av[mode9codes.TNC1] = dzone_has_nonzero_attractions - av[mode9codes.TNC2] = dzone_has_nonzero_attractions - av[mode9codes.TAXI] = dzone_has_nonzero_attractions - av[mode9codes.TRANSIT] = ( - f"(actualdest_transit_ivtt_{peaky} < 999) " - f"& (actualdest_transit_approach_walktime_{peaky} < 999) " - f"& (actualdest_transit_approach_drivetime_{peaky} < 999) " - f"& ({dzone_has_nonzero_attractions})" - ) - av[mode9codes.WALK] = f"(actualdest_log_attractions_{purpose} > -666)&(actualdest_auto_dist_OFFPEAK < 3)" - av[mode9codes.BIKE] = f"(actualdest_log_attractions_{purpose} > -666)&(actualdest_auto_dist_OFFPEAK < 12)" - num = n_modes - for i in range(n_sampled_dests): - altdest_has_nonzero_attractions = f"altdest{i + 1:04d}_auto_avail_{purpose}" - av[num + mode9codes.AUTO] = altdest_has_nonzero_attractions - av[num + mode9codes.HOV2] = altdest_has_nonzero_attractions - av[num + mode9codes.HOV3] = altdest_has_nonzero_attractions - av[num + mode9codes.TNC1] = altdest_has_nonzero_attractions - av[num + mode9codes.TNC2] = altdest_has_nonzero_attractions - av[num + mode9codes.TAXI] = altdest_has_nonzero_attractions - av[num + mode9codes.TRANSIT] = f"altdest{i + 1:04d}_transit_avail_{purpose}" - av[num + mode9codes.WALK] = f"altdest{i + 1:04d}_walk_avail_{purpose}" - av[num + mode9codes.BIKE] = f"altdest{i + 1:04d}_bike_avail_{purpose}" - num += n_modes - - return av - - -def model_builder( - purpose, - include_actual_dest=True, - n_sampled_dests=5, - parameter_values=None, - constraints=True, - n_threads=-1, - application_mode=False, - explicit_av=True, -): - """ - Construct a larch Model for mode and destination choice. - - This function creates the structure of the model and sets parameter - values within that structure if given. To ensure consistency, the - same code is used to contruct models for estimation and for application, - although slight changes in structure are applied based on the arguments - as documented below. - - Parameters - ---------- - purpose : str - include_actual_dest : bool - The "actual" observed destination is included for estimation, but - not in application. - n_sampled_dests : int - For estimation, only a subset of destinations are sampled using a - weighted importance sampling. In application, this is set to the - full number of zones and no sampling weights are applied. - parameter_values : Mapping - The values to use for model parameters. Typically not provided here - for estimation, but should be provided for application. - constraints : bool - Whether to include estimation constraints in the model specification. - In application, parameters are not changed so constraints are - unnecessary. - n_threads : int, default -1 - Number of threads to use for computation. Set to -1 to use threads for - all processessor cores. - application_mode - explicit_av - - Returns - ------- - - """ - - - log.debug(f"model_builder({purpose}, n_sampled_dests={n_sampled_dests})") - - n_modes = len(mode9names) - - alt_codes, alt_names = alt_codes_and_names( - n_sampled_dests=n_sampled_dests, - include_actual_dest=include_actual_dest, - ) - from larch.numba import DataFrames - dummy_dfs = DataFrames( - alt_codes=alt_codes, - alt_names=alt_names, - ) - - if explicit_av: - av = model_choice_availability(purpose, n_sampled_dests, include_actual_dest) - - import larch.numba - m = larch.numba.Model( - dataservice=dummy_dfs, - n_threads=n_threads, - ) - - m.title = f"{purpose} Mode & Destination" - - if explicit_av: - m.availability_co_vars = av - - if include_actual_dest: - model_utility_for_dest( - m, - dest_number=-1, - purpose=purpose, - n_modes=n_modes, - ) - - for i in range(n_sampled_dests): - model_utility_for_dest( - m, - dest_number=i, - purpose=purpose, - n_modes=n_modes, - ) - - m.unmangle() - _lock_value(m, "samp_af", value=1.0) - _lock_value(m, "log_attraction", value=1.0) - _lock_value(m, "unavail", value=-999) - - # initial setting of nesting parameters - m.set_value("Mu-HiredCar", 0.4) - m.set_value("Mu-Dest", 0.7) - - m.set_value("cost", maximum=-0.00001) - # m.set_value("auto_time", maximum=-0.01, minimum=-0.03) - # m.set_value("tnc_time", maximum=-0.01, minimum=-0.03) - # m.set_value("transit_ivtt", maximum=-0.01, minimum=-0.03) - m.set_value("totaltime", maximum=-0.01, minimum=-0.03) - if "ivtt_longtransit" in m: - m.set_value("ivtt_longtransit", maximum=-0.0001, minimum=-0.03) - m.set_value("ovtt_dist", maximum=-0.001) - if parameter_values is None: - m.set_values( - cost=-0.0001, - # auto_time=-0.01, - tnc_time=-0.02, - totaltime=-0.015, - ovtt_dist=-0.03, - Const_TNC1=-1.0, - Const_TNC2=-1.0, - Const_Transit=-1.0, - intrazonal=-0.1, - ) - else: - m.set_values(**parameter_values) - - if constraints: - from larch.model.constraints import RatioBound - if purpose=='HBWL': - vot_constraint = RatioBound(P("totaltime"), P("cost"), min_ratio=0.0001, max_ratio=0.5, scale=1) - elif purpose=='HBWH': - vot_constraint = RatioBound(P("totaltime"), P("cost"), min_ratio=0.5, max_ratio=1.5, scale=1) - else: - vot_constraint = RatioBound(P("totaltime"), P("cost"), min_ratio=0.0001, max_ratio=1.0, scale=1) - - m.constraints = [ - # RatioBound(P("ovtt"), P("totaltime"), min_ratio=1.5, max_ratio=3.0, scale=1), - RatioBound(P("Mu-HiredCar"), P("Mu-Dest"), min_ratio=1e-5, max_ratio=0.75, scale=1), - RatioBound(P("Mu-PrivateCar"), P("Mu-Dest"), min_ratio=1e-5, max_ratio=0.75, scale=1), - vot_constraint, - ] - - if application_mode: - m._preload_tree_structure() - - m.set_cap() - return m - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/cmap_logging.py b/src/Mode-Dest-TOD/cmap_modedest/cmap_logging.py deleted file mode 100644 index 4962486..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/cmap_logging.py +++ /dev/null @@ -1,121 +0,0 @@ -import os -import logging -from logging.handlers import RotatingFileHandler -LOGGER_NAME = 'CMAP' -LOG_FORMAT = '[{elapsedTime}] {name:s}:{levelname:s}: {message:s}' -WORKERLOG_FORMAT = '[{asctime}][{elapsedTime}] {name:s}:{levelname:s}: {message:s}' - -def format_elapsed_time(duration_milliseconds): - hours, rem = divmod(duration_milliseconds/1000, 3600) - minutes, seconds = divmod(rem, 60) - if hours: - return ("{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds)) - else: - return ("{:0>2}:{:05.2f}".format(int(minutes),seconds)) - - -class ElapsedTimeFormatter(logging.Formatter): - def format(self, record): - record.elapsedTime = format_elapsed_time(record.relativeCreated) - return super(ElapsedTimeFormatter, self).format(record) - -def getLogger(name=None): - return logging.getLogger(name or LOGGER_NAME) - -def getSubLogger(subname): - return logging.getLogger(f"{LOGGER_NAME}.{subname}") - -def log_to_stderr(level=30, log_dir=None): - """ - Turn on logging and add a handler which prints to stderr - - Parameters - ---------- - level : int - minimum level of the messages that will be logged - """ - import time - logger = logging.getLogger(LOGGER_NAME) - - # avoid creation of multiple stream handlers for logging to console - for entry in logger.handlers: - if isinstance(entry, logging.StreamHandler) and (entry.formatter._fmt == LOG_FORMAT): - return logger - - formatter = ElapsedTimeFormatter(LOG_FORMAT, style='{') - handler = logging.StreamHandler() - handler.setLevel(level) - handler.setFormatter(formatter) - logger.addHandler(handler) - if log_dir is not None: - # also log to a file - filehandler = RotatingFileHandler( - filename=os.path.join(log_dir, f"{time.strftime('cmap_trip_log_master_%Y%m%d_%H%M%S')}.log"), - mode='a', - maxBytes=1_000_000, - backupCount=10, - ) - filehandler.setLevel(level) - filehandler.setFormatter(formatter) - logger.addHandler(filehandler) - else: - filehandler = None - logger.propagate = False - logger.setLevel(level) - - larch_logger = logging.getLogger("Larch") - if filehandler is not None: - larch_logger.addHandler(filehandler) - larch_logger.addHandler(handler) - larch_logger.setLevel(level) - - return logger - - -def log_df(df, logger=None, level=20, verbose=0, indent=" "): - from io import StringIO - if logger is None or isinstance(logger, str): - from logging import getLogger - logger = getLogger(logger) - with StringIO() as buffer: - df.info(verbose=verbose, buf=buffer) - info = buffer.getvalue() - if indent: - import textwrap - info = textwrap.indent(info, indent, lambda line: True) - logger.log(level, info) - - -def get_worker_log(log_dir, level=20): - """ - Turn on logging and add a handler which writes to a process-specific log file - - Parameters - ---------- - level : int - minimum level of the messages that will be logged - """ - - os.makedirs(log_dir, exist_ok=True) - - logger = logging.getLogger(LOGGER_NAME) - - # avoid creation of multiple stream handlers for logging to worker log - for entry in logger.handlers: - if isinstance(entry, RotatingFileHandler) and (entry.formatter._fmt == WORKERLOG_FORMAT): - return logger - - formatter = ElapsedTimeFormatter(WORKERLOG_FORMAT, style='{') - handler = RotatingFileHandler( - filename=os.path.join(log_dir, f"cmap_trip_log_{os.getpid()}.log"), - mode='a', - maxBytes=1_000_000, - backupCount=10, - ) - handler.setLevel(level) - handler.setFormatter(formatter) - logger.addHandler(handler) - logger.propagate = False - logger.setLevel(level) - - return logger diff --git a/src/Mode-Dest-TOD/cmap_modedest/configuration.py b/src/Mode-Dest-TOD/cmap_modedest/configuration.py deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/__init__.py deleted file mode 100644 index fd1c057..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/__init__.py +++ /dev/null @@ -1,267 +0,0 @@ -import cloudpickle -import numpy as np -import pandas as pd -import tempfile -import larch -from ..addict import Dict -from pathlib import Path -try: - from sharrow import Flow -except ImportError: - Flow = type(np) - -try: - from geopandas import GeoDataFrame -except ImportError: - GeoDataFrame = () - -from .filepaths import FileNames, PathAttr -from .skims_handler import DictSkims -from logging import getLogger -log = getLogger("CMAP") - -class DataHandler: - - serial_dir = PathAttr() - - def __init__( - self, - filenames=None, - serial_dir=None, - tg_detail=False, - tripclass='typical', - backfill_uncompressed_skims=False, - **kwargs, - ): - - self._jedi_names = set() - - self.artifacts = {} - # artifacts tell how to reload things if they are not cached - # this makes it easier to pass this DataHandler to subprocesses, - # as we don't need to serialize data that is already serialized. - - self._cache = {} - # the _cache is where we store things that we have already loaded - # in this process, so they are available in RAM already. - - log.info("loading filenames") - if filenames is None: - filenames = FileNames(**kwargs) - - if serial_dir is None: - log.debug("create serial temp dir") - self._temporary_dir = tempfile.TemporaryDirectory() - serial_dir = self._temporary_dir.name - - log.debug("serial_dir init") - self.serial_dir = serial_dir - - log.debug("filenames init") - self.filenames = filenames - - log.info("loading hhv_types") - from .household_types import load_household_types - self['hhv_types'] = load_household_types() - - log.info("loading distr") - from .distr_handler import load_distr - self['distr'] = load_distr(filenames) - self._jedi_names.add('distr') - - log.info("loading m01") - from .m01_handler import load_m01 - self['m01'] = load_m01(filenames) - self._jedi_names.add('m01') - - log.info("loading m023") - from .m023_handler import load_m023 - self['m023'] = load_m023(filenames) - self._jedi_names.add('m023') - - log.info("loading shapes") - from .shp_handler import load_zone_shapes - self['zone_shp'] = load_zone_shapes(filenames) - self._jedi_names.add('zone_shp') - - log.info("loading skims") - from .skims_handler import load_skims - self['skims'] = load_skims( - filenames, self, backfill_uncompressed_skims=backfill_uncompressed_skims, - ) - self._jedi_names.add('skims') - - log.info("loading tg") - from .tg_handler import load_tg, load_hh_enum - tripgens = load_tg(filenames, with_detail=tg_detail) - self['tripclass'] = tripclass - for k, tg in tripgens.items(): - # self[f'trip_attractions8_{k}'] = tg.trip_attractions8 - # self[f'trip_productions8_{k}'] = tg.trip_productions8 - # self[f'zone_productions8_{k}'] = tg.zone_productions8 - self[f'trip_attractions5_{k}'] = tg.trip_attractions5 # needed - # self[f'trip_productions5_{k}'] = tg.trip_productions5 - self[f'zone_productions5_{k}'] = tg.zone_productions5 # needed - # if tg_detail: - # self[f'trip_attractions_detail_{k}'] = tg.trip_attractions_detail - # self[f'trip_productions_detail_{k}'] = tg.trip_productions_detail - self._jedi_names.add('tripclass') - self._jedi_names.add('trip_attractions5') - self._jedi_names.add('zone_productions5') - - log.info("loading hh enumeration") - hh_enum, hh_tabulation = load_hh_enum(filenames) - self['hh_enum'] = hh_enum - self['hh_tabulation'] = hh_tabulation - self._jedi_names.add('hh_enum') - self._jedi_names.add('hh_tabulation') - - log.info("loading parking") - from .parking_handler import load_cbd_parking - parking = load_cbd_parking(filenames) - self['cbd_parking_prices'] = parking.cbd_parking_prices - self['cbd_parking_price_prob'] = parking.cbd_parking_price_prob - self['cbd_parking'] = parking.cbd_parking - self['cbd_parking2'] = parking.cbd_parking2 - self['CBD_PARKING_ZONES'] = parking.CBD_PARKING_ZONES - self._jedi_names.add('cbd_parking_prices') - self._jedi_names.add('cbd_parking_price_prob') - self._jedi_names.add('cbd_parking') - self._jedi_names.add('cbd_parking2') - self._jedi_names.add('CBD_PARKING_ZONES') - - log.info("loading visitor trip tables") - from .visitors import load_visitor_trips - visitor_trip_growth = self.cfg.get("visitor_trips_growth_factor", 1.0) - self['visitor_trips'] = load_visitor_trips(filenames, scale_factor=visitor_trip_growth) - self._jedi_names.add('visitor_trips') - - log.info("loading of data handlers complete") - - def __dir__(self): - return self._jedi_names | self.__dict__.keys() - - @property - def cfg(self): - return self.filenames.cfg - - @property - def choice_model_params(self): - return self.filenames.choice_model_params - - def __getstate__(self): - return { - 'artifacts': self.artifacts, - 'filenames': self.filenames, - '_serial_dir': self._serial_dir, - } - - def __setstate__(self, state): - self._cache = {} - self.artifacts = state['artifacts'] - self.filenames = state['filenames'] - self._serial_dir = state['_serial_dir'] - - def __setitem__(self, key, value): - self._cache[key] = value - if not isinstance(key, str): - raise ValueError("keys must be str") - if isinstance(value, GeoDataFrame): - filename = self.serial_dir / f"{key}.pkl" - with open(filename, "wb") as f: - cloudpickle.dump(value, f) - self.artifacts[key] = ('pickle', filename) - elif isinstance(value, pd.DataFrame): - filename = self.serial_dir / f"{key}.pq" - try: - value.to_parquet(filename) - except ValueError: - filename = self.serial_dir / f"{key}.h5" - value.to_hdf(filename, key) - self.artifacts[key] = ('DataFrame.h5', filename) - else: - self.artifacts[key] = ('DataFrame', filename) - elif isinstance(value, pd.Series): - filename = self.serial_dir / f"{key}.spq" - pd.DataFrame(value).to_parquet(filename) - self.artifacts[key] = ('Series', filename) - elif isinstance(value, np.ndarray): - filename = self.serial_dir / f"{key}.nm" - mm = np.memmap( - filename, - dtype=value.dtype, - mode='w+', - shape=value.shape, - ) - mm[:] = value[:] - self.artifacts[key] = ('array', filename, value.dtype, value.shape) - elif isinstance(value, larch.OMX): - filename = value.filename - self.artifacts[key] = ('OMX', filename) - elif isinstance(value, DictSkims): - filename = self.serial_dir / f"{key}.pkl" - with open(filename, "wb") as f: - cloudpickle.dump(value, f) - self.artifacts[key] = ('DictSkims', filename) - elif isinstance(value, Dict): - self.artifacts[key] = ('Dict', set(value.keys())) - for k1, v1 in value.items(): - self[f"{key}.{k1}"] = v1 - elif isinstance(value, Flow): - pass # Flow objects are thread-local - else: - filename = self.serial_dir / f"{key}.pkl" - with open(filename, "wb") as f: - cloudpickle.dump(value, f) - self.artifacts[key] = ('pickle', filename) - - def __getitem__(self, key): - if key == 'trip_attractions5': - return self[f'trip_attractions5_{self.tripclass}'] - elif key == 'zone_productions5': - return self[f'zone_productions5_{self.tripclass}'] - if key in self._cache: - return self._cache[key] - art = self.artifacts[key] - if art[0] == 'DataFrame': - result = pd.read_parquet(art[1]) - elif art[0] == 'DataFrame.h5': - result = pd.read_hdf(art[1], key) - elif art[0] == 'Series': - result = pd.read_parquet(art[1]).iloc[:,0] - elif art[0] == 'array': - result = np.memmap( - art[1], - dtype=art[2], - mode='r+', - shape=art[3], - ) - elif art[0] == 'OMX': - result = larch.OMX(art[1], 'r') - elif art[0] == 'Dict': - result = Dict() - for k1 in art[1]: - result[k1] = self[f"{key}.{k1}"] - elif art[0] == 'pickle': - with open(art[1], "rb") as f: - result = cloudpickle.load(f) - elif art[0] == 'DictSkims': - with open(art[1], "rb") as f: - result = cloudpickle.load(f) - from .skims_handler import _load_skims_step_2 - _load_skims_step_2(result, self) - else: - raise TypeError(art[0]) - self._cache[key] = result - return result - - def __getattr__(self, item): - try: - return self[item] - except: - raise AttributeError(item) - - @property - def n_internal_zones(self): - return len(self.m01) - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/distr_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/distr_handler.py deleted file mode 100644 index 47f7201..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/distr_handler.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging -log = logging.getLogger('CMAP') -import pandas as pd -from ..addict import Dict - -def read_distr(filename): - raw = pd.read_csv(filename, header=None, index_col=0) - raw.columns = pd.MultiIndex.from_product( - [ - ['metra','ctarail','bus','feederbus','pnr'], - ['p1','p2','p3'], - ], - names = ['submode', 'param'] - ) - raw.index.name = 'zone' - result = raw.stack('submode') - return result - -def load_distr(filenames): - distr = Dict() - log.info(f"reading HW distr file from: {filenames.HW_DISTR}") - distr.HW = read_distr(filenames.HW_DISTR) - log.info(f"reading HO distr file from: {filenames.HO_DISTR}") - distr.HO = read_distr(filenames.HO_DISTR) - log.info(f"reading NH distr file from: {filenames.NH_DISTR}") - distr.NH = read_distr(filenames.NH_DISTR) - return distr - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/filepaths.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/filepaths.py deleted file mode 100644 index 6ff5d17..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/filepaths.py +++ /dev/null @@ -1,284 +0,0 @@ -from pathlib import Path -import os -import glob -import time -import pandas as pd -import numpy as np -import yaml -from ..addict import Dict -from ..util import search_path - -import logging -log = logging.getLogger('CMAP') - -_here = os.path.abspath(os.path.dirname(__file__)) -emme_database_dir = os.path.normpath(os.path.join(_here, "../tests/data")) - - -class PathAttr: - - def __set_name__(self, owner, name): - self.public_name = name - self.private_name = '_' + name - - def __init__(self, can_null=True, change_callback=None): - self.can_null = can_null - self.change_callback = change_callback - - def __get__(self, obj, objtype): - return getattr(obj, self.private_name) - - def __set__(self, obj, value): - if value is None: - if not self.can_null: - raise ValueError(f'cannot set {self.private_name[1:]} to None') - else: - value = Path(value) - try: - prior = getattr(obj, self.private_name) - except AttributeError: - self.on_change(obj, value) - else: - if prior != value: - self.on_change(obj, value) - log.debug(f"setattr {self.private_name} = {value}") - setattr(obj, self.private_name, value) - - def on_change(self, obj, new_value): - log.debug(f"on_change {self.public_name}") - if self.change_callback: - self.change_callback(obj, new_value) - - -def _changed_emme_database_dir(filenames, new_db_dir): - cfgfile = new_db_dir / f"cmap_trip_config.yaml" - with open(cfgfile, 'r') as f: - filenames.cfg = Dict(yaml.load(f, Loader=yaml.SafeLoader)) - -def _make_dirs(filenames, new_dir): - if new_dir and not os.path.exists(new_dir): - os.makedirs(new_dir) - - -class FileNames: - - emme_database_dir = PathAttr(can_null=False, change_callback=_changed_emme_database_dir) - emmemat_dir = PathAttr(can_null=True) - cache_dir = PathAttr(change_callback=_make_dirs) - zone_shapefile = PathAttr() - - def __init__( - self, - emme_database_dir, - cache_dir=None, - emmemat_dir=None, - zone_shapefile=None, - ): - self._memory_mapped_skim = {} - self.emme_database_dir = emme_database_dir - self.emmemat_dir = emmemat_dir - self.cache_dir = cache_dir - self.zone_shapefile = zone_shapefile - self._temporary_dir = None - if self.choice_model_param_file and os.path.exists(self.choice_model_param_file): - with open(self.choice_model_param_file, 'r') as f: - self.choice_model_params = Dict(yaml.load(f, Loader=yaml.SafeLoader)) - else: - self.choice_model_params = Dict() - - - def __getattr__(self, item): - - def _log_path_search(label, *args): - pth = search_path(*args) - log.debug(f"FILEPATH({label})={pth}") - return pth - - if item == 'temp_dir': - if self._temporary_dir is None: - import tempfile - self._temporary_dir = tempfile.TemporaryDirectory() - return Path(self._temporary_dir.name) - if item[-6:] == "_DISTR": - return _log_path_search( - item, - self.emme_database_dir / f"{item}.TXT", - self.emme_database_dir / f"defaults_base_year/{item}.TXT", - ) - if item[-4:] == "_M01": - return _log_path_search( - item, - self.emme_database_dir / f"{item}.TXT", - self.emme_database_dir / f"defaults_base_year/{item}.TXT", - ) - if item[-5:] == "_M023": - return _log_path_search( - item, - self.emme_database_dir / f"{item}.TXT", - self.emme_database_dir / f"defaults_base_year/{item}.TXT", - ) - if item[-9:] == "_CBDPARK0": - return _log_path_search( - item, - self.emme_database_dir / f"{item[:-1]}.TXT", - self.emme_database_dir / f"defaults_base_year/{item[:-1]}.TXT", - ) - if item[-8:] == "_CBDPARK": - return self.cache_dir / f"__{item}.TXT" - if item[-9:] == "_CBDPARK2": - return self.cache_dir / f"__{item}.TXT" - if item[-6:] == "_skims": - raise NotImplementedError - # if self.omx_skims_dir: - # return self.omx_skims_dir / f"{item}.omx" - # else: - # return self.emme_database_dir / f"{item}.omx" - if item[:2] == "mf": - if self.emmemat_dir: - return self.emmemat_dir / f"{item}.emx" - else: - return self.emme_database_dir / "emmemat" / f"{item}.emx" - if item != "_memory_mapped_skim" and item in self._memory_mapped_skim: - return self._memory_mapped_skim[item] - if item[:6] == "map_mf": - if self.emmemat_dir: - pth = self.emmemat_dir / f"{item[4:]}.emx" - else: - pth = self.emme_database_dir / "emmemat" / f"{item[4:]}.emx" - mapped_skim = np.memmap(pth, dtype='f4', mode='r') - nzones = int(np.sqrt(mapped_skim.shape[0])) - mapped_skim = self._memory_mapped_skim[item] = mapped_skim.reshape([nzones,nzones]) - return mapped_skim - if item == "config": - return self._emme_database_dir / f"cmap_trip_config.yaml" - if item == "choice_model_param_file": - result = search_path( - self.emme_database_dir / f"choice_model_params.yaml", - self.cache_dir / f"choice_model_params.yaml", - ) - if result is None: - result = self.cache_dir / f"choice_model_params.yaml" - return result - if item == "tod_model_param_file": - return search_path( - self.emme_database_dir / f"tod_model_params.yaml", - self.cache_dir / f"tod_model_params.yaml", - ) - if item == "zone_districts": - return search_path( - self.emme_database_dir / f"CMAP_Zone_Districts.csv.gz", - self.cache_dir / f"CMAP_Zone_Districts.csv.gz", - ) - if item == "emmemat": - if self.emmemat_dir: - return self.emmemat_dir - else: - return self.emme_database_dir/"emmemat" - if item == "value_of_time_buckets": - return search_path( - self.emme_database_dir / f"value_of_time_buckets.csv", - self.cache_dir / f"value_of_time_buckets.csv", - ) - raise AttributeError(item) - - @property - def tripgen_sas(self): - return latest_matching( - self.emme_database_dir / "tg/sas/data/tg*.sas7bdat" - ) or latest_matching( - self.emme_database_dir / "tg*.sas7bdat" - ) or latest_matching( - self.cache_dir / "tg*.sas7bdat" - ) - - @property - def hh_enum(self): - return latest_matching( - self.emme_database_dir / "TG_HHENUM_OUTPUT.TXT.gz" - ) or latest_matching( - self.cache_dir / "TG_HHENUM_OUTPUT.TXT.gz" - ) or latest_matching( - self.emme_database_dir / "TG_HHENUM_OUTPUT.TXT" - ) or latest_matching( - self.cache_dir / "TG_HHENUM_OUTPUT.TXT" - ) or latest_matching( - self.emme_database_dir / "defaults_base_year/TG_HHENUM_OUTPUT.TXT.gz" - ) - - def save(self, name, data): - try: - if isinstance(data, pd.DataFrame): - if self.cache_dir: - pth = self.cache_dir / f"{name}.pq" - else: - pth = f"{name}.pq" - data.to_parquet(pth) - else: - raise TypeError(str(type(data))) - except Exception as err: - import warnings - warnings.warn(f"failed to save {name}: {err}") - - def load(self, name): - if self.cache_dir: - pth = self.cache_dir / f"{name}.pq" - else: - pth = f"{name}.pq" - if os.path.exists(pth): - return pd.read_parquet(pth) - # else file does not exist - return None - - # def use_emmemat_archive(self, archive_file): - # import zipfile - # import tempfile - # self.temp_emmemat_dir = tempfile.TemporaryDirectory() - # with zipfile.ZipFile(archive_file, 'r') as zip_ref: - # zip_ref.extractall(self.temp_emmemat_dir.name) - # self.emmemat_dir = self.temp_emmemat_dir.name - - - -def _insensitive_glob(pattern): - def either(c): - return '[%s%s]' % (c.lower(), c.upper()) if c.isalpha() else c - return ''.join(map(either, pattern)) - - -def latest_matching(pattern, echo=False, case_insensitive=False, expanduser=True): - """Get the most recently modified file matching the glob pattern - - Parameters - ---------- - pattern : str - A glob pattern to match on - echo : bool, default False - If true, print the last modified time for each matching file - case_insensitive : bool, default False - Tf true, the glob pattern will be modified to be case insensitive. - expanduser : bool, default true - Should each pattern be passed through the `os.path.expanduser` function? - - Returns - ------- - str - The filename of the most recently modified file matching the glob pattern - - """ - if expanduser: - pattern = os.path.expanduser(pattern) - if case_insensitive: - pattern = _insensitive_glob(pattern) - files = glob.glob(pattern) - propose = None - propose_mtime = 0 - for file in files: - (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file) - if echo: - print (file,"last modified: %s" % time.ctime(mtime)) - if mtime > propose_mtime: - propose_mtime = mtime - propose = file - return propose - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.csv b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.csv deleted file mode 100644 index 9ca1106..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.csv +++ /dev/null @@ -1,625 +0,0 @@ -CODE,N_CHILDREN,N_WORKERS,N_ADULTS,N_VEHICLES,HOUSEHOLDER_AGE -1,0,0,1,0,<35 -2,0,0,2,0,<35 -3,0,0,3,0,<35 -4,0,0,4+,0,<35 -5,0,1,1,0,<35 -6,0,1,2,0,<35 -7,0,1,3,0,<35 -8,0,1,4+,0,<35 -9,0,2,2,0,<35 -10,0,2,3,0,<35 -11,0,2,4+,0,<35 -12,0,3+,3,0,<35 -13,0,3+,4+,0,<35 -14,1,0,1,0,<35 -15,1,0,2,0,<35 -16,1,0,3,0,<35 -17,1,0,4+,0,<35 -18,1,1,1,0,<35 -19,1,1,2,0,<35 -20,1,1,3,0,<35 -21,1,1,4+,0,<35 -22,1,2,2,0,<35 -23,1,2,3,0,<35 -24,1,2,4+,0,<35 -25,1,3+,3,0,<35 -26,1,3+,4+,0,<35 -27,2,0,1,0,<35 -28,2,0,2,0,<35 -29,2,0,3,0,<35 -30,2,0,4+,0,<35 -31,2,1,1,0,<35 -32,2,1,2,0,<35 -33,2,1,3,0,<35 -34,2,1,4+,0,<35 -35,2,2,2,0,<35 -36,2,2,3,0,<35 -37,2,2,4+,0,<35 -38,2,3+,3,0,<35 -39,2,3+,4+,0,<35 -40,3+,0,1,0,<35 -41,3+,0,2,0,<35 -42,3+,0,3,0,<35 -43,3+,0,4+,0,<35 -44,3+,1,1,0,<35 -45,3+,1,2,0,<35 -46,3+,1,3,0,<35 -47,3+,1,4+,0,<35 -48,3+,2,2,0,<35 -49,3+,2,3,0,<35 -50,3+,2,4+,0,<35 -51,3+,3+,3,0,<35 -52,3+,3+,4+,0,<35 -53,0,0,1,1,<35 -54,0,0,2,1,<35 -55,0,0,3,1,<35 -56,0,0,4+,1,<35 -57,0,1,1,1,<35 -58,0,1,2,1,<35 -59,0,1,3,1,<35 -60,0,1,4+,1,<35 -61,0,2,2,1,<35 -62,0,2,3,1,<35 -63,0,2,4+,1,<35 -64,0,3+,3,1,<35 -65,0,3+,4+,1,<35 -66,1,0,1,1,<35 -67,1,0,2,1,<35 -68,1,0,3,1,<35 -69,1,0,4+,1,<35 -70,1,1,1,1,<35 -71,1,1,2,1,<35 -72,1,1,3,1,<35 -73,1,1,4+,1,<35 -74,1,2,2,1,<35 -75,1,2,3,1,<35 -76,1,2,4+,1,<35 -77,1,3+,3,1,<35 -78,1,3+,4+,1,<35 -79,2,0,1,1,<35 -80,2,0,2,1,<35 -81,2,0,3,1,<35 -82,2,0,4+,1,<35 -83,2,1,1,1,<35 -84,2,1,2,1,<35 -85,2,1,3,1,<35 -86,2,1,4+,1,<35 -87,2,2,2,1,<35 -88,2,2,3,1,<35 -89,2,2,4+,1,<35 -90,2,3+,3,1,<35 -91,2,3+,4+,1,<35 -92,3+,0,1,1,<35 -93,3+,0,2,1,<35 -94,3+,0,3,1,<35 -95,3+,0,4+,1,<35 -96,3+,1,1,1,<35 -97,3+,1,2,1,<35 -98,3+,1,3,1,<35 -99,3+,1,4+,1,<35 -100,3+,2,2,1,<35 -101,3+,2,3,1,<35 -102,3+,2,4+,1,<35 -103,3+,3+,3,1,<35 -104,3+,3+,4+,1,<35 -105,0,0,1,2,<35 -106,0,0,2,2,<35 -107,0,0,3,2,<35 -108,0,0,4+,2,<35 -109,0,1,1,2,<35 -110,0,1,2,2,<35 -111,0,1,3,2,<35 -112,0,1,4+,2,<35 -113,0,2,2,2,<35 -114,0,2,3,2,<35 -115,0,2,4+,2,<35 -116,0,3+,3,2,<35 -117,0,3+,4+,2,<35 -118,1,0,1,2,<35 -119,1,0,2,2,<35 -120,1,0,3,2,<35 -121,1,0,4+,2,<35 -122,1,1,1,2,<35 -123,1,1,2,2,<35 -124,1,1,3,2,<35 -125,1,1,4+,2,<35 -126,1,2,2,2,<35 -127,1,2,3,2,<35 -128,1,2,4+,2,<35 -129,1,3+,3,2,<35 -130,1,3+,4+,2,<35 -131,2,0,1,2,<35 -132,2,0,2,2,<35 -133,2,0,3,2,<35 -134,2,0,4+,2,<35 -135,2,1,1,2,<35 -136,2,1,2,2,<35 -137,2,1,3,2,<35 -138,2,1,4+,2,<35 -139,2,2,2,2,<35 -140,2,2,3,2,<35 -141,2,2,4+,2,<35 -142,2,3+,3,2,<35 -143,2,3+,4+,2,<35 -144,3+,0,1,2,<35 -145,3+,0,2,2,<35 -146,3+,0,3,2,<35 -147,3+,0,4+,2,<35 -148,3+,1,1,2,<35 -149,3+,1,2,2,<35 -150,3+,1,3,2,<35 -151,3+,1,4+,2,<35 -152,3+,2,2,2,<35 -153,3+,2,3,2,<35 -154,3+,2,4+,2,<35 -155,3+,3+,3,2,<35 -156,3+,3+,4+,2,<35 -157,0,0,1,3+,<35 -158,0,0,2,3+,<35 -159,0,0,3,3+,<35 -160,0,0,4+,3+,<35 -161,0,1,1,3+,<35 -162,0,1,2,3+,<35 -163,0,1,3,3+,<35 -164,0,1,4+,3+,<35 -165,0,2,2,3+,<35 -166,0,2,3,3+,<35 -167,0,2,4+,3+,<35 -168,0,3+,3,3+,<35 -169,0,3+,4+,3+,<35 -170,1,0,1,3+,<35 -171,1,0,2,3+,<35 -172,1,0,3,3+,<35 -173,1,0,4+,3+,<35 -174,1,1,1,3+,<35 -175,1,1,2,3+,<35 -176,1,1,3,3+,<35 -177,1,1,4+,3+,<35 -178,1,2,2,3+,<35 -179,1,2,3,3+,<35 -180,1,2,4+,3+,<35 -181,1,3+,3,3+,<35 -182,1,3+,4+,3+,<35 -183,2,0,1,3+,<35 -184,2,0,2,3+,<35 -185,2,0,3,3+,<35 -186,2,0,4+,3+,<35 -187,2,1,1,3+,<35 -188,2,1,2,3+,<35 -189,2,1,3,3+,<35 -190,2,1,4+,3+,<35 -191,2,2,2,3+,<35 -192,2,2,3,3+,<35 -193,2,2,4+,3+,<35 -194,2,3+,3,3+,<35 -195,2,3+,4+,3+,<35 -196,3+,0,1,3+,<35 -197,3+,0,2,3+,<35 -198,3+,0,3,3+,<35 -199,3+,0,4+,3+,<35 -200,3+,1,1,3+,<35 -201,3+,1,2,3+,<35 -202,3+,1,3,3+,<35 -203,3+,1,4+,3+,<35 -204,3+,2,2,3+,<35 -205,3+,2,3,3+,<35 -206,3+,2,4+,3+,<35 -207,3+,3+,3,3+,<35 -208,3+,3+,4+,3+,<35 -209,0,0,1,0,35-64 -210,0,0,2,0,35-64 -211,0,0,3,0,35-64 -212,0,0,4+,0,35-64 -213,0,1,1,0,35-64 -214,0,1,2,0,35-64 -215,0,1,3,0,35-64 -216,0,1,4+,0,35-64 -217,0,2,2,0,35-64 -218,0,2,3,0,35-64 -219,0,2,4+,0,35-64 -220,0,3+,3,0,35-64 -221,0,3+,4+,0,35-64 -222,1,0,1,0,35-64 -223,1,0,2,0,35-64 -224,1,0,3,0,35-64 -225,1,0,4+,0,35-64 -226,1,1,1,0,35-64 -227,1,1,2,0,35-64 -228,1,1,3,0,35-64 -229,1,1,4+,0,35-64 -230,1,2,2,0,35-64 -231,1,2,3,0,35-64 -232,1,2,4+,0,35-64 -233,1,3+,3,0,35-64 -234,1,3+,4+,0,35-64 -235,2,0,1,0,35-64 -236,2,0,2,0,35-64 -237,2,0,3,0,35-64 -238,2,0,4+,0,35-64 -239,2,1,1,0,35-64 -240,2,1,2,0,35-64 -241,2,1,3,0,35-64 -242,2,1,4+,0,35-64 -243,2,2,2,0,35-64 -244,2,2,3,0,35-64 -245,2,2,4+,0,35-64 -246,2,3+,3,0,35-64 -247,2,3+,4+,0,35-64 -248,3+,0,1,0,35-64 -249,3+,0,2,0,35-64 -250,3+,0,3,0,35-64 -251,3+,0,4+,0,35-64 -252,3+,1,1,0,35-64 -253,3+,1,2,0,35-64 -254,3+,1,3,0,35-64 -255,3+,1,4+,0,35-64 -256,3+,2,2,0,35-64 -257,3+,2,3,0,35-64 -258,3+,2,4+,0,35-64 -259,3+,3+,3,0,35-64 -260,3+,3+,4+,0,35-64 -261,0,0,1,1,35-64 -262,0,0,2,1,35-64 -263,0,0,3,1,35-64 -264,0,0,4+,1,35-64 -265,0,1,1,1,35-64 -266,0,1,2,1,35-64 -267,0,1,3,1,35-64 -268,0,1,4+,1,35-64 -269,0,2,2,1,35-64 -270,0,2,3,1,35-64 -271,0,2,4+,1,35-64 -272,0,3+,3,1,35-64 -273,0,3+,4+,1,35-64 -274,1,0,1,1,35-64 -275,1,0,2,1,35-64 -276,1,0,3,1,35-64 -277,1,0,4+,1,35-64 -278,1,1,1,1,35-64 -279,1,1,2,1,35-64 -280,1,1,3,1,35-64 -281,1,1,4+,1,35-64 -282,1,2,2,1,35-64 -283,1,2,3,1,35-64 -284,1,2,4+,1,35-64 -285,1,3+,3,1,35-64 -286,1,3+,4+,1,35-64 -287,2,0,1,1,35-64 -288,2,0,2,1,35-64 -289,2,0,3,1,35-64 -290,2,0,4+,1,35-64 -291,2,1,1,1,35-64 -292,2,1,2,1,35-64 -293,2,1,3,1,35-64 -294,2,1,4+,1,35-64 -295,2,2,2,1,35-64 -296,2,2,3,1,35-64 -297,2,2,4+,1,35-64 -298,2,3+,3,1,35-64 -299,2,3+,4+,1,35-64 -300,3+,0,1,1,35-64 -301,3+,0,2,1,35-64 -302,3+,0,3,1,35-64 -303,3+,0,4+,1,35-64 -304,3+,1,1,1,35-64 -305,3+,1,2,1,35-64 -306,3+,1,3,1,35-64 -307,3+,1,4+,1,35-64 -308,3+,2,2,1,35-64 -309,3+,2,3,1,35-64 -310,3+,2,4+,1,35-64 -311,3+,3+,3,1,35-64 -312,3+,3+,4+,1,35-64 -313,0,0,1,2,35-64 -314,0,0,2,2,35-64 -315,0,0,3,2,35-64 -316,0,0,4+,2,35-64 -317,0,1,1,2,35-64 -318,0,1,2,2,35-64 -319,0,1,3,2,35-64 -320,0,1,4+,2,35-64 -321,0,2,2,2,35-64 -322,0,2,3,2,35-64 -323,0,2,4+,2,35-64 -324,0,3+,3,2,35-64 -325,0,3+,4+,2,35-64 -326,1,0,1,2,35-64 -327,1,0,2,2,35-64 -328,1,0,3,2,35-64 -329,1,0,4+,2,35-64 -330,1,1,1,2,35-64 -331,1,1,2,2,35-64 -332,1,1,3,2,35-64 -333,1,1,4+,2,35-64 -334,1,2,2,2,35-64 -335,1,2,3,2,35-64 -336,1,2,4+,2,35-64 -337,1,3+,3,2,35-64 -338,1,3+,4+,2,35-64 -339,2,0,1,2,35-64 -340,2,0,2,2,35-64 -341,2,0,3,2,35-64 -342,2,0,4+,2,35-64 -343,2,1,1,2,35-64 -344,2,1,2,2,35-64 -345,2,1,3,2,35-64 -346,2,1,4+,2,35-64 -347,2,2,2,2,35-64 -348,2,2,3,2,35-64 -349,2,2,4+,2,35-64 -350,2,3+,3,2,35-64 -351,2,3+,4+,2,35-64 -352,3+,0,1,2,35-64 -353,3+,0,2,2,35-64 -354,3+,0,3,2,35-64 -355,3+,0,4+,2,35-64 -356,3+,1,1,2,35-64 -357,3+,1,2,2,35-64 -358,3+,1,3,2,35-64 -359,3+,1,4+,2,35-64 -360,3+,2,2,2,35-64 -361,3+,2,3,2,35-64 -362,3+,2,4+,2,35-64 -363,3+,3+,3,2,35-64 -364,3+,3+,4+,2,35-64 -365,0,0,1,3+,35-64 -366,0,0,2,3+,35-64 -367,0,0,3,3+,35-64 -368,0,0,4+,3+,35-64 -369,0,1,1,3+,35-64 -370,0,1,2,3+,35-64 -371,0,1,3,3+,35-64 -372,0,1,4+,3+,35-64 -373,0,2,2,3+,35-64 -374,0,2,3,3+,35-64 -375,0,2,4+,3+,35-64 -376,0,3+,3,3+,35-64 -377,0,3+,4+,3+,35-64 -378,1,0,1,3+,35-64 -379,1,0,2,3+,35-64 -380,1,0,3,3+,35-64 -381,1,0,4+,3+,35-64 -382,1,1,1,3+,35-64 -383,1,1,2,3+,35-64 -384,1,1,3,3+,35-64 -385,1,1,4+,3+,35-64 -386,1,2,2,3+,35-64 -387,1,2,3,3+,35-64 -388,1,2,4+,3+,35-64 -389,1,3+,3,3+,35-64 -390,1,3+,4+,3+,35-64 -391,2,0,1,3+,35-64 -392,2,0,2,3+,35-64 -393,2,0,3,3+,35-64 -394,2,0,4+,3+,35-64 -395,2,1,1,3+,35-64 -396,2,1,2,3+,35-64 -397,2,1,3,3+,35-64 -398,2,1,4+,3+,35-64 -399,2,2,2,3+,35-64 -400,2,2,3,3+,35-64 -401,2,2,4+,3+,35-64 -402,2,3+,3,3+,35-64 -403,2,3+,4+,3+,35-64 -404,3+,0,1,3+,35-64 -405,3+,0,2,3+,35-64 -406,3+,0,3,3+,35-64 -407,3+,0,4+,3+,35-64 -408,3+,1,1,3+,35-64 -409,3+,1,2,3+,35-64 -410,3+,1,3,3+,35-64 -411,3+,1,4+,3+,35-64 -412,3+,2,2,3+,35-64 -413,3+,2,3,3+,35-64 -414,3+,2,4+,3+,35-64 -415,3+,3+,3,3+,35-64 -416,3+,3+,4+,3+,35-64 -417,0,0,1,0,>65 -418,0,0,2,0,>65 -419,0,0,3,0,>65 -420,0,0,4+,0,>65 -421,0,1,1,0,>65 -422,0,1,2,0,>65 -423,0,1,3,0,>65 -424,0,1,4+,0,>65 -425,0,2,2,0,>65 -426,0,2,3,0,>65 -427,0,2,4+,0,>65 -428,0,3+,3,0,>65 -429,0,3+,4+,0,>65 -430,1,0,1,0,>65 -431,1,0,2,0,>65 -432,1,0,3,0,>65 -433,1,0,4+,0,>65 -434,1,1,1,0,>65 -435,1,1,2,0,>65 -436,1,1,3,0,>65 -437,1,1,4+,0,>65 -438,1,2,2,0,>65 -439,1,2,3,0,>65 -440,1,2,4+,0,>65 -441,1,3+,3,0,>65 -442,1,3+,4+,0,>65 -443,2,0,1,0,>65 -444,2,0,2,0,>65 -445,2,0,3,0,>65 -446,2,0,4+,0,>65 -447,2,1,1,0,>65 -448,2,1,2,0,>65 -449,2,1,3,0,>65 -450,2,1,4+,0,>65 -451,2,2,2,0,>65 -452,2,2,3,0,>65 -453,2,2,4+,0,>65 -454,2,3+,3,0,>65 -455,2,3+,4+,0,>65 -456,3+,0,1,0,>65 -457,3+,0,2,0,>65 -458,3+,0,3,0,>65 -459,3+,0,4+,0,>65 -460,3+,1,1,0,>65 -461,3+,1,2,0,>65 -462,3+,1,3,0,>65 -463,3+,1,4+,0,>65 -464,3+,2,2,0,>65 -465,3+,2,3,0,>65 -466,3+,2,4+,0,>65 -467,3+,3+,3,0,>65 -468,3+,3+,4+,0,>65 -469,0,0,1,1,>65 -470,0,0,2,1,>65 -471,0,0,3,1,>65 -472,0,0,4+,1,>65 -473,0,1,1,1,>65 -474,0,1,2,1,>65 -475,0,1,3,1,>65 -476,0,1,4+,1,>65 -477,0,2,2,1,>65 -478,0,2,3,1,>65 -479,0,2,4+,1,>65 -480,0,3+,3,1,>65 -481,0,3+,4+,1,>65 -482,1,0,1,1,>65 -483,1,0,2,1,>65 -484,1,0,3,1,>65 -485,1,0,4+,1,>65 -486,1,1,1,1,>65 -487,1,1,2,1,>65 -488,1,1,3,1,>65 -489,1,1,4+,1,>65 -490,1,2,2,1,>65 -491,1,2,3,1,>65 -492,1,2,4+,1,>65 -493,1,3+,3,1,>65 -494,1,3+,4+,1,>65 -495,2,0,1,1,>65 -496,2,0,2,1,>65 -497,2,0,3,1,>65 -498,2,0,4+,1,>65 -499,2,1,1,1,>65 -500,2,1,2,1,>65 -501,2,1,3,1,>65 -502,2,1,4+,1,>65 -503,2,2,2,1,>65 -504,2,2,3,1,>65 -505,2,2,4+,1,>65 -506,2,3+,3,1,>65 -507,2,3+,4+,1,>65 -508,3+,0,1,1,>65 -509,3+,0,2,1,>65 -510,3+,0,3,1,>65 -511,3+,0,4+,1,>65 -512,3+,1,1,1,>65 -513,3+,1,2,1,>65 -514,3+,1,3,1,>65 -515,3+,1,4+,1,>65 -516,3+,2,2,1,>65 -517,3+,2,3,1,>65 -518,3+,2,4+,1,>65 -519,3+,3+,3,1,>65 -520,3+,3+,4+,1,>65 -521,0,0,1,2,>65 -522,0,0,2,2,>65 -523,0,0,3,2,>65 -524,0,0,4+,2,>65 -525,0,1,1,2,>65 -526,0,1,2,2,>65 -527,0,1,3,2,>65 -528,0,1,4+,2,>65 -529,0,2,2,2,>65 -530,0,2,3,2,>65 -531,0,2,4+,2,>65 -532,0,3+,3,2,>65 -533,0,3+,4+,2,>65 -534,1,0,1,2,>65 -535,1,0,2,2,>65 -536,1,0,3,2,>65 -537,1,0,4+,2,>65 -538,1,1,1,2,>65 -539,1,1,2,2,>65 -540,1,1,3,2,>65 -541,1,1,4+,2,>65 -542,1,2,2,2,>65 -543,1,2,3,2,>65 -544,1,2,4+,2,>65 -545,1,3+,3,2,>65 -546,1,3+,4+,2,>65 -547,2,0,1,2,>65 -548,2,0,2,2,>65 -549,2,0,3,2,>65 -550,2,0,4+,2,>65 -551,2,1,1,2,>65 -552,2,1,2,2,>65 -553,2,1,3,2,>65 -554,2,1,4+,2,>65 -555,2,2,2,2,>65 -556,2,2,3,2,>65 -557,2,2,4+,2,>65 -558,2,3+,3,2,>65 -559,2,3+,4+,2,>65 -560,3+,0,1,2,>65 -561,3+,0,2,2,>65 -562,3+,0,3,2,>65 -563,3+,0,4+,2,>65 -564,3+,1,1,2,>65 -565,3+,1,2,2,>65 -566,3+,1,3,2,>65 -567,3+,1,4+,2,>65 -568,3+,2,2,2,>65 -569,3+,2,3,2,>65 -570,3+,2,4+,2,>65 -571,3+,3+,3,2,>65 -572,3+,3+,4+,2,>65 -573,0,0,1,3+,>65 -574,0,0,2,3+,>65 -575,0,0,3,3+,>65 -576,0,0,4+,3+,>65 -577,0,1,1,3+,>65 -578,0,1,2,3+,>65 -579,0,1,3,3+,>65 -580,0,1,4+,3+,>65 -581,0,2,2,3+,>65 -582,0,2,3,3+,>65 -583,0,2,4+,3+,>65 -584,0,3+,3,3+,>65 -585,0,3+,4+,3+,>65 -586,1,0,1,3+,>65 -587,1,0,2,3+,>65 -588,1,0,3,3+,>65 -589,1,0,4+,3+,>65 -590,1,1,1,3+,>65 -591,1,1,2,3+,>65 -592,1,1,3,3+,>65 -593,1,1,4+,3+,>65 -594,1,2,2,3+,>65 -595,1,2,3,3+,>65 -596,1,2,4+,3+,>65 -597,1,3+,3,3+,>65 -598,1,3+,4+,3+,>65 -599,2,0,1,3+,>65 -600,2,0,2,3+,>65 -601,2,0,3,3+,>65 -602,2,0,4+,3+,>65 -603,2,1,1,3+,>65 -604,2,1,2,3+,>65 -605,2,1,3,3+,>65 -606,2,1,4+,3+,>65 -607,2,2,2,3+,>65 -608,2,2,3,3+,>65 -609,2,2,4+,3+,>65 -610,2,3+,3,3+,>65 -611,2,3+,4+,3+,>65 -612,3+,0,1,3+,>65 -613,3+,0,2,3+,>65 -614,3+,0,3,3+,>65 -615,3+,0,4+,3+,>65 -616,3+,1,1,3+,>65 -617,3+,1,2,3+,>65 -618,3+,1,3,3+,>65 -619,3+,1,4+,3+,>65 -620,3+,2,2,3+,>65 -621,3+,2,3,3+,>65 -622,3+,2,4+,3+,>65 -623,3+,3+,3,3+,>65 -624,3+,3+,4+,3+,>65 \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.py deleted file mode 100644 index 7b55f95..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/household_types.py +++ /dev/null @@ -1,23 +0,0 @@ -import os -import pandas as pd - -def load_household_types(): - - hhv_cats = { - 'N_CHILDREN': ['0', '1', '2', '3+'], - 'N_WORKERS': ['0', '1', '2', '3+'], - 'N_ADULTS': ['1', '2', '3', '4+'], - 'N_VEHICLES': ['0', '1', '2', '3+'], - 'HOUSEHOLDER_AGE': ['<35', '35-64', '>65'], - } - - hhv_types = pd.read_csv( - os.path.join(os.path.dirname(__file__), "household_types.csv"), - index_col=0, - ) - - for k, v in hhv_cats.items(): - hhv_types[k] = hhv_types[k].astype(pd.CategoricalDtype(v, ordered=True)) - - return hhv_types - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m01_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m01_handler.py deleted file mode 100755 index ca5e0bf..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m01_handler.py +++ /dev/null @@ -1,171 +0,0 @@ - -import logging -log = logging.getLogger('CMAP') -import pandas as pd -import numpy as np -from ..addict import Dict -from .filepaths import latest_matching -from ..util import search_path - -def read_m01(filename): - raw = pd.read_csv(filename, header=None, index_col=0) - - columns = [ - 'zone_type', - 'pnr_parking_cost', - 'zone_income', - 'pnr_flag', - 'first_wait_bus_peak', - 'first_wait_bus_offpeak', - 'first_wait_feeder_peak', - 'first_wait_feeder_offpeak', - ] - - # autocc column only appears in HW files - if len(raw.columns) == len(columns)+1: - columns.append('autocc') - - raw.columns = columns - raw.index.name = 'zone' - return raw - - -def load_m01(filenames): - m01 = Dict() - - m01.HW = read_m01(filenames.ALLPURPOSE_M01) - # There is only one unique m01 file - # the others are simply copies - # m01.HO = read_m01(filenames.PDHO_M01) - # m01.NH = read_m01(filenames.PDNH_M01) - - m01.HW['taxi_wait_pk'] = m01.HW.zone_type.map(filenames.cfg.taxi.wait_time.peak) - m01.HW['taxi_wait_op'] = m01.HW.zone_type.map(filenames.cfg.taxi.wait_time.offpeak) - - m01.HW['tnc_solo_wait_pk'] = m01.HW.zone_type.map(filenames.cfg.tnc.wait_time.peak) - m01.HW['tnc_solo_wait_op'] = m01.HW.zone_type.map(filenames.cfg.tnc.wait_time.offpeak) - m01.HW['tnc_pool_wait_pk'] = m01.HW.zone_type.map(filenames.cfg.tnc_pooled.wait_time.peak) - m01.HW['tnc_pool_wait_op'] = m01.HW.zone_type.map(filenames.cfg.tnc_pooled.wait_time.offpeak) - - return m01.HW - - -def attach_areatypes(dh, df, prefix, suffix, targetzone): - """ - Attach area type and default auto propensity - - Parameters - ---------- - dh - df - prefix - suffix - targetzone - - Returns - ------- - - """ - m01 = dh.m01 - - if isinstance(targetzone, str): - targetzone = np.asarray(df[targetzone]) - - if prefix and prefix[-1]!="_": - prefix = f"{prefix}_" - - if suffix and suffix[0]!="_": - suffix = f"_{suffix}" - - def _map(x, y): - if isinstance(x, pd.Series): - return x.map(y) - else: - return y[x] - - areatype = m01['zone_type'] - - # auto propensity is reloaded every time we attach to ensure it is up-to-date - auto_propensity_file = search_path( - dh.filenames.cache_dir / "computed_auto_propensity.csv", - dh.filenames.emme_database_dir / "computed_auto_propensity.csv", - dh.filenames.emme_database_dir / "defaults_base_year/default_auto_propensity.csv", - dh.filenames.emme_database_dir / "defaults_base_year/default_auto_propensity.csv.gz", - ) - autopropensity = pd.read_csv(auto_propensity_file, index_col=0)['auto_propensity'] - df[f'{prefix}areatype{suffix}'] = np.asarray(_map(targetzone,areatype)) - df[f'{prefix}autopropensity{suffix}'] = np.asarray(_map(targetzone,autopropensity)) - return df - - -def attach_hired_car_waits(dh, df, prefix, origin_zone): - """ - Attach taxi and TNC wait times to a dataframe. - - Parameters - ---------- - dh : DataHandler - df : DataFrame - New columns will be added to this dataframe. - prefix : str - This prefix will be added to the new columns. - origin_zone : str or pd.Series or int - The origin zone for each row in `df`, given as the column - name or a separate indexed-alike Series. - - Returns - ------- - df : DataFrame - """ - m01 = dh.m01 - - if isinstance(origin_zone, str): - origin_zone = df[origin_zone] - - if prefix and prefix[-1]!="_": - prefix = f"{prefix}_" - - def _map(x, y): - if isinstance(x, pd.Series): - return x.map(y) - else: - return y[x] - - # Add taxi and TNC wait time data - taxi_wait_pk = m01['taxi_wait_pk'] - taxi_wait_op = m01['taxi_wait_op'] - df[f'{prefix}taxi_wait_time_PEAK'] = _map(origin_zone,taxi_wait_pk) - df[f'{prefix}taxi_wait_time_OFFPEAK'] = _map(origin_zone,taxi_wait_op) - # df[f'{prefix}taxi_wait_time'] = ( - # origin_zone.map(taxi_wait_pk) * trips.in_peak - # + origin_zone.map(taxi_wait_op) * ~trips.in_peak - # ) - tnc_solo_wait_pk = m01['tnc_solo_wait_pk'] - tnc_solo_wait_op = m01['tnc_solo_wait_op'] - df[f'{prefix}tnc_solo_wait_time_PEAK'] = _map(origin_zone,tnc_solo_wait_pk) - df[f'{prefix}tnc_solo_wait_time_OFFPEAK'] = _map(origin_zone,tnc_solo_wait_op) - # df[f'{prefix}tnc_solo_wait_time'] = ( - # origin_zone.map(tnc_solo_wait_pk) * trips.in_peak - # + origin_zone.map(tnc_solo_wait_op) * ~trips.in_peak - # ) - tnc_pool_wait_pk = m01['tnc_pool_wait_pk'] - tnc_pool_wait_op = m01['tnc_pool_wait_op'] - df[f'{prefix}tnc_pool_wait_time_PEAK'] = _map(origin_zone,tnc_pool_wait_pk) - df[f'{prefix}tnc_pool_wait_time_OFFPEAK'] = _map(origin_zone,tnc_pool_wait_op) - # df[f'{prefix}tnc_pool_wait_time'] = ( - # origin_zone.map(tnc_pool_wait_pk) * trips.in_peak - # + origin_zone.map(tnc_pool_wait_op) * ~trips.in_peak - # ) - return df - -def sample_hh_income_cats(dh, otaz, n, income_breaks='5', random_state=None, sigma=1.2, trunc_min=None, trunc_max=None): - from ..incomes import random_incomes - return random_incomes( - median_income=dh.m01.zone_income[otaz]*100, - replications=n, - random_state=random_state, - sigma=sigma, - bins=income_breaks, - trunc_min=trunc_min, - trunc_max=trunc_max, - ) diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m023_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m023_handler.py deleted file mode 100644 index 74fb202..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/m023_handler.py +++ /dev/null @@ -1,39 +0,0 @@ -import pandas as pd -import numpy as np -from ..addict import Dict - -def read_m023(filename): - m023 = Dict() - with open(filename, 'rt') as f: - line = f.readline().split() - m023.CTA_BUS_BOARDING_FARE = int(line[0]) - m023.CTA_RAIL_BOARDING_FARE = int(line[1]) - m023.CTA_FIRST_XFER_FARE = int(line[2]) - m023.CTA_CBD_LINK_UP_FARE = int(line[3]) - - line = f.readline().split() - m023.FEEDER_BUS_BOARDING_FARE = int(line[0]) - m023.FEEDER_BUS_CBD_FARE = int(line[1]) - - line = f.readline().split() - m023.PACE_BUS_BOARDING_FARE = int(line[0]) - m023.PACE_BUS_FIRST_XFER_FARE = int(line[1]) - - line = f.readline().split() - m023.AUTO_OPERATING_COST_BY_SPEED = [int(j) for j in line[:8]] - line = f.readline().split() - m023.AUTO_OPERATING_COST_BY_SPEED.extend([int(j) for j in line[:8]]) - m023.AUTO_OPERATING_COST_BY_SPEED = np.asarray(m023.AUTO_OPERATING_COST_BY_SPEED) - - line = f.readline().split() - m023.AUTO_OPERATING_COST_BY_ZONETYPE = [int(j) for j in line[:4]] - m023.AUTO_OPERATING_COST_BY_ZONETYPE = np.asarray(m023.AUTO_OPERATING_COST_BY_ZONETYPE) - - return m023 - - -def load_m023(filenames): - - m023 = read_m023(filenames.ALLPURPOSE_M023) - return m023 - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/pa_trip_types.csv b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/pa_trip_types.csv deleted file mode 100644 index 91101cd..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/pa_trip_types.csv +++ /dev/null @@ -1,50 +0,0 @@ -trip_type,description,purpose_category,pair_type -1,worker home-based work low-income,HBWL,PA -2,worker home-based work hi-income,HBWH,PA -3,worker home-based work-related,HBW,PA -4,worker home-based school,HBW,PA -5,worker home-based nonhome/work at residence,HBOR,PA -6,worker home-based nonhome/work not at residence,HBO,PA -7,worker home-based shop,HBS,PA -8,worker work-based nonhome/work at residence,NHBR,PA -9,worker work-based nonhome/work not at residence,NHB,PA -10,worker work-based shop,NHBS,PA -11,worker work-based work,NHB,PA -12,worker nonhome/work at residence nonhome/work at residence,NHBR,OD -13,worker nonhome/work at residence nonhome/work not at residence,NHB,OD -14,worker nonhome/work at residence shop,NHBS,OD -15,worker nonhome/work not at residence nonhome/work at residence,NHBR,OD -16,worker nonhome/work not at residence nonhome/work not at residence,NHB,OD -17,worker nonhome/work not at residence shop,NHBS,OD -18,worker shop nonhome/work at residence,NHBR,OD -19,worker shop nonhome/work not at residence,NHB,OD -20,worker shop shop,NHBS,OD -21,non-working adult home-based school,HBW,PA -22,non-working adult home-based nonhome at residence,HBOR,PA -23,non-working adult home-based nonhome not at residence,HBO,PA -24,non-working adult home-based shop,HBS,PA -25,non-working adult nonhome at residence nonhome at residence,NHBR,OD -26,non-working adult nonhome at residence nonhome not at residence,NHB,OD -27,non-working adult nonhome at residence shop,NHBS,OD -28,non-working adult nonhome not at residence nonhome at residence,NHBR,OD -29,non-working adult nonhome not at residence nonhome not at residence,NHB,OD -30,non-working adult nonhome not at residence shop,NHBS,OD -31,non-working adult shop nonhome at residence,NHBR,OD -32,non-working adult shop nonhome not at residence,NHB,OD -33,non-working adult shop shop,NHBS,OD -34,child home-based school,EXCLUDE,PA -35,child home-based nonhome at residence,HBOR,PA -36,child home-based nonhome not at residence,HBO,PA -37,child home-based shop,HBS,PA -38,child school nonhome at residence,NHBR,PA -39,child school nonhome not at residence,NHB,PA -40,child school shop,NHBS,PA -41,child nonhome at residence nonhome at residence,NHBR,OD -42,child nonhome at residence nonhome not at residence,NHB,OD -43,child nonhome at residence shop,NHBS,OD -44,child nonhome not at residence nonhome at residence,NHBR,OD -45,child nonhome not at residence nonhome not at residence,NHB,OD -46,child nonhome not at residence shop,NHBS,OD -47,child shop nonhome at residence,NHBR,OD -48,child shop nonhome not at residence,NHB,OD -49,child shop shop,NHBS,OD \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/parking_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/parking_handler.py deleted file mode 100644 index 6b3136a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/parking_handler.py +++ /dev/null @@ -1,74 +0,0 @@ -import os - -import numpy as np -import pandas as pd -from ..addict import Dict - -def load_cbd_parking(filenames): - - if os.path.exists(filenames.HW_CBDPARK0): - # split the HW_CBDPARK file into its two primary parts - with open(filenames.HW_CBDPARK0, 'rt') as f: - lines = f.readlines() - def secondpart(line): - beginning = line.split(",", 1)[0] - try: - beginning = int(beginning) - except: - return 0 - if beginning < 10_000: - return 0 - return 1 - with open(filenames.HW_CBDPARK, 'wt') as f: - f.write("".join(i for i in lines if not secondpart(i))) - with open(filenames.HW_CBDPARK2, 'wt') as f: - f.write("".join(i for i in lines if secondpart(i))) - - cbd_parking = pd.read_csv( - filenames.HW_CBDPARK, - header=None, - names=['ZoneID', 'CumProb', 'ThresholdPrice', 'SavePrice', 'WalkSeconds'], - ) - cbd_parking.CumProb /= 10000. - # cbd_parking['SumPrice'] = cbd_parking.ThresholdPrice + cbd_parking.SavePrice - cbd_parking['rownum'] = cbd_parking.groupby(['ZoneID']).cumcount() - - def decumulate(x): - x_ = np.array(x) - x_[1:] -= x[:-1] - return x_ - cbd_parking['Prob'] = cbd_parking.groupby("ZoneID")['CumProb'].transform(decumulate) - cbd_parking['WeightedPrice'] = cbd_parking['Prob'] * cbd_parking['ThresholdPrice'] - cbd_parking_prices = cbd_parking.set_index(["ZoneID",'rownum']).ThresholdPrice.unstack() - cbd_parking_price_prob = cbd_parking.set_index(["ZoneID",'rownum']).Prob.unstack() - - for zone_to, zone_source in filenames.cfg.parking_costs.cbd_nearby.items(): - cbd_parking_prices.loc[zone_to] = cbd_parking_prices.loc[zone_source] - cbd_parking_price_prob.loc[zone_to] = cbd_parking_price_prob.loc[zone_source] - - cbd_parking_prices.sort_index(inplace=True) - cbd_parking_price_prob.sort_index(inplace=True) - - CBD_PARKING_ZONES = dict(zip(cbd_parking_prices.index, np.arange(len(cbd_parking_prices.index)))) - - cbd_parking2 = pd.read_csv( - filenames.HW_CBDPARK2, - header=None, - names=[ - 'IncomeCeiling', - 'FreeParkingPct', - 'TransitPct', - 'AutoOcc1Pct', - 'AutoOcc2Pct', - 'AutoOcc3Pct', - 'AutoOcc4Pct', - ], - ) - - parking = Dict() - parking.cbd_parking = cbd_parking - parking.cbd_parking_prices = cbd_parking_prices - parking.cbd_parking_price_prob = cbd_parking_price_prob - parking.cbd_parking2 = cbd_parking2 - parking.CBD_PARKING_ZONES = CBD_PARKING_ZONES - return parking diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/shp_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/shp_handler.py deleted file mode 100644 index 7ede3c6..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/shp_handler.py +++ /dev/null @@ -1,11 +0,0 @@ - -import geopandas as gpd - - -def load_zone_shapes(filenames): - zone_shp = gpd.read_file( - filenames.zone_shapefile - ).set_index('zone17') - return zone_shp - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/skims_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/skims_handler.py deleted file mode 100644 index d4bba73..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/skims_handler.py +++ /dev/null @@ -1,226 +0,0 @@ -import numpy as np -import logging -log = logging.getLogger('CMAP') - - -""" -# Mode Choice Model Impedances - -## Highway Costs - -### Times and distances - -Skims: -HBW trips - Times – mf44 (SOV AM peak), mf76 (HOV AM peak) - Distances - mf45 (SOV AM peak), mf77 (HOV AM peak) - -HBO/NHB trips -Times – mf46 (SOV midday) -Distances - mf47 (SOV midday) - -### Parking Costs - -HBW trips to the Central Area – Monte Carlo simulation using -costs from MCHW_CBDPARK.TXT - -All other trips – zonal Park and Ride cost from MCxx_M01.TXT - -Hours of parking: HBW=10, HBO=6, NHB=3 - -### Auto Operating Costs - -Supplied by MCxx_M023.TXT in 5 MPH increments - -## Transit Costs - -Times and fares Skims: -HBW trips -In-vehicle time – mf822 (AM peak) -Out of vehicle time – mf823 (AM peak) [walk transfer but not access/egress] -Headway – mf838 (AM peak) -Fare – mf828 (AM peak) - -HBO/NHB trips -In-vehicle time – mf922 (midday) -Out of vehicle time – mf923 (midday) [walk transfer but not access/egress] -Headway – mf938 (midday) -Fare – mf928 (midday) - -Access/egress are simulated for each traveler. - First mode and last mode are obtained from transit skims - (mf829|mf929 and mf831|mf931) – these are used to determine - which of the 5 access/egress modes (walk, bus, feeder bus, P&R, K&R) - are simulated. That information is used to pull the appropriate data - from MCxx_DISTR: average zonal distance and standard deviation of - the modes to simulate actual distance. - -""" - -from ..addict import Dict -import larch -import os -from os.path import join as pj -from ..skims import read_skims - - -class DictSkims(Dict): - # defines special pickling - def __getstate__(self): - return self.get('filename', None) - def __setstate__(self, state): - self.update(_load_skims(state)) - def __reduce__(self): - return ( - type(self), - (), - self.__getstate__(), - ) - - -def load_skims(filenames, dh=None, backfill_uncompressed_skims=False): - from ..util import search_path - return _load_skims( - search_path(filenames.emmemat), - dh=dh, - backfill_uncompressed_skims=backfill_uncompressed_skims, - ) - - -def _load_skims( - filename_emmemat, - dh=None, - backfill_uncompressed_skims=False, - use_compressed_skims=None, -): - try: - if use_compressed_skims is None: - if dh is None: - use_compressed_skims = False - else: - use_compressed_skims = dh.cfg.get("use_compressed_skims", False) - - skims = DictSkims() - log.debug(f"filename emmemat = {filename_emmemat}") - skims.filename = filename_emmemat - skims.raw = read_skims( - filename_emmemat, - backfill_uncompressed_skims=backfill_uncompressed_skims, - use_compressed_skims=use_compressed_skims, - ) - - skims.raw['mf45'] = skims.raw['mf45'].load() - skims.raw['mf47'] = skims.raw['mf47'].load() - - skims.auto.col_mapping = dict( - am_time='mf44', - am_dist='mf45', - am_toll_loinc='mf111', - am_toll_hiinc='mf114', - md_time='mf46', - md_dist='mf47', - md_toll='mf117', - am_time_hov='mf76', - am_dist_hov='mf77', - am_toll_hov_loinc='mf112', - am_toll_hov_hiinc='mf115', - am_opcost='am_opcost', - am_opcost_hov='am_opcost_hov', - md_opcost='md_opcost', - ) - - skims.transit_pk.col_mapping = Dict( - ivtt= 'mf822', - ovtt= 'mf823', - headway= 'mf838', - fare= 'mf828', - firstmode= 'mf829', - prioritymode='mf830', - lastmode= 'mf831', - ) - - skims.transit_op.col_mapping = Dict( - ivtt= 'mf922', - ovtt= 'mf923', - headway= 'mf938', - fare= 'mf928', - firstmode= 'mf929', - prioritymode='mf930', - lastmode= 'mf931', - ) - - if dh is not None: - skims = _load_skims_step_2(skims, dh) - return skims - except: - log.exception("exception in _load_skims") - raise - -def _load_skims_step_2(skims, dh): - """ - Some post-processing when `dh` is available - - Parameters - ---------- - skims - dh - - Returns - ------- - skimss - """ - try: - try: - skims.raw['mf829'] - except KeyError: - if dh is None: - raise ValueError("no data_handler defined, and transit skim convolution is needed") - from ..transit_skim_convolution import skim_convol - dh['skims'] = skims - skim_convol(dh, peak=True) - - try: - skims.raw['mf929'] - except KeyError: - if dh is None: - raise ValueError("no data_handler defined, and transit skim convolution is needed") - from ..transit_skim_convolution import skim_convol - dh['skims'] = skims - skim_convol(dh, peak=False) - - # skims.first_mode_peak = skims.transit_pk.raw[pick_in(skims.transit_pk.raw, 'mf829_$', 'mf829')][:].astype(np.int8)+1 - # skims.priority_mode_peak = skims.transit_pk.raw[pick_in(skims.transit_pk.raw, 'mf830_$', 'mf830')][:].astype(np.int8)+1 - # skims.last_mode_peak = skims.transit_pk.raw[pick_in(skims.transit_pk.raw, 'mf831_$', 'mf831')][:].astype(np.int8)+1 - # skims.first_mode_offpeak = skims.transit_op.raw[pick_in(skims.transit_op.raw, 'mf929_$', 'mf929')][:].astype(np.int8)+1 - # skims.priority_mode_offpeak = skims.transit_op.raw[pick_in(skims.transit_op.raw, 'mf930_$', 'mf930')][:].astype(np.int8)+1 - # skims.last_mode_offpeak = skims.transit_op.raw[pick_in(skims.transit_op.raw, 'mf931_$', 'mf931')][:].astype(np.int8)+1 - skims.first_mode_peak = skims.raw['mf829'].load().values.astype(np.int8)+1 - skims.priority_mode_peak = skims.raw['mf830'].load().values.astype(np.int8)+1 - skims.last_mode_peak = skims.raw['mf831'].load().values.astype(np.int8)+1 - - skims.first_mode_offpeak = skims.raw['mf929'].load().values.astype(np.int8)+1 - skims.priority_mode_offpeak = skims.raw['mf930'].load().values.astype(np.int8)+1 - skims.last_mode_offpeak = skims.raw['mf931'].load().values.astype(np.int8)+1 - - def to_speed_bucket(_d, _t): - return np.where( - skims.raw[skims.auto.col_mapping[_t]].load(), - np.round(np.ceil( - skims.raw[skims.auto.col_mapping[_d]].load() / - skims.raw[skims.auto.col_mapping[_t]].load() * 60. / 5. - )), - 0 - ).astype(np.uint8) - def to_opcost(_d, _t): - return ( - dh.m023.AUTO_OPERATING_COST_BY_SPEED[to_speed_bucket(_d, _t)] / 100. - * skims.raw[skims.auto.col_mapping[_d]].load() - ) - skims.raw['am_opcost'] = to_opcost('am_dist', 'am_time') - skims.raw['am_opcost_hov'] = to_opcost('am_dist_hov', 'am_time_hov') - skims.raw['md_opcost'] = to_opcost('md_dist', 'md_time') - - return skims - except: - log.exception("exception in _load_skims") - raise diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tabler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tabler.py deleted file mode 100644 index b3daa55..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tabler.py +++ /dev/null @@ -1 +0,0 @@ -from sharrow import Table \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tg_handler.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tg_handler.py deleted file mode 100644 index 5fc2d18..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/tg_handler.py +++ /dev/null @@ -1,129 +0,0 @@ -import os.path -import numpy as np -import pandas as pd -import gzip -from ..addict import Dict -from ..util import search_path -import logging - - - -def load_hh_enum(filenames): - - hhv = pd.read_csv( - filenames.hh_enum, - header=None, - names=["subzone", 'zone', 'hhvtype'] - ) - tabulation = ( - hhv - .groupby(["zone","hhvtype"]) - .size() - .unstack() - .reindex(pd.RangeIndex(1, 3633, name='TAZ')) - .reindex(pd.RangeIndex(1, 625, name='hhvtype'), axis=1) - .fillna(0) - ) - return hhv, tabulation - - - -def load_tg(filenames, with_detail=False): - - - pa_trip_types = pd.read_csv( - os.path.join(os.path.dirname(__file__), "pa_trip_types.csv"), - index_col=0, - ) - purpose_categories = pa_trip_types.purpose_category - - trip49_filenames = {} - trip49_filenames['typical'] = search_path( - filenames.cache_dir / "TRIP49_PA_OUT.TXT.gz", - filenames.cache_dir / "TRIP49_PA_OUT.TXT", - filenames.emme_database_dir / "TRIP49_PA_OUT.TXT.gz", - filenames.emme_database_dir / "TRIP49_PA_OUT.TXT", - filenames.emme_database_dir / "defaults_base_year/TRIP49_PA_OUT.TXT.gz", - filenames.emme_database_dir / "defaults_base_year/TRIP49_PA_OUT.TXT", - ) - # secondary WFH trip generation - trip49_filenames['wfh'] = search_path( - filenames.cache_dir / "TRIP49_PA_WFH_OUT.TXT.gz", - filenames.cache_dir / "TRIP49_PA_WFH_OUT.TXT", - filenames.emme_database_dir / "TRIP49_PA_WFH_OUT.TXT.gz", - filenames.emme_database_dir / "TRIP49_PA_WFH_OUT.TXT", - filenames.emme_database_dir / "defaults_base_year/TRIP49_PA_WFH_OUT.TXT.gz", - filenames.emme_database_dir / "defaults_base_year/TRIP49_PA_WFH_OUT.TXT", - ) - - log = logging.getLogger('CMAP') - result = {} - for tripclass, trip49_filename in trip49_filenames.items(): - - log.info(f"reading {tripclass} trip generation from: {trip49_filename}") - - if os.path.splitext(trip49_filename)[1] == '.gz': - f = gzip.open(trip49_filename, 'rb') - else: - f = open(trip49_filename, 'rb') - try: - trip49 = pd.read_fwf( - f, - widths=[6, 6, 2, 9, 9], - names=['subzone', 'zone', 'trip_type', 'productions', 'attractions'], - ) - finally: - f.close() - - trip49["purpose_category"] = trip49["trip_type"].map(purpose_categories) - - # Certain trip types are NHB but generated as P-A, convert them to O-D - nhb_pa = (pa_trip_types['purpose_category'].isin(['NHB', 'NHBR', 'NHBS'])) & (pa_trip_types['pair_type'] == 'PA') - trip49["mix_PA"] = trip49["trip_type"].map(nhb_pa) - mixed_PA = (trip49['productions'] + trip49['attractions']) / 2 - trip49.loc[trip49["mix_PA"], 'productions'] = mixed_PA.loc[trip49["mix_PA"]] - trip49.loc[trip49["mix_PA"], 'attractions'] = mixed_PA.loc[trip49["mix_PA"]] - - trip49z = trip49.groupby(["zone", "purpose_category"])[['productions', 'attractions']].sum() - prodns = trip49z['productions'].unstack().fillna(0.0) - attrns = trip49z['attractions'].unstack().fillna(0.0) - - if with_detail: - trip49z_detail = trip49.groupby(["zone", "trip_type"])[['productions', 'attractions']].sum() - prodns_detail = trip49z_detail['productions'].unstack().fillna(0.0) - attrns_detail = trip49z_detail['attractions'].unstack().fillna(0.0) - - for xns in (prodns, attrns): - # There are high and low income work purposes. We push all the non-income bound - # home-based mandatory purposes into income-related groups based on the relative - # share in the income-bound values - income_generic_mandatory = xns["HBW"] - lo_income_share_mandatory = (xns["HBWL"] / (xns["HBWL"] + xns["HBWH"])).where((xns["HBWL"] + xns["HBWH"])>0, 0) - hi_income_share_mandatory = 1 - lo_income_share_mandatory - xns["HBWL"] += income_generic_mandatory * lo_income_share_mandatory - xns["HBWH"] += income_generic_mandatory * hi_income_share_mandatory - xns.drop(columns=['HBW', 'EXCLUDE'], inplace=True) - - pd.concat([prodns.stack().rename("productions"), attrns.stack().rename("attractions")], axis=1).to_csv( - filenames.cache_dir / "trips_PA_by_purpose.csv" - ) - - tg = Dict() - tg.trip_attractions8 = attrns.copy() - tg.trip_productions8 = prodns.copy() - tg.zone_productions8 = prodns.round().astype(int).copy() - - for xns in (prodns, attrns): - xns['HBO'] = xns['HBO'] + xns['HBOR'] - xns['NHB'] = xns['NHB'] + xns['NHBR'] + xns['NHBS'] - xns.drop(columns=['HBOR', 'NHBR', 'NHBS'], inplace=True) - - tg.trip_attractions5 = attrns - tg.trip_productions5 = prodns - tg.zone_productions5 = prodns.round().astype(int) - if with_detail: - tg.trip_attractions_detail = attrns_detail - tg.trip_productions_detail = prodns_detail - result[tripclass] = tg - - return result diff --git a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/visitors.py b/src/Mode-Dest-TOD/cmap_modedest/data_handlers/visitors.py deleted file mode 100644 index 0c0612b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/data_handlers/visitors.py +++ /dev/null @@ -1,39 +0,0 @@ -import numpy as np -import pandas as pd -import logging -from ..util import search_path - - -def load_visitor_trips(filenames, scale_factor=1.0): - """ - Generate visitor trips. - - The raw visitor table includes fractional trips. - This function converts to integer trips by making - random draws from the trip table. - - Parameters - ---------- - filenames : Filenames - scale_factor : float, default 1.0 - - Returns - ------- - trips : pd.DataFrame - A square trip table with integer O-D trips by visitors - """ - filename = search_path( - filenames.cache_dir / "CMAP_TripTable_VisitorsWeekday.csv.gz", - filenames.emme_database_dir / "CMAP_TripTable_VisitorsWeekday.csv.gz", - filenames.emme_database_dir / "defaults_base_year/CMAP_TripTable_VisitorsWeekday.csv.gz", - ) - logging.getLogger('CMAP').info(f"reading visitor trip table from: {filename}") - trips = pd.read_csv(filename) - n = trips['trips'].sum() - trip_wt = trips['trips'] / n - n_trips = int(np.round(n * scale_factor)) - visit_trips = np.random.default_rng(42).choice(len(trips), n_trips, p=trip_wt) - trips.drop(columns=['trips'], inplace=True) - trips['visitor_trips'] = pd.Series(visit_trips).value_counts() - trips.fillna(0, inplace=True) - return trips.pivot("start_taz", "end_taz", "visitor_trips").fillna(0).astype(int) diff --git a/src/Mode-Dest-TOD/cmap_modedest/deadheading.py b/src/Mode-Dest-TOD/cmap_modedest/deadheading.py deleted file mode 100644 index 8ac89c9..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/deadheading.py +++ /dev/null @@ -1,144 +0,0 @@ -import numpy as np -import pandas as pd -import warnings -from .time_of_day_model import time_period_names, time_period_codes - -import logging -log = logging.getLogger('CMAP') - -def compute_deadhead_trip_table( - dh, - trips, - intrazonal_factor=0.5, - traveltime_factor=-1.0, - stats=False, -): - """ - Compute a trip table of deadhead trips taken by taxis and TNCs. - - Parameters - ---------- - dh : DataHandler - trips : dask.DataFrame - The assembled primary trips (not including hired car deadheading) - as a dask DataFrame. - intrazonal_factor : float - The pseudo-value of travel time for intrazonal trips, which include - implied travel time as well as a constant adjustment. - traveltime_factor : float, default -1.0 - A parameter to calibrate the overall length of deadhead trips, used as - the coefficient in a gravity model. - stats : bool - Display length distribution of deadhead trips, when in a Jupyter - notebook. - - Returns - ------- - DataFrame - """ - result = {} - random_generator = np.random.default_rng([12345,67890]) - - for tname, tcode in zip(time_period_names, time_period_codes): - log.info(f"compute_deadhead_trip_table: {tname}") - - # We try this twice, as there is a rare sync problem in numexpr that - # makes this fail. - try: - trips_by_od = ( - trips - .query("mode in (4,5,6)") - .query(f"timeperiod in ('{tname}',)") - .groupby(["o_zone", "d_zone"])['trips'] - .sum() - .compute() - .unstack(0) - .fillna(0) - ).reindex( - index=dh.skims.raw[f'mf46{tcode}'].indexes['otaz'], - columns=dh.skims.raw[f'mf46{tcode}'].indexes['dtaz'], - ).fillna(0) - except KeyError: - import numexpr.necompiler - numexpr.necompiler._numexpr_cache.clear() - trips_by_od = ( - trips - .query("mode in (4,5,6)") - .query(f"timeperiod in ('{tname}',)") - .groupby(["o_zone", "d_zone"])['trips'] - .sum() - .compute() - .unstack(0) - .fillna(0) - ).reindex( - index=dh.skims.raw[f'mf46{tcode}'].indexes['otaz'], - columns=dh.skims.raw[f'mf46{tcode}'].indexes['dtaz'], - ).fillna(0) - - deadhead_dests = trips_by_od.sum() # hired car trip origins - deadhead_origs = trips_by_od.sum(1) # hired car trip destinations - - auto_travel_time = dh.skims.raw[f'mf46{tcode}'].values - intrazonal_value = np.eye(auto_travel_time.shape[0]) * intrazonal_factor - wgt_matrix = np.exp(traveltime_factor*(auto_travel_time + intrazonal_value)) - - # Fratar the deadhead weights to the deadhead productions and attractions - for iter in range(10): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=RuntimeWarning) - w = np.nan_to_num(wgt_matrix / wgt_matrix.sum(0)) * np.expand_dims(deadhead_dests, 0) - wgt_matrix = np.nan_to_num(w / np.expand_dims(w.sum(1), 1)) * np.expand_dims(deadhead_origs, 1) - - chx = {} - - triptable = np.zeros(wgt_matrix.shape, dtype=np.int32) - - for row in range(wgt_matrix.shape[0]): - rowsum = wgt_matrix[row].sum() - n = int(np.round(rowsum)) - if n: - chx[row] = random_generator.choice(wgt_matrix.shape[1], size=n, p=wgt_matrix[row] / rowsum) - for k in chx[row]: - triptable[row, k] += 1 - - triptable = pd.DataFrame( - triptable, - index=dh.skims.raw[f'mf46{tcode}'].indexes['otaz'], - columns=dh.skims.raw[f'mf46{tcode}'].indexes['dtaz'], - ).fillna(0) - triptable.index.name = 'o_zone' - triptable.columns.name = 'd_zone' - triptable = triptable.stack().fillna(0).reset_index() - - triptable['timeperiod'] = tname - triptable['mode'] = 1 - triptable['purpose'] = 'DEAD' - triptable['a_zone'] = triptable['d_zone'] - - triptable = triptable.set_index([ - 'purpose', 'mode', 'o_zone', 'd_zone', 'a_zone', 'timeperiod' - ]) - - result[tname] = triptable.loc[triptable.iloc[:,0] > 0].copy() - result[tname].columns = ['trips'] - - if stats: - import matplotlib.pyplot as plt - from xmle import Show - from IPython.display import display - - tt = dh.skims.raw[[f'mf46{tcode}']].at_df( - result[tname] - .reset_index()[['o_zone', 'd_zone']] - .rename(columns=dict(o_zone='otaz', d_zone='dtaz')) - ) - rr = result[tname].copy() - rr['time'] = tt[f'mf46{tcode}'].values - fig, ax = plt.subplots() - ax.hist(rr['time'], weights=rr['trips']) - ax.set_title(tname) - ax.set_xlabel("minutes") - display(Show(fig)) - plt.close() - - return pd.concat([r for r in result.values()]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/__init__.py deleted file mode 100644 index c523523..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -import larch -from larch import P,X,PX -import os -import pandas as pd -import numpy as np -import cmap_modedest -from ..addict import Dict -from pathlib import Path - -from ..util import resource_usage, start_memory_tracing, ping_memory_tracing - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_choice.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_choice.py deleted file mode 100644 index f36f588..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_choice.py +++ /dev/null @@ -1,863 +0,0 @@ -import numpy as np -import pandas as pd -import os -from ..addict import Dict -import larch as larch -from larch import P,X -from larch.util.figures import distribution_figure, share_figure -from larch.util.data_expansion import piecewise_linear -from IPython.display import display, HTML - -import logging -log = logging.getLogger('CMAP') - -def L(*args): - if len(args)==1 and isinstance(args[0], str) and args[0][0]=="#": - log.info(args[0]) - else: - s = "\n".join(str(i) for i in args) - s = "\n"+s - log.info(s.replace("\n","\n ")) - - -from ..transit_approach import transit_approach -from .est_data import dh -from ..choice_model import model_builder - -from .est_config import mode_modeled, n_sampled_dests -from .est_survey import trips -from .est_sample_dest import sample_dest_zones_and_data -from ..util import resource_usage -from ..modecodes import mode9names - - -L( - "###### data statistics ######", - trips['tripPurpose'].value_counts(), - trips.mode3.value_counts() -) - -L("###### sample_dest_zones_and_data ######") - -# Null out invalid data # now in survey_data -# transit_cols = ['ivtt','ovtt','headway','fare','firstmode','lastmode'] -# for a in transit_cols: -# to_nan = trips[f'transit_{a}'] > 999 -# trips.loc[to_nan,f'transit_{a}'] = np.nan - - -L("## ae_approach_los ##") -from .est_survey import ae_approach_los - -trip_approach_distances, ae_los = ae_approach_los(trips) - -L("## sample_dest_zones_and_data ##") -TRIP_ALTS_CACHE_FILE = f"trip_alts_n{n_sampled_dests}_vx14" - -trip_alt_df = dh.filenames.load(TRIP_ALTS_CACHE_FILE) -if trip_alt_df is None: - trip_alt_df = sample_dest_zones_and_data( - trips, - n_zones=dh.n_internal_zones, - n_sampled_dests=n_sampled_dests, - keep_trips_cols=[ - 'd_zone', - 'mode5', - 'mode5code', - 'mode7', - 'mode7code', - 'mode9', - 'mode9code', - 'incomeLevel', - 'tripCat', - 'tripPurpose', - 'auto_dist', - 'auto_time', - 'auto_parking_cost', - 'transit_fare', - 'transit_ivtt', - 'transit_ovtt', - 'transit_headway', - 'transit_approach_cost', - 'transit_approach_drivetime', - 'transit_approach_walktime', - 'transit_approach_waittime', - 'taxi_wait_time', - 'taxi_fare', - 'tnc_solo_wait_time', - 'tnc_pool_wait_time', - 'tnc_solo_fare', - 'tnc_pool_fare', - 'hhinc_dollars', - 'timeperiod', - 'mode_and_time', - 'actualdest', - 'ozone_areatype', - 'ozone_autopropensity', - 'autopropensity', - 'areatype', - 'hhveh', - 'hhsize', - 'hhadults', - 'paFlip', - 'auto_time_hov', - 'auto_toll', - 'auto_toll_hiinc', - 'auto_toll_loinc', - 'auto_toll_hov_loinc', - 'auto_toll_hov_hiinc', - 'auto_opcost', - 'auto_opcost_hov', - ] - ) - - # - # display(HTML(f"

auto_dist statistics

")) - # display(trip_alt_df['auto_dist'].statistics()) - # - # display(HTML(f"

altdest0001_auto_dist statistics

")) - # display(trip_alt_df['altdest0001_auto_dist'].statistics()) - # - - - L("## invalid_walktime ##") - for peaky in ['PEAK', 'OFFPEAK']: - invalid_walktime = trip_alt_df[f'actualdest_transit_approach_walktime_{peaky}'] > 180 - trip_alt_df.loc[invalid_walktime, f'actualdest_transit_approach_walktime_{peaky}'] = np.nan - - L("## invalid_drivetime ##") - for peaky in ['PEAK', 'OFFPEAK']: - invalid_drivetime = trip_alt_df[f'actualdest_transit_approach_drivetime_{peaky}'] > 180 - trip_alt_df.loc[invalid_drivetime, f'actualdest_transit_approach_drivetime_{peaky}'] = np.nan - - for i in range(n_sampled_dests): - for peaky in ['PEAK', 'OFFPEAK']: - L(f"# approach simulate for altdest{i + 1:04d} {peaky} ") - # q = (trips.tripPurpose == purpose) - # _trips_by_purpose = trip_alt_df[q] - result_purpose = transit_approach( - dh, - trip_alt_df.o_zone, - trip_alt_df[f'altdest{i + 1:04d}'], - 'HW' if peaky=='PEAK' else 'HO', - replication=1, - approach_distances=None, - trace=False, - random_state=123 + i, - ) - for key in ['drivetime', 'walktime', 'cost', 'waittime']: - v = result_purpose[key][:, 0].astype(float) - if key in ['drivetime', 'walktime', 'waittime']: - v[v > 180] = np.nan - trip_alt_df.loc[:, f'altdest{i + 1:04d}_transit_approach_{key}_{peaky}'] = v - - dh.filenames.save(TRIP_ALTS_CACHE_FILE, trip_alt_df) - -from ..choice_model import alt_codes_and_names - -alt_codes, alt_names = alt_codes_and_names( - n_sampled_dests=n_sampled_dests, - include_actual_dest=True, -) - - -dats = Dict() -mods = Dict() -mods_preload = Dict() - -from ..purposes import purposes5, purposes_to_peaky -purposes = purposes5 - - -altdest_tags = lambda suffix: [ - f'altdest{i + 1:04d}_{suffix}' - for i in range(n_sampled_dests) -] - -altdest_tags_div = lambda suffix1, suffix2: [ - f'altdest{i + 1:04d}_{suffix1}/altdest{i + 1:04d}_{suffix2}' - for i in range(n_sampled_dests) -] - - -# `ca_folds` defines how ca_folded (see below) is built -ca_folds = { - "nAttractions_HBWH": ['actualdest_log_attractions_HBWH'] + altdest_tags("log_attractions_HBWH"), - "nAttractions_HBWL": ['actualdest_log_attractions_HBWL'] + altdest_tags("log_attractions_HBWL"), - "nAttractions_HBS": ['actualdest_log_attractions_HBS'] + altdest_tags("log_attractions_HBS"), - "nAttractions_HBO": ['actualdest_log_attractions_HBO'] + altdest_tags("log_attractions_HBO"), - "nAttractions_NHB": ['actualdest_log_attractions_NHB'] + altdest_tags("log_attractions_NHB"), - "auto_dist_OFFPEAK": ['actualdest_auto_dist_OFFPEAK'] + altdest_tags("auto_dist_OFFPEAK"), - "auto_dist_PEAK": ['actualdest_auto_dist_PEAK'] + altdest_tags("auto_dist_PEAK"), - "auto_time_OFFPEAK": ['actualdest_auto_time_OFFPEAK'] + altdest_tags("auto_time_OFFPEAK"), - "auto_time_PEAK": ['actualdest_auto_time_PEAK'] + altdest_tags("auto_time_PEAK"), - "transit_ivtt_PEAK": ['actualdest_transit_ivtt_PEAK'] + altdest_tags("transit_ivtt_PEAK"), - "transit_ivtt_OFFPEAK": ['actualdest_transit_ivtt_OFFPEAK'] + altdest_tags("transit_ivtt_OFFPEAK"), - "transit_ovtt_OFFPEAK": ['actualdest_transit_ovtt_OFFPEAK'] + altdest_tags("transit_ovtt_OFFPEAK"), - "transit_approach_waittime_OFFPEAK": ['actualdest_transit_approach_waittime_OFFPEAK'] + altdest_tags("transit_approach_waittime_OFFPEAK"), - "transit_approach_walktime_OFFPEAK": ['actualdest_transit_approach_walktime_OFFPEAK'] + altdest_tags("transit_approach_walktime_OFFPEAK"), -} - -# TODO check data on transit_approach_waittime_OFFPEAK - -# `ca_folded` will contain, by purpose, destination-specific data for later analysis -ca_folded = Dict() - -cached_model_filename = lambda purpose: dh.filenames.cache_dir / f"choicemodel_{purpose}_hc.xlsx" -cached_model_filereport = lambda purpose: dh.filenames.cache_dir / f"choicemodel_{purpose}_hc_report.xlsx" - -for purpose in purposes: - - # define filter for this trip purpose - q = (trip_alt_df['tripCat'] == purpose) - - # assemble quantitative (size) factors - # We use the attractions defined in the model's Trip Generation step. - log.debug(f"size_of_altdests for {purpose}") - size_of_altdests = [ - np.log(np.fmax( - dh.trip_attractions5.loc[ - trip_alt_df[q][f"altdest{i + 1:04d}"], - purpose, - ].reset_index( - drop=True - ), - 1e-300, # nonzero but tiny - )).rename( - f'altdest{i + 1:04d}_log_attractions_{purpose}' - ) - for i in range(n_sampled_dests) - ] - - log.debug(f"actualdest_log_attractions for {purpose}") - _df = pd.concat( - [ - trip_alt_df[q].reset_index(), - np.log(np.fmax( - dh.trip_attractions5.loc[ - trips[q].d_zone, - purpose, - ].reset_index( - drop=True - ), - 1e-300, # nonzero but tiny - )).rename( - f'actualdest_log_attractions_{purpose}' - ), - ] + size_of_altdests, - axis=1, - ) - - peaky = 'PEAK' if 'W' in purpose else 'OFFPEAK' - - positive_attractions = (_df[f'actualdest_log_attractions_{purpose}'] > -666) - _df[f'actualdest_transit_avail_{purpose}'] = ( - (_df[f'actualdest_transit_ivtt_{peaky}'] < 999) - & (_df[f'actualdest_transit_approach_walktime_{peaky}'] < 999) - & (_df[f'actualdest_transit_approach_drivetime_{peaky}'] < 999) - & positive_attractions - ) - _df[f'actualdest_auto_avail_{purpose}'] = positive_attractions - _df[f'actualdest_walk_avail_{purpose}'] = positive_attractions & (_df[f'actualdest_auto_dist_OFFPEAK'] < 3) - _df[f'actualdest_bike_avail_{purpose}'] = positive_attractions & (_df[f'actualdest_auto_dist_OFFPEAK'] < 12) - for i in range(n_sampled_dests): - positive_attractions = (_df[f'altdest{i + 1:04d}_log_attractions_{purpose}'] > -666) - _df[f'altdest{i + 1:04d}_transit_avail_{purpose}'] = ( - ( _df[f'altdest{i + 1:04d}_transit_ivtt_{peaky}'] < 999) - & (_df[f'altdest{i + 1:04d}_transit_ovtt_{peaky}'] < 999) - & (_df[f'altdest{i + 1:04d}_transit_approach_walktime_{peaky}'] < 999) - & (_df[f'altdest{i + 1:04d}_transit_approach_drivetime_{peaky}'] < 999) - & positive_attractions - ) - _df[f'altdest{i + 1:04d}_auto_avail_{purpose}'] = positive_attractions - _df[f'altdest{i + 1:04d}_walk_avail_{purpose}'] = positive_attractions & (_df[f'altdest{i + 1:04d}_auto_dist_OFFPEAK'] < 3) - _df[f'altdest{i + 1:04d}_bike_avail_{purpose}'] = positive_attractions & (_df[f'altdest{i + 1:04d}_auto_dist_OFFPEAK'] < 12) - # Build IDCA folded data for later analysis - _ca_folded = {} - for k, v in ca_folds.items(): - if 'nAttractions' in k: - if purpose not in k: - continue - folder = np.exp(_df[v]) - else: - folder = _df[v] - folder.columns = range(len(v)) - _ca_folded[k] = folder.stack().rename(k) - ca_folded[purpose] = pd.DataFrame(_ca_folded) - - ca_folded[purpose]['walktime_dist'] = ( - ca_folded[purpose]['transit_approach_walktime_OFFPEAK'] - / ca_folded[purpose]['auto_dist_OFFPEAK'] - ) - - # Model's actual data - dfs = dats[purpose] = larch.DataFrames( - co=_df, - alt_codes=alt_codes, - alt_names=alt_names, - ch='mode9code', - # av=pd.DataFrame({ - # k: _df.eval(v) - # for k, v in av.items() - # }).astype(np.int8), - ) - - cached_model_file = cached_model_filename(purpose) - if 0 and os.path.exists(cached_model_file) and purpose != "NHB": - m = mods[purpose] = larch.Model.load( - cached_model_file - ) - mods_preload[purpose] = True - else: - m = mods[purpose] = model_builder( - purpose, - include_actual_dest=True, - n_sampled_dests=n_sampled_dests, - parameter_values=None, - constraints=True, - ) - mods_preload[purpose] = False - m.dataservice = dfs - m.load_data() - m.diagnosis = m.doctor(repair_ch_av="-") - - - - -L("## model parameter estimation ##") - -Pr = Dict() - -nests_per_dest = 3 # CHANGE ME if/when the number of nests per destination is altered in `model_builder` - - - -figures = Dict() - -def dest_profiler( - purpose, -): - n_modes = len(mode9names) - _offset = (n_sampled_dests + 1) * n_modes + nests_per_dest-1 - _ch = mods[purpose].dataframes.data_ch_cascade(mods[purpose].graph)\ - .iloc[:, _offset:-1:nests_per_dest].stack().values - _av = mods[purpose].dataframes.data_av_cascade(mods[purpose].graph)\ - .iloc[:, _offset:-1:nests_per_dest].stack().values - - if purposes_to_peaky[purpose]: - - figdef = Dict() - figdef[f'auto_dist_PEAK'].bins = 50 - figdef[f'auto_dist_PEAK'].range = (0, 50) - # figdef[f'auto_dist_{peaky}'].xscale = {'value':'symlog', 'linthresh':2, 'linscale':0.3} - # figdef[f'auto_dist_{peaky}'].xmajorticks = [0, 1, 2, 5, 10, 20, 50] - # figdef[f'auto_dist_{peaky}'].xminorticks = np.concatenate([ - # np.arange(0, 10), - # np.arange(10, 20, 2), - # np.arange(20, 50, 3), - # ]) - - figdef[f'auto_time_PEAK'].bins = 90 - figdef[f'auto_time_PEAK'].range = (0, 90) - # figdef[f'auto_time_{peaky}'].xscale = {'value':'symlog', 'linthresh':2, 'linscale':0.3} - # figdef[f'auto_time_{peaky}'].xmajorticks = [0, 1, 2, 5, 10, 20, 50] - # figdef[f'auto_time_{peaky}'].xminorticks = np.concatenate([ - # np.arange(0, 10), - # np.arange(10, 20, 2), - # np.arange(20, 50, 3), - # np.arange(50, 90, 5), - # ]) - else: - figdef = Dict() - figdef[f'auto_dist_OFFPEAK'].bins = 50 - figdef[f'auto_dist_OFFPEAK'].range = (0, 50) - figdef[f'auto_time_OFFPEAK'].bins = 60 - figdef[f'auto_time_OFFPEAK'].range = (0, 60) - - for x in figdef: - tag = x.replace("_OFFPEAK","").replace("_PEAK","") - figures.distribution[purpose][tag] = distribution_figure( - ca_folded[purpose][x], - probability=Pr.ByDest[purpose].stack().values, - choices=_ch, - availability=_av, - xlabel=None, - ylabel='Relative Frequency', - style='hist', - bins=figdef[x].bins, - pct_bins=20, - range=figdef[x].range, - prob_label="Modeled", - obs_label="Observed", - bw_method=None, - discrete=None, - ax=None, - format='png', - #header=f"{purpose} / {x} Distribution", - accumulator=True, - xscale=figdef[x].xscale or None, - xmajorticks=figdef[x].xmajorticks or None, - xminorticks=figdef[x].xminorticks or None, - coincidence_ratio=True, - ) - display(HTML(f"

{mods[purpose].title} Destinations by {tag}

")) - display(figures.distribution[purpose][tag]) - - - - -def transit_profiler_X( - purpose, -): - n_modes = len(mode9names) - _offset = (n_sampled_dests + 1) * n_modes + nests_per_dest-1 - _ch = mods[purpose].dataframes.data_ch_cascade(mods[purpose].graph)\ - .iloc[:, :(n_sampled_dests + 1) * n_modes] - _ch.columns = pd.MultiIndex.from_product([ - np.arange(n_sampled_dests + 1), - mode9names, - ], names=['dest', 'mode']) - _ch = _ch.xs("TRANSIT", axis=1, level="mode").stack().values - - _av = mods[purpose].dataframes.data_av_cascade(mods[purpose].graph)\ - .iloc[:, :(n_sampled_dests + 1) * n_modes] - _av.columns = pd.MultiIndex.from_product([ - np.arange(n_sampled_dests + 1), - mode9names, - ], names=['dest', 'mode']) - _av = _av.xs("TRANSIT", axis=1, level="mode").stack().values - - if purposes_to_peaky[purpose]: - - figdef = Dict() - figdef[f'auto_dist_PEAK'].bins = 50 - figdef[f'auto_dist_PEAK'].range = (0, 50) - figdef[f'transit_ivtt_PEAK'].bins = int(120/5) - figdef[f'transit_ivtt_PEAK'].range = (0, 120) - else: - figdef = Dict() - figdef[f'auto_dist_OFFPEAK'].bins = 30 - figdef[f'auto_dist_OFFPEAK'].range = (0, 30) - figdef[f'transit_ivtt_OFFPEAK'].bins = int(120/5) - figdef[f'transit_ivtt_OFFPEAK'].range = (0, 120) - - for x in figdef: - tag = x.replace("_OFFPEAK","").replace("_PEAK","") - figures.transit_dist[purpose][tag] = distribution_figure( - ca_folded[purpose][x], - probability=Pr.ByMode[purpose].xs("TRANSIT", axis=1, level="mode").stack().values, - choices=_ch, - availability=_av, - xlabel=None, - ylabel='Relative Frequency', - style='hist', - bins=figdef[x].bins, - pct_bins=20, - range=figdef[x].range, - prob_label="Modeled", - obs_label="Observed", - bw_method=None, - discrete=None, - ax=None, - format='png', - #header=f"{purpose} / {x} Distribution", - accumulator=True, - xscale=figdef[x].xscale or None, - xmajorticks=figdef[x].xmajorticks or None, - xminorticks=figdef[x].xminorticks or None, - coincidence_ratio=True, - ) - display(HTML(f"

{mods[purpose].title} Transit Usage by {tag}

")) - display(figures.transit_dist[purpose][tag]) - - - - -def mode_usage_profiler( - purpose, - modename, - figdef, -): - n_modes = len(mode9names) - _offset = (n_sampled_dests + 1) * n_modes + nests_per_dest-1 - _ch = mods[purpose].dataframes.data_ch_cascade(mods[purpose].graph)\ - .iloc[:, :(n_sampled_dests + 1) * n_modes] - _ch.columns = pd.MultiIndex.from_product([ - np.arange(n_sampled_dests + 1), - mode9names, - ], names=['dest', 'mode']) - _ch = _ch.xs(modename, axis=1, level="mode").stack().values - - _av = mods[purpose].dataframes.data_av_cascade(mods[purpose].graph)\ - .iloc[:, :(n_sampled_dests + 1) * n_modes] - _av.columns = pd.MultiIndex.from_product([ - np.arange(n_sampled_dests + 1), - mode9names, - ], names=['dest', 'mode']) - _av = _av.xs(modename, axis=1, level="mode").stack().values - - for x in figdef: - tag = x.replace("_OFFPEAK","").replace("_PEAK","") - figures[f'{modename}_dist'][purpose][tag] = distribution_figure( - ca_folded[purpose][x], - probability=Pr.ByMode[purpose].xs(modename, axis=1, level="mode").stack().values, - choices=_ch, - availability=_av, - xlabel=None, - ylabel='Relative Frequency', - style='hist', - bins=figdef[x].bins, - pct_bins=20, - range=figdef[x].range, - prob_label="Modeled", - obs_label="Observed", - bw_method=None, - discrete=None, - ax=None, - format='png', - #header=f"{purpose} / {x} Distribution", - accumulator=True, - xscale=figdef[x].xscale or None, - xmajorticks=figdef[x].xmajorticks or None, - xminorticks=figdef[x].xminorticks or None, - coincidence_ratio=True, - ) - display(HTML(f"

{mods[purpose].title} {modename} Usage by {tag}

")) - display(figures[f'{modename}_dist'][purpose][tag]) - - -def walk_profiler(purpose): - figdef = Dict() - figdef[f'auto_dist_OFFPEAK'].bins = 20 - figdef[f'auto_dist_OFFPEAK'].range = (0, 5) - return mode_usage_profiler(purpose, "WALK", figdef) - -def transit_profiler(purpose): - figdef = Dict() - if purposes_to_peaky[purpose]: - figdef[f'auto_dist_PEAK'].bins = 50 - figdef[f'auto_dist_PEAK'].range = (0, 50) - figdef[f'transit_ivtt_PEAK'].bins = int(120/5) - figdef[f'transit_ivtt_PEAK'].range = (0, 120) - else: - figdef[f'auto_dist_OFFPEAK'].bins = 30 - figdef[f'auto_dist_OFFPEAK'].range = (0, 30) - figdef[f'transit_ivtt_OFFPEAK'].bins = int(120/5) - figdef[f'transit_ivtt_OFFPEAK'].range = (0, 120) - return mode_usage_profiler(purpose, "TRANSIT", figdef) - - - -def value_of_time_profiler(purpose): - m = mods[purpose] - time_params = [ - 'ivtt', - 'totaltime', - 'auto_time', - 'tnc_time', - 'transit_ivtt', - 'transit_ovtt', - 'ovtt', - 'walk_time', - 'bike_time', - 'walk_time[1]: up to 0.5', - 'walk_time[2]: 0.5 to 1.0', - 'walk_time[3]: over 1.0', - ] - result = {} - for t in time_params: - if t in m: - result[t] = ((P(t) * 60) / (P.cost)).set_fmt("${:.2f}/hr").string(m) - result = pd.DataFrame(pd.Series(result, name='Value of Time')) - figures.vot[purpose] = result - display(result) - -def mode_share_profiler( - purpose, -): - d_codes = np.arange(n_sampled_dests+1) - - _pr = Pr.ByMode[purpose].stack(0) - # _pr = _pr.stack([0,2]).sum(1).unstack() - - _ch = mods[purpose].dataframes.data_ch.copy() - _ch.columns=pd.MultiIndex.from_product([ - d_codes, - mode9names, - ]) - _ch = _ch.stack(0) - # _ch = _ch.stack([0,2]).sum(1).unstack() - - peaky = 'PEAK' if purposes_to_peaky[purpose] else 'OFFPEAK' - - figdef = Dict() - figdef[f'auto_dist_{peaky}'].bins = np.logspace(np.log10(1),np.log10(51),10)-1 - # np.concatenate([ - # np.arange(0, 10, 1), # first 1 mile bins to 10 miles - # np.arange(10, 20, 2), # then 2 mile bins to 20 miles - # np.arange(20, 51, 5), # then 5 mile bins to 50 miles - # ]) - - for x in figdef: - tag = x.replace("_OFFPEAK","").replace("_PEAK","") - figures.share[purpose][tag] = share_figure( - x=ca_folded[purpose][x], - probability=_pr.fillna(0), - choices=_ch, - style='stacked', - bins=figdef[x].bins, - format='png', - #header=f"{purpose} Mode Share by {x}" - xscale={'value':'symlog', 'linthresh':2, 'linscale':0.5}, - xmajorticks=[0, 1, 2, 5, 10, 20, 50], - xminorticks=np.concatenate([ - np.arange(0, 10), - np.arange(10, 20, 2), - np.arange(20, 50, 3), - ]), - ) - display(HTML(f"

{mods[purpose].title} Mode Shares by {tag}

")) - display(figures.share[purpose][tag]) - - - -def mode_choice_summary(m): - ch_av_summary = m.dataframes.choice_avail_summary().iloc[:-1] - for k in ['available', 'available weighted', 'available unweighted']: - try: - ch_av_summary[k] = ch_av_summary[k].astype(int) - except KeyError: - pass - pr_summary = m.probability(return_dataframe=True).sum() - ch_av_summary['model prob'] = pr_summary - ch_av_summary.index = pd.MultiIndex.from_product( - [ - np.arange(n_sampled_dests + 1), - mode9names, - ], - names=['dest', 'mode'], - ) - result = ch_av_summary.groupby('mode').sum() - display(HTML(f"

{m.title} Mode Choices Summary

")) - display(result) - return result - -def estimation(n_mu_dest_search_grids=5, n_mu_car_search_grids=5, purposes=None, force_reestimate=False): - - if purposes is None: - from ..purposes import purposes5 - purposes = purposes5 - - for purpose, m in mods.items(): - - if purposes is not None and purpose not in purposes: continue - - m.dataframes.autoscale_weights() - display(HTML(f"

{m.title}

")) - if not mods_preload[purpose] or force_reestimate: - holdfast_cache = m.pf.holdfast.copy() - minimums_cache = m.pf.minimum.copy() - maximums_cache = m.pf.maximum.copy() - # GRID SEARCH on MU - r = None - - n_search_grids = n_mu_dest_search_grids*n_mu_car_search_grids - search_grid_num = 1 - - for mu_Dest in np.linspace(0.25, 1.0, n_mu_dest_search_grids): - for mu_HiredCar in np.linspace(0.05, mu_Dest*0.75, n_mu_car_search_grids): # force some mu on hired car - m.set_values("init") - m.lock_value("Mu-Dest", mu_Dest) - m.lock_value("Mu-HiredCar", mu_HiredCar) - m.lock_value("Mu-PrivateCar", mu_HiredCar) - r = m.maximize_loglike( - prior_result=r, - return_dashboard=True, - method='SLSQP', - options={'maxiter': 1000}, - bhhh_start=5, - iteration_number_tail=f" Grid Search {search_grid_num}/{n_search_grids}" - ) - search_grid_num += 1 - m.pf['holdfast'] = holdfast_cache - m.pf['minimum'] = minimums_cache - m.pf['maximum'] = maximums_cache - m.set_values("best", respect_holdfast=False) - # small perturbation to encourage a little movement - log.info(f"loglike currently {r.get('loglike', 'missing')}") - - m.set_value('Const_WALK', m['Const_WALK'].value * 0.5) - m.set_value('Const_Transit', m['Const_Transit'].value * 0.5) - m.set_value('Const_HOV2', m['Const_HOV2'].value * 0.5) - m.set_value('Const_HOV3', m['Const_HOV3'].value * 0.5) - m.set_value('Const_TAXI', m['Const_TAXI'].value * 0.5) - m.set_value('Const_TNC1', m['Const_TNC1'].value * 0.5) - m.set_value('Const_TNC2', m['Const_TNC2'].value * 0.5) - - log.info(f"loglike perturbed {m.loglike()}") - - - log.info(f"Unlocked Estimation from iteration number {r.get('iteration_number', 'NO ITER NUM')}") - # final maximize from grid search best, probably minimal improvement from here - r = m.maximize_loglike( - prior_result=r, - return_dashboard=True, - method='SLSQP', - options={'maxiter': 1000}, - ) - log.info(f"Final Estimation at iteration number {r.get('iteration_number', 'NO ITER NUM')}") - - # # holdfast_cache = mods.HBO.pf.holdfast.copy() - # # mu_params = [i for i in mods.HBO.pf.index if 'Mu-' in i] - # # m.pf.loc[mu_params, 'holdfast'] = 1 - # # m.constraint_intensity = 100.0 - # # r = m.maximize_loglike(method='SLSQP', options={'maxiter': 20}, bhhh_start=5, return_dashboard=True) - # # m.pf['holdfast'] = holdfast_cache - # # m.constraint_intensity = 0.0 - # m.maximize_loglike( - # method='SLSQP', - # options={'maxiter':1000}, - # #prior_result=r, - # bhhh_start=5, - # ) - m.calculate_parameter_covariance() - m.to_xlsx( - cached_model_filename(purpose) - ) - summary = m.most_recent_estimation_result.copy() - summary.pop('x', None) - summary.pop('d_loglike', None) - summary.pop('nit', None) - display(larch.util.dictx(summary).__xml__()) - display(m.estimation_statistics()) - _pr = m.probability(return_dataframe='names', include_nests=True) - n_elemental_alts = (n_sampled_dests+1)*len(mode9names) - Pr.ByDest[purpose] = _pr.iloc[:,n_elemental_alts+nests_per_dest-1:-1:nests_per_dest] - Pr.ByMode[purpose] = _pr.iloc[:,:n_elemental_alts] - Pr.ByMode[purpose].columns = pd.MultiIndex.from_product([ - np.arange(n_sampled_dests+1), - mode9names, - ], names=['dest','mode']) - - display(HTML(f"

{m.title}

")) - display(m.parameter_summary()) - - try: - mode_choice_summary_table = mode_choice_summary(m) - except: - log.exception("exception in mode_choice_summary") - mode_choice_summary_success = False - else: - mode_choice_summary_success = True - - try: - dest_profiler(purpose) - except: - log.exception("exception in dest_profiler") - dest_profiler_success = False - else: - dest_profiler_success = True - - try: - mode_share_profiler(purpose) - except: - log.exception("exception in mode_share_profiler") - mode_share_profiler_success = False - else: - mode_share_profiler_success = True - - try: - transit_profiler(purpose) - except: - log.exception("exception in transit_profiler") - transit_profiler_success = False - else: - transit_profiler_success = True - - try: - walk_profiler(purpose) - except: - log.exception("exception in walk_profiler") - walk_profiler_success = False - else: - walk_profiler_success = True - - try: - value_of_time_profiler(purpose) - except: - log.exception("exception in value_of_time_profiler") - value_of_time_profiler_success = False - else: - value_of_time_profiler_success = True - - xl = m.to_xlsx( - cached_model_filereport(purpose), - save_now=False - ) - try: - if dest_profiler_success: - xl.add_content_tab( - figures.distribution[purpose]['auto_dist'], - sheetname="Figures", - heading="Destination Probabilities by Distance", - ) - xl.add_content_tab( - figures.distribution[purpose]['auto_time'], - sheetname="Figures", - heading="Destination Probabilities by Auto Travel Time", - ) - if mode_share_profiler_success: - xl.add_content_tab( - figures.share[purpose]['auto_dist'], - sheetname="Figures", - heading="Mode Choice by Distance", - ) - if mode_choice_summary_success: - xl.add_content_tab( - mode_choice_summary_table, - sheetname="Applied", - heading="Mode Choice Summary", - ) - if transit_profiler_success: - xl.add_content_tab( - figures.TRANSIT_dist[purpose]['auto_dist'], - sheetname="Figures", - heading="Transit Usage by Distance", - ) - xl.add_content_tab( - figures.TRANSIT_dist[purpose]['transit_ivtt'], - sheetname="Figures", - heading="Transit Usage by Transit IVTT", - ) - else: - log.warning("transit_profiler_success is False") - if walk_profiler_success: - xl.add_content_tab( - figures.WALK_dist[purpose]['auto_dist'], - sheetname="Figures", - heading="Total Walking by Distance", - ) - if value_of_time_profiler_success: - xl.add_content_tab( - figures.vot[purpose], - sheetname="Figures", - heading="Value of Time", - ) - finally: - xl.save() - - with open(dh.filenames.choice_model_param_file, 'w', encoding="utf-8") as cmp_yaml: - print("---", file=cmp_yaml) - for purpose in purposes: - print(f"{purpose}:", file=cmp_yaml) - for k, v in mods[purpose].pf.value.items(): - if ':' in k: - k = f'"{k}"' - print(f' {k:24s}: {v}', file=cmp_yaml) - print("", file=cmp_yaml) - print("...", file=cmp_yaml) - - return mods - -resource_usage.check() -L("## est_choice complete ##") diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_config.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_config.py deleted file mode 100644 index c2a3ca9..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_config.py +++ /dev/null @@ -1,137 +0,0 @@ -from ..util import search_path - -## CONFIG ## - -n_sampled_dests = 25 -# The number of destination to sample during estimation -# This has no effect on application, where there is no sampling used. - -EstimationDir = search_path( - "~/Cambridge Systematics/PROJ CMAP Trip-Based - General/Estimation", - "~/OneDrive/Cambridge Systematics/PROJ CMAP Trip-Based - General/Estimation", - "other/possible/path/to/Estimation", -) -# Add local paths to the "Estimation" directory here. -# The contents of this directory itself are not to be published on GitHub - -EstimationSkimsDir = search_path( - "~/LocalGit/cmap-trip-model/Database/emmemat", - "~/Git/cmap-trip-model/Database/emmemat", -) - -############ - - -mode_complete = { - 101:'Walk', - 102:'My own bike', - 103:'Divvy bike', - 104:'Zagster bike', - 201:'Motorcycle/moped', - 202:'Auto / van / truck (as the driver) ', - 203:'Auto / van / truck (as the passenger) ', - 301:'Carpool/vanpool', - 401:'School bus', - 500:'Rail and Bus', - 501:'Bus (CTA, PACE, Huskie Line, Indiana)', - 502:'Dial-a-Ride', - 503:'Call-n-Ride', - 504:'Paratransit', - 505:'Train (CTA, METRA, South Shore Line)', - 506:'Local transit (NIRPC region)', - 509:'Transit (specific mode not reported or imputed)', - 601:'Private shuttle bus', - 701:'Taxi', - 702:'Private limo', - 703:'Private car', - 704:'Uber/Lyft', - 705:'Via/Uber Pool/Lyft Line (shared ride)', - 801:'Airplane', - 997:'[$MODE2_O]', -} - -mode_modeled = { - 101: None, # 'Walk', - 102: None, # 'My own bike', - 103: None, # 'Divvy bike', - 104: None, # 'Zagster bike', - 201: 'AUTO', - 202: 'AUTO', - 203: 'AUTO', - 301: 'AUTO', - 401: None, # 'School bus', - 500: 'TRANSIT', - 501: 'TRANSIT', - 502: None, # 'Dial-a-Ride', - 503: None, # 'Call-n-Ride', - 504: None, # 'Paratransit', - 505: 'TRANSIT', - 506: 'TRANSIT', - 509: 'TRANSIT', - 601: None, # 'Private shuttle bus', - 701: 'TNC', # 'Taxi', - 702: None, # 'Private limo', - 703: None, # 'Private car', - 704: 'TNC', # 'Uber/Lyft', - 705: 'TNC', # 'Via/Uber Pool/Lyft Line (shared ride)', - 801: None, # Airplane - 997: None, # Fill-in-the-blank -} - - -mode_modeled5 = { - 101: None, # 'Walk', - 102: None, # 'My own bike', - 103: None, # 'Divvy bike', - 104: None, # 'Zagster bike', - 201: 'AUTO', - 202: 'AUTO', - 203: 'AUTO', - 301: 'AUTO', - 401: None, # 'School bus', - 500: 'TRANSIT', - 501: 'TRANSIT', - 502: None, # 'Dial-a-Ride', - 503: None, # 'Call-n-Ride', - 504: None, # 'Paratransit', - 505: 'TRANSIT', - 506: 'TRANSIT', - 509: 'TRANSIT', - 601: None, # 'Private shuttle bus', - 701: 'TAXI', # 'Taxi', - 702: None, # 'Private limo', - 703: None, # 'Private car', - 704: 'TNC1', # 'Uber/Lyft', - 705: 'TNC2', # 'Via/Uber Pool/Lyft Line (shared ride)', - 801: None, # Airplane - 997: None, # Fill-in-the-blank -} - - -mode_modeled7 = { - 101: 'WALK', # 'Walk', - 102: 'BIKE', # 'My own bike', - 103: 'BIKE', # 'Divvy bike', - 104: 'BIKE', # 'Zagster bike', - 201: 'AUTO', - 202: 'AUTO', - 203: 'AUTO', - 301: 'AUTO', - 401: None, # 'School bus', - 500: 'TRANSIT', - 501: 'TRANSIT', - 502: None, # 'Dial-a-Ride', - 503: None, # 'Call-n-Ride', - 504: None, # 'Paratransit', - 505: 'TRANSIT', - 506: 'TRANSIT', - 509: 'TRANSIT', - 601: None, # 'Private shuttle bus', - 701: 'TAXI', # 'Taxi', - 702: None, # 'Private limo', - 703: None, # 'Private car', - 704: 'TNC1', # 'Uber/Lyft', - 705: 'TNC2', # 'Via/Uber Pool/Lyft Line (shared ride)', - 801: None, # Airplane - 997: None, # Fill-in-the-blank -} \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_data.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_data.py deleted file mode 100644 index a584775..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_data.py +++ /dev/null @@ -1,25 +0,0 @@ -import os -import cmap_modedest - -from .est_logging import L -from .est_config import EstimationDir, EstimationSkimsDir - -L("###### Set Directories and Prep Data ######") - -from ..data_handlers import DataHandler - - -dh = DataHandler( - emme_database_dir=os.path.join(cmap_modedest.__path__[0], "../tests/data"), - #omx_skims_dir=EstimationDir/"SkimsForEstimation", - cache_dir=EstimationDir/"cache", - zone_shapefile=EstimationDir/"../GIS/From CMAP/zones17.shp", - #emmemat_archive=EstimationDir/"SkimsForEstimation/emmemat.zip", - emmemat_dir=EstimationSkimsDir, - tg_detail=True, -) - -dh.SURVEY_DATA_DIR = EstimationDir/"../HTS/preproc" -dh.AE_DATA_DIR = EstimationDir/"../HTS/cmap-proc" - -L("Data Handlers Ready") diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_logging.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_logging.py deleted file mode 100644 index b240d38..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_logging.py +++ /dev/null @@ -1,13 +0,0 @@ -import cmap_modedest - -log = cmap_modedest.log_to_stderr(level=10) - - -def L(*args): - """Short logging function for estimation""" - if len(args) == 1 and isinstance(args[0], str) and args[0][0] == "#": - log.info(args[0]) - else: - s = "\n".join(str(i) for i in args) - s = "\n"+s - log.info(s.replace("\n", "\n ")) diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_sample_dest.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_sample_dest.py deleted file mode 100644 index 1c78d21..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_sample_dest.py +++ /dev/null @@ -1,270 +0,0 @@ -import numpy as np -import pandas as pd -import cmap_modedest -import sharrow as sh - -from .est_data import dh -skims = dh.skims -aggregate_attractions = np.fmin( - dh.trip_attractions5.sum(1), - np.percentile(dh.trip_attractions5.sum(1), 99.5), -) -zone_shp = dh.zone_shp -m01 = dh.m01 -from ..tnc_costs import taxi_cost, tnc_solo_cost, tnc_pool_cost -from ..purposes import purposes5, purposes3, purposes8, purposesA - -log = cmap_modedest.log_to_stderr(level=10) - - -def default_weighting_by_distance(distances): - return 1 / distances ** 2 - - -def sample_dest_zones(trips, n_zones, n_sampled_dests=20, wgt_func=None): - """ - Sample destinations for a set of origins. - - Parameters - ---------- - trips : DataFrame - n_zones : int - n_sampled_dests : int - wgt_func : callable, optional - This callable takes a 1-d array of distances to candidate - destination zones as input, and returns a same-shape array - of sampling weights. If not provided, the default scheme is - used, see `default_weighting_by_distance`. - - Returns - ------- - trip_alt_dest : array[len(trips), n_sampled_dests] of int - trip_alt_wgts : array[len(trips), n_sampled_dests] of float - trip_obs_wgts : array[len(trips)] of float - """ - if wgt_func is None: - wgt_func = default_weighting_by_distance - trip_alt_dest = np.zeros([len(trips), n_sampled_dests], dtype=np.int32) - trip_alt_wgts = np.zeros([len(trips), n_sampled_dests], dtype=np.float32) - trip_obs_wgts = np.zeros([len(trips)], dtype=np.float32) - for zone_index in range(n_zones): - zone_id = zone_index+1 - trips_from_this_zone = trips['o_zone'] == zone_id - n_trips_from_this_zone = trips_from_this_zone.sum() - if n_trips_from_this_zone == 0: - continue - zone_rgen = np.random.default_rng(zone_id) - from ..skims.names import skim_tags - distances = skims.raw[skim_tags.auto_md_dist].load()[zone_index, :n_zones] - distances[zone_index] = float(np.sqrt(zone_shp.loc[[zone_id]].area)/5280) - #distances = np.fmax(distances, 0.33) - zone_weight = wgt_func(distances).astype(np.float64) - zone_weight *= aggregate_attractions - zone_weight /= zone_weight.sum() - samp_dest = zone_rgen.choice( - n_zones, - size=(n_trips_from_this_zone,n_sampled_dests), - p=zone_weight, - ) - trip_alt_dest[trips_from_this_zone] = samp_dest+1 - trip_alt_wgts[trips_from_this_zone] = zone_weight.values[samp_dest] - trip_obs_wgts[trips_from_this_zone] = zone_weight.values[trips.loc[trips_from_this_zone, 'd_zone']-1] - return trip_alt_dest, trip_alt_wgts, trip_obs_wgts - - -def sample_dest_zones_and_data( - trips, - n_zones, - n_sampled_dests=20, - wgt_func=None, - ozone_col='o_zone', - labeler=lambda i: f'altdest{i + 1:04d}', - keep_trips_cols=(), -): - log.debug("sample_dest_zones()") - trip_alt_dest, trip_alt_wgts, trip_obs_wgts = sample_dest_zones( - trips, n_zones, n_sampled_dests, wgt_func, - ) - - _keep_trips_cols = [] - for k in keep_trips_cols: - if k in trips.columns: - _keep_trips_cols.append(k) - k = f"actualdest_{k}" - if k in trips.columns: - _keep_trips_cols.append(k) - for t in ['PEAK', 'OFFPEAK']: - if f"{k}_{t}" in trips.columns: - _keep_trips_cols.append(f"{k}_{t}") - for purpose in purposesA: - if f"{k}_{purpose}" in trips.columns: - _keep_trips_cols.append(f"{k}_{purpose}") - for purpose3 in purposes3: - if f"{k}_{purpose3}" in trips.columns: - _keep_trips_cols.append(f"{k}_{purpose3}") - - trip_alt_dest_df = trips[[ozone_col, 'in_peak', *_keep_trips_cols]] - - log.debug("trip_alt_dest_df.join()") - trip_alt_dest_df = trip_alt_dest_df.join( - pd.DataFrame( - trip_alt_dest, - index=trips.index, - columns=[labeler(i) for i in range(trip_alt_dest.shape[1])], - ) - ) - trip_alt_dest_df['actualdest_samp_wgt'] = trip_obs_wgts - trip_alt_dest_df = trip_alt_dest_df.join( - pd.DataFrame( - trip_alt_wgts, - index=trips.index, - columns=[f'{labeler(i)}_samp_wgt' for i in range(trip_alt_dest.shape[1])], - ), - ) - - flipY = trips.paFlip - flipN = 1-trips.paFlip - - from .est_survey import attach_selected_skims_sh - for i in range(n_sampled_dests): - - origin_zone = trip_alt_dest_df.o_zone * flipN + trip_alt_dest_df[labeler(i)] * flipY - destin_zone = trip_alt_dest_df.o_zone * flipY + trip_alt_dest_df[labeler(i)] * flipN - - # attach auto skims - log.debug(f"attach auto skims <{i}>") - flow = sh.SharedData( - ['otaz', 'dtaz', 'in_peak'], - skims=dh.skims.raw - ).setup_flow({ - f'{labeler(i)}_auto_time': f'skims.mf44 if in_peak else skims.mf46', - f'{labeler(i)}_auto_dist': f'skims.mf45 if in_peak else skims.mf47', - f'{labeler(i)}_auto_op_dist': 'skims.mf47', - f'{labeler(i)}_auto_time_PEAK': 'skims.mf44', - f'{labeler(i)}_auto_time_hov_PEAK': 'skims.mf76', - f'{labeler(i)}_auto_time_OFFPEAK': 'skims.mf46', - f'{labeler(i)}_auto_dist_PEAK': 'skims.mf45', - f'{labeler(i)}_auto_dist_OFFPEAK': 'skims.mf47', - f'{labeler(i)}_auto_toll_loinc_PEAK': f'skims.mf111', - f'{labeler(i)}_auto_toll_hiinc_PEAK': f'skims.mf114', - f'{labeler(i)}_auto_toll_OFFPEAK': f'skims.mf117', - f'{labeler(i)}_auto_toll_hov_loinc_PEAK': f'skims.mf112', - f'{labeler(i)}_auto_toll_hov_hiinc_PEAK': f'skims.mf115', - f'{labeler(i)}_auto_opcost_PEAK': 'skims.am_opcost', - f'{labeler(i)}_auto_opcost_hov_PEAK': 'skims.am_opcost_hov', - f'{labeler(i)}_auto_opcost_OFFPEAK': 'skims.md_opcost', - }) - auto_cols = flow.load( - trip_alt_dest_df[['o_zone', labeler(i), 'in_peak']].rename( - columns={'o_zone':'otaz', labeler(i):'dtaz'} - ), - as_dataframe=True, - ) - trip_alt_dest_df = pd.concat([trip_alt_dest_df, auto_cols], axis=1) - - # add areatypes - from ..data_handlers.m01_handler import attach_areatypes - trip_alt_dest_df = attach_areatypes(dh, trip_alt_dest_df, labeler(i), '', labeler(i)) # altdest0000_areatype - - # set intrazonal auto_dist - intrazonal = (trip_alt_dest_df['o_zone'] == trip_alt_dest_df[labeler(i)]) - intrazonal_zone_area = dh.zone_shp.loc[trip_alt_dest_df.loc[intrazonal, labeler(i)]].Shape_Area # square feet - intrazonal_dist = np.sqrt(intrazonal_zone_area).to_numpy() / 5280 * 0.667 - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_dist_OFFPEAK'] = intrazonal_dist - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_dist_PEAK'] = intrazonal_dist - - # set intrazonal auto_time - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_time_PEAK'] = ( - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_dist_PEAK'] - * 60 / (trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_areatype'].map( - lambda y: dh.cfg.intrazonal_auto_speed.peak.get(y, 15))) - ) - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_time_OFFPEAK'] = ( - trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_auto_dist_OFFPEAK'] - * 60 / (trip_alt_dest_df.loc[intrazonal, f'{labeler(i)}_areatype'].map( - lambda y: dh.cfg.intrazonal_auto_speed.offpeak.get(y, 15))) - ) - - # Add taxi and TNC wait time data - from ..data_handlers.m01_handler import attach_hired_car_waits - trip_alt_dest_df = attach_hired_car_waits(dh, trip_alt_dest_df, labeler(i), origin_zone) - # Add taxi and TNC fare data - for t in ['PEAK', 'OFFPEAK']: - trip_alt_dest_df[f'{labeler(i)}_taxi_fare_{t}'] = taxi_cost( - dh, - trip_alt_dest_df[f'{labeler(i)}_auto_time_{t}'], - trip_alt_dest_df[f'{labeler(i)}_auto_dist_{t}'], - origin_zone, - destin_zone, - ) - trip_alt_dest_df[f'{labeler(i)}_tnc_solo_fare_{t}'] = tnc_solo_cost( - dh, - trip_alt_dest_df[f'{labeler(i)}_auto_time_{t}'], - trip_alt_dest_df[f'{labeler(i)}_auto_dist_{t}'], - origin_zone, - destin_zone, - 1 if (t=='PEAK') else 0, - ) - trip_alt_dest_df[f'{labeler(i)}_tnc_pool_fare_{t}'] = tnc_pool_cost( - dh, - trip_alt_dest_df[f'{labeler(i)}_auto_time_{t}'], - trip_alt_dest_df[f'{labeler(i)}_auto_dist_{t}'], - origin_zone, - destin_zone, - 1 if (t=='PEAK') else 0, - ) - - # attach transit skims - log.debug(f"attach transit skims <{i}>") - skim_tags = ('ivtt','ovtt','headway','fare','firstmode','prioritymode','lastmode') - - transit_joint = {} - for k in skim_tags: - _pk = dh.skims.transit_pk.col_mapping[k] - _op = dh.skims.transit_op.col_mapping[k] - transit_joint[f'{labeler(i)}_transit_{k}'] = f"skims.{_pk} if in_peak else skims.{_op}" - transit_joint[f'{labeler(i)}_transit_{k}_PEAK'] = f"skims.{_pk}" - transit_joint[f'{labeler(i)}_transit_{k}_OFFPEAK'] = f"skims.{_op}" - flow = sh.SharedData( - ['otaz', 'dtaz', 'in_peak'], - skims=dh.skims.raw - ).setup_flow(transit_joint) - new_cols = flow.load( - trip_alt_dest_df[['o_zone', labeler(i), 'in_peak']].rename(columns={'o_zone':'otaz', labeler(i):'dtaz'}), - as_dataframe=True, - ) - trip_alt_dest_df = pd.concat([trip_alt_dest_df, new_cols], axis=1) - - if np.any(trip_alt_dest_df.isna()): - print(trip_alt_dest_df.isna().sum()) - pass - else: - pass - - # clipping to set invalid skim values to NaN?, facilitates more useful statistics. - log.debug(f"clipping to set invalid skim values to NaN <{i}>") - for j in ['ivtt', 'ovtt', 'headway', 'fare']: - x = trip_alt_dest_df[f'{labeler(i)}_transit_{j}'] - trip_alt_dest_df.loc[x>9999, f'{labeler(i)}_transit_{j}'] = np.nan - for t in ['PEAK', 'OFFPEAK']: - varname = f'{labeler(i)}_transit_{j}_{t}' - x = trip_alt_dest_df[varname] - trip_alt_dest_df.loc[x > 9999, varname] = np.nan - - # parking costs - from ..parking_costs import parking_cost_v2 - from ..purposes import purposes_to_3 - for purpose in purposes5: - _parking_cost, _free_parking = parking_cost_v2( - dh, - destin_zone, - trip_alt_dest_df['hhinc_dollars'], - dh.cfg.default_activity_durations[purposes_to_3[purpose]], - purposes_to_3[purpose], - random_state=hash(purpose) + 1, - ) - trip_alt_dest_df[f'{labeler(i)}_auto_parking_cost_{purpose}'] = _parking_cost - trip_alt_dest_df[f'{labeler(i)}_auto_parking_free_{purpose}'] = _free_parking - - return trip_alt_dest_df - diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_skims_convol.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_skims_convol.py deleted file mode 100644 index d9664a6..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_skims_convol.py +++ /dev/null @@ -1,29 +0,0 @@ -import os - -from .est_logging import L -from .est_data import dh -filenames = dh.filenames - -L("###### Skims Convolution ######") -from cmap_modedest.transit_skim_convolution import skim_convol -emmemat_in_dir = os.path.dirname(filenames.mf822) - -filenames.pk_transit_skims = filenames.cache_dir / "peak.omx" -if not os.path.exists(filenames.pk_transit_skims): - skim_convol( - dh, - peak=True, - ) -else: - L("# using cached peak skims") - -filenames.op_transit_skims = filenames.cache_dir / "offpeak.omx" -if not os.path.exists(filenames.op_transit_skims): - skim_convol( - dh, - peak=False, - ) -else: - L("# using cached offpeak skims") - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_survey.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_survey.py deleted file mode 100644 index cec5e4e..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_survey.py +++ /dev/null @@ -1,565 +0,0 @@ -import logging -log = logging.getLogger('CMAP') -import re -from ..addict import Dict - -import pandas as pd -import numpy as np -from os.path import join as pj -from .est_config import mode_modeled, mode_modeled5, mode_modeled7 -from ..incomes import income_levels_1, income_levels_2 -from ..timeperiods import hours_by_timeperiod -from ..purposes import purposes_to_3, purposes5 - -import cmap_modedest -from .est_data import dh -from cmap_modedest.modecodes import ( - N_DIST_TO_TYPES, - DIST_TO_BUS, - DIST_TO_CTA_RAIL, - DIST_TO_METRA, - DIST_TO_FEEDER_BUS, - DIST_TO_PARK_N_RIDE_STATION, -) -from cmap_modedest.transit_approach import N_TRIP_ENDS, transit_approach -cfg = dh.cfg -skims = dh.skims - - -TRIPS_CACHE_FILE = "trips_with_ae_vx24" - -hh = pd.read_csv(dh.SURVEY_DATA_DIR / 'household.csv') -ae = pd.read_csv(dh.AE_DATA_DIR / 'access_egress.csv') - -core_cbd_zones = [ - 1, 2, 3, 4, 5, 6, - 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, - 20, 21, 22, 23, 24, - 26, 27, 28, 29, 30, - 32, 33, 34, 35, 36, - 37, 38, 39, 40, 41, - 43, 44, 45, 46, 47, -] - -trips = dh.filenames.load(TRIPS_CACHE_FILE) -if trips is None: - - trips = pd.read_csv(dh.SURVEY_DATA_DIR / 'trips.csv') - trips.info() - - raw_place = pd.read_csv(dh.SURVEY_DATA_DIR / "../RawData/place.csv") - trips = trips.join( - raw_place[['sampno', 'placeno', 'perno', 'companions']].set_index(['sampno', 'placeno', 'perno']), - on=['sampno', 'placeno', 'perno'] - ) - trips.info() - - # attach tpurp from origin end of trip - trips['previous_placeno'] = trips.placeno - 1 - trips = trips.join( - raw_place - [['sampno', 'placeno', 'perno', 'tpurp']] - .rename(columns={'tpurp': 'previous_tpurp'}) - .set_index(['sampno', 'placeno', 'perno']), - on=['sampno', 'previous_placeno', 'perno'], - ) - trips.info() - - - raw_person = pd.read_csv(dh.SURVEY_DATA_DIR / "../RawData/person.csv") - raw_person["is_adult"] = ((raw_person['age'] >= 18) | (raw_person['aage'] >= 5) | (raw_person['age18'] == 1)) - hhadults = raw_person.groupby("sampno")["is_adult"].sum().rename("hhadults") - trips = trips.join(hhadults, on="sampno") - - from ..modecodes import mode7names, mode9names - - # Convert trips to 3 modes only (auto, transit, tnc), and drop all other trips - trips['mode3'] = trips['mode'].map(mode_modeled).astype('category') - trips['mode5'] = trips['mode'].map(mode_modeled5).astype('category') - trips['mode7'] = trips['mode'].map(mode_modeled7).astype(pd.CategoricalDtype(mode7names)) - trips['mode9'] = trips['mode'].map(mode_modeled7) - trips.loc[(trips.companions == 1) & (trips.mode7 == 'AUTO'),'mode9'] = "HOV2" - trips.loc[(trips.companions >= 2) & (trips.mode7 == 'AUTO'),'mode9'] = "HOV3" - trips['mode9'] = trips['mode9'].astype(pd.CategoricalDtype(mode9names)) - - trips_filter = ~trips['mode9'].isna() - - trips = trips.merge(ae, how='left', on=['sampno', 'perno', 'placeno']) - - # identify home-based other trips that are actually home-based shopping trips - is_HBShop = (trips['tripCat'] == 'HBO') & ( - ( - (trips['previous_tpurp'] == 1) & (trips['tpurp'].isin([8, 9, 10])) - ) | ( - (trips['tpurp'] == 1) & (trips['previous_tpurp'].isin([8, 9, 10])) - ) - ) - trips.loc[is_HBShop, 'tripCat'] = 'HBS' - - oz = 'o_zone' - dz = 'd_zone' - pz = 'p_zone' - az = 'a_zone' - - - # develop production & attraction zones - trips[pz] = trips[oz] - trips[az] = trips[dz] - - flip_pa = (trips['PA'] == 0) - # trips.loc[flip_pa, [pz,az]] = trips.loc[flip_pa, [az,pz]].values - trips_filter &= ~trips[pz].isna() - trips_filter &= ~trips[az].isna() - - # Filter trips based on rules - trips = trips[trips_filter].copy() - - # Convert zone codes to integers - trips[[pz,az,oz,dz]] = trips[[pz,az,oz,dz]].astype(int) - - # Convert tripCat to category - trips['tripCat'] = trips['tripCat'].astype('category') - - trips['tripPurpose'] = trips['tripCat'].map(purposes_to_3) - - # hour_re = re.compile(r'.*\s([0-9]+):[0-9]+:[0-9]+') - # def get_hour(y): - # match = hour_re.match(y) - # if match: - # return int(match.group(1)) - # else: - # return -1 - trips['arrHalfHour'] = np.floor(trips['arrHour']*2)/2 - trips['depHalfHour'] = np.floor(trips['depHour']*2)/2 - trips['in_am_peak'] = trips['depHour'].between(6.5,9.5) | trips['arrHour'].between(6.5,9.5) - trips['in_pm_peak'] = trips['depHour'].between(14.5,19) | trips['arrHour'].between(14.5,19) - trips['in_peak'] = trips['in_am_peak'] | trips['in_pm_peak'] - - trips['timeperiod'] = np.floor(trips.depHour).astype(int).map(hours_by_timeperiod) - - hhinc_dollars = trips.hhinc.map(income_levels_1) - hhinc_dollars = hhinc_dollars.fillna(trips.hhinc2.map(income_levels_2)) - hhinc_dollars = hhinc_dollars.fillna(57_999) - trips['hhinc_dollars'] = hhinc_dollars - - # Append skims to trips - for k, s in skims.items(): - if k not in ('auto', 'transit_pk', 'transit_op'): continue - log.debug(f"adding skims for {k}") - trips_1 = skims.raw[list(s.col_mapping.values())].iat_df( - pd.DataFrame({ - 'otaz': trips[pz] - 1, - 'dtaz': trips[az] - 1, - }) - ) - renames = dict([(value, f"{k}_{key}") for key, value in s.col_mapping.items()]) - trips_2 = trips_1[s.col_mapping.values()].rename(columns=renames) - trips = pd.concat([trips, trips_2], axis=1) - - # Append reverse transit skims to trips - for k, s in skims.items(): - if k not in ('transit_pk', 'transit_op'): continue - log.debug(f"adding reverse skims for {k}") - trips_1 = skims.raw[list(s.col_mapping.values())].iat_df( - pd.DataFrame({ - 'otaz': trips[az] - 1, - 'dtaz': trips[pz] - 1, - }) - ) - renames = dict([(value, f"{k}_{key}_reverse") for key, value in s.col_mapping.items()]) - trips_2 = trips_1[s.col_mapping.values()].rename(columns=renames) - trips = pd.concat([trips, trips_2], axis=1) - - # Match time period skims - peak = trips['in_peak'] - hw = trips['tripPurpose'] == 'HW' - auto_cols = ['time','dist'] - for a in auto_cols: - trips[f'auto_{a}'] = trips[f'auto_md_{a}'] - trips.loc[peak,f'auto_{a}'] = trips.loc[peak,f'auto_am_{a}'] - trips[f'actualdest_auto_{a}'] = trips[f'auto_{a}'] - trips[f'actualdest_auto_{a}_OFFPEAK' ] = trips[f'auto_md_{a}'] - trips[f'actualdest_auto_{a}_PEAK' ] = trips[f'auto_am_{a}'] - - trips[f'actualdest_auto_time_hov_PEAK'] = trips[f'auto_am_time_hov'] - trips[f'actualdest_auto_toll_loinc_PEAK'] = trips[f'auto_am_toll_loinc'] - trips[f'actualdest_auto_toll_hiinc_PEAK'] = trips[f'auto_am_toll_hiinc'] - trips[f'actualdest_auto_toll_OFFPEAK'] = trips[f'auto_md_toll'] - trips[f'actualdest_auto_toll_hov_loinc_PEAK'] = trips[f'auto_am_toll_hov_loinc'] - trips[f'actualdest_auto_toll_hov_hiinc_PEAK'] = trips[f'auto_am_toll_hov_hiinc'] - - trips[f'actualdest_auto_opcost_PEAK'] = trips[f'auto_am_opcost'] - trips[f'actualdest_auto_opcost_hov_PEAK'] = trips[f'auto_am_opcost_hov'] - trips[f'actualdest_auto_opcost_OFFPEAK'] = trips[f'auto_md_opcost'] - - # add areatypes - log.debug(f"attach areatypes") - from ..data_handlers.m01_handler import attach_areatypes - trips = attach_areatypes(dh, trips, 'actualdest', '', 'd_zone') # actualdest_areatype - trips = attach_areatypes(dh, trips, 'ozone', '', 'o_zone') # ozone_areatype - - # set intrazonal auto_dist - log.debug(f"set intrazonal auto_dist") - intrazonal = (trips['o_zone'] == trips['d_zone']) - intrazonal_zone_area = dh.zone_shp.loc[trips.loc[intrazonal, 'o_zone']].Shape_Area # square feet - intra_dist = np.sqrt(intrazonal_zone_area).to_numpy() / 5280 * 0.667 - trips.loc[intrazonal, f'actualdest_auto_dist_OFFPEAK'] = intra_dist - trips.loc[intrazonal, f'actualdest_auto_dist_PEAK'] = intra_dist - - # set intrazonal auto_time - trips.loc[intrazonal, f'actualdest_auto_time_PEAK'] = ( - trips.loc[intrazonal, f'actualdest_auto_dist_PEAK'] - * 60/(trips.loc[intrazonal, 'actualdest_areatype'].map(lambda y: dh.cfg.intrazonal_auto_speed.peak.get(y, 15))) - ) - trips.loc[intrazonal, f'actualdest_auto_time_OFFPEAK'] = ( - trips.loc[intrazonal, f'actualdest_auto_dist_OFFPEAK'] - * 60/(trips.loc[intrazonal, 'actualdest_areatype'].map(lambda y: dh.cfg.intrazonal_auto_speed.offpeak.get(y, 15))) - ) - - transit_cols = ['ivtt','ovtt','headway','fare','firstmode','lastmode','prioritymode'] - for a in transit_cols: - trips[f'transit_{a}'] = trips[f'transit_op_{a}'] - trips.loc[peak,f'transit_{a}'] = trips.loc[peak,f'transit_pk_{a}'] - # convert invalid to nan - to_nan = trips[f'transit_{a}'] >= 9999 - trips.loc[to_nan,f'transit_{a}'] = np.nan - to_nan = trips[f'transit_pk_{a}'] >= 9999 - trips.loc[to_nan,f'transit_pk_{a}'] = np.nan - to_nan = trips[f'transit_op_{a}'] >= 9999 - trips.loc[to_nan,f'transit_op_{a}'] = np.nan - trips[f'actualdest_transit_{a}'] = trips[f'transit_{a}'] - trips[f'actualdest_transit_{a}_OFFPEAK'] = trips[f'transit_op_{a}'] - trips[f'actualdest_transit_{a}_PEAK' ] = trips[f'transit_pk_{a}'] - - # trips = trips.drop([f'auto_am_{a}' for a in auto_cols], axis=1) - # trips = trips.drop([f'auto_md_{a}' for a in auto_cols], axis=1) - # trips = trips.drop([f'transit_pk_{a}' for a in transit_cols], axis=1) - # trips = trips.drop([f'transit_op_{a}' for a in transit_cols], axis=1) - - - # attach transit_approach model data - for t in ['single', 'max', 'mean']: - trips[f'ae_drivetime_{t}'] = 0 - trips[f'ae_walktime_{t}'] = 0 - trips[f'ae_cost_{t}'] = 0 - trips[f'ae_waittime_{t}'] = 0 - - #trips[f'actualdest_auto_parking_cost'] = 0 # Check this is never used - from ..transit_approach import transit_approach - from ..parking_costs import parking_cost_v2 - - for purpose in ['HW','HO','NH']: - # HW gets peak period - # HO gets off-peak period - # NH gets off-peak period AND cannot use park-and-ride - q = (trips.tripPurpose == purpose) - _trips_by_purpose = trips[q] - result_purpose = transit_approach( - dh, - _trips_by_purpose.o_zone, - _trips_by_purpose.d_zone, - purpose, - replication=50, - approach_distances=None, - trace=False, - random_state=hash(purpose), - ) - - for key in ['drivetime', 'walktime', 'cost', 'waittime']: - trips.loc[q, f'ae_{key}_max'] = result_purpose[key].max(1) - trips.loc[q, f'ae_{key}_mean'] = result_purpose[key].mean(1) - trips.loc[q, f'ae_{key}_single'] = result_purpose[key][:,0] - - for purpose in purposes5: - - # Attach parking costs - _parking_cost, _free_parking = parking_cost_v2( - dh, - trips.d_zone, - trips.hhinc_dollars, - cfg.default_activity_durations[purposes_to_3[purpose]], - purposes_to_3[purpose], - random_state=hash(purpose)+1, - ) - trips[f'actualdest_auto_parking_cost_{purpose}'] = _parking_cost - trips[f'actualdest_auto_parking_free_{purpose}'] = _free_parking - - trips[f'actualdest_auto_parking_free_{purpose}'] = trips[f'actualdest_auto_parking_free_{purpose}'].fillna(0) - - # for n in trips.index: - # out = transit_approach( - # trips.o_zone[n], trips.d_zone[n], 'HW' if trips.in_peak[n] else 'HO', replication=50 - # ) - # trips.loc[n, 'ae_drivetime_max'] = out.drivetime.max() - # trips.loc[n, 'ae_walktime_max'] = out.walktime.max() - # trips.loc[n, 'ae_cost_max'] = out.cost.max() - # trips.loc[n, 'ae_waittime_max'] = out.waittime.max() - # trips.loc[n, 'ae_drivetime_mean'] = out.drivetime.mean() - # trips.loc[n, 'ae_walktime_mean'] = out.walktime.mean() - # trips.loc[n, 'ae_cost_mean'] = out.cost.mean() - # trips.loc[n, 'ae_waittime_mean'] = out.waittime.mean() - # trips.loc[n, 'ae_drivetime_single'] = out.drivetime[0] - # trips.loc[n, 'ae_walktime_single'] = out.walktime[0] - # trips.loc[n, 'ae_cost_single'] = out.cost[0] - # trips.loc[n, 'ae_waittime_single'] = out.waittime[0] - - trips['touches_core_cbd'] = trips['o_zone'].isin(core_cbd_zones) | trips['d_zone'].isin(core_cbd_zones) - trips['transit_trip_not_in_skim'] = trips.eval("~(0 < transit_ivtt < 999) and mode3=='TRANSIT'") - trips['crow_distance'] = np.sqrt((trips.X_coord1 - trips.X_coord2)**2 + (trips.Y_coord1 - trips.Y_coord2)**2) / 5280 - - flipY = trips.paFlip - flipN = 1 - trips.paFlip - - trips_origin = trips.o_zone * flipN + trips.d_zone * flipY - - from ..data_handlers.m01_handler import attach_hired_car_waits - - trips = attach_hired_car_waits(dh, trips, 'actualdest', trips_origin) - - # taxi_wait_pk = dh.m01['taxi_wait_pk'] - # taxi_wait_op = dh.m01['taxi_wait_op'] - # trips['actualdest_taxi_wait_time_PEAK'] = trips_origin.map(taxi_wait_pk) - # trips['actualdest_taxi_wait_time_OFFPEAK'] = trips_origin.map(taxi_wait_op) - # trips['actualdest_taxi_wait_time'] = ( - # trips['actualdest_taxi_wait_time_PEAK'] * trips.in_peak - # + trips['actualdest_taxi_wait_time_OFFPEAK'] * ~trips.in_peak - # ) - # - # tnc_solo_wait_pk = dh.m01['tnc_solo_wait_pk'] - # tnc_solo_wait_op = dh.m01['tnc_solo_wait_op'] - # trips['actualdest_tnc_solo_wait_time_PEAK'] = trips_origin.map(tnc_solo_wait_pk) - # trips['actualdest_tnc_solo_wait_time_OFFPEAK'] = trips_origin.map(tnc_solo_wait_op) - # trips['actualdest_tnc_solo_wait_time'] = ( - # trips['actualdest_tnc_solo_wait_time_PEAK'] * trips.in_peak - # + trips['actualdest_tnc_solo_wait_time_OFFPEAK'] * ~trips.in_peak - # ) - # - # tnc_pool_wait_pk = dh.m01['tnc_pool_wait_pk'] - # tnc_pool_wait_op = dh.m01['tnc_pool_wait_op'] - # trips['actualdest_tnc_pool_wait_time_PEAK'] = trips_origin.map(tnc_pool_wait_pk) - # trips['actualdest_tnc_pool_wait_time_OFFPEAK'] = trips_origin.map(tnc_pool_wait_op) - # trips['actualdest_tnc_pool_wait_time'] = ( - # trips['actualdest_tnc_pool_wait_time_PEAK'] * trips.in_peak - # + trips['actualdest_tnc_pool_wait_time_OFFPEAK'] * ~trips.in_peak - # ) - - from ..tnc_costs import tnc_solo_cost, taxi_cost, tnc_pool_cost, peak_tnc_pricing - - for t in ['PEAK', 'OFFPEAK']: - - trips[f'actualdest_taxi_fare_{t}'] = taxi_cost( - dh, - trips[f'actualdest_auto_time_{t}'], - trips[f'actualdest_auto_dist_{t}'], - trips['o_zone'], - trips['d_zone'], - ) - - trips[f'actualdest_tnc_solo_fare_{t}'] = tnc_solo_cost( - dh, - trips[f'actualdest_auto_time_{t}'], - trips[f'actualdest_auto_dist_{t}'], - trips['o_zone'], - trips['d_zone'], - 1 if (t=='PEAK') else 0, - ) - - trips[f'actualdest_tnc_pool_fare_{t}'] = tnc_pool_cost( - dh, - trips[f'actualdest_auto_time_{t}'], - trips[f'actualdest_auto_dist_{t}'], - trips['o_zone'], - trips['d_zone'], - 1 if (t=='PEAK') else 0, - ) - - trips['actualdest'] = trips['d_zone'] - trips['mode3code'] = trips.mode3.cat.codes + 1 - trips['mode5code'] = trips.mode5.cat.codes + 1 - trips['mode7code'] = trips.mode7.cat.codes + 1 - trips['mode9code'] = trips.mode9.cat.codes + 1 - - trips['mode_and_time'] = trips.mode5code + trips.timeperiod * 5 - - dh.filenames.save(TRIPS_CACHE_FILE, trips) - -# columns not compatible with Parquet -trips['crow_distance_q5'] = pd.qcut(trips.crow_distance, 5) - - - -def attach_selected_skims( - od_df, - o_col, - d_col, - omx, - skim_cols, -): - """ - Attach selected columns from an OMX file to a DataFrame. - - Parameters - ---------- - od_df : pandas.DataFrame - o_col, d_col : str - Names of the O and D columns in `od_df`. - omx : OMX - skim_cols : Tuple[str, Dict[str, str]] - Top level keys of this pseudo-dict give filters on `od_df` that - ideally give a mutually exclusive and collectively exhaustive - partition. Top level values are dicts, from which the keys - are the skim columns to pull for this partition group and the - values are the names of the ultimate columns to attach. - Final column value names in all partition groups should be - the same to populate a common set of columns in the output. - - Returns - ------- - pandas.DataFrame - """ - cols_to_add = {} - for filter_qry, use_cols in skim_cols: - for c in use_cols.values(): - if c not in od_df.columns: - cols_to_add[c] = np.nan - df = od_df.assign(**cols_to_add) - for filter_qry, use_cols in skim_cols: - if filter_qry: - group = od_df.query(filter_qry) - else: - group = od_df - s = omx.get_rc_dataframe( - group[o_col] - 1, - group[d_col] - 1, - use_cols, - ) - df.update(s) - return df - - -def attach_selected_skims_sh( - od_df, - o_col, - d_col, - dataset, - skim_cols, -): - """ - Attach selected columns from an OMX file to a DataFrame. - - Parameters - ---------- - od_df : pandas.DataFrame - o_col, d_col : str - Names of the O and D columns in `od_df`. - dataset : sharrow.Dataset - skim_cols : Tuple[str, Dict[str, str]] - Top level keys of this pseudo-dict give filters on `od_df` that - ideally give a mutually exclusive and collectively exhaustive - partition. Top level values are dicts, from which the keys - are the skim columns to pull for this partition group and the - values are the names of the ultimate columns to attach. - Final column value names in all partition groups should be - the same to populate a common set of columns in the output. - - Returns - ------- - pandas.DataFrame - """ - cols_to_add = {} - for filter_qry, use_cols in skim_cols: - for c in use_cols.values(): - if c not in od_df.columns: - cols_to_add[c] = np.nan - df = od_df.assign(**cols_to_add) - for filter_qry, use_cols in skim_cols: - if filter_qry: - group = od_df.query(filter_qry) - else: - group = od_df - s = dataset[list(use_cols.keys())].iat_df(pd.DataFrame(dict( - otaz=group[o_col].values - 1, - dtaz=group[d_col].values - 1, - ))).rename(columns=use_cols) - df.update(s) - return df - -# pMode == 3 -# walk -> DIST_TO_BUS -# -# pMode == 6 -# bus -> DIST_TO_BUS -# walk -> DIST_TO_CTA_RAIL -# pnr -> DIST_TO_PARK_N_RIDE_STATION -# -# pMode == 7 -# bus -> DIST_TO_BUS -# walk -> DIST_TO_METRA -# pnr -> DIST_TO_PARK_N_RIDE_STATION -# feeder -> DIST_TO_FEEDER_BUS - -def ae_approach_los(trips): - approach_distances = np.full([len(trips), N_DIST_TO_TYPES, N_TRIP_ENDS], 999.0) - fm3 = trips.transit_firstmode == 3 - approach_distances[fm3, DIST_TO_BUS, 0] = trips[fm3].walkAccDistance - fm6 = trips.transit_firstmode == 6 - approach_distances[fm6, DIST_TO_BUS, 0] = trips[fm6].busAccDistance - approach_distances[fm6, DIST_TO_CTA_RAIL, 0] = trips[fm6].walkAccDistance - approach_distances[fm6, DIST_TO_PARK_N_RIDE_STATION, 0] = trips[fm6].pnrAccDistance - fm7 = trips.transit_firstmode == 7 - approach_distances[fm7, DIST_TO_BUS, 0] = trips[fm7].busAccDistance - approach_distances[fm7, DIST_TO_METRA, 0] = trips[fm7].walkAccDistance - approach_distances[fm7, DIST_TO_PARK_N_RIDE_STATION, 0] = trips[fm7].pnrAccDistance - approach_distances[fm7, DIST_TO_FEEDER_BUS, 0] = trips[fm7].feederAccDistance - - lm3 = trips.transit_lastmode == 3 - approach_distances[lm3, DIST_TO_BUS, 1] = trips[lm3].walkEgrDistance - lm6 = trips.transit_lastmode == 6 - approach_distances[lm6, DIST_TO_BUS, 1] = trips[lm6].busEgrDistance - approach_distances[lm6, DIST_TO_CTA_RAIL, 1] = trips[lm6].walkEgrDistance - lm7 = trips.transit_lastmode == 7 - approach_distances[lm7, DIST_TO_BUS, 1] = trips[lm7].busEgrDistance - approach_distances[lm7, DIST_TO_METRA, 1] = trips[lm7].walkEgrDistance - - result = Dict() - for peaky in ['PEAK','OFFPEAK']: - # q = (trips.tripPurpose == purpose3) - # _trips_by_purpose = trips[q] - result[peaky] = transit_approach( - dh, - trips.o_zone, - trips.d_zone, - 'HW' if peaky=='PEAK' else 'HO', - replication=1, - approach_distances=approach_distances, - trace=False, - random_state=123, - ) - - for key in ['drivetime', 'walktime', 'cost', 'waittime']: - trips[f'transit_approach_{key}_{peaky}'] = result[peaky][key].reshape(-1) - trips[f'actualdest_transit_approach_{key}_{peaky}'] = result[peaky][key].reshape(-1) - trips[f'transit_approach_acc_mode_{peaky}'] = result[peaky]['approach_mode'][...,0].reshape(-1) - trips[f'transit_approach_egr_mode_{peaky}'] = result[peaky]['approach_mode'][...,1].reshape(-1) - - ad = pd.DataFrame( - approach_distances.reshape([-1, 10]), - columns=[ - 'acc_DIST_TO_BUS', - 'egr_DIST_TO_BUS', - 'acc_DIST_TO_CTA_RAIL', - 'egr_DIST_TO_CTA_RAIL', - 'acc_DIST_TO_METRA', - 'egr_DIST_TO_METRA', - 'acc_DIST_TO_FEEDER_BUS', - 'egr_DIST_TO_FEEDER_BUS', - 'acc_DIST_TO_PARK_N_RIDE_STATION', - 'egr_DIST_TO_PARK_N_RIDE_STATION', - ], - index=trips.index, - ) - for c in ad.columns: - trips[c] = ad[c] - - return approach_distances, result diff --git a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_timeofday.py b/src/Mode-Dest-TOD/cmap_modedest/estimation/est_timeofday.py deleted file mode 100644 index 2bb06f8..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/estimation/est_timeofday.py +++ /dev/null @@ -1,60 +0,0 @@ -import numpy as np -import pandas as pd -from pathlib import Path -from larch.numba import P, X, Model, OMX, DataFrames -# from larch import P, X, Model, OMX, DataFrames -from IPython.display import display, HTML -from larch.util.data_expansion import piecewise_linear - -from ..time_of_day_model import tod_model_builder - -def estimate_tod(dh, mods, to_pickle=True): - cached_todmodel_filename = lambda purpose: dh.filenames.cache_dir / f"choicemodel_{purpose}_timeofday.xlsx" - - tod_models = {} - tod_skims = dh.skims.raw[[f'mf46{j}' for j in range(1,9)]] - - for purpose, mode_dest_model in mods.items(): - co = mode_dest_model.dataservice.data_co.query("mode9 in ('AUTO','HOV2','HOV3','TAXI','TNC1','TNC2')").copy() - co['timeperiod1'] = co['timeperiod'] + 1 - co = co.join( - tod_skims.iat_df( - pd.DataFrame({ - 'otaz': co['o_zone'] - 1, - 'dtaz': co['d_zone'] - 1, - }) - ) - ) - tod_model = tod_model_builder(purpose, data_co=co, ch_name='timeperiod1') - tod_model.estimate() - display(HTML(f"

{tod_model.title}

")) - display(tod_model.parameter_summary()) - display(tod_model.estimation_statistics()) - - xl = tod_model.to_xlsx( - cached_todmodel_filename(purpose), - save_now=True - ) - tod_models[purpose] = tod_model - - if to_pickle: - if to_pickle is True: - to_pickle = dh.filenames.cache_dir / "tod_models.pkl" - import cloudpickle - with open(to_pickle, "wb") as f: - cloudpickle.dump(tod_models, f) - - # save cached parameters - param_yaml_file = dh.filenames.cache_dir / "tod_model_parameters.yaml" - with open(param_yaml_file, 'w', encoding="utf-8") as cmp_yaml: - print("---", file=cmp_yaml) - for purpose in tod_models.keys(): - print(f"{purpose}:", file=cmp_yaml) - for k, v in tod_models[purpose].pf.value.items(): - if ':' in k: - k = f'"{k}"' - print(f' {k:24s}: {v}', file=cmp_yaml) - print("", file=cmp_yaml) - print("...", file=cmp_yaml) - - return tod_models \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__init__.py deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/__init__.py deleted file mode 100644 index d81e905..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/__init__.py +++ /dev/null @@ -1,467 +0,0 @@ -import numba -import numpy as np - -from .f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM import o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM -from .f_transit_ivtt_PEAK import transit_ivtt_PEAK -from .f_transit_ivtt_OFFPEAK import transit_ivtt_OFFPEAK -from .f_transit_ovtt_PEAK import transit_ovtt_PEAK -from .f_transit_ovtt_OFFPEAK import transit_ovtt_OFFPEAK -from .f_transit_fare_PEAK import transit_fare_PEAK -from .f_transit_fare_OFFPEAK import transit_fare_OFFPEAK -from .f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW import piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW -from .f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI import piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI -from .f_autopropensity import autopropensity -from .f_auto_time_PEAK import auto_time_PEAK -from .f_auto_dist_PEAK import auto_dist_PEAK -from .f_auto_time_OFFPEAK import auto_time_OFFPEAK -from .f_auto_dist_OFFPEAK import auto_dist_OFFPEAK -from .f_auto_opcost_PEAK import auto_opcost_PEAK -from .f_auto_opcost_hov_PEAK import auto_opcost_hov_PEAK -from .f_auto_opcost_OFFPEAK import auto_opcost_OFFPEAK -from .f_auto_toll_hiinc_PEAK import auto_toll_hiinc_PEAK -from .f_auto_toll_loinc_PEAK import auto_toll_loinc_PEAK -from .f_auto_toll_hov_hiinc_PEAK import auto_toll_hov_hiinc_PEAK -from .f_auto_toll_hov_loinc_PEAK import auto_toll_hov_loinc_PEAK -from .f_auto_toll_OFFPEAK import auto_toll_OFFPEAK -from .f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W import piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W -from .f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET import piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET -from .f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD import piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD -from .f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P import piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P -from .f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK import piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK -from .f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD import piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD -from .f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ import piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ -from .f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX import piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX -from .f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS import piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS -from .f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B import piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B -from .f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R import piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R -from .f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63 import piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63 -from .f_taxi_fare_PEAK import taxi_fare_PEAK -from .f_taxi_fare_OFFPEAK import taxi_fare_OFFPEAK -from .f_tnc_solo_fare_PEAK import tnc_solo_fare_PEAK -from .f_tnc_solo_fare_OFFPEAK import tnc_solo_fare_OFFPEAK -from .f_tnc_pool_fare_PEAK import tnc_pool_fare_PEAK -from .f_tnc_pool_fare_OFFPEAK import tnc_pool_fare_OFFPEAK -from .f_taxi_wait_time_PEAK import taxi_wait_time_PEAK -from .f_taxi_wait_time_OFFPEAK import taxi_wait_time_OFFPEAK -from .f_tnc_solo_wait_time_PEAK import tnc_solo_wait_time_PEAK -from .f_tnc_solo_wait_time_OFFPEAK import tnc_solo_wait_time_OFFPEAK -from .f_tnc_pool_wait_time_PEAK import tnc_pool_wait_time_PEAK -from .f_tnc_pool_wait_time_OFFPEAK import tnc_pool_wait_time_OFFPEAK -from .f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2 import taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2 -from .f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6 import taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6 -from .f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS import tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS -from .f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO import tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO -from .f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV import tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV -from .f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB import tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB -from .f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR import fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR -from .f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN import fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN -from .f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL import fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL -from .f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID import fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID -from .f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF import fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF -from .f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI import fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI -from .f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7 import fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7 -from .f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX import fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX -from .f_log_attractions_HBWH import log_attractions_HBWH -from .f_log_attractions_HBWL import log_attractions_HBWL -from .f_log_attractions_HBS import log_attractions_HBS -from .f_log_attractions_HBO import log_attractions_HBO -from .f_log_attractions_NHB import log_attractions_NHB -from .f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V import log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V -from .f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD import log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD -from .f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL import log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL -from .f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ import log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ -from .f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM import log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM - - -@numba.jit(cache=True, parallel=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def runner(argarray, inputarray, __attractions__HBO, __attractions__HBS, __attractions__HBWH, __attractions__HBWL, __attractions__NHB, __auto_skims__am_dist, __auto_skims__am_opcost, __auto_skims__am_opcost_hov, __auto_skims__am_time, __auto_skims__am_toll_hiinc, __auto_skims__am_toll_hov_hiinc, __auto_skims__am_toll_hov_loinc, __auto_skims__am_toll_loinc, __auto_skims__md_dist, __auto_skims__md_opcost, __auto_skims__md_time, __auto_skims__md_toll, __d_autopropensity__autopropensity, __dzone__zone_type, __ozone__taxi_wait_op, __ozone__taxi_wait_pk, __ozone__tnc_pool_wait_op, __ozone__tnc_pool_wait_pk, __ozone__tnc_solo_wait_op, __ozone__tnc_solo_wait_pk, __ozone__zone_type, __transit_op__fare, __transit_op__ivtt, __transit_op__ovtt, __transit_pk__fare, __transit_pk__ivtt, __transit_pk__ovtt, dtype=np.float64, min_shape_0=0): - out_size = max(argarray.shape[0], min_shape_0) - if out_size != argarray.shape[0]: - result = np.zeros((out_size, 70), dtype=dtype) - else: - result = np.empty((out_size, 70), dtype=dtype) - if out_size > 1000: - for j in numba.prange(out_size): - result[j, 0] = o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM(argarray[j], inputarray[j], result[j], ) - result[j, 1] = transit_ivtt_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__ivtt) - result[j, 2] = transit_ivtt_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__ivtt) - result[j, 3] = transit_ovtt_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__ovtt) - result[j, 4] = transit_ovtt_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__ovtt) - result[j, 5] = transit_fare_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__fare) - result[j, 6] = transit_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__fare) - result[j, 7] = piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW(argarray[j], inputarray[j], result[j], ) - result[j, 8] = piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI(argarray[j], inputarray[j], result[j], ) - result[j, 9] = autopropensity(argarray[j], inputarray[j], result[j], __d_autopropensity__autopropensity) - result[j, 10] = auto_time_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_time) - result[j, 11] = auto_dist_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 12] = auto_time_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_time) - result[j, 13] = auto_dist_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 14] = auto_opcost_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_opcost) - result[j, 15] = auto_opcost_hov_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_opcost_hov) - result[j, 16] = auto_opcost_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_opcost) - result[j, 17] = auto_toll_hiinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hiinc) - result[j, 18] = auto_toll_loinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_loinc) - result[j, 19] = auto_toll_hov_hiinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hov_hiinc) - result[j, 20] = auto_toll_hov_loinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hov_loinc) - result[j, 21] = auto_toll_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_toll) - result[j, 22] = piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 23] = piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 24] = piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 25] = piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 26] = piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 27] = piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 28] = piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 29] = piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 30] = piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 31] = piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 32] = piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 33] = piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 34] = taxi_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 35] = taxi_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 36] = tnc_solo_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 37] = tnc_solo_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 38] = tnc_pool_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 39] = tnc_pool_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 40] = taxi_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__taxi_wait_pk) - result[j, 41] = taxi_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__taxi_wait_op) - result[j, 42] = tnc_solo_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_solo_wait_pk) - result[j, 43] = tnc_solo_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_solo_wait_op) - result[j, 44] = tnc_pool_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_pool_wait_pk) - result[j, 45] = tnc_pool_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_pool_wait_op) - result[j, 46] = taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__taxi_wait_pk) - result[j, 47] = taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__taxi_wait_op) - result[j, 48] = tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__tnc_solo_wait_pk) - result[j, 49] = tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__tnc_solo_wait_op) - result[j, 50] = tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__tnc_pool_wait_pk) - result[j, 51] = tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__tnc_pool_wait_op) - result[j, 52] = fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 53] = fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 54] = fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 55] = fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 56] = fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 57] = fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 58] = fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 59] = fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 60] = log_attractions_HBWH(argarray[j], inputarray[j], result[j], __attractions__HBWH) - result[j, 61] = log_attractions_HBWL(argarray[j], inputarray[j], result[j], __attractions__HBWL) - result[j, 62] = log_attractions_HBS(argarray[j], inputarray[j], result[j], __attractions__HBS) - result[j, 63] = log_attractions_HBO(argarray[j], inputarray[j], result[j], __attractions__HBO) - result[j, 64] = log_attractions_NHB(argarray[j], inputarray[j], result[j], __attractions__NHB) - result[j, 65] = log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V(argarray[j], inputarray[j], result[j], __attractions__HBWH) - result[j, 66] = log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD(argarray[j], inputarray[j], result[j], __attractions__HBWL) - result[j, 67] = log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL(argarray[j], inputarray[j], result[j], __attractions__HBS) - result[j, 68] = log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ(argarray[j], inputarray[j], result[j], __attractions__HBO) - result[j, 69] = log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM(argarray[j], inputarray[j], result[j], __attractions__NHB) - else: - for j in range(out_size): - result[j, 0] = o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM(argarray[j], inputarray[j], result[j], ) - result[j, 1] = transit_ivtt_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__ivtt) - result[j, 2] = transit_ivtt_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__ivtt) - result[j, 3] = transit_ovtt_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__ovtt) - result[j, 4] = transit_ovtt_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__ovtt) - result[j, 5] = transit_fare_PEAK(argarray[j], inputarray[j], result[j], __transit_pk__fare) - result[j, 6] = transit_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __transit_op__fare) - result[j, 7] = piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW(argarray[j], inputarray[j], result[j], ) - result[j, 8] = piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI(argarray[j], inputarray[j], result[j], ) - result[j, 9] = autopropensity(argarray[j], inputarray[j], result[j], __d_autopropensity__autopropensity) - result[j, 10] = auto_time_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_time) - result[j, 11] = auto_dist_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 12] = auto_time_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_time) - result[j, 13] = auto_dist_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 14] = auto_opcost_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_opcost) - result[j, 15] = auto_opcost_hov_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_opcost_hov) - result[j, 16] = auto_opcost_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_opcost) - result[j, 17] = auto_toll_hiinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hiinc) - result[j, 18] = auto_toll_loinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_loinc) - result[j, 19] = auto_toll_hov_hiinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hov_hiinc) - result[j, 20] = auto_toll_hov_loinc_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_toll_hov_loinc) - result[j, 21] = auto_toll_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_toll) - result[j, 22] = piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 23] = piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 24] = piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 25] = piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 26] = piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 27] = piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD(argarray[j], inputarray[j], result[j], __auto_skims__am_dist) - result[j, 28] = piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 29] = piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 30] = piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 31] = piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 32] = piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 33] = piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63(argarray[j], inputarray[j], result[j], __auto_skims__md_dist) - result[j, 34] = taxi_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 35] = taxi_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 36] = tnc_solo_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 37] = tnc_solo_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 38] = tnc_pool_fare_PEAK(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __auto_skims__am_time) - result[j, 39] = tnc_pool_fare_OFFPEAK(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __auto_skims__md_time) - result[j, 40] = taxi_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__taxi_wait_pk) - result[j, 41] = taxi_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__taxi_wait_op) - result[j, 42] = tnc_solo_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_solo_wait_pk) - result[j, 43] = tnc_solo_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_solo_wait_op) - result[j, 44] = tnc_pool_wait_time_PEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_pool_wait_pk) - result[j, 45] = tnc_pool_wait_time_OFFPEAK(argarray[j], inputarray[j], result[j], __ozone__tnc_pool_wait_op) - result[j, 46] = taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__taxi_wait_pk) - result[j, 47] = taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__taxi_wait_op) - result[j, 48] = tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__tnc_solo_wait_pk) - result[j, 49] = tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__tnc_solo_wait_op) - result[j, 50] = tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV(argarray[j], inputarray[j], result[j], __auto_skims__am_dist, __ozone__tnc_pool_wait_pk) - result[j, 51] = tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB(argarray[j], inputarray[j], result[j], __auto_skims__md_dist, __ozone__tnc_pool_wait_op) - result[j, 52] = fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 53] = fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 54] = fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 55] = fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 56] = fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 57] = fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 58] = fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 59] = fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX(argarray[j], inputarray[j], result[j], __dzone__zone_type, __ozone__zone_type) - result[j, 60] = log_attractions_HBWH(argarray[j], inputarray[j], result[j], __attractions__HBWH) - result[j, 61] = log_attractions_HBWL(argarray[j], inputarray[j], result[j], __attractions__HBWL) - result[j, 62] = log_attractions_HBS(argarray[j], inputarray[j], result[j], __attractions__HBS) - result[j, 63] = log_attractions_HBO(argarray[j], inputarray[j], result[j], __attractions__HBO) - result[j, 64] = log_attractions_NHB(argarray[j], inputarray[j], result[j], __attractions__NHB) - result[j, 65] = log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V(argarray[j], inputarray[j], result[j], __attractions__HBWH) - result[j, 66] = log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD(argarray[j], inputarray[j], result[j], __attractions__HBWL) - result[j, 67] = log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL(argarray[j], inputarray[j], result[j], __attractions__HBS) - result[j, 68] = log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ(argarray[j], inputarray[j], result[j], __attractions__HBO) - result[j, 69] = log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM(argarray[j], inputarray[j], result[j], __attractions__NHB) - return result - -def _map_index(dim_name, values): - raise KeyError(dim_name) - - -def set_shared_data(transit_pk, transit_op, auto_skims, ozone, dzone, attractions, o_autopropensity, d_autopropensity): - global name_space - name_space = {} - name_space['__transit_pk__ivtt'] = transit_pk['ivtt'] - name_space['__transit_pk__ovtt'] = transit_pk['ovtt'] - name_space['__transit_pk__headway'] = transit_pk['headway'] - name_space['__transit_pk__fare'] = transit_pk['fare'] - name_space['__transit_pk__firstmode'] = transit_pk['firstmode'] - name_space['__transit_pk__prioritymode'] = transit_pk['prioritymode'] - name_space['__transit_pk__lastmode'] = transit_pk['lastmode'] - name_space['__transit_op__ivtt'] = transit_op['ivtt'] - name_space['__transit_op__ovtt'] = transit_op['ovtt'] - name_space['__transit_op__headway'] = transit_op['headway'] - name_space['__transit_op__fare'] = transit_op['fare'] - name_space['__transit_op__firstmode'] = transit_op['firstmode'] - name_space['__transit_op__prioritymode'] = transit_op['prioritymode'] - name_space['__transit_op__lastmode'] = transit_op['lastmode'] - name_space['__auto_skims__am_time'] = auto_skims['am_time'] - name_space['__auto_skims__am_dist'] = auto_skims['am_dist'] - name_space['__auto_skims__am_toll_loinc'] = auto_skims['am_toll_loinc'] - name_space['__auto_skims__am_toll_hiinc'] = auto_skims['am_toll_hiinc'] - name_space['__auto_skims__md_time'] = auto_skims['md_time'] - name_space['__auto_skims__md_dist'] = auto_skims['md_dist'] - name_space['__auto_skims__md_toll'] = auto_skims['md_toll'] - name_space['__auto_skims__am_time_hov'] = auto_skims['am_time_hov'] - name_space['__auto_skims__am_dist_hov'] = auto_skims['am_dist_hov'] - name_space['__auto_skims__am_toll_hov_loinc'] = auto_skims['am_toll_hov_loinc'] - name_space['__auto_skims__am_toll_hov_hiinc'] = auto_skims['am_toll_hov_hiinc'] - name_space['__auto_skims__am_opcost'] = auto_skims['am_opcost'] - name_space['__auto_skims__am_opcost_hov'] = auto_skims['am_opcost_hov'] - name_space['__auto_skims__md_opcost'] = auto_skims['md_opcost'] - name_space['__ozone__zone_type'] = ozone['zone_type'] - name_space['__ozone__pnr_parking_cost'] = ozone['pnr_parking_cost'] - name_space['__ozone__zone_income'] = ozone['zone_income'] - name_space['__ozone__pnr_flag'] = ozone['pnr_flag'] - name_space['__ozone__first_wait_bus_peak'] = ozone['first_wait_bus_peak'] - name_space['__ozone__first_wait_bus_offpeak'] = ozone['first_wait_bus_offpeak'] - name_space['__ozone__first_wait_feeder_peak'] = ozone['first_wait_feeder_peak'] - name_space['__ozone__first_wait_feeder_offpeak'] = ozone['first_wait_feeder_offpeak'] - name_space['__ozone__autocc'] = ozone['autocc'] - name_space['__ozone__taxi_wait_pk'] = ozone['taxi_wait_pk'] - name_space['__ozone__taxi_wait_op'] = ozone['taxi_wait_op'] - name_space['__ozone__tnc_solo_wait_pk'] = ozone['tnc_solo_wait_pk'] - name_space['__ozone__tnc_solo_wait_op'] = ozone['tnc_solo_wait_op'] - name_space['__ozone__tnc_pool_wait_pk'] = ozone['tnc_pool_wait_pk'] - name_space['__ozone__tnc_pool_wait_op'] = ozone['tnc_pool_wait_op'] - name_space['__dzone__zone_type'] = dzone['zone_type'] - name_space['__dzone__pnr_parking_cost'] = dzone['pnr_parking_cost'] - name_space['__dzone__zone_income'] = dzone['zone_income'] - name_space['__dzone__pnr_flag'] = dzone['pnr_flag'] - name_space['__dzone__first_wait_bus_peak'] = dzone['first_wait_bus_peak'] - name_space['__dzone__first_wait_bus_offpeak'] = dzone['first_wait_bus_offpeak'] - name_space['__dzone__first_wait_feeder_peak'] = dzone['first_wait_feeder_peak'] - name_space['__dzone__first_wait_feeder_offpeak'] = dzone['first_wait_feeder_offpeak'] - name_space['__dzone__autocc'] = dzone['autocc'] - name_space['__dzone__taxi_wait_pk'] = dzone['taxi_wait_pk'] - name_space['__dzone__taxi_wait_op'] = dzone['taxi_wait_op'] - name_space['__dzone__tnc_solo_wait_pk'] = dzone['tnc_solo_wait_pk'] - name_space['__dzone__tnc_solo_wait_op'] = dzone['tnc_solo_wait_op'] - name_space['__dzone__tnc_pool_wait_pk'] = dzone['tnc_pool_wait_pk'] - name_space['__dzone__tnc_pool_wait_op'] = dzone['tnc_pool_wait_op'] - name_space['__attractions__HBO'] = attractions['HBO'] - name_space['__attractions__HBS'] = attractions['HBS'] - name_space['__attractions__HBWH'] = attractions['HBWH'] - name_space['__attractions__HBWL'] = attractions['HBWL'] - name_space['__attractions__NHB'] = attractions['NHB'] - name_space['__o_autopropensity__autopropensity'] = o_autopropensity['autopropensity'] - name_space['__d_autopropensity__autopropensity'] = d_autopropensity['autopropensity'] - - -meta_match_names_idx = {'otaz_idx': 0, 'dtaz_idx': 1} - - -import numpy as np -import numba as nb -import pandas as pd -import pyarrow as pa -import xarray as xr -import sharrow as sh -import inspect -import warnings -from contextlib import suppress - - - - -def load_raw(args, inputs, name_space, runner, dtype=None): - with warnings.catch_warnings(): - warnings.filterwarnings('ignore', category=nb.NumbaExperimentalFeatureWarning) - if len(args): - assembled_args = np.stack(args).T - else: - assembled_args = None - if len(inputs): - assembled_inputs = np.stack(inputs).T - else: - assembled_inputs = np.empty([assembled_args.shape[0], 0], dtype=np.float32) - if assembled_args is None: - assembled_args = np.empty([assembled_inputs.shape[0], 0], dtype=np.float32) - try: - named_args = ['__attractions__HBO', '__attractions__HBS', '__attractions__HBWH', '__attractions__HBWL', '__attractions__NHB', '__auto_skims__am_dist', '__auto_skims__am_opcost', '__auto_skims__am_opcost_hov', '__auto_skims__am_time', '__auto_skims__am_toll_hiinc', '__auto_skims__am_toll_hov_hiinc', '__auto_skims__am_toll_hov_loinc', '__auto_skims__am_toll_loinc', '__auto_skims__md_dist', '__auto_skims__md_opcost', '__auto_skims__md_time', '__auto_skims__md_toll', '__d_autopropensity__autopropensity', '__dzone__zone_type', '__ozone__taxi_wait_op', '__ozone__taxi_wait_pk', '__ozone__tnc_pool_wait_op', '__ozone__tnc_pool_wait_pk', '__ozone__tnc_solo_wait_op', '__ozone__tnc_solo_wait_pk', '__ozone__zone_type', '__transit_op__fare', '__transit_op__ivtt', '__transit_op__ovtt', '__transit_pk__fare', '__transit_pk__ivtt', '__transit_pk__ovtt'] - arguments = [] - for arg in named_args: - next_arg = name_space[arg] - if isinstance(next_arg, xr.DataArray): - next_arg = next_arg.load() - arguments.append(np.asarray(next_arg)) - if dtype is not None: - return runner(assembled_args, assembled_inputs, *arguments, dtype=dtype) - else: - return runner(assembled_args, assembled_inputs, *arguments) - except nb.TypingError: - raise - except KeyError as err: - # raise the inner key error which is more helpful - context = getattr(err, "__context__", None) - if context: - raise context - else: - raise err - - -def load( - source, - as_dataframe=False, - as_table=False, - dtype=None, -): - if source is None: - raise ValueError("no base table or source table") - indexes = _get_indexes(source)[0] - inputs = _get_inputs(source) - result = load_raw(indexes, inputs, name_space, runner=runner, dtype=dtype) - if as_dataframe: - index = getattr(source, 'index', None) - return pd.DataFrame(result, index=index, columns=function_names) - elif as_table: - return pa.table({k: result[:, n] for n, k in enumerate(function_names)}) - return result - - -def merge(source, dtype=None): - """ - Merge the data created by this flow into the source. - - Parameters - ---------- - source : Dataset or Table or DataFrame - dtype : str or dtype - The loaded data will be generated with this dtype. - - Returns - ------- - merged : Dataset or Table or DataFrame - The same data type as `source` is returned. - """ - assert isinstance(source, (xr.Dataset, pa.Table, pd.DataFrame, sh.Table)) - new_cols = load(source, dtype=dtype) - if isinstance(source, (pa.Table, sh.Table)): - for n, k in enumerate(function_names): - source = source.append_column(k, [new_cols[:, n]]) - else: - for n, k in enumerate(function_names): - source[k] = new_cols[:, n] - return source - - -def _get_indexes(source_table, cache_dynamic_indexes=None): - if cache_dynamic_indexes is None: - cache_dynamic_indexes = True - - def geti(i): - nonlocal source_table - if i is not None: - try: - return np.asarray(source_table[i]) - except KeyError: - if i[:10] == '__dynamic_': - if "@" in i: - i_complete = i - i, i_from = i.split("@", 1) - else: - i_complete = i - i_from = i[10:] - index_to_map = None - with suppress(KeyError): - index_to_map = source_table[i_from] - if index_to_map is None: - if isinstance(source_table, pd.DataFrame): - if i_from == "index" and source_table.index.names == [None]: - index_to_map = source_table.index - elif i_from in source_table.index.names: - index_to_map = source_table.index.get_level_values(i_from) - if index_to_map is None: - raise KeyError(i_complete) - indexed_vals = _map_index(i[10:], index_to_map) - if cache_dynamic_indexes: - if isinstance(source_table, (pa.Table)): - source_table = source_table.append_column(i_complete, [indexed_vals]) - else: - source_table[i_complete] = indexed_vals - return indexed_vals - else: - idx = getattr(source_table, 'index', None) - if idx is not None: - if i in idx.names: - return np.asarray(idx.get_level_values(i)) - if i == 'index' and len(idx.names)==1: - return np.asarray(idx) - raise - else: - return np.arange(source_table.shape[0]) - index_keys = meta_match_names_idx.keys() - return tuple(geti(i) for i in index_keys), source_table - - -def _get_inputs(source_table, dtype=np.float32): - input_keys = input_name_positions.keys() - return tuple( - np.asarray(source_table[i], dtype=dtype) - for i in input_keys - ) - - - -input_name_positions = {'dtaz': 0, 'otaz': 1} -function_names = ['o_zone == dtaz', 'transit_ivtt_PEAK', 'transit_ivtt_OFFPEAK', 'transit_ovtt_PEAK', 'transit_ovtt_OFFPEAK', 'transit_fare_PEAK', 'transit_fare_OFFPEAK', 'piece(transit_ivtt_OFFPEAK, None, 20)', 'piece(transit_ivtt_OFFPEAK, 20, None)', 'autopropensity', 'auto_time_PEAK', 'auto_dist_PEAK', 'auto_time_OFFPEAK', 'auto_dist_OFFPEAK', 'auto_opcost_PEAK', 'auto_opcost_hov_PEAK', 'auto_opcost_OFFPEAK', 'auto_toll_hiinc_PEAK', 'auto_toll_loinc_PEAK', 'auto_toll_hov_hiinc_PEAK', 'auto_toll_hov_loinc_PEAK', 'auto_toll_OFFPEAK', 'piece(auto_dist_PEAK,None,0.5)', 'piece(auto_dist_PEAK,0.5,1.0)', 'piece(auto_dist_PEAK,1.0,None)', 'piece(auto_dist_PEAK,None,5)', 'piece(auto_dist_PEAK,5,10)', 'piece(auto_dist_PEAK,10,None)', 'piece(auto_dist_OFFPEAK,None,0.5)', 'piece(auto_dist_OFFPEAK,0.5,1.0)', 'piece(auto_dist_OFFPEAK,1.0,None)', 'piece(auto_dist_OFFPEAK,None,5)', 'piece(auto_dist_OFFPEAK,5,10)', 'piece(auto_dist_OFFPEAK,10,None)', 'taxi_fare_PEAK', 'taxi_fare_OFFPEAK', 'tnc_solo_fare_PEAK', 'tnc_solo_fare_OFFPEAK', 'tnc_pool_fare_PEAK', 'tnc_pool_fare_OFFPEAK', 'taxi_wait_time_PEAK', 'taxi_wait_time_OFFPEAK', 'tnc_solo_wait_time_PEAK', 'tnc_solo_wait_time_OFFPEAK', 'tnc_pool_wait_time_PEAK', 'tnc_pool_wait_time_OFFPEAK', 'taxi_wait_time_PEAK/auto_dist_PEAK', 'taxi_wait_time_OFFPEAK/auto_dist_OFFPEAK', 'tnc_solo_wait_time_PEAK/auto_dist_PEAK', 'tnc_solo_wait_time_OFFPEAK/auto_dist_OFFPEAK', 'tnc_pool_wait_time_PEAK/auto_dist_PEAK', 'tnc_pool_wait_time_OFFPEAK/auto_dist_OFFPEAK', 'fmax(ozone_areatype, areatype)==1', 'fmax(ozone_areatype, areatype)==2', 'fmax(ozone_areatype, areatype)==3', 'fmax(ozone_areatype, areatype)==4', 'fmin(ozone_areatype, areatype)==1', 'fmin(ozone_areatype, areatype)==2', 'fmin(ozone_areatype, areatype)==3', 'fmin(ozone_areatype, areatype)==4', 'log_attractions_HBWH', 'log_attractions_HBWL', 'log_attractions_HBS', 'log_attractions_HBO', 'log_attractions_NHB', 'log_attractions_HBWH > -666', 'log_attractions_HBWL > -666', 'log_attractions_HBS > -666', 'log_attractions_HBO > -666', 'log_attractions_NHB > -666'] - -# Greetings, tinkerer! The `defs_hash` included here is a safety -# measure to prevent unknowing users creating a mess by modifying -# the code in this module so that it no longer matches the expected -# variable definitions. If you want to modify this code, you should -# delete this hash to allow the code to run without any checks, but -# you do so at your own risk. -defs_hash = 'XUCQEOOTEO3UREF2YYT73XUJ24======' diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/__init__.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/__init__.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_funcs.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_funcs.py deleted file mode 100644 index 4a2efbf..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_funcs.py +++ /dev/null @@ -1,6 +0,0 @@ -import numba -import numpy as np -import pickle - -taxi_cost = pickle.loads(b'\x80\x05\x95\x17\x05\x00\x00\x00\x00\x00\x00\x8c\x14numba.core.serialize\x94\x8c\x0ecustom_rebuild\x94\x93\x94h\x00\x8c\x18_unpickle__CustomPickled\x94\x93\x94B\xbf\x04\x00\x00\x80\x04\x95\xb4\x04\x00\x00\x00\x00\x00\x00\x8c\x13numba.core.registry\x94\x8c\rCPUDispatcher\x94\x93\x94}\x94(\x8c\x04uuid\x94\x8c$6003875c-d52d-11eb-8449-acde48001122\x94\x8c\x07py_func\x94\x8c\x14numba.core.serialize\x94\x8c\x11_rebuild_function\x94\x93\x94(K\x04C\x04a\r\r\n\x94B"\x03\x00\x00\xe3\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x03\x00\x00\x00C\x00\x00\x00s^\x00\x00\x00|\x04j\x00|\x00|\x04j\x01\x14\x00\x17\x00|\x01|\x04j\x02\x14\x00\x17\x00}\x05|\x04j\x03rZd\x01}\x06t\x04|\x04j\x05j\x06\x83\x01D\x00]\x1a}\x07|\x04j\x05|\x07\x19\x00|\x02k\x02r0d\x02}\x06\x01\x00qLq0|\x06rZ|\x05|\x04j\x037\x00}\x05|\x05S\x00)\x03\xe1U\x01\x00\x00\n Compute taxi fare.\n\n A single set of rates (Chicago medallion rates for in-city trips)\n is used; fares for taxi trips outside Chicago are close to this\n rate and rare enough that more precision is unneeded.\n\n Parameters\n ----------\n auto_time, auto_dist : array-like\n\n Returns\n -------\n fare : array-like\n FT)\x07\xda\tflag_pull\xda\nper_minute\xda\x08per_mile\xda\x12airport_pickup_fee\xda\x05range\xda\x14airport_pickup_zones\xda\x04size)\x08\xda\tauto_time\xda\tauto_dist\xda\x06o_zone\xda\x06d_zone\xda\x10taxi_cost_struct\xda\x04cost\xda\x0ebucket_applies\xda\x01i\xa9\x00r\x11\x00\x00\x00\xfa`/Users/jeffnewman/LocalGit/cmap_trip-based_model/src/Mode-Dest-TOD/cmap_modedest/fast/tnc_los.py\xda\ttaxi_cost \x00\x00\x00s\x1e\x00\x00\x00\x00\x12\x04\x01\x08\xff\x02\x02\x08\xfe\x02\xff\x02\x05\x06\x01\x04\x01\x10\x01\x0e\x01\x04\x01\x06\x01\x04\x01\n\x02\x94\x87\x94}\x94(\x8c\x05range\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94\x8c\x08__name__\x94\x8c\x1acmap_modedest.fast.tnc_los\x94u\x8c\ttaxi_cost\x94NNt\x94R\x94h\x07\x8c\x12_function_setstate\x94\x93\x94h\x16}\x94\x8c\x05cells\x94)s\x86R0\x8c\x06locals\x94}\x94\x8c\rtargetoptions\x94}\x94(\x8c\x08nopython\x94\x88\x8c\x0bboundscheck\x94Nu\x8c\timpl_kind\x94\x8c\x06direct\x94\x8c\x0bcan_compile\x94\x88\x8c\x04sigs\x94]\x94u\x86\x94.\x94\x85\x94R\x94\x85\x94R\x94.') -tnc_cost = pickle.loads(b'\x80\x05\x95\xf2\x05\x00\x00\x00\x00\x00\x00\x8c\x14numba.core.serialize\x94\x8c\x0ecustom_rebuild\x94\x93\x94h\x00\x8c\x18_unpickle__CustomPickled\x94\x93\x94B\x9a\x05\x00\x00\x80\x04\x95\x8f\x05\x00\x00\x00\x00\x00\x00\x8c\x13numba.core.registry\x94\x8c\rCPUDispatcher\x94\x93\x94}\x94(\x8c\x04uuid\x94\x8c$60039bfc-d52d-11eb-8449-acde48001122\x94\x8c\x07py_func\x94\x8c\x14numba.core.serialize\x94\x8c\x11_rebuild_function\x94\x93\x94(K\x04C\x04a\r\r\n\x94B\xe5\x03\x00\x00\xe3\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x03\x00\x00\x00C\x00\x00\x00s\xcc\x00\x00\x00|\x04j\x00|\x00\x14\x00|\x04j\x01|\x01\x14\x00\x17\x00|\x04j\x02\x17\x00}\x05t\x03|\x05|\x04j\x04\x83\x02|\x04j\x05\x17\x00}\x05|\x04j\x06rzd\x01}\x06t\x07|\x04j\x08j\t\x83\x01D\x00](}\x07|\x04j\x08|\x07\x19\x00|\x02k\x02sb|\x04j\x08|\x07\x19\x00|\x03k\x02rBd\x02}\x06\x01\x00qlqB|\x06rz|\x05|\x04j\x067\x00}\x05|\x04j\nr\xc8d\x01}\x06t\x07|\x04j\x0bj\t\x83\x01D\x00](}\x07|\x04j\x0b|\x07\x19\x00|\x02k\x02s\xb0|\x04j\x0b|\x07\x19\x00|\x03k\x02r\x90d\x02}\x06\x01\x00q\xbaq\x90|\x06r\xc8|\x05|\x04j\n7\x00}\x05|\x05S\x00)\x03\xe1n\x01\x00\x00\n Compute the TNC cost.\n\n Parameters\n ----------\n auto_time, auto_dist : float\n The auto travel time and distance for a set of trips.\n o_zone, d_zone : int\n Zone numbers for origin and destination\n tnc_cost_struct : TncCostStruct\n Use the correct struct for peak/offpeak and solo/shared.\n\n Returns\n -------\n float\n FT)\x0c\xda\nper_minute\xda\x08per_mile\xda\tbase_fare\xda\x03max\xda\x08min_fare\xda\x0bbooking_fee\xda\x0bspecial_fee\xda\x05range\xda\rspecial_zones\xda\x04size\xda\x0cdowntown_fee\xda\x0edowntown_zones)\x08\xda\tauto_time\xda\tauto_dist\xda\x06o_zone\xda\x06d_zone\xda\x0ftnc_cost_struct\xda\x04cost\xda\x0ebucket_applies\xda\x01i\xa9\x00r\x16\x00\x00\x00\xfa`/Users/jeffnewman/LocalGit/cmap_trip-based_model/src/Mode-Dest-TOD/cmap_modedest/fast/tnc_los.py\xda\x08tnc_costA\x00\x00\x00s0\x00\x00\x00\x00\x13\x08\x01\x08\xff\x02\x02\x04\xfe\x02\xff\x02\x05\x12\x02\x06\x01\x04\x01\x10\x01\x1c\x01\x04\x01\x06\x01\x04\x01\n\x02\x06\x01\x04\x01\x10\x01\x1c\x01\x04\x01\x06\x01\x04\x01\n\x02\x94\x87\x94}\x94(\x8c\x03max\x94\x8c\x08builtins\x94\x8c\x03max\x94\x93\x94\x8c\x05range\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94\x8c\x08__name__\x94\x8c\x1acmap_modedest.fast.tnc_los\x94u\x8c\x08tnc_cost\x94NNt\x94R\x94h\x07\x8c\x12_function_setstate\x94\x93\x94h\x1a}\x94\x8c\x05cells\x94)s\x86R0\x8c\x06locals\x94}\x94\x8c\rtargetoptions\x94}\x94(\x8c\x08nopython\x94\x88\x8c\x0bboundscheck\x94Nu\x8c\timpl_kind\x94\x8c\x06direct\x94\x8c\x0bcan_compile\x94\x88\x8c\x04sigs\x94]\x94u\x86\x94.\x94\x85\x94R\x94\x85\x94R\x94.') diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_funcs.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_funcs.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_vars.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_vars.py deleted file mode 100644 index 4f90f20..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_vars.py +++ /dev/null @@ -1,7 +0,0 @@ -import pickle - -taxi_cost_struct = pickle.loads(b'\x80\x05\x95\xd9\x00\x00\x00\x00\x00\x00\x00\x8c\x1acmap_modedest.fast.tnc_los\x94\x8c\x0eTaxiCostStruct\x94\x93\x94(ME\x01G@D\xd5`A\x897LK\xe1M\x90\x01\x8c\x12numpy.core.numeric\x94\x8c\x0b_frombuffer\x94\x93\x94(\x96 \x00\x00\x00\x00\x00\x00\x00}\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00\x00\x00\x00\x00\xee\x01\x00\x00\x00\x00\x00\x00\xf3\x01\x00\x00\x00\x00\x00\x00\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94\x89\x88\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bK\x04\x85\x94\x8c\x01C\x94t\x94R\x94t\x94\x81\x94.') -tnc_solo_peak_struct = pickle.loads(b'\x80\x05\x95\xd1\x02\x00\x00\x00\x00\x00\x00\x8c\x1acmap_modedest.fast.tnc_los\x94\x8c\rTncCostStruct\x94\x93\x94(K\x88K\x1cKmM\xe5\x01M\x01\x01M\xf4\x01K\x00\x8c\x12numpy.core.numeric\x94\x8c\x0b_frombuffer\x94\x93\x94(\x968\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00}\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00\x00\x00\x00\x00\xee\x01\x00\x00\x00\x00\x00\x00\xf3\x01\x00\x00\x00\x00\x00\x00p\x00\x00\x00\x00\x00\x00\x00q\x00\x00\x00\x00\x00\x00\x00\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94\x89\x88\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bK\x07\x85\x94\x8c\x01C\x94t\x94R\x94h\x05(\x96\xc8\x01\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00%\x00\x00\x00\x00\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x00\'\x00\x00\x00\x00\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00\x00\x00\x00\x00/\x00\x00\x00\x00\x00\x00\x001\x00\x00\x00\x00\x00\x00\x002\x00\x00\x00\x00\x00\x00\x003\x00\x00\x00\x00\x00\x00\x004\x00\x00\x00\x00\x00\x00\x007\x00\x00\x00\x00\x00\x00\x008\x00\x00\x00\x00\x00\x00\x009\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00=\x00\x00\x00\x00\x00\x00\x00>\x00\x00\x00\x00\x00\x00\x00?\x00\x00\x00\x00\x00\x00\x00\x94h\x0cK9\x85\x94h\x10t\x94R\x94t\x94\x81\x94.') -tnc_solo_offpeak_struct = pickle.loads(b'\x80\x05\x95\xd1\x02\x00\x00\x00\x00\x00\x00\x8c\x1acmap_modedest.fast.tnc_los\x94\x8c\rTncCostStruct\x94\x93\x94(K\x88K\x1cKmM\xe5\x01M\x01\x01M\xf4\x01K\x00\x8c\x12numpy.core.numeric\x94\x8c\x0b_frombuffer\x94\x93\x94(\x968\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00}\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00\x00\x00\x00\x00\xee\x01\x00\x00\x00\x00\x00\x00\xf3\x01\x00\x00\x00\x00\x00\x00p\x00\x00\x00\x00\x00\x00\x00q\x00\x00\x00\x00\x00\x00\x00\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94\x89\x88\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bK\x07\x85\x94\x8c\x01C\x94t\x94R\x94h\x05(\x96\xc8\x01\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00%\x00\x00\x00\x00\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x00\'\x00\x00\x00\x00\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00\x00\x00\x00\x00/\x00\x00\x00\x00\x00\x00\x001\x00\x00\x00\x00\x00\x00\x002\x00\x00\x00\x00\x00\x00\x003\x00\x00\x00\x00\x00\x00\x004\x00\x00\x00\x00\x00\x00\x007\x00\x00\x00\x00\x00\x00\x008\x00\x00\x00\x00\x00\x00\x009\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00=\x00\x00\x00\x00\x00\x00\x00>\x00\x00\x00\x00\x00\x00\x00?\x00\x00\x00\x00\x00\x00\x00\x94h\x0cK9\x85\x94h\x10t\x94R\x94t\x94\x81\x94.') -tnc_pool_peak_struct = pickle.loads(b'\x80\x05\x95\xd0\x02\x00\x00\x00\x00\x00\x00\x8c\x1acmap_modedest.fast.tnc_los\x94\x8c\rTncCostStruct\x94\x93\x94(KDK\x00KjK\x00M\x01\x01M\xf4\x01K\x00\x8c\x12numpy.core.numeric\x94\x8c\x0b_frombuffer\x94\x93\x94(\x968\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00}\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00\x00\x00\x00\x00\xee\x01\x00\x00\x00\x00\x00\x00\xf3\x01\x00\x00\x00\x00\x00\x00p\x00\x00\x00\x00\x00\x00\x00q\x00\x00\x00\x00\x00\x00\x00\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94\x89\x88\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bK\x07\x85\x94\x8c\x01C\x94t\x94R\x94h\x05(\x96\xc8\x01\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00%\x00\x00\x00\x00\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x00\'\x00\x00\x00\x00\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00\x00\x00\x00\x00/\x00\x00\x00\x00\x00\x00\x001\x00\x00\x00\x00\x00\x00\x002\x00\x00\x00\x00\x00\x00\x003\x00\x00\x00\x00\x00\x00\x004\x00\x00\x00\x00\x00\x00\x007\x00\x00\x00\x00\x00\x00\x008\x00\x00\x00\x00\x00\x00\x009\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00=\x00\x00\x00\x00\x00\x00\x00>\x00\x00\x00\x00\x00\x00\x00?\x00\x00\x00\x00\x00\x00\x00\x94h\x0cK9\x85\x94h\x10t\x94R\x94t\x94\x81\x94.') -tnc_pool_offpeak_struct = pickle.loads(b'\x80\x05\x95\xd0\x02\x00\x00\x00\x00\x00\x00\x8c\x1acmap_modedest.fast.tnc_los\x94\x8c\rTncCostStruct\x94\x93\x94(KDK\x00KjK\x00M\x01\x01M\xf4\x01K\x00\x8c\x12numpy.core.numeric\x94\x8c\x0b_frombuffer\x94\x93\x94(\x968\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00}\x00\x00\x00\x00\x00\x00\x00~\x00\x00\x00\x00\x00\x00\x00\xee\x01\x00\x00\x00\x00\x00\x00\xf3\x01\x00\x00\x00\x00\x00\x00p\x00\x00\x00\x00\x00\x00\x00q\x00\x00\x00\x00\x00\x00\x00\x94\x8c\x05numpy\x94\x8c\x05dtype\x94\x93\x94\x8c\x02i8\x94\x89\x88\x87\x94R\x94(K\x03\x8c\x01<\x94NNNJ\xff\xff\xff\xffJ\xff\xff\xff\xffK\x00t\x94bK\x07\x85\x94\x8c\x01C\x94t\x94R\x94h\x05(\x96\xc8\x01\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00#\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00%\x00\x00\x00\x00\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x00\'\x00\x00\x00\x00\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00.\x00\x00\x00\x00\x00\x00\x00/\x00\x00\x00\x00\x00\x00\x001\x00\x00\x00\x00\x00\x00\x002\x00\x00\x00\x00\x00\x00\x003\x00\x00\x00\x00\x00\x00\x004\x00\x00\x00\x00\x00\x00\x007\x00\x00\x00\x00\x00\x00\x008\x00\x00\x00\x00\x00\x00\x009\x00\x00\x00\x00\x00\x00\x00<\x00\x00\x00\x00\x00\x00\x00=\x00\x00\x00\x00\x00\x00\x00>\x00\x00\x00\x00\x00\x00\x00?\x00\x00\x00\x00\x00\x00\x00\x94h\x0cK9\x85\x94h\x10t\x94R\x94t\x94\x81\x94.') diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_vars.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/extra_vars.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_OFFPEAK.py deleted file mode 100644 index a50153a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_dist_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return __auto_skims__md_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_PEAK.py deleted file mode 100644 index 53e50be..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_dist_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return __auto_skims__am_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_dist_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_OFFPEAK.py deleted file mode 100644 index 4107f13..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_opcost_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_opcost -): - return __auto_skims__md_opcost[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_PEAK.py deleted file mode 100644 index 043d805..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_opcost_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_opcost -): - return __auto_skims__am_opcost[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_hov_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_hov_PEAK.py deleted file mode 100644 index 3cb9fcc..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_hov_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_opcost_hov_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_opcost_hov -): - return __auto_skims__am_opcost_hov[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_hov_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_opcost_hov_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_OFFPEAK.py deleted file mode 100644 index fcface8..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_time_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_time -): - return __auto_skims__md_time[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_PEAK.py deleted file mode 100644 index 308ec21..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_time_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_time -): - return __auto_skims__am_time[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_time_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_OFFPEAK.py deleted file mode 100644 index c169b1c..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_toll_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_toll -): - return np.fmax(__auto_skims__md_toll[_args[0], _args[1]], 0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hiinc_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hiinc_PEAK.py deleted file mode 100644 index 61d7089..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hiinc_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_toll_hiinc_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_toll_hiinc -): - return np.fmax(__auto_skims__am_toll_hiinc[_args[0], _args[1]], 0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hiinc_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hiinc_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_hiinc_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_hiinc_PEAK.py deleted file mode 100644 index d77ec33..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_hiinc_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_toll_hov_hiinc_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_toll_hov_hiinc -): - return np.fmax(__auto_skims__am_toll_hov_hiinc[_args[0], _args[1]], 0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_hiinc_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_hiinc_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_loinc_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_loinc_PEAK.py deleted file mode 100644 index 22c7941..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_loinc_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_toll_hov_loinc_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_toll_hov_loinc -): - return np.fmax(__auto_skims__am_toll_hov_loinc[_args[0], _args[1]], 0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_loinc_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_hov_loinc_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_loinc_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_loinc_PEAK.py deleted file mode 100644 index bda3b6a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_loinc_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_toll_loinc_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_toll_loinc -): - return np.fmax(__auto_skims__am_toll_loinc[_args[0], _args[1]], 0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_loinc_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_auto_toll_loinc_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_autopropensity.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_autopropensity.py deleted file mode 100644 index 26d0d4d..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_autopropensity.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def autopropensity( - _args, - _inputs, - _outputs, - __d_autopropensity__autopropensity -): - return __d_autopropensity__autopropensity[_args[1],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_autopropensity.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_autopropensity.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR.py deleted file mode 100644 index 78cb643..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return max(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 1 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___1_OWXSNW5EFKHSRO2IUCB6DHTR.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN.py deleted file mode 100644 index 63aa595..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return max(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 2 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___2_FIT25FYRGELBEONPX2MTPZFN.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL.py deleted file mode 100644 index fffecee..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return max(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 3 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___3_LIPIKNXA6ZB3PUNRJBVIHATL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID.py deleted file mode 100644 index 576db9b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return max(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 4 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmax_ozone_areatype__areatype___4_J3D56DXM2MR6NEMIQ6ALSFID.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF.py deleted file mode 100644 index 14d4e60..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return min(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 1 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___1_OTNZJFEFZT7N3JG6YKEUWGTF.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI.py deleted file mode 100644 index 1e743ea..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return min(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 2 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___2_FY4D7BMCO2N4QRIA6QIIWTZI.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7.py deleted file mode 100644 index c7c4a5d..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return min(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 3 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___3_34BD5WGYZOPLALWPB2MCWKA7.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX.py deleted file mode 100644 index 44f26be..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX( - _args, - _inputs, - _outputs, - __dzone__zone_type, __ozone__zone_type -): - return min(__ozone__zone_type[_args[0],], __dzone__zone_type[_args[1],]) == 4 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_fmin_ozone_areatype__areatype___4_64S6AODYPVZP57LTAC522OHX.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO.py deleted file mode 100644 index ad7884f..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBO( - _args, - _inputs, - _outputs, - __attractions__HBO -): - return log(__attractions__HBO[_args[1],]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ.py deleted file mode 100644 index bcdbdeb..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ( - _args, - _inputs, - _outputs, - __attractions__HBO -): - return log(__attractions__HBO[_args[1],]) > -666 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBO____666_5VORECHSLO2A6MKP5I3SGJVQ.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS.py deleted file mode 100644 index 50a1cb5..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBS( - _args, - _inputs, - _outputs, - __attractions__HBS -): - return log(__attractions__HBS[_args[1],]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL.py deleted file mode 100644 index dac95e3..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL( - _args, - _inputs, - _outputs, - __attractions__HBS -): - return log(__attractions__HBS[_args[1],]) > -666 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBS____666_L3ZMVRT365KFSBLEDVABFEGL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH.py deleted file mode 100644 index 2e92b51..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBWH( - _args, - _inputs, - _outputs, - __attractions__HBWH -): - return log(__attractions__HBWH[_args[1],]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V.py deleted file mode 100644 index 638cd9e..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V( - _args, - _inputs, - _outputs, - __attractions__HBWH -): - return log(__attractions__HBWH[_args[1],]) > -666 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWH____666_GW3RKVJQOVET3XE7MYE2MA7V.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL.py deleted file mode 100644 index bf302cc..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBWL( - _args, - _inputs, - _outputs, - __attractions__HBWL -): - return log(__attractions__HBWL[_args[1],]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD.py deleted file mode 100644 index 03e9d24..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD( - _args, - _inputs, - _outputs, - __attractions__HBWL -): - return log(__attractions__HBWL[_args[1],]) > -666 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_HBWL____666_IQGLCTAX7EZOXKEFCIBK33BD.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB.py deleted file mode 100644 index a76ad09..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_NHB( - _args, - _inputs, - _outputs, - __attractions__NHB -): - return log(__attractions__NHB[_args[1],]) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM.py deleted file mode 100644 index 529c3ff..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM( - _args, - _inputs, - _outputs, - __attractions__NHB -): - return log(__attractions__NHB[_args[1],]) > -666 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_log_attractions_NHB____666_3GFB7KMY3JN5TSJE4MRRR2HM.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM.py deleted file mode 100644 index 8d0d860..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM( - _args, - _inputs, - _outputs, - -): - return _inputs[1] == _inputs[0] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_o_zone____dtaz_HXCH5HUPIDPV3EWONWFXBZHM.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX.py deleted file mode 100644 index 11bc0b9..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], 0.5, 1.0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_0_5_1_0__HZLL3YOGUR763JRQHG7SM6TX.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63.py deleted file mode 100644 index 0d67afc..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], 10, None) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_10_None__6EE7X5PWAQKBS6WQUONWVI63.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS.py deleted file mode 100644 index cbe8bc9..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], 1.0, None) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_1_0_None__FBK6GF2KEWWDN7AL3ENVH3VS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R.py deleted file mode 100644 index d93d41c..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], 5, 10) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_5_10__5RQTWWGPPCPP6EQU6ZV5MX2R.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ.py deleted file mode 100644 index 55a397b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], None, 0.5) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_0_5__537AWC5AWFXLM3TRB3PPSGYZ.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B.py deleted file mode 100644 index 8aa0e5c..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B( - _args, - _inputs, - _outputs, - __auto_skims__md_dist -): - return piece(__auto_skims__md_dist[_args[0], _args[1]], None, 5) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_OFFPEAK_None_5__YWXA4HRZAVEZKC7EV5M2AX3B.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET.py deleted file mode 100644 index f3e83e1..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], 0.5, 1.0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_0_5_1_0__4K5ZPM55FQJVFMWKUPZIQ2ET.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD.py deleted file mode 100644 index 5cdfe54..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], 10, None) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_10_None__L3GKJNRUTTFCDUYV65K7KFQD.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD.py deleted file mode 100644 index aaadc74..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], 1.0, None) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_1_0_None__FMBHM5APW4TIH6B5EKSKSXYD.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK.py deleted file mode 100644 index 552904b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], 5, 10) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_5_10__DSXTFACXD5HSWU7YKUPQEGAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W.py deleted file mode 100644 index 869dc31..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], None, 0.5) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_0_5__NZ6HG4EJYEENT2OAOBDF3W5W.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P.py deleted file mode 100644 index b605969..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P( - _args, - _inputs, - _outputs, - __auto_skims__am_dist -): - return piece(__auto_skims__am_dist[_args[0], _args[1]], None, 5) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_auto_dist_PEAK_None_5__7D72ALZRBNSP634JYUY7IV5P.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI.py deleted file mode 100644 index 4e77239..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI( - _args, - _inputs, - _outputs, - -): - return piece(_outputs[2], 20, None) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__20__None__2SYXPZCTOY3PKAO2L4ALLHLI.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW.py deleted file mode 100644 index 59e58bd..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW( - _args, - _inputs, - _outputs, - -): - return piece(_outputs[2], None, 20) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_piece_transit_ivtt_OFFPEAK__None__20__54N5BOFSYCN6SMRBKXM4V4TW.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_OFFPEAK.py deleted file mode 100644 index 07b281b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_fare_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __auto_skims__md_time -): - return taxi_cost(__auto_skims__md_time[_args[0], _args[1]], __auto_skims__md_dist[_args[0], _args[1]], _inputs[1], _inputs[0], taxi_cost_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_PEAK.py deleted file mode 100644 index 2dc2c8b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_fare_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __auto_skims__am_time -): - return taxi_cost(__auto_skims__am_time[_args[0], _args[1]], __auto_skims__am_dist[_args[0], _args[1]], _inputs[1], _inputs[0], taxi_cost_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_fare_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK.py deleted file mode 100644 index f40744c..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_wait_time_OFFPEAK( - _args, - _inputs, - _outputs, - __ozone__taxi_wait_op -): - return __ozone__taxi_wait_op[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6.py deleted file mode 100644 index 0156f1a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __ozone__taxi_wait_op -): - return __ozone__taxi_wait_op[_args[0],] / __auto_skims__md_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_OFFPEAK_auto_dist_OFFPEAK_HC62HOLRZIWJJDAOIFX5XHV6.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK.py deleted file mode 100644 index 8a09c16..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_wait_time_PEAK( - _args, - _inputs, - _outputs, - __ozone__taxi_wait_pk -): - return __ozone__taxi_wait_pk[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2.py deleted file mode 100644 index 585a40a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __ozone__taxi_wait_pk -): - return __ozone__taxi_wait_pk[_args[0],] / __auto_skims__am_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_taxi_wait_time_PEAK_auto_dist_PEAK_CBYSKDURSGAJ4RHX2ASS76Q2.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_OFFPEAK.py deleted file mode 100644 index 90bf1df..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_fare_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __auto_skims__md_time -): - return tnc_cost(__auto_skims__md_time[_args[0], _args[1]], __auto_skims__md_dist[_args[0], _args[1]], _inputs[1], _inputs[0], tnc_pool_offpeak_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_PEAK.py deleted file mode 100644 index 68906b3..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_fare_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __auto_skims__am_time -): - return tnc_cost(__auto_skims__am_time[_args[0], _args[1]], __auto_skims__am_dist[_args[0], _args[1]], _inputs[1], _inputs[0], tnc_pool_peak_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_fare_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK.py deleted file mode 100644 index a190a78..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_wait_time_OFFPEAK( - _args, - _inputs, - _outputs, - __ozone__tnc_pool_wait_op -): - return __ozone__tnc_pool_wait_op[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB.py deleted file mode 100644 index 88e23d4..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __ozone__tnc_pool_wait_op -): - return __ozone__tnc_pool_wait_op[_args[0],] / __auto_skims__md_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_OFFPEAK_auto_dist_OFFPEAK_FNBOP5IL57Q6SQM4VB7EXQBB.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK.py deleted file mode 100644 index 8e749a2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_wait_time_PEAK( - _args, - _inputs, - _outputs, - __ozone__tnc_pool_wait_pk -): - return __ozone__tnc_pool_wait_pk[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV.py deleted file mode 100644 index 90bfa02..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __ozone__tnc_pool_wait_pk -): - return __ozone__tnc_pool_wait_pk[_args[0],] / __auto_skims__am_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_pool_wait_time_PEAK_auto_dist_PEAK_NHA453KUTMUKTUCSMA2XQQZV.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_OFFPEAK.py deleted file mode 100644 index 83a3231..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_fare_OFFPEAK( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __auto_skims__md_time -): - return tnc_cost(__auto_skims__md_time[_args[0], _args[1]], __auto_skims__md_dist[_args[0], _args[1]], _inputs[1], _inputs[0], tnc_solo_offpeak_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_PEAK.py deleted file mode 100644 index d6256cf..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_fare_PEAK( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __auto_skims__am_time -): - return tnc_cost(__auto_skims__am_time[_args[0], _args[1]], __auto_skims__am_dist[_args[0], _args[1]], _inputs[1], _inputs[0], tnc_solo_peak_struct) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_fare_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK.py deleted file mode 100644 index 8e40c74..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_wait_time_OFFPEAK( - _args, - _inputs, - _outputs, - __ozone__tnc_solo_wait_op -): - return __ozone__tnc_solo_wait_op[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO.py deleted file mode 100644 index ea179b2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO( - _args, - _inputs, - _outputs, - __auto_skims__md_dist, __ozone__tnc_solo_wait_op -): - return __ozone__tnc_solo_wait_op[_args[0],] / __auto_skims__md_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_OFFPEAK_auto_dist_OFFPEAK_CA5RZWRWZJWFNZATH2HHD3TO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK.py deleted file mode 100644 index d3a8667..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_wait_time_PEAK( - _args, - _inputs, - _outputs, - __ozone__tnc_solo_wait_pk -): - return __ozone__tnc_solo_wait_pk[_args[0],] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS.py deleted file mode 100644 index 7c55798..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS( - _args, - _inputs, - _outputs, - __auto_skims__am_dist, __ozone__tnc_solo_wait_pk -): - return __ozone__tnc_solo_wait_pk[_args[0],] / __auto_skims__am_dist[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_tnc_solo_wait_time_PEAK_auto_dist_PEAK_2EZZEATSM4EAHST74DMGSFSS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_OFFPEAK.py deleted file mode 100644 index e401cfc..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_fare_OFFPEAK( - _args, - _inputs, - _outputs, - __transit_op__fare -): - return __transit_op__fare[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_PEAK.py deleted file mode 100644 index 3f1b119..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_fare_PEAK( - _args, - _inputs, - _outputs, - __transit_pk__fare -): - return __transit_pk__fare[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_fare_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_OFFPEAK.py deleted file mode 100644 index 5862f24..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ivtt_OFFPEAK( - _args, - _inputs, - _outputs, - __transit_op__ivtt -): - return __transit_op__ivtt[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_PEAK.py deleted file mode 100644 index 09e64ce..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ivtt_PEAK( - _args, - _inputs, - _outputs, - __transit_pk__ivtt -): - return __transit_pk__ivtt[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ivtt_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_OFFPEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_OFFPEAK.py deleted file mode 100644 index d149882..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_OFFPEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ovtt_OFFPEAK( - _args, - _inputs, - _outputs, - __transit_op__ovtt -): - return __transit_op__ovtt[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_OFFPEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_OFFPEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_PEAK.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_PEAK.py deleted file mode 100644 index 3a13606..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_PEAK.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid -from .extra_funcs import * -from .extra_vars import * - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ovtt_PEAK( - _args, - _inputs, - _outputs, - __transit_pk__ovtt -): - return __transit_pk__ovtt[_args[0], _args[1]] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_PEAK.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S1/f_transit_ovtt_PEAK.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/__init__.py deleted file mode 100644 index a7c1930..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/__init__.py +++ /dev/null @@ -1,312 +0,0 @@ -import numba -import numpy as np - -from .f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX import transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX -from .f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S import transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S -from .f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J import transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J -from .f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP import transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP -from .f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73 import transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73 -from .f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM import transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM -from .f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2 import transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2 -from .f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V import transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V -from .f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST import hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST -from .f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO import hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO -from .f_auto_parking_cost_HBWH import auto_parking_cost_HBWH -from .f_auto_parking_cost_HBWL import auto_parking_cost_HBWL -from .f_auto_parking_cost_HBO import auto_parking_cost_HBO -from .f_auto_parking_cost_HBS import auto_parking_cost_HBS -from .f_auto_parking_cost_NHB import auto_parking_cost_NHB -from .f_auto_parking_cost_HBOR import auto_parking_cost_HBOR -from .f_auto_parking_cost_NHBR import auto_parking_cost_NHBR -from .f_auto_parking_cost_NHBS import auto_parking_cost_NHBS -from .f_samp_wgt import samp_wgt -from .f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL import log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL -from .f_transit_avail_HBWH import transit_avail_HBWH -from .f_transit_avail_HBWL import transit_avail_HBWL -from .f_transit_avail_HBS import transit_avail_HBS -from .f_transit_avail_HBO import transit_avail_HBO -from .f_transit_avail_NHB import transit_avail_NHB -from .f_auto_avail_HBWH import auto_avail_HBWH -from .f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3 import _1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3 -from .f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE import _1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE -from .f_auto_avail_HBWL import auto_avail_HBWL -from .f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63 import _1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63 -from .f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2 import _1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2 -from .f_auto_avail_HBS import auto_avail_HBS -from .f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX import _1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX -from .f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6 import _1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6 -from .f_auto_avail_HBO import auto_avail_HBO -from .f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX import _1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX -from .f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY import _1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY -from .f_auto_avail_NHB import auto_avail_NHB -from .f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6 import _1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6 -from .f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF import _1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF - - -@numba.jit(cache=True, parallel=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def runner(argarray, inputarray, dtype=np.float64, min_shape_0=0): - out_size = max(argarray.shape[0], min_shape_0) - if out_size != argarray.shape[0]: - result = np.zeros((out_size, 40), dtype=dtype) - else: - result = np.empty((out_size, 40), dtype=dtype) - if out_size > 1000: - for j in numba.prange(out_size): - result[j, 0] = transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX(argarray[j], inputarray[j], result[j], ) - result[j, 1] = transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S(argarray[j], inputarray[j], result[j], ) - result[j, 2] = transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J(argarray[j], inputarray[j], result[j], ) - result[j, 3] = transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP(argarray[j], inputarray[j], result[j], ) - result[j, 4] = transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73(argarray[j], inputarray[j], result[j], ) - result[j, 5] = transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM(argarray[j], inputarray[j], result[j], ) - result[j, 6] = transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2(argarray[j], inputarray[j], result[j], ) - result[j, 7] = transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V(argarray[j], inputarray[j], result[j], ) - result[j, 8] = hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST(argarray[j], inputarray[j], result[j], ) - result[j, 9] = hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO(argarray[j], inputarray[j], result[j], ) - result[j, 10] = auto_parking_cost_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 11] = auto_parking_cost_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 12] = auto_parking_cost_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 13] = auto_parking_cost_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 14] = auto_parking_cost_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 15] = auto_parking_cost_HBOR(argarray[j], inputarray[j], result[j], ) - result[j, 16] = auto_parking_cost_NHBR(argarray[j], inputarray[j], result[j], ) - result[j, 17] = auto_parking_cost_NHBS(argarray[j], inputarray[j], result[j], ) - result[j, 18] = samp_wgt(argarray[j], inputarray[j], result[j], ) - result[j, 19] = log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL(argarray[j], inputarray[j], result[j], ) - result[j, 20] = transit_avail_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 21] = transit_avail_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 22] = transit_avail_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 23] = transit_avail_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 24] = transit_avail_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 25] = auto_avail_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 26] = _1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3(argarray[j], inputarray[j], result[j], ) - result[j, 27] = _1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE(argarray[j], inputarray[j], result[j], ) - result[j, 28] = auto_avail_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 29] = _1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63(argarray[j], inputarray[j], result[j], ) - result[j, 30] = _1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2(argarray[j], inputarray[j], result[j], ) - result[j, 31] = auto_avail_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 32] = _1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX(argarray[j], inputarray[j], result[j], ) - result[j, 33] = _1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6(argarray[j], inputarray[j], result[j], ) - result[j, 34] = auto_avail_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 35] = _1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX(argarray[j], inputarray[j], result[j], ) - result[j, 36] = _1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY(argarray[j], inputarray[j], result[j], ) - result[j, 37] = auto_avail_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 38] = _1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6(argarray[j], inputarray[j], result[j], ) - result[j, 39] = _1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF(argarray[j], inputarray[j], result[j], ) - else: - for j in range(out_size): - result[j, 0] = transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX(argarray[j], inputarray[j], result[j], ) - result[j, 1] = transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S(argarray[j], inputarray[j], result[j], ) - result[j, 2] = transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J(argarray[j], inputarray[j], result[j], ) - result[j, 3] = transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP(argarray[j], inputarray[j], result[j], ) - result[j, 4] = transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73(argarray[j], inputarray[j], result[j], ) - result[j, 5] = transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM(argarray[j], inputarray[j], result[j], ) - result[j, 6] = transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2(argarray[j], inputarray[j], result[j], ) - result[j, 7] = transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V(argarray[j], inputarray[j], result[j], ) - result[j, 8] = hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST(argarray[j], inputarray[j], result[j], ) - result[j, 9] = hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO(argarray[j], inputarray[j], result[j], ) - result[j, 10] = auto_parking_cost_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 11] = auto_parking_cost_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 12] = auto_parking_cost_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 13] = auto_parking_cost_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 14] = auto_parking_cost_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 15] = auto_parking_cost_HBOR(argarray[j], inputarray[j], result[j], ) - result[j, 16] = auto_parking_cost_NHBR(argarray[j], inputarray[j], result[j], ) - result[j, 17] = auto_parking_cost_NHBS(argarray[j], inputarray[j], result[j], ) - result[j, 18] = samp_wgt(argarray[j], inputarray[j], result[j], ) - result[j, 19] = log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL(argarray[j], inputarray[j], result[j], ) - result[j, 20] = transit_avail_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 21] = transit_avail_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 22] = transit_avail_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 23] = transit_avail_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 24] = transit_avail_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 25] = auto_avail_HBWH(argarray[j], inputarray[j], result[j], ) - result[j, 26] = _1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3(argarray[j], inputarray[j], result[j], ) - result[j, 27] = _1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE(argarray[j], inputarray[j], result[j], ) - result[j, 28] = auto_avail_HBWL(argarray[j], inputarray[j], result[j], ) - result[j, 29] = _1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63(argarray[j], inputarray[j], result[j], ) - result[j, 30] = _1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2(argarray[j], inputarray[j], result[j], ) - result[j, 31] = auto_avail_HBS(argarray[j], inputarray[j], result[j], ) - result[j, 32] = _1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX(argarray[j], inputarray[j], result[j], ) - result[j, 33] = _1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6(argarray[j], inputarray[j], result[j], ) - result[j, 34] = auto_avail_HBO(argarray[j], inputarray[j], result[j], ) - result[j, 35] = _1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX(argarray[j], inputarray[j], result[j], ) - result[j, 36] = _1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY(argarray[j], inputarray[j], result[j], ) - result[j, 37] = auto_avail_NHB(argarray[j], inputarray[j], result[j], ) - result[j, 38] = _1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6(argarray[j], inputarray[j], result[j], ) - result[j, 39] = _1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF(argarray[j], inputarray[j], result[j], ) - return result - -def _map_index(dim_name, values): - raise KeyError(dim_name) - - -def set_shared_data(): - global name_space - name_space = {} - - -meta_match_names_idx = {} - - -import numpy as np -import numba as nb -import pandas as pd -import pyarrow as pa -import xarray as xr -import sharrow as sh -import inspect -import warnings -from contextlib import suppress - - - - -def load_raw(args, inputs, name_space, runner, dtype=None): - with warnings.catch_warnings(): - warnings.filterwarnings('ignore', category=nb.NumbaExperimentalFeatureWarning) - if len(args): - assembled_args = np.stack(args).T - else: - assembled_args = None - if len(inputs): - assembled_inputs = np.stack(inputs).T - else: - assembled_inputs = np.empty([assembled_args.shape[0], 0], dtype=np.float32) - if assembled_args is None: - assembled_args = np.empty([assembled_inputs.shape[0], 0], dtype=np.float32) - try: - named_args = [] - arguments = [] - for arg in named_args: - next_arg = name_space[arg] - if isinstance(next_arg, xr.DataArray): - next_arg = next_arg.load() - arguments.append(np.asarray(next_arg)) - if dtype is not None: - return runner(assembled_args, assembled_inputs, *arguments, dtype=dtype) - else: - return runner(assembled_args, assembled_inputs, *arguments) - except nb.TypingError: - raise - except KeyError as err: - # raise the inner key error which is more helpful - context = getattr(err, "__context__", None) - if context: - raise context - else: - raise err - - -def load( - source, - as_dataframe=False, - as_table=False, - dtype=None, -): - if source is None: - raise ValueError("no base table or source table") - indexes = _get_indexes(source)[0] - inputs = _get_inputs(source) - result = load_raw(indexes, inputs, name_space, runner=runner, dtype=dtype) - if as_dataframe: - index = getattr(source, 'index', None) - return pd.DataFrame(result, index=index, columns=function_names) - elif as_table: - return pa.table({k: result[:, n] for n, k in enumerate(function_names)}) - return result - - -def merge(source, dtype=None): - """ - Merge the data created by this flow into the source. - - Parameters - ---------- - source : Dataset or Table or DataFrame - dtype : str or dtype - The loaded data will be generated with this dtype. - - Returns - ------- - merged : Dataset or Table or DataFrame - The same data type as `source` is returned. - """ - assert isinstance(source, (xr.Dataset, pa.Table, pd.DataFrame, sh.Table)) - new_cols = load(source, dtype=dtype) - if isinstance(source, (pa.Table, sh.Table)): - for n, k in enumerate(function_names): - source = source.append_column(k, [new_cols[:, n]]) - else: - for n, k in enumerate(function_names): - source[k] = new_cols[:, n] - return source - - -def _get_indexes(source_table, cache_dynamic_indexes=None): - if cache_dynamic_indexes is None: - cache_dynamic_indexes = True - - def geti(i): - nonlocal source_table - if i is not None: - try: - return np.asarray(source_table[i]) - except KeyError: - if i[:10] == '__dynamic_': - if "@" in i: - i_complete = i - i, i_from = i.split("@", 1) - else: - i_complete = i - i_from = i[10:] - index_to_map = None - with suppress(KeyError): - index_to_map = source_table[i_from] - if index_to_map is None: - if isinstance(source_table, pd.DataFrame): - if i_from == "index" and source_table.index.names == [None]: - index_to_map = source_table.index - elif i_from in source_table.index.names: - index_to_map = source_table.index.get_level_values(i_from) - if index_to_map is None: - raise KeyError(i_complete) - indexed_vals = _map_index(i[10:], index_to_map) - if cache_dynamic_indexes: - if isinstance(source_table, (pa.Table)): - source_table = source_table.append_column(i_complete, [indexed_vals]) - else: - source_table[i_complete] = indexed_vals - return indexed_vals - else: - idx = getattr(source_table, 'index', None) - if idx is not None: - if i in idx.names: - return np.asarray(idx.get_level_values(i)) - if i == 'index' and len(idx.names)==1: - return np.asarray(idx) - raise - else: - return np.arange(source_table.shape[0]) - index_keys = meta_match_names_idx.keys() - return tuple(geti(i) for i in index_keys), source_table - - -def _get_inputs(source_table, dtype=np.float32): - input_keys = input_name_positions.keys() - return tuple( - np.asarray(source_table[i], dtype=dtype) - for i in input_keys - ) - - - -input_name_positions = {'auto_dist_OFFPEAK': 0, 'auto_dist_PEAK': 1, 'log_attractions_HBO': 2, 'log_attractions_HBS': 3, 'log_attractions_HBWH': 4, 'log_attractions_HBWL': 5, 'log_attractions_NHB': 6, 'transit_approach_drivetime_OFFPEAK': 7, 'transit_approach_drivetime_PEAK': 8, 'transit_approach_waittime_OFFPEAK': 9, 'transit_approach_waittime_PEAK': 10, 'transit_approach_walktime_OFFPEAK': 11, 'transit_approach_walktime_PEAK': 12, 'transit_ivtt_OFFPEAK': 13, 'transit_ivtt_PEAK': 14, 'transit_ovtt_OFFPEAK': 15, 'transit_ovtt_PEAK': 16} -function_names = ['transit_approach_drivetime_PEAK/auto_dist_PEAK', 'transit_approach_waittime_PEAK/auto_dist_PEAK', 'transit_approach_walktime_PEAK/auto_dist_PEAK', 'transit_ovtt_PEAK/auto_dist_PEAK', 'transit_approach_drivetime_OFFPEAK/auto_dist_OFFPEAK', 'transit_approach_waittime_OFFPEAK/auto_dist_OFFPEAK', 'transit_approach_walktime_OFFPEAK/auto_dist_OFFPEAK', 'transit_ovtt_OFFPEAK/auto_dist_OFFPEAK', 'hard_sigmoid(transit_approach_walktime_PEAK, 4.0, 2.0)', 'hard_sigmoid(transit_approach_walktime_OFFPEAK, 4.0, 2.0)', 'auto_parking_cost_HBWH', 'auto_parking_cost_HBWL', 'auto_parking_cost_HBO', 'auto_parking_cost_HBS', 'auto_parking_cost_NHB', 'auto_parking_cost_HBOR', 'auto_parking_cost_NHBR', 'auto_parking_cost_NHBS', 'samp_wgt', 'log(1/samp_wgt)', 'transit_avail_HBWH', 'transit_avail_HBWL', 'transit_avail_HBS', 'transit_avail_HBO', 'transit_avail_NHB', 'auto_avail_HBWH', '1-auto_avail_HBWH', '1-transit_avail_HBWH', 'auto_avail_HBWL', '1-auto_avail_HBWL', '1-transit_avail_HBWL', 'auto_avail_HBS', '1-auto_avail_HBS', '1-transit_avail_HBS', 'auto_avail_HBO', '1-auto_avail_HBO', '1-transit_avail_HBO', 'auto_avail_NHB', '1-auto_avail_NHB', '1-transit_avail_NHB'] - -# Greetings, tinkerer! The `defs_hash` included here is a safety -# measure to prevent unknowing users creating a mess by modifying -# the code in this module so that it no longer matches the expected -# variable definitions. If you want to modify this code, you should -# delete this hash to allow the code to run without any checks, but -# you do so at your own risk. -defs_hash = 'JLORNT6V2GU5GKGOGY25DSK2SA======' diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/__init__.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/__init__.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX.py deleted file mode 100644 index 196f0d0..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[34] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBO_EKWWH33ZEA3VXLR4UYBVLRUX.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX.py deleted file mode 100644 index 6021d18..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[31] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBS_JA6SY3LPJJDVZQF7IFNL4EWX.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3.py deleted file mode 100644 index 50955fe..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[25] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWH_RSSCN3EFDQ2CM4RPVZVAP7K3.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63.py deleted file mode 100644 index 7bae017..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[28] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_HBWL_VWN3Q4WQRAVVJ5ZTYY4OHM63.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6.py deleted file mode 100644 index 01950cd..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[37] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_auto_avail_NHB_XHHWLREMVWOEBM6NUQF7EFH6.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY.py deleted file mode 100644 index 62e033c..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[23] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBO_K3RWOEPC3IXNAPRPQQJCHORY.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6.py deleted file mode 100644 index 8e1bdce..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[22] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBS_5CZV3HKDPQJDWZME2XMN7NW6.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE.py deleted file mode 100644 index 905c093..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[20] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWH_NMEWQX35KIWZJMZ5IZZTZHOE.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2.py deleted file mode 100644 index 132b894..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[21] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_HBWL_MPZ7IOPMILS7SZEG5T2D6HG2.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF.py deleted file mode 100644 index 15d6136..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def _1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF( - _args, - _inputs, - _outputs, - -): - return 1 - _outputs[24] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f__1_transit_avail_NHB_WN7OPNQOSVQ544PG5Q2ZGTNF.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBO.py deleted file mode 100644 index 97f64e8..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_avail_HBO( - _args, - _inputs, - _outputs, - -): - return _inputs[2] > -9998 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBS.py deleted file mode 100644 index efa8332..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_avail_HBS( - _args, - _inputs, - _outputs, - -): - return _inputs[3] > -9998 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWH.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWH.py deleted file mode 100644 index 003f33a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWH.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_avail_HBWH( - _args, - _inputs, - _outputs, - -): - return _inputs[4] > -9998 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWH.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWH.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWL.py deleted file mode 100644 index 2c4dd9b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_avail_HBWL( - _args, - _inputs, - _outputs, - -): - return _inputs[5] > -9998 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_HBWL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_NHB.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_NHB.py deleted file mode 100644 index 212f7a2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_NHB.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_avail_NHB( - _args, - _inputs, - _outputs, - -): - return _inputs[6] > -9998 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_NHB.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_avail_NHB.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBO.py deleted file mode 100644 index e672b1f..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_HBO( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBOR.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBOR.py deleted file mode 100644 index 66268b7..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBOR.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_HBOR( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBOR.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBOR.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBS.py deleted file mode 100644 index df6d3ab..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_HBS( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWH.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWH.py deleted file mode 100644 index 0191aa2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWH.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_HBWH( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWH.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWH.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWL.py deleted file mode 100644 index bb94bb2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_HBWL( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_HBWL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHB.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHB.py deleted file mode 100644 index d08c175..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHB.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_NHB( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHB.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHB.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBR.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBR.py deleted file mode 100644 index 47c2972..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBR.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_NHBR( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBR.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBR.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBS.py deleted file mode 100644 index 2b02df6..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def auto_parking_cost_NHBS( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_auto_parking_cost_NHBS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO.py deleted file mode 100644 index fac81d8..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO( - _args, - _inputs, - _outputs, - -): - return hard_sigmoid(_inputs[11], 4.0, 2.0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_OFFPEAK__4_0__2_0__FPYQ4GNCVUNJNUMJTUIBMLKO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST.py deleted file mode 100644 index e0bd3be..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST( - _args, - _inputs, - _outputs, - -): - return hard_sigmoid(_inputs[12], 4.0, 2.0) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_hard_sigmoid_transit_approach_walktime_PEAK__4_0__2_0__AJ26DYAVZX7MOBOG5SOJABST.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL.py deleted file mode 100644 index 571d66e..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL( - _args, - _inputs, - _outputs, - -): - return 0.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_log_1_samp_wgt__PLSMOODNF77UOPHIVH6I2WBL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_samp_wgt.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_samp_wgt.py deleted file mode 100644 index 24f6e4a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_samp_wgt.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def samp_wgt( - _args, - _inputs, - _outputs, - -): - return 1.0 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_samp_wgt.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_samp_wgt.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73.py deleted file mode 100644 index ec46953..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73( - _args, - _inputs, - _outputs, - -): - return _inputs[7] / _inputs[0] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_OFFPEAK_auto_dist_OFFPEAK_U2242PIA3ZL4MJS726HCCG73.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX.py deleted file mode 100644 index 607fb27..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX( - _args, - _inputs, - _outputs, - -): - return _inputs[8] / _inputs[1] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_drivetime_PEAK_auto_dist_PEAK_SVETJXGBSVYEYM7OVBAQW2PX.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM.py deleted file mode 100644 index 79f01ca..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM( - _args, - _inputs, - _outputs, - -): - return _inputs[9] / _inputs[0] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_OFFPEAK_auto_dist_OFFPEAK_22UIGWVENT7RTALQKKOHEPXM.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S.py deleted file mode 100644 index 1d62e39..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S( - _args, - _inputs, - _outputs, - -): - return _inputs[10] / _inputs[1] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_waittime_PEAK_auto_dist_PEAK_YHJNF2B3VEICSZL64Y2XLV4S.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2.py deleted file mode 100644 index 71aa571..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2( - _args, - _inputs, - _outputs, - -): - return _inputs[11] / _inputs[0] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_OFFPEAK_auto_dist_OFFPEAK_ITAE2YOSBIY76DBTPIPT6QD2.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J.py deleted file mode 100644 index 3c18880..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J( - _args, - _inputs, - _outputs, - -): - return _inputs[12] / _inputs[1] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_approach_walktime_PEAK_auto_dist_PEAK_T52CC4SUBMFSLGDNMCSO7A7J.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBO.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBO.py deleted file mode 100644 index 1486d27..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBO.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_avail_HBO( - _args, - _inputs, - _outputs, - -): - return (_inputs[13] < 999) & (_inputs[11] < 999) & (_inputs[7] < 999) & (_inputs[2] > -9998) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBO.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBO.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBS.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBS.py deleted file mode 100644 index cfd01f6..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBS.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_avail_HBS( - _args, - _inputs, - _outputs, - -): - return (_inputs[13] < 999) & (_inputs[11] < 999) & (_inputs[7] < 999) & (_inputs[3] > -9998) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBS.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBS.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWH.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWH.py deleted file mode 100644 index 3a39e56..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWH.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_avail_HBWH( - _args, - _inputs, - _outputs, - -): - return (_inputs[14] < 999) & (_inputs[12] < 999) & (_inputs[8] < 999) & (_inputs[4] > -9998) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWH.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWH.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWL.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWL.py deleted file mode 100644 index 9ae5ea4..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWL.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_avail_HBWL( - _args, - _inputs, - _outputs, - -): - return (_inputs[14] < 999) & (_inputs[12] < 999) & (_inputs[8] < 999) & (_inputs[5] > -9998) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWL.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_HBWL.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_NHB.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_NHB.py deleted file mode 100644 index a6d4ee2..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_NHB.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_avail_NHB( - _args, - _inputs, - _outputs, - -): - return (_inputs[13] < 999) & (_inputs[11] < 999) & (_inputs[7] < 999) & (_inputs[6] > -9998) diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_NHB.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_avail_NHB.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V.py deleted file mode 100644 index 530c3d6..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V( - _args, - _inputs, - _outputs, - -): - return _inputs[15] / _inputs[0] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_OFFPEAK_auto_dist_OFFPEAK_IY4UAVBMS2HPHNYZJLSMWG3V.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP.py b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP.py deleted file mode 100644 index f9af209..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP.py +++ /dev/null @@ -1,16 +0,0 @@ - -import numba -import numpy as np -from numpy import log, exp, log1p, expm1 -from sharrow.maths import piece, hard_sigmoid - - - -@numba.jit(cache=True, error_model='numpy', boundscheck=False, nopython=True, fastmath=True) -def transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP( - _args, - _inputs, - _outputs, - -): - return _inputs[16] / _inputs[1] diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP.py.lock b/src/Mode-Dest-TOD/cmap_modedest/fast/__sc/S2/f_transit_ovtt_PEAK_auto_dist_PEAK_UIAXX4VIE5PP53PJMCSMEFOP.py.lock deleted file mode 100755 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/application_data.py b/src/Mode-Dest-TOD/cmap_modedest/fast/application_data.py deleted file mode 100644 index 8d839fe..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/application_data.py +++ /dev/null @@ -1,335 +0,0 @@ -import larch -import numpy as np -from numba import njit, vectorize -import pandas as pd -import pyarrow as pa -from sharrow import Dataset, SharedData, Table, local_cache - -from .tnc_los import tnc_los_functions, taxi_cost, tnc_cost -from ..cmap_logging import getLogger, getSubLogger -from ..purposes import purposesA -log = getLogger() - -def application_data(dh): - """ - This function precompiles the application data flow. - - It includes a bunch of random data formatted the same manner as the real - data will be, so that the code can be optimized ahead of time. - - Parameters - ---------- - dh - - Returns - ------- - sharrow.Flow - """ - log = getSubLogger("fast.application_data") - - log.info("preparing application data") - - #taxi_cost, tnc_solo_cost, tnc_pool_cost = \ - tnc_los_functions(dh) - - otazi, dtazi = np.random.choice(3000, 60000), np.random.choice(3000, 60000) - - tbl = Table({ - 'otaz_idx': otazi, - 'dtaz_idx': dtazi, - 'otaz': otazi + 1, - 'dtaz': dtazi + 1, - 'chooser_row': np.arange(otazi.size) - }) - - ozones = Dataset.from_dataframe( - dh.m01.set_index( - dh.m01.index.rename("otaz"), - ), - ).squash_index(otaz='otaz_idx') - - attractions = Dataset.from_dataframe( - dh.trip_attractions5.astype(np.float64).set_index( - dh.trip_attractions5.index.rename("dtaz"), - ), - ).squash_index(dtaz='dtaz_idx') - - omx_auto = dh.skims.raw.select_and_rename( - {v:k for k,v in dh.skims.auto.col_mapping.items()} - ).squash_index(otaz='otaz_idx', dtaz='dtaz_idx') - - # inject intrazonal distance into auto skims - # set intrazonal auto_dist - intrazonal_zone_area = dh.zone_shp.area # square feet - intrazonal_dist = np.sqrt(intrazonal_zone_area) / 5280 * 0.667 - np.fill_diagonal( - omx_auto['am_dist'].values, - intrazonal_dist, - ) - np.fill_diagonal( - omx_auto['md_dist'].values, - intrazonal_dist, - ) - - omx_transit_pk = dh.skims.raw.select_and_rename( - {v:k for k,v in dh.skims.transit_pk.col_mapping.items()} - ).squash_index(otaz='otaz_idx', dtaz='dtaz_idx') - - omx_transit_op = dh.skims.raw.select_and_rename( - {v:k for k,v in dh.skims.transit_op.col_mapping.items()} - ).squash_index(otaz='otaz_idx', dtaz='dtaz_idx') - - # load lastest computed autopropensity as a pd.DataFrame - from ..data_handlers.m01_handler import attach_areatypes - autopropensity = attach_areatypes( - dh, - pd.DataFrame(index=dh.m01.index), - "", - "", - targetzone=dh.m01.index, - )[['autopropensity']] - o_autopropensity = Dataset.from_dataframe( - autopropensity.set_index( - autopropensity.index.rename("otaz"), - ) - ).squash_index(otaz='otaz_idx') - d_autopropensity = Dataset.from_dataframe( - autopropensity.set_index( - autopropensity.index.rename("dtaz"), - ) - ).squash_index(dtaz='dtaz_idx') - - - tg = SharedData( - tbl, - **{ - 'transit_pk': omx_transit_pk, - 'transit_op': omx_transit_op, - 'auto_skims': omx_auto, - 'ozone': ozones, - 'dzone': ozones.set_match_names({"otaz_idx":'dtaz_idx'}), - 'attractions': attractions, - 'o_autopropensity': o_autopropensity, - 'd_autopropensity': d_autopropensity, - }, - extra_funcs=( - taxi_cost, tnc_cost, - ), - extra_vars=dict( - taxi_cost_struct=dh.cfg['taxi_cost_struct'], - tnc_solo_peak_struct=dh.cfg['tnc_cost_struct_solo_peak'], - tnc_solo_offpeak_struct=dh.cfg['tnc_cost_struct_solo_peak'], - tnc_pool_peak_struct=dh.cfg['tnc_cost_struct_pool_peak'], - tnc_pool_offpeak_struct=dh.cfg['tnc_cost_struct_pool_peak'], - ), - ) - - log.info("setup application data flow") - ss = tg.setup_flow({ - - 'o_zone == dtaz': 'otaz == dtaz', #### fails dtype - - 'transit_ivtt_PEAK' : 'transit_pk.ivtt', - 'transit_ivtt_OFFPEAK': 'transit_op.ivtt', - 'transit_ovtt_PEAK' : 'transit_pk.ovtt', - 'transit_ovtt_OFFPEAK': 'transit_op.ovtt', - 'transit_fare_PEAK' : 'transit_pk.fare', - 'transit_fare_OFFPEAK': 'transit_op.fare', - - 'piece(transit_ivtt_OFFPEAK, None, 20)': 'piece(transit_ivtt_OFFPEAK, None, 20)', - 'piece(transit_ivtt_OFFPEAK, 20, None)': 'piece(transit_ivtt_OFFPEAK, 20, None)', - 'autopropensity': 'd_autopropensity.autopropensity', - - 'auto_time_PEAK': 'auto_skims.am_time', - 'auto_dist_PEAK': 'auto_skims.am_dist', - 'auto_time_OFFPEAK': 'auto_skims.md_time', - 'auto_dist_OFFPEAK': 'auto_skims.md_dist', - 'auto_opcost_PEAK': 'auto_skims.am_opcost', - 'auto_opcost_hov_PEAK': 'auto_skims.am_opcost_hov', - 'auto_opcost_OFFPEAK': 'auto_skims.md_opcost', - 'auto_toll_hiinc_PEAK': 'np.fmax(auto_skims.am_toll_hiinc, 0)', - 'auto_toll_loinc_PEAK': 'np.fmax(auto_skims.am_toll_loinc, 0)', - 'auto_toll_hov_hiinc_PEAK': 'np.fmax(auto_skims.am_toll_hov_hiinc, 0)', - 'auto_toll_hov_loinc_PEAK': 'np.fmax(auto_skims.am_toll_hov_loinc, 0)', - 'auto_toll_OFFPEAK': 'np.fmax(auto_skims.md_toll, 0)', - - 'piece(auto_dist_PEAK,None,0.5)': 'piece(auto_skims.am_dist,None,0.5)', - 'piece(auto_dist_PEAK,0.5,1.0)' : 'piece(auto_skims.am_dist,0.5,1.0)', - 'piece(auto_dist_PEAK,1.0,None)': 'piece(auto_skims.am_dist,1.0,None)', - 'piece(auto_dist_PEAK,None,5)' : 'piece(auto_skims.am_dist,None,5)', - 'piece(auto_dist_PEAK,5,10)' : 'piece(auto_skims.am_dist,5,10)', - 'piece(auto_dist_PEAK,10,None)' : 'piece(auto_skims.am_dist,10,None)', - - 'piece(auto_dist_OFFPEAK,None,0.5)': 'piece(auto_skims.md_dist,None,0.5)', - 'piece(auto_dist_OFFPEAK,0.5,1.0)' : 'piece(auto_skims.md_dist,0.5,1.0)', - 'piece(auto_dist_OFFPEAK,1.0,None)': 'piece(auto_skims.md_dist,1.0,None)', - 'piece(auto_dist_OFFPEAK,None,5)' : 'piece(auto_skims.md_dist,None,5)', - 'piece(auto_dist_OFFPEAK,5,10)' : 'piece(auto_skims.md_dist,5,10)', - 'piece(auto_dist_OFFPEAK,10,None)' : 'piece(auto_skims.md_dist,10,None)', - - 'taxi_fare_PEAK': 'taxi_cost(auto_skims.am_time, auto_skims.am_dist, otaz, dtaz, taxi_cost_struct)', - 'taxi_fare_OFFPEAK': 'taxi_cost(auto_skims.md_time, auto_skims.md_dist, otaz, dtaz, taxi_cost_struct)', - 'tnc_solo_fare_PEAK': 'tnc_cost(auto_skims.am_time, auto_skims.am_dist, otaz, dtaz, tnc_solo_peak_struct)', - 'tnc_solo_fare_OFFPEAK': 'tnc_cost(auto_skims.md_time, auto_skims.md_dist, otaz, dtaz, tnc_solo_offpeak_struct)', - 'tnc_pool_fare_PEAK': 'tnc_cost(auto_skims.am_time, auto_skims.am_dist, otaz, dtaz, tnc_pool_peak_struct)', - 'tnc_pool_fare_OFFPEAK': 'tnc_cost(auto_skims.md_time, auto_skims.md_dist, otaz, dtaz, tnc_pool_offpeak_struct)', - - 'taxi_wait_time_PEAK' : 'ozone.taxi_wait_pk', - 'taxi_wait_time_OFFPEAK' : 'ozone.taxi_wait_op', - 'tnc_solo_wait_time_PEAK' : 'ozone.tnc_solo_wait_pk', - 'tnc_solo_wait_time_OFFPEAK': 'ozone.tnc_solo_wait_op', - 'tnc_pool_wait_time_PEAK' : 'ozone.tnc_pool_wait_pk', - 'tnc_pool_wait_time_OFFPEAK': 'ozone.tnc_pool_wait_op', - - 'taxi_wait_time_PEAK/auto_dist_PEAK' : 'ozone.taxi_wait_pk/auto_skims.am_dist', - 'taxi_wait_time_OFFPEAK/auto_dist_OFFPEAK' : 'ozone.taxi_wait_op/auto_skims.md_dist', - 'tnc_solo_wait_time_PEAK/auto_dist_PEAK' : 'ozone.tnc_solo_wait_pk/auto_skims.am_dist', - 'tnc_solo_wait_time_OFFPEAK/auto_dist_OFFPEAK': 'ozone.tnc_solo_wait_op/auto_skims.md_dist', - 'tnc_pool_wait_time_PEAK/auto_dist_PEAK' : 'ozone.tnc_pool_wait_pk/auto_skims.am_dist', - 'tnc_pool_wait_time_OFFPEAK/auto_dist_OFFPEAK': 'ozone.tnc_pool_wait_op/auto_skims.md_dist', - - 'fmax(ozone_areatype, areatype)==1': 'max(ozone.zone_type, dzone.zone_type)==1', - 'fmax(ozone_areatype, areatype)==2': 'max(ozone.zone_type, dzone.zone_type)==2', - 'fmax(ozone_areatype, areatype)==3': 'max(ozone.zone_type, dzone.zone_type)==3', - 'fmax(ozone_areatype, areatype)==4': 'max(ozone.zone_type, dzone.zone_type)==4', - - 'fmin(ozone_areatype, areatype)==1': 'min(ozone.zone_type, dzone.zone_type)==1', - 'fmin(ozone_areatype, areatype)==2': 'min(ozone.zone_type, dzone.zone_type)==2', - 'fmin(ozone_areatype, areatype)==3': 'min(ozone.zone_type, dzone.zone_type)==3', - 'fmin(ozone_areatype, areatype)==4': 'min(ozone.zone_type, dzone.zone_type)==4', - - 'log_attractions_HBWH': 'log(attractions.HBWH)', - 'log_attractions_HBWL': 'log(attractions.HBWL)', - 'log_attractions_HBS': 'log(attractions.HBS)', - 'log_attractions_HBO': 'log(attractions.HBO)', - 'log_attractions_NHB': 'log(attractions.NHB)', - # 'log_attractions_HBOR': 'log(attractions.HBOR)', - # 'log_attractions_NHBR': 'log(attractions.NHBR)', - # 'log_attractions_NHBS': 'log(attractions.NHBS)', - - 'log_attractions_HBWH > -666': 'log(attractions.HBWH) > -666', - 'log_attractions_HBWL > -666': 'log(attractions.HBWL) > -666', - 'log_attractions_HBS > -666': 'log(attractions.HBS) > -666', - 'log_attractions_HBO > -666': 'log(attractions.HBO) > -666', - 'log_attractions_NHB > -666': 'log(attractions.NHB) > -666', - # 'log_attractions_HBOR > -666': 'log(attractions.HBOR) > -666', - # 'log_attractions_NHBR > -666': 'log(attractions.NHBR) > -666', - # 'log_attractions_NHBS > -666': 'log(attractions.NHBS) > -666', - - }, dtype="float64", cache_dir=local_cache(), name="S1") - - try: - log.debug("load first run") - df = ss.load(tbl, as_dataframe=True, dtype=np.float64) - log.debug("load second run") - df2 = ss.load(tbl, as_dataframe=True, dtype=np.float64) - log.debug("check first and second run are equal") - try: - pd.testing.assert_frame_equal(df, df2) - except AssertionError as err: - log.exception(err) - # from ..cmap_logging import log_df - # log_df(df2, logger=log, verbose=1, level=10) - - return ss - finally: - log.info("application_data flow ready") - - - - -def application_data2(dh, in_table): - log = getSubLogger("fast.application_data2") - log.info("prepare application_data2") - - coldefs = { - - 'transit_approach_drivetime_PEAK/auto_dist_PEAK': f'transit_approach_drivetime_PEAK/auto_dist_PEAK', - 'transit_approach_waittime_PEAK/auto_dist_PEAK': f'transit_approach_waittime_PEAK/auto_dist_PEAK', - 'transit_approach_walktime_PEAK/auto_dist_PEAK': f'transit_approach_walktime_PEAK/auto_dist_PEAK', - 'transit_ovtt_PEAK/auto_dist_PEAK': f'transit_ovtt_PEAK/auto_dist_PEAK', - - 'transit_approach_drivetime_OFFPEAK/auto_dist_OFFPEAK': f'transit_approach_drivetime_OFFPEAK/auto_dist_OFFPEAK', - 'transit_approach_waittime_OFFPEAK/auto_dist_OFFPEAK': f'transit_approach_waittime_OFFPEAK/auto_dist_OFFPEAK', - 'transit_approach_walktime_OFFPEAK/auto_dist_OFFPEAK': f'transit_approach_walktime_OFFPEAK/auto_dist_OFFPEAK', - 'transit_ovtt_OFFPEAK/auto_dist_OFFPEAK': f'transit_ovtt_OFFPEAK/auto_dist_OFFPEAK', - - 'hard_sigmoid(transit_approach_walktime_PEAK, 4.0, 2.0)': f'hard_sigmoid(transit_approach_walktime_PEAK, 4.0, 2.0)', - 'hard_sigmoid(transit_approach_walktime_OFFPEAK, 4.0, 2.0)': f'hard_sigmoid(transit_approach_walktime_OFFPEAK, 4.0, 2.0)', - - # # TODO fix auto parking cost - # # _parking_cost, _free_parking = parking_cost_v2( - - 'auto_parking_cost_HBWH': '0.0', - 'auto_parking_cost_HBWL': '0.0', - 'auto_parking_cost_HBO': '0.0', - 'auto_parking_cost_HBS': '0.0', - 'auto_parking_cost_NHB': '0.0', - 'auto_parking_cost_HBOR': '0.0', - 'auto_parking_cost_NHBR': '0.0', - 'auto_parking_cost_NHBS': '0.0', - - 'samp_wgt': '1.0', - 'log(1/samp_wgt)': '0.0', - - 'transit_avail_HBWH': ( - "(transit_ivtt_PEAK < 999)" - "& (transit_approach_walktime_PEAK < 999)" - "& (transit_approach_drivetime_PEAK < 999)" - "& (log_attractions_HBWH > -9998)" - ), - 'transit_avail_HBWL': ( - "(transit_ivtt_PEAK < 999)" - "& (transit_approach_walktime_PEAK < 999)" - "& (transit_approach_drivetime_PEAK < 999)" - "& (log_attractions_HBWL > -9998)" - ), - 'transit_avail_HBS': ( - "(transit_ivtt_OFFPEAK < 999)" - "& (transit_approach_walktime_OFFPEAK < 999)" - "& (transit_approach_drivetime_OFFPEAK < 999)" - "& (log_attractions_HBS > -9998)" - ), - 'transit_avail_HBO': ( - "(transit_ivtt_OFFPEAK < 999)" - "& (transit_approach_walktime_OFFPEAK < 999)" - "& (transit_approach_drivetime_OFFPEAK < 999)" - "& (log_attractions_HBO > -9998)" - ), - 'transit_avail_NHB': ( - "(transit_ivtt_OFFPEAK < 999)" - "& (transit_approach_walktime_OFFPEAK < 999)" - "& (transit_approach_drivetime_OFFPEAK < 999)" - "& (log_attractions_NHB > -9998)" - ), - } - - for purpose in purposesA: - coldefs.update({ - f'auto_avail_{purpose}': f'log_attractions_{purpose} > -9998', - f'1-auto_avail_{purpose}': f'1-auto_avail_{purpose}', - f'1-transit_avail_{purpose}': f'1-transit_avail_{purpose}', - }) - - log.info("setup application data step 2 flow") - processor = SharedData(in_table).setup_flow( - coldefs, - cache_dir=local_cache(), - name="S2", - dtype="float64", - ) - - try: - log.debug("load first hit") - df = processor.load(in_table, as_dataframe=True) - log.debug("load second hit") - df2 = processor.load(in_table, as_dataframe=True) - log.debug("check first and second hits are equal") - try: - pd.testing.assert_frame_equal(df, df2) - except AssertionError as err: - log.exception(err) - return processor - finally: - log.info("application_data2 flow ready") - diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/parking_cost.py b/src/Mode-Dest-TOD/cmap_modedest/fast/parking_cost.py deleted file mode 100644 index c4f8c91..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/parking_cost.py +++ /dev/null @@ -1,102 +0,0 @@ -import numpy as np -import numba as nb - -def compile_parking_cost_v2(dh): - - cbd_parking_price_prob_array = np.zeros([dh.cbd_parking_price_prob.index.max(), 5], dtype=np.float32) - for dtaz, priceprob in dh.cbd_parking_price_prob.iterrows(): - cbd_parking_price_prob_array[dtaz-1, :] = priceprob.to_numpy() - - cbd_parking_prices_array = np.zeros([dh.cbd_parking_price_prob.index.max(), 5], dtype=np.float32) - for dtaz, prices in dh.cbd_parking_prices.iterrows(): - cbd_parking_prices_array[dtaz-1, :] = prices.to_numpy() - - zone_type_array = dh.m01.zone_type.to_numpy().astype(np.int32) - - default_parking_costs_array = np.zeros([ - 4, # purposes - 4, # zonetypes - ]) - - default_parking_costs_array[0, 0] = dh.cfg.parking_costs.defaults.HW[1] - default_parking_costs_array[0, 1] = dh.cfg.parking_costs.defaults.HW[2] - default_parking_costs_array[0, 2] = dh.cfg.parking_costs.defaults.HW[3] - default_parking_costs_array[0, 3] = dh.cfg.parking_costs.defaults.HW[4] - - default_parking_costs_array[1, 0] = dh.cfg.parking_costs.defaults.HW[1] - default_parking_costs_array[1, 1] = dh.cfg.parking_costs.defaults.HW[2] - default_parking_costs_array[1, 2] = dh.cfg.parking_costs.defaults.HW[3] - default_parking_costs_array[1, 3] = dh.cfg.parking_costs.defaults.HW[4] - - default_parking_costs_array[2, 0] = dh.cfg.parking_costs.defaults.HO[1] - default_parking_costs_array[2, 1] = dh.cfg.parking_costs.defaults.HO[2] - default_parking_costs_array[2, 2] = dh.cfg.parking_costs.defaults.HO[3] - default_parking_costs_array[2, 3] = dh.cfg.parking_costs.defaults.HO[4] - - default_parking_costs_array[3, 0] = dh.cfg.parking_costs.defaults.NH[1] - default_parking_costs_array[3, 1] = dh.cfg.parking_costs.defaults.NH[2] - default_parking_costs_array[3, 2] = dh.cfg.parking_costs.defaults.NH[3] - default_parking_costs_array[3, 3] = dh.cfg.parking_costs.defaults.NH[4] - - IncomeCeiling = dh.cbd_parking2.IncomeCeiling.to_numpy() - FreeParkingPct = dh.cbd_parking2.FreeParkingPct.to_numpy() - - @nb.njit - def parking_cost_v2( - DEST, - INCOME, - HOURS, - purpose, - random_seed=None, - ): - - """ - Draw a parking cost from the random distribution in the destination zone. - - Parameters - ---------- - DEST : int - TAZ ID for destination - INCOME : float - HOURS : float - Number of hours of parking to pay for - purpose : int - 0:'HW', 1:'HW, 2:'HO', 3:'NH' - random_seed : int, optional - - Returns - ------- - CAPK, WALK3, INTOCC, BLK, SI : array, shape[ITER] - parking cost, walktime, vehicle occupancy, blocks walked, savings rate - """ - - if random_seed is not None: - np.random.seed(random_seed) - - rand_free_parking = np.random.rand() * 100. # Free Parking randomizer - rand_parking_price = np.random.rand() # Parking Rate randomizer - #RAN5 = np.random.rand() * 100. # Auto Occupancy randomizer - - hourly_cost = 0 - if DEST <= cbd_parking_price_prob_array.shape[0]: - for i in range(5): - rand_parking_price -= cbd_parking_price_prob_array[DEST-1, i] - if rand_parking_price < 0: - hourly_cost = cbd_parking_prices_array[DEST-1, i] - break - - if hourly_cost == 0: - dest_zone_type = zone_type_array[DEST-1] - hourly_cost = default_parking_costs_array[purpose, dest_zone_type-1] - - free_parking = False - for j2 in range(5): - if INCOME <= IncomeCeiling[j2]: - if rand_free_parking <= FreeParkingPct[j2]: - hourly_cost = 0.0 - free_parking = True - break - - return hourly_cost*HOURS, free_parking - - return parking_cost_v2 \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/random_generator.py b/src/Mode-Dest-TOD/cmap_modedest/fast/random_generator.py deleted file mode 100644 index 7fc05c1..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/random_generator.py +++ /dev/null @@ -1,42 +0,0 @@ -import numba as nb -import numbers -import numpy as np - -@nb.njit -def check_random_generator(seed): - """ - Turn a seed into a numpy RandomState instance - - Parameters - ---------- - seed : None | int | instance of Generator - If seed is None, return a default Generator. - If seed is an int, return a new Generator instance seeded with seed. - If seed is already a Generator instance, return it. - Otherwise raise ValueError. - """ - if seed is not None: - return default_rng() - if isinstance(seed, numbers.Integral): - return default_rng(SeedSequence(seed % 1<<32)) - if isinstance(seed, Generator): - return seed - raise ValueError('%r cannot be used to seed a random generator instance' % seed) - - -@nb.njit -def multichoices(probs, samplesizes, seeds=None): - choice_table = np.zeros(probs.shape, dtype=np.int32) - for i in range(probs.shape[0]): - if seeds is not None: - np.random.seed(seeds[i]) - pr = probs[i] - samplesize = samplesizes[i] - for k in range(samplesize): - rando = np.random.random() - for j in range(probs.shape[1]): - rando -= pr[j] - if rando < 0: - choice_table[i, j] += 1 - break - return choice_table diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/tnc_los.py b/src/Mode-Dest-TOD/cmap_modedest/fast/tnc_los.py deleted file mode 100644 index 1b05655..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/tnc_los.py +++ /dev/null @@ -1,388 +0,0 @@ -import numba as nb -import numpy as np -import pandas as pd -import yaml -from ..addict import Dict -from collections import namedtuple -from typing import NamedTuple - -zone_to_cents_t = nb.types.DictType(nb.int32, nb.float32) - - -class TaxiCostStruct(NamedTuple): - flag_pull: float - per_minute: float - per_mile: float - airport_pickup_fee: float - airport_pickup_zones: np.ndarray - - -class TncCostStruct(NamedTuple): - base_fare: float - per_minute: float - per_mile: float - min_fare: float - booking_fee: float - special_fee: float - downtown_fee: float - special_zones: np.ndarray - downtown_zones: np.ndarray - - -@nb.njit(cache=True) -def taxi_cost(auto_time, auto_dist, o_zone, d_zone, taxi_cost_struct): - """ - Compute taxi fare. - - A single set of rates (Chicago medallion rates for in-city trips) - is used; fares for taxi trips outside Chicago are close to this - rate and rare enough that more precision is unneeded. - - Parameters - ---------- - auto_time, auto_dist : array-like - - Returns - ------- - fare : array-like - """ - cost = ( - taxi_cost_struct.flag_pull - + auto_time * taxi_cost_struct.per_minute - + auto_dist * taxi_cost_struct.per_mile - ) - if taxi_cost_struct.airport_pickup_fee: - bucket_applies = False - for i in range(taxi_cost_struct.airport_pickup_zones.size): - if taxi_cost_struct.airport_pickup_zones[i] == o_zone: - bucket_applies = True - break - if bucket_applies: - cost += taxi_cost_struct.airport_pickup_fee - - return cost - -@nb.njit(cache=True) -def tnc_cost(auto_time, auto_dist, o_zone, d_zone, tnc_cost_struct): - """ - Compute the TNC cost. - - Parameters - ---------- - auto_time, auto_dist : float - The auto travel time and distance for a set of trips. - o_zone, d_zone : int - Zone numbers for origin and destination - tnc_cost_struct : TncCostStruct - Use the correct struct for peak/offpeak and solo/shared. - - Returns - ------- - float - """ - cost = ( - tnc_cost_struct.per_minute * auto_time - + tnc_cost_struct.per_mile * auto_dist - + tnc_cost_struct.base_fare - ) - cost = max(cost, tnc_cost_struct.min_fare) + tnc_cost_struct.booking_fee - - if tnc_cost_struct.special_fee: - bucket_applies = False - for i in range(tnc_cost_struct.special_zones.size): - if tnc_cost_struct.special_zones[i] == o_zone or tnc_cost_struct.special_zones[i] == d_zone: - bucket_applies = True - break - if bucket_applies: - cost += tnc_cost_struct.special_fee - - if tnc_cost_struct.downtown_fee: - bucket_applies = False - for i in range(tnc_cost_struct.downtown_zones.size): - if tnc_cost_struct.downtown_zones[i] == o_zone or tnc_cost_struct.downtown_zones[i] == d_zone: - bucket_applies = True - break - if bucket_applies: - cost += tnc_cost_struct.downtown_fee - - return cost - - -### CONFIG ### - -def tnc_los_functions(dh): - - with open(dh.filenames.config, 'rt') as yf: - cfg = Dict(yaml.safe_load(yf)) - cfg.freeze() - - taxi_cost_flag_pull = cfg.taxi.cost.flag_pull - taxi_cost_per_minute = cfg.taxi.cost.per_minute - taxi_cost_per_mile = cfg.taxi.cost.per_mile - - tnc_cost_peak_per_minute = cfg.tnc.cost.peak.per_minute - tnc_cost_peak_per_mile = cfg.tnc.cost.peak.per_mile - tnc_cost_peak_base_fare = cfg.tnc.cost.peak.base_fare - tnc_cost_peak_min_fare = cfg.tnc.cost.peak.min_fare - tnc_cost_peak_booking_fee = cfg.tnc.cost.peak.booking_fee - tnc_cost_offpeak_per_minute = cfg.tnc.cost.offpeak.per_minute - tnc_cost_offpeak_per_mile = cfg.tnc.cost.offpeak.per_mile - tnc_cost_offpeak_base_fare = cfg.tnc.cost.offpeak.base_fare - tnc_cost_offpeak_min_fare = cfg.tnc.cost.offpeak.min_fare - tnc_cost_offpeak_booking_fee= cfg.tnc.cost.offpeak.booking_fee - - tnc_surcharge_rates = {} - for k,v in cfg.tnc.surcharge_rates.items(): - tnc_surcharge_rates[k] = np.float32(v) - - tnc_surcharge_zones = {} - for k, v in cfg.tnc.surcharge_zones.items(): - tnc_surcharge_zones[k] = np.asarray(v, dtype=np.int32) - - tnc_surcharges = tuple( - (k, tnc_surcharge_rates[k], tnc_surcharge_zones[k]) - for k in tnc_surcharge_zones - ) - - tncpool_cost_peak_per_minute = cfg.tnc_pooled.cost.peak.per_minute - tncpool_cost_peak_per_mile = cfg.tnc_pooled.cost.peak.per_mile - tncpool_cost_peak_base_fare = cfg.tnc_pooled.cost.peak.base_fare - tncpool_cost_peak_min_fare = cfg.tnc_pooled.cost.peak.min_fare - tncpool_cost_peak_booking_fee = cfg.tnc_pooled.cost.peak.booking_fee - tncpool_cost_offpeak_per_minute = cfg.tnc_pooled.cost.offpeak.per_minute - tncpool_cost_offpeak_per_mile = cfg.tnc_pooled.cost.offpeak.per_mile - tncpool_cost_offpeak_base_fare = cfg.tnc_pooled.cost.offpeak.base_fare - tncpool_cost_offpeak_min_fare = cfg.tnc_pooled.cost.offpeak.min_fare - tncpool_cost_offpeak_booking_fee= cfg.tnc_pooled.cost.offpeak.booking_fee - - tncpool_surcharge_rates = {} - for k,v in cfg.tnc_pooled.surcharge_rates.items(): - tncpool_surcharge_rates[k] = np.float32(v) - - tncpool_surcharge_zones = {} - for k, v in cfg.tnc_pooled.surcharge_zones.items(): - tncpool_surcharge_zones[k] = np.asarray(v, dtype=np.int32) - - tncpool_surcharges = tuple( - (k, tncpool_surcharge_rates[k], tncpool_surcharge_zones[k]) - for k in tncpool_surcharge_zones - ) - - dh.cfg['taxi_cost_struct'] = TaxiCostStruct( - flag_pull = cfg.taxi.cost.flag_pull, - per_minute = cfg.taxi.cost.per_minute, - per_mile = cfg.taxi.cost.per_mile, - airport_pickup_fee = cfg.taxi.cost.airport_departure, - airport_pickup_zones=np.asarray(cfg.taxi.cost.airport_zones), - ) - - dh.cfg['tnc_cost_struct_solo_peak'] = TncCostStruct( - base_fare=cfg.tnc.cost.peak.base_fare, - per_minute=cfg.tnc.cost.peak.per_minute, - per_mile=cfg.tnc.cost.peak.per_mile, - min_fare=cfg.tnc.cost.peak.min_fare, - booking_fee=cfg.tnc.cost.peak.booking_fee, - special_fee=cfg.tnc.surcharge_rates.special, - special_zones=np.asarray(cfg.tnc.surcharge_zones.special), - downtown_fee=cfg.tnc.surcharge_rates.downtown, - downtown_zones=np.asarray(cfg.tnc.surcharge_zones.downtown), - ) - - dh.cfg['tnc_cost_struct_solo_offpeak'] = TncCostStruct( - base_fare=cfg.tnc.cost.offpeak.base_fare, - per_minute=cfg.tnc.cost.offpeak.per_minute, - per_mile=cfg.tnc.cost.offpeak.per_mile, - min_fare=cfg.tnc.cost.offpeak.min_fare, - booking_fee=cfg.tnc.cost.offpeak.booking_fee, - special_fee=cfg.tnc.surcharge_rates.special, - special_zones=np.asarray(cfg.tnc.surcharge_zones.special), - downtown_fee=cfg.tnc.surcharge_rates.downtown, - downtown_zones=np.asarray(cfg.tnc.surcharge_zones.downtown), - ) - - dh.cfg['tnc_cost_struct_pool_peak'] = TncCostStruct( - base_fare=cfg.tnc_pooled.cost.peak.base_fare, - per_minute=cfg.tnc_pooled.cost.peak.per_minute, - per_mile=cfg.tnc_pooled.cost.peak.per_mile, - min_fare=cfg.tnc_pooled.cost.peak.min_fare, - booking_fee=cfg.tnc_pooled.cost.peak.booking_fee, - special_fee=cfg.tnc_pooled.surcharge_rates.special, - special_zones=np.asarray(cfg.tnc_pooled.surcharge_zones.special), - downtown_fee=cfg.tnc_pooled.surcharge_rates.downtown, - downtown_zones=np.asarray(cfg.tnc_pooled.surcharge_zones.downtown), - ) - - dh.cfg['tnc_cost_struct_pool_offpeak'] = TncCostStruct( - base_fare=cfg.tnc_pooled.cost.offpeak.base_fare, - per_minute=cfg.tnc_pooled.cost.offpeak.per_minute, - per_mile=cfg.tnc_pooled.cost.offpeak.per_mile, - min_fare=cfg.tnc_pooled.cost.offpeak.min_fare, - booking_fee=cfg.tnc_pooled.cost.offpeak.booking_fee, - special_fee=cfg.tnc_pooled.surcharge_rates.special, - special_zones=np.asarray(cfg.tnc_pooled.surcharge_zones.special), - downtown_fee=cfg.tnc_pooled.surcharge_rates.downtown, - downtown_zones=np.asarray(cfg.tnc_pooled.surcharge_zones.downtown), - ) - - - ############## - # - # @nb.njit(cache=True) - # def taxi_cost(auto_time, auto_dist, taxi_cost_struct): - # """ - # Compute taxi fare. - # - # A single set of rates (Chicago medallion rates for in-city trips) - # is used; fares for taxi trips outside Chicago are close to this - # rate and rare enough that more precision is unneeded. - # - # Parameters - # ---------- - # auto_time, auto_dist : array-like - # - # Returns - # ------- - # fare : array-like - # """ - # return ( - # taxi_cost_struct.flag_pull - # + auto_time * taxi_cost_struct.per_minute - # + auto_dist * taxi_cost_struct.per_mile - # ) - # - # - # @nb.njit - # def tnc_cost(auto_time, auto_dist, o_zone, d_zone, tnc_cost_struct): - # """ - # Compute the TNC cost. - # - # Parameters - # ---------- - # auto_time, auto_dist : float - # The auto travel time and distance for a set of trips. - # o_zone, d_zone : int - # Zone numbers for origin and destination - # tnc_cost_struct : TncCostStruct - # Use the correct struct for peak/offpeak and solo/shared. - # - # Returns - # ------- - # float - # """ - # cost = ( - # tnc_cost_struct.per_minute * auto_time - # + tnc_cost_struct.per_mile * auto_dist - # + tnc_cost_struct.base_fare - # ) - # cost = max(cost, tnc_cost_struct.min_fare) + tnc_cost_struct.booking_fee - # - # if tnc_cost_struct.special_fee: - # bucket_applies = False - # for i in range(tnc_cost_struct.special_zones.size): - # if tnc_cost_struct.special_zones[i] == o_zone or tnc_cost_struct.special_zones[i] == d_zone: - # bucket_applies = True - # break - # if bucket_applies: - # cost += tnc_cost_struct.special_fee - # - # if tnc_cost_struct.downtown_fee: - # bucket_applies = False - # for i in range(tnc_cost_struct.downtown_zones.size): - # if tnc_cost_struct.downtown_zones[i] == o_zone or tnc_cost_struct.downtown_zones[i] == d_zone: - # bucket_applies = True - # break - # if bucket_applies: - # cost += tnc_cost_struct.downtown_fee - # - # return cost - # - # - # - # @nb.njit - # def tnc_solo_cost(auto_time, auto_dist, o_zone, d_zone, peak): - # """ - # Compute the solo rider TNC cost. - # - # Parameters - # ---------- - # auto_time, auto_dist : float - # The auto travel time and distance for a set of trips. - # o_zone, d_zone : int - # Zone numbers for origin and destination - # peak : bool - # Whether this trip is peak or offpeak. - # - # Returns - # ------- - # float - # """ - # if peak: - # cost = ( - # tnc_cost_peak_per_minute * auto_time - # + tnc_cost_peak_per_mile * auto_dist - # + tnc_cost_peak_base_fare - # ) - # cost = max(cost, tnc_cost_peak_min_fare) + tnc_cost_peak_booking_fee - # else: - # cost = ( - # tnc_cost_offpeak_per_minute * auto_time - # + tnc_cost_offpeak_per_mile * auto_dist - # + tnc_cost_offpeak_base_fare - # ) - # cost = max(cost, tnc_cost_offpeak_min_fare) + tnc_cost_offpeak_booking_fee - # - # for bucket_name, bucket_price, bucket_zones in tnc_surcharges: - # if bucket_price: - # bucket_applies = False - # for i in range(bucket_zones.size): - # if bucket_zones[i] == o_zone or bucket_zones[i] == d_zone: - # bucket_applies = True - # if bucket_applies: - # cost += bucket_price - # return cost - # - # - # @nb.njit - # def tnc_pool_cost(auto_time, auto_dist, o_zone, d_zone, peak): - # """ - # Compute the solo rider TNC cost. - # - # Parameters - # ---------- - # auto_time, auto_dist : float - # The auto travel time and distance for a set of trips. - # o_zone, d_zone : int - # Zone numbers for origin and destination - # peak : bool - # Whether this trip is peak or offpeak. - # - # Returns - # ------- - # float - # """ - # if peak: - # cost = ( - # tncpool_cost_peak_per_minute * auto_time - # + tncpool_cost_peak_per_mile * auto_dist - # + tncpool_cost_peak_base_fare - # ) - # cost = max(cost, tncpool_cost_peak_min_fare) + tncpool_cost_peak_booking_fee - # else: - # cost = ( - # tncpool_cost_offpeak_per_minute * auto_time - # + tncpool_cost_offpeak_per_mile * auto_dist - # + tncpool_cost_offpeak_base_fare - # ) - # cost = max(cost, tncpool_cost_offpeak_min_fare) + tncpool_cost_offpeak_booking_fee - # - # for bucket_name, bucket_price, bucket_zones in tncpool_surcharges: - # if bucket_price: - # bucket_applies = False - # for i in range(bucket_zones.size): - # if bucket_zones[i] == o_zone or bucket_zones[i] == d_zone: - # bucket_applies = True - # if bucket_applies: - # cost += bucket_price - # return cost - # - # return taxi_cost, tnc_solo_cost, tnc_pool_cost \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/transit/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/fast/transit/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/transit/access_egress_distance.py b/src/Mode-Dest-TOD/cmap_modedest/fast/transit/access_egress_distance.py deleted file mode 100644 index 211afd7..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/transit/access_egress_distance.py +++ /dev/null @@ -1,165 +0,0 @@ -import numpy as np -import numba as nb - -from ...modecodes import * -FRONT_END = 0 -BACK_END = 1 -N_TRIP_ENDS = 2 - - -@nb.njit -def trunc_normal(loc, scale): - rv = np.float32(np.random.normal(loc, scale)) - return max(rv, 0.06) - - -@nb.njit -def sloped_linear(x_min, x_max, ratio=1.0): - if ratio == 1.0: - return np.float32(np.random.uniform(x_min, x_max)) - else: - span = x_max - x_min - if span != 0: - slope = (1.0-ratio)/span - else: - slope = (1.0-ratio) - area =.5*(1+ratio)*span - y = np.float32(np.random.uniform(0.0, 1.0)) * area - zp = np.sqrt(ratio * ratio + 2 * slope * y) - if slope: - return ((zp - ratio) / slope) + x_min - else: - return (zp - ratio) + x_min - - -@nb.njit -def simulate_ae_dist(p1,p2,p3): - - # use_normal = (p3 == 101) - if p3 == 101: - return trunc_normal(p1,p2) - - # use_slopey = (p3 < 101) - if p3 < 101: - return sloped_linear(p1, p2, p3) - - #use_nan = (p3 == 999) - return 255.0 - - - -def compile_simulate_approach_distances( - dh, -): - """ - - Parameters - ---------- - zone : array-like - Zone id (1-based) - attached_mode : int - Number for first or last mode (as matches this approach) - trip_purpose : {'HW','HO','NH'} - Trip purpose, used to select DISTR table and possibly filter - approach modes - trip_end : {0,1} - Zero if approach to first mode, one if approach from last mode - out : array-like - Output array must already exist, as a float dtype, - with shape [replications, N_APPROACH_MODES, ] - - """ - # random_state = check_random_state(random_state) - - distr_array = np.stack([ - dh.distr['HW'], - dh.distr['HO'], - dh.distr['NH'], - ]).reshape((3,-1,5,3)).astype(np.float32) - - _BUS = dh.distr['HW'].loc[1].index.get_loc('bus') - _CTARAIL = dh.distr['HW'].loc[1].index.get_loc('ctarail') - _FEEDERBUS = dh.distr['HW'].loc[1].index.get_loc('feederbus') - _METRA = dh.distr['HW'].loc[1].index.get_loc('metra') - _PNR = dh.distr['HW'].loc[1].index.get_loc('pnr') - - @nb.njit(parallel=True) - def simulate_approach_distances_arr( - zone, - attached_mode, - trip_purpose, - trip_end, - out, - ): - """ - - Parameters - ---------- - zone : int - attached_mode : int - trip_purpose : int - trip_end : int - out : array[float32], shape=(5,) - - Returns - ------- - - """ - assert out.shape[-1] == 5, "last dimension must be 5" - if trip_purpose == 'HW': - distr_ = distr_array[0,zone-1] - elif trip_purpose == 'HO': - distr_ = distr_array[1,zone-1] - else: #if trip_purpose == 'NH': - distr_ = distr_array[2,zone-1] - for J in range(N_DIST_TO_TYPES): - # OBTAIN APPROACH DISTANCES TO FIVE MODES - if (J == DIST_TO_BUS): - distr_params = distr_[_BUS] - elif (J == DIST_TO_CTA_RAIL) and (attached_mode == TransitModeCode_CTA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS CTA RAIL - distr_params = distr_[_CTARAIL] - elif (J == DIST_TO_METRA) and (attached_mode == TransitModeCode_METRA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_[_METRA] - elif (J == DIST_TO_FEEDER_BUS) and (attached_mode == TransitModeCode_METRA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_[_FEEDERBUS] - elif (J == DIST_TO_PARK_N_RIDE_STATION) and (trip_end == FRONT_END): - # PARK AND RIDE STATION DISTANCE OBTAINED WHEN TRIP END IS FRONT - distr_params = distr_[_PNR] - else: - distr_params = np.full(3, 999, dtype=np.float32) - if out.ndim == 2: - for k in range(out.shape[0]): - out[k,J] = simulate_ae_dist( - distr_params[0], - distr_params[1], - distr_params[2], - ) - else: - out[J] = simulate_ae_dist( - distr_params[0], - distr_params[1], - distr_params[2], - ) - - @nb.njit(parallel=True) - def simulate_approach_distances_multi( - zones, - attached_modes, - trip_purpose, - trip_end, - outs, - ): - assert zones.shape[0] == attached_modes.shape[0] == outs.shape[0] - for i in nb.prange(zones.shape[0]): - simulate_approach_distances_arr( - zones[i], - attached_modes[i], - trip_purpose, - trip_end, - outs[i], - ) - - return simulate_approach_distances_arr, simulate_approach_distances_multi \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/fast/transit/approach.py b/src/Mode-Dest-TOD/cmap_modedest/fast/transit/approach.py deleted file mode 100644 index a33cc51..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/fast/transit/approach.py +++ /dev/null @@ -1,836 +0,0 @@ - -import numpy as np -import numba as nb -import logging -from ...addict import Dict -from typing import Generator -from collections import namedtuple - -log = logging.getLogger('CMAP') - -from .access_egress_distance import compile_simulate_approach_distances -from ...ae_distance_sim import simulate_ae_dist -from ...purposes import purposes_to_3 - -# trip types -HW = 'HW' # HOME PRODUCTIONS TO WORK ATTRACTIONS -HO = 'HO' # HOME PRODUCTIONS TO NON-WORK/NON-HOME ATTRACTIONS -NH = 'NH' # NON-HOME PRODUCTIONS TO NON-HOME ATTRACTIONS - -ITER = 50 # NUMBER OF TRIPS USED TO COMPUTE AVERAGE IMPEDANCES - -from ...modecodes import ( - APPROACH_WALK, - APPROACH_BUS, - APPROACH_PARK_N_RIDE, - APPROACH_KISS_N_RIDE, - APPROACH_FEEDER_BUS, - N_APPROACH_MODES, - APPROACH_MODE_NAMES, - DIST_TO_BUS, - DIST_TO_CTA_RAIL, - DIST_TO_METRA, - DIST_TO_FEEDER_BUS, - DIST_TO_PARK_N_RIDE_STATION, - N_DIST_TO_TYPES, - TransitModeCode_CTA_RAIL, - TransitModeCode_METRA_RAIL, - TransitModeCode_CTA_EXPRESS_BUS, - TransitModeCode_CTA_REGULAR_BUS, - TransitModeCode_PACE_BUS, -) - - - -FRONT_END = 0 -BACK_END = 1 -N_TRIP_ENDS = 2 - -SPDWLK = np.float32(30.) -# SPDWLK = SYSTEM-WIDE SPEED OF WALKING, -# DEFAULT IS 30 TENTHS OF A MILE PER HOUR - -SPEEDS = np.array([7., 15., 20., 30., 5., 10., 12., 17.]) -# SPEEDS = SPEEDS OF APPROACH AUTO AND BUS BY ZONE AREA TYPE -# AUTO APPROACH SPEEDS: -# ZONE TYPE 1 (CHICAGO CBD) DEFAULT IS 7 MPH -# ZONE TYPE 2 (CHICAGO REMAINDER) DEFAULT IS 15 MPH -# ZONE TYPE 3 (DENSE SUBURB) DEFAULT IS 20 MPH -# ZONE TYPE 4 (SPARSE SUBURB) DEFAULT IS 30 MPH -# BUS APPROACH SPEEDS: -# ZONE TYPE 1 (CHICAGO CBD) DEFAULT IS 5 MPH -# ZONE TYPE 2 (CHICAGO REMAINDER) DEFAULT IS 10 MPH -# ZONE TYPE 3 (DENSE SUBURB) DEFAULT IS 12 MPH -# ZONE TYPE 4 (SPARSE SUBURB) DEFAULT IS 17 MPH - -DRVOT = 14 -# DRVOT = DRIVER'S VALUE OF TIME, DEFAULT IS 14 CENTS/MIN - -OVT_IVT_RATIO = 2.0 - - - -AFC1 = 35 # AUTO FIXED COSTS FOR AUTO DRIVER IN CENTS -AFC2 = 20 # AUTO FIXED COSTS FOR AUTO PASSENGER IN CENTS - -# W2PNR = WALK TIME TO STATION FROM PARK AND RIDE LOT, -# DEFAULT IS 2 MINUTES -W2PNR = 2 - -TransitApproachStruct = namedtuple('TransitApproachStruct', [ - 'fwbus_pk', - 'fwfdr_pk', - 'fwbus_op', - 'fwfdr_op', - 'ZTYPE', - 'FM_pk', - 'LM_pk', - 'FM_op', - 'LM_op', - 'FEEDER_BUS_BOARDING_FARE', - 'FEEDER_BUS_CBD_FARE', - 'CTA_CBD_LINK_UP_FARE', - 'CTA_FIRST_XFER_FARE', - 'PACE_BUS_FIRST_XFER_FARE', - 'PNRAVL', - 'PRCOST', - 'AUTO_OPERATING_COST_BY_ZONETYPE', - 'distr_array', - 'distr_BUS', - 'distr_CTARAIL', - 'distr_FEEDERBUS', - 'distr_METRA', - 'distr_PNR', -]) - -# class TransitApproachStruct(_TransitApproachStruct): -# def __new__(cls, *args, **kwargs): -# if len(args) == 1 and len(kwargs) == 0: -# if isinstance(args[0], cls): -# return args[0] -# elif isinstance(args[0], Generator): -# return super().__new__(cls, *args[0]) -# return super().__new__(cls, *args, **kwargs) - - -def compile_transit_approach( - dh, -): - """ - Replaces TRAPP fortran. - - Parameters - ---------- - dh : DataHandler - ozone, dzone : int or array-like - Zone ID numbers. If array-like, should be arrays of the same shape. - TPTYPE : {'HW', 'HO', 'NH'} - Trip type - replication : int - Number of simulation replications - - Returns - ------- - Dict - Containing: - - drivetime : array of int32, shape [replication] - simulated in vehicle (drive) approach times, in minutes - - walktime : array of int32, shape [replication] - simulated out of vehicle (walk) approach times, in minutes - - cost : array of int32, shape [replication] - simulated approach costs, in cents - - waittime : array of int32, shape [replication] - simulated approach waiting times - - approach_mode : array of int8, shape [replication, 2] - simulated best approach modes - = approach_distances : array of float32, shape [replication, N_DIST_TO_TYPES, N_TRIP_ENDS] - - Notes - ----- - When ozone, dzone are given as arrays, all returned arrays have one extra front - dimension matching these arrays. - - """ - - PACE_BUS_BOARDING_FARE = dh.m023.PACE_BUS_BOARDING_FARE - PACE_BUS_FIRST_XFER_FARE = dh.m023.PACE_BUS_FIRST_XFER_FARE - FEEDER_BUS_BOARDING_FARE = dh.m023.FEEDER_BUS_BOARDING_FARE - FEEDER_BUS_CBD_FARE = dh.m023.FEEDER_BUS_CBD_FARE - - CTA_FIRST_XFER_FARE = dh.m023.CTA_FIRST_XFER_FARE - CTA_CBD_LINK_UP_FARE = dh.m023.CTA_CBD_LINK_UP_FARE - - AUTO_OPERATING_COST_BY_ZONETYPE = dh.m023.AUTO_OPERATING_COST_BY_ZONETYPE # AVERAGE OPERATING COST PER MILE FOR AUTO, BY ZONE TYPE - - m01_df = dh.m01 - - ZTYPE = m01_df['zone_type'].to_numpy() - fwbus_pk = m01_df['first_wait_bus_peak'].to_numpy().astype(np.float32) # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr_pk = m01_df['first_wait_feeder_peak'].to_numpy().astype(np.float32) # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - fwbus_op = m01_df['first_wait_bus_offpeak'].to_numpy().astype(np.float32) # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr_op = m01_df['first_wait_feeder_offpeak'].to_numpy().astype(np.float32) # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - PNRAVL = m01_df['pnr_flag'].astype(bool).to_numpy() # park-n-ride available, by zone - PRCOST = m01_df['pnr_parking_cost'].to_numpy().astype(np.float32) # park-n-ride cost, by zone - - FM_pk = dh.skims.first_mode_peak.astype(np.int32) - LM_pk = dh.skims.last_mode_peak.astype(np.int32) - FM_op = dh.skims.first_mode_offpeak.astype(np.int32) - LM_op = dh.skims.last_mode_offpeak.astype(np.int32) - - # simulate_approach_distances, simulate_approach_distances2 = compile_simulate_approach_distances(dh) - distr_array = np.stack([ - dh.distr['HW'], - dh.distr['HO'], - dh.distr['NH'], - ]).reshape((3,-1,5,3)).astype(np.float32) - - distr_BUS = dh.distr['HW'].loc[1].index.get_loc('bus') - distr_CTARAIL = dh.distr['HW'].loc[1].index.get_loc('ctarail') - distr_FEEDERBUS = dh.distr['HW'].loc[1].index.get_loc('feederbus') - distr_METRA = dh.distr['HW'].loc[1].index.get_loc('metra') - distr_PNR = dh.distr['HW'].loc[1].index.get_loc('pnr') - - - - trapp_struct = TransitApproachStruct( - fwbus_pk= fwbus_pk, - fwfdr_pk= fwfdr_pk, - fwbus_op= fwbus_op, - fwfdr_op= fwfdr_op, - ZTYPE= ZTYPE, - FM_pk= FM_pk, - LM_pk= LM_pk, - FM_op= FM_op, - LM_op= LM_op, - FEEDER_BUS_BOARDING_FARE= FEEDER_BUS_BOARDING_FARE, - FEEDER_BUS_CBD_FARE= FEEDER_BUS_CBD_FARE, - CTA_CBD_LINK_UP_FARE= CTA_CBD_LINK_UP_FARE, - CTA_FIRST_XFER_FARE= CTA_FIRST_XFER_FARE, - PACE_BUS_FIRST_XFER_FARE= PACE_BUS_FIRST_XFER_FARE, - PNRAVL= PNRAVL, - PRCOST= PRCOST, - AUTO_OPERATING_COST_BY_ZONETYPE= AUTO_OPERATING_COST_BY_ZONETYPE, - distr_array=distr_array, - distr_BUS = distr_BUS, - distr_CTARAIL = distr_CTARAIL, - distr_FEEDERBUS = distr_FEEDERBUS, - distr_METRA = distr_METRA, - distr_PNR = distr_PNR, - ) - - - return trapp_struct - - -def transit_approach_distances( - trapp_struct, - ozone, - dzone, - TPTYPE, - n_reps=50, - random_seed=None, -): - if random_seed is not None: - try: - seed_base = np.int32(random_seed) - except TypeError: - if isinstance(random_seed, np.random.Generator): - seed_base = random_seed.integers(0, 2147483647, dtype=np.int32) - else: - raise - else: - seed_base = np.int32(0) - TPTYPE = purposes_to_3.get(TPTYPE, 'NH') - approach_distances = np.zeros((ozone.shape[0], n_reps, 5, 2), dtype=np.float32) - seeds = np.zeros(ozone.shape[0], dtype=np.int32) - _transit_approach_distances(trapp_struct, ozone, dzone, TPTYPE, seed_base, approach_distances, seeds) - return approach_distances, seeds - - -@nb.njit(parallel=True, cache=True) -def _transit_approach_distances( - trapp_struct, - ozone, - dzone, - TPTYPE, - seed_base, - approach_distances, - seeded, -): - # struct data - ZTYPE = trapp_struct.ZTYPE - FM_pk = trapp_struct.FM_pk - LM_pk = trapp_struct.LM_pk - FM_op = trapp_struct.FM_op - LM_op = trapp_struct.LM_op - distr_array = trapp_struct.distr_array - distr_BUS = trapp_struct.distr_BUS - distr_CTARAIL = trapp_struct.distr_CTARAIL - distr_FEEDERBUS = trapp_struct.distr_FEEDERBUS - distr_METRA = trapp_struct.distr_METRA - distr_PNR = trapp_struct.distr_PNR - - assert approach_distances.shape[-2:] == (5,2), \ - "last dimensions approach_distances must be (5,2)" - - for z in nb.prange(ozone.shape[0]): - - ozone_idx = ozone[z]-1 - dzone_idx = dzone[z]-1 - - seed = np.int32(seed_base) + (np.int32(ozone_idx) << 14) + np.int32(dzone_idx) - seeded[z] = seed - np.random.seed(seed) - - # - # GET ZONE TYPES - # - ozone_type = ZTYPE[ozone_idx] - dzone_type = ZTYPE[dzone_idx] - # - # GET INTERCHANGE ATTRIBUTES - # FM=FIRST MODE,LM=LAST MODE,PM=PRIORITY MODE - # - if TPTYPE == 0: - FM = FM_pk[ozone_idx, dzone_idx] - LM = LM_pk[ozone_idx, dzone_idx] - else: - FM = FM_op[ozone_idx, dzone_idx] - LM = LM_op[ozone_idx, dzone_idx] - # - # INET TRANSIT NETWORK STORES SOME SUBURBAN BUS LINES (MODE=6) - # AS MODE=5 DUE TO ARRAY SIZE LIMITS. IF MODE=5 AND - # ZONE TYPE NO. 1 IS OUTSIDE OF CHICAGO, THEN CHANGE MODE TO 6. - # - - if (FM == 5) and (ozone_type > 2): - FM = 6 - if (LM == 5) and (dzone_type > 2): - LM = 6 - - # - # GET APPROACH DISTANCES FOR FIRST AND LAST MODES - # - for trip_end in [0,1]: - if trip_end == 0: - zone = ozone[z] - attached_mode = FM - else: - zone = dzone[z] - attached_mode = LM - if TPTYPE == 'HW': - distr_ = distr_array[0, zone - 1] - elif TPTYPE == 'HO': - distr_ = distr_array[1, zone - 1] - else: # if TPTYPE == 'NH': - distr_ = distr_array[2, zone - 1] - for J in range(N_DIST_TO_TYPES): - # OBTAIN APPROACH DISTANCES TO FIVE MODES - if (J == DIST_TO_BUS): - distr_params = distr_[distr_BUS] - elif (J == DIST_TO_CTA_RAIL) and (attached_mode == TransitModeCode_CTA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS CTA RAIL - distr_params = distr_[distr_CTARAIL] - elif (J == DIST_TO_METRA) and (attached_mode == TransitModeCode_METRA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_[distr_METRA] - elif (J == DIST_TO_FEEDER_BUS) and (attached_mode == TransitModeCode_METRA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_[distr_FEEDERBUS] - elif (J == DIST_TO_PARK_N_RIDE_STATION) and (trip_end == FRONT_END): - # PARK AND RIDE STATION DISTANCE OBTAINED WHEN TRIP END IS FRONT - distr_params = distr_[distr_PNR] - else: - distr_params = np.full(3, 999, dtype=np.float32) - for k in range(approach_distances.shape[1]): - if distr_params[2] == 101: # use_normal = (p3 == 101) - rv = np.random.normal(distr_params[0], distr_params[1]) - approach_distances[z, k, J, trip_end] = np.float32(min(max(rv, 0.06), 200.0)) - elif distr_params[2] < 101: # use_slopey = (p3 < 101) - x_min = distr_params[0] - x_max = distr_params[1] - ratio = distr_params[2] - if ratio == 1.0: - approach_distances[z, k, J, trip_end] = np.float32(min(np.random.uniform(x_min, x_max), 200.0)) - else: - span = x_max - x_min - if span != 0: - slope = (1.0 - ratio) / span - else: - slope = (1.0 - ratio) - area = .5 * (1 + ratio) * span - y = np.float32(np.random.uniform(0.0, 1.0)) * area - zp = np.sqrt(ratio * ratio + 2 * slope * y) - if slope: - rv = ((zp - ratio) / slope) + x_min - else: - rv = (zp - ratio) + x_min - approach_distances[z, k, J, trip_end] = min(max(rv, 0.06), 200.0) - else: # use_nan = (p3 == 999) - approach_distances[z, k, J, trip_end] = 255.0 - - -@nb.njit(cache=True) -def transit_approach( - trapp_struct, - ozone, - dzone, - TPTYPE, - approach_distances, - out, -): - # struct data - fwbus_pk = trapp_struct.fwbus_pk # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr_pk = trapp_struct.fwfdr_pk # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - fwbus_op = trapp_struct.fwbus_op # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr_op = trapp_struct.fwfdr_op # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - ZTYPE = trapp_struct.ZTYPE - FM_pk = trapp_struct.FM_pk - LM_pk = trapp_struct.LM_pk - FM_op = trapp_struct.FM_op - LM_op = trapp_struct.LM_op - FEEDER_BUS_BOARDING_FARE = trapp_struct.FEEDER_BUS_BOARDING_FARE - FEEDER_BUS_CBD_FARE = trapp_struct.FEEDER_BUS_CBD_FARE - CTA_CBD_LINK_UP_FARE = trapp_struct.CTA_CBD_LINK_UP_FARE - CTA_FIRST_XFER_FARE = trapp_struct.CTA_FIRST_XFER_FARE - PACE_BUS_FIRST_XFER_FARE = trapp_struct.PACE_BUS_FIRST_XFER_FARE - PNRAVL = trapp_struct.PNRAVL - PRCOST = trapp_struct.PRCOST - AUTO_OPERATING_COST_BY_ZONETYPE = trapp_struct.AUTO_OPERATING_COST_BY_ZONETYPE - - # random_state = check_random_state(random_state or ozone+dzone) - replication = approach_distances.shape[1] - - # if trace: - # log.log(trace, f"transit_approach({ozone},{dzone},{TPTYPE},{replication})") - - # convert inputs to length-1 vectors if not already vectors - # ozone = np.asanyarray(ozone) - # dzone = np.asanyarray(dzone) - vector_len = ozone.shape[0] - assert vector_len == dzone.shape[0] - - ozone_idx = ozone-1 - dzone_idx = dzone-1 - - # ZTYPE = m01_df['zone_type'].to_numpy() - # fwbus_pk = m01_df['first_wait_bus_peak'].to_numpy() # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - # fwfdr_pk = m01_df['first_wait_feeder_peak'].to_numpy() # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - # fwbus_op = m01_df['first_wait_bus_offpeak'].to_numpy() # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - # fwfdr_op = m01_df['first_wait_feeder_offpeak'].to_numpy() # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - # PNRAVL = m01_df['pnr_flag'].astype(bool).to_numpy() # park-n-ride available, by zone - # PRCOST = m01_df['pnr_parking_cost'].to_numpy() # park-n-ride cost, by zone - - if TPTYPE == HW: - fwbus = fwbus_pk # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr = fwfdr_pk # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - else: - fwbus = fwbus_op # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr = fwfdr_op # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - - # -- INITIALIZE VALUES -- - approach_cost = np.zeros((vector_len, replication, N_APPROACH_MODES), dtype=np.float32) - approach_waittime = np.zeros((vector_len, replication, N_APPROACH_MODES), dtype=np.float32) - approach_drivetime = np.zeros((vector_len, replication, N_APPROACH_MODES), dtype=np.float32) - approach_walktime = np.zeros((vector_len, replication, N_APPROACH_MODES), dtype=np.float32) - TVAR4 = np.zeros((vector_len, replication, 5), dtype=np.float32) - - best_approach_mode = np.zeros((vector_len,replication, N_TRIP_ENDS), dtype=np.int8) - best_cost = np.zeros((vector_len, replication, N_TRIP_ENDS), dtype=np.int32) - best_waittime = np.zeros((vector_len, replication, N_TRIP_ENDS), dtype=np.int32) - best_walktime = np.zeros((vector_len, replication, N_TRIP_ENDS), dtype=np.int32) - best_drivetime = np.zeros((vector_len, replication, N_TRIP_ENDS), dtype=np.int32) - # - # GET ZONE TYPES - # - ozone_type = ZTYPE[ozone_idx] - dzone_type = ZTYPE[dzone_idx] - # - # GET INTERCHANGE ATTRIBUTES - # FM=FIRST MODE,LM=LAST MODE,PM=PRIORITY MODE - # - FM = np.empty(ozone_idx.size, dtype=np.int8) - LM = np.empty(ozone_idx.size, dtype=np.int8) - if TPTYPE == 'HW': - for i in range(ozone_idx.size): - FM[i] = FM_pk[ozone_idx[i], dzone_idx[i]] - LM[i] = LM_pk[ozone_idx[i], dzone_idx[i]] - else: - for i in range(ozone_idx.size): - FM[i] = FM_op[ozone_idx[i], dzone_idx[i]] - LM[i] = LM_op[ozone_idx[i], dzone_idx[i]] - # - # INET TRANSIT NETWORK STORES SOME SUBURBAN BUS LINES (MODE=6) - # AS MODE=5 DUE TO ARRAY SIZE LIMITS. IF MODE=5 AND - # ZONE TYPE NO. 1 IS OUTSIDE OF CHICAGO, THEN CHANGE MODE TO 6. - # - - FM[(FM == 5) & (ozone_type > 2)] = 6 - LM[(LM == 5) & (ozone_type > 2)] = 6 - - # - # GET APPROACH DISTANCES FOR FIRST AND LAST MODES - # - - assert approach_distances.shape == (vector_len, replication, N_DIST_TO_TYPES, N_TRIP_ENDS) - - # CHECK FIRST/LAST MODES AND COMPUTE APPROACH TIME AND COST - # - # ARRAYS approach_walktime,APCOST,approach_drivetime CONTAIN TIME TO WALK,APPROACH COST, - # AND IN-VEHICLE APPROACH TIME RESPECTIVELY. THESE ARRAYS HAVE FIVE - # ELEMENTS FOR FIVE POSSIBLE APPROACH MODES.( 1-WALK,2-BUS, - # 3-PARK & RIDE,4-KISS & RIDE,AND 5-FEEDER BUS) - # - - for I in range(N_TRIP_ENDS): - # I=1 GET VALUES FOR ORIGIN - # I=2 GET VALUES FOR DESTINATION - if (I == FRONT_END): - Z = ozone - M = FM - else: # I == BACK_END - Z = dzone - M = LM - - ZTYPE_Z = ZTYPE[Z-1] - - # - # IN THIS CASE WE ARE MAKING THE STATION PARKING COST FOR HOME BASED OTHER AND - # NON-HOME BASED TRIPS EQUAL TO 60 PERCENT OF HOME BASED WORK - # CHANGE MADE 12/8/93 BY GWS NEXT LINE - # IF(TPTYPE.NE.1) PRCOST(Z) = PRCOST(Z) * 0.6 - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # NONWORK PARK AND RIDE PARKING COST IS NOW READ FROM M01. IN MANY - # CASES THE NONWORK PNR COSTS ARE HIGHER THAN WORK DUE TO - # DISCOUNTING OF MONTHLY PARKING FEES. - # - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # SET HIGH STARTING VALUE OF TVAR5 - TVAR5 = np.full((vector_len, replication), 1.E10) - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # IN CALCULATING TVAR4 AND TVAR5 - # IN-VEHICLE TIME = DRVOT = 20 CENTS/MIN - # OUT-OF-VEHICLE TIME = 40 CENTS/MIN - # PASSENGER TIME = 0.5 DRIVER TIME - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # - # FOLLOWING SECTION ADDED BY EASH TO SIMPLIFY LOGIC - # IF M IS BUS (MODE<7) THEN ONLY POSSIBLE APPROACH COST IS TIME TO - # WALK TO BUS. OTHER APPROACH COSTS AND TIMES ARE LINE=HAUL. - t1 = (M < TransitModeCode_CTA_RAIL) - if np.any(t1): - J = APPROACH_WALK - approach_walktime[t1,:,J] = approach_distances[t1,:, DIST_TO_BUS, I] / SPDWLK * 600. - # INCREASE WALK TIME IN CHICAGO CBD FOR WORK TRIPS - cbd_work = t1 & (ZTYPE_Z == 1) & (TPTYPE == HW) - approach_walktime[cbd_work,:,J] *= 1.20 - - # if (ZTYPE_Z == 1 and TPTYPE == HW): - # approach_walktime[:, 0] = approach_walktime[:, 0] * 1.20 - TVAR4[t1,:, J] = approach_walktime[t1,:, 0] * DRVOT * 2.0 - TVAR5[t1,:] = TVAR4[t1,:, J] - best_approach_mode.reshape((vector_len,replication,N_TRIP_ENDS))[t1,:, I] = 0 - best_drivetime[t1,:, I] = 0 - best_walktime[t1,:, I] = approach_walktime[t1,:, 0] + .5 - best_cost[t1, :, I] = 0 - best_waittime[t1,:, I] = 0 - for J in [APPROACH_BUS, APPROACH_PARK_N_RIDE, APPROACH_KISS_N_RIDE, APPROACH_FEEDER_BUS]: - TVAR4[t1,:, J] = 0.0 - approach_cost[t1, :, J] = 0.0 - approach_waittime[t1, :, J] = 0.0 - approach_drivetime[t1,:, J] = 0.0 - approach_walktime[t1,:, J] = 0.0 - - t = (M >= TransitModeCode_CTA_RAIL) - if np.any(t): - # REMAINDER OF SUBROUTINE FOR RAIL TRANSIT/COMMUTER RAIL ONLY - # GET VALUES FOR FIVE ALTERNATIVES - for J in range(5): - TVAR4[t,:, J] = 0.0 - approach_cost[t, :, J] = 0.0 - approach_waittime[t,:,J] = 0.0 - approach_drivetime[t,:, J] = 0.0 - approach_walktime[t,:, J] = 0.0 - - K = np.maximum(0, M - 6).astype(np.int8) # 0 for BUS, 1 for CTA RAIL(7-1), 2 for METRA(8-1) - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=0(WALK).COMPUTE WALKING TIME TO FIRST MODE.NO COST OR IN-VEHICLE TIME - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - if J == APPROACH_WALK: - - for _kt in range(approach_distances.shape[2]): - kt = t & (K == _kt) - approach_walktime[kt,:, J] = approach_distances[kt, :, _kt, I] / SPDWLK * 600. - # INCREASE WALK TIME IN CHICAGO CBD FOR WORK TRIPS - cbd_work = t & (ZTYPE_Z == 1) & (TPTYPE == HW) - approach_walktime[cbd_work,:, J] *= 1.20 - # if (ZTYPE_Z == 1 and TPTYPE == HW): - # approach_walktime[:, J] = approach_walktime[:, J] * 1.20 - TVAR4[t,:, J] = approach_walktime[t,:, J] * DRVOT * 2.0 - # ADD APPROACH TIMES AND COSTS - EVERYTHING SHOULD NOW BE IN CENTS - TVAR4[t,:, J] += approach_cost[t, :, J] - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=1(BUS) FIRST MODE. COMPUTE WALKING TIME, COST, AND IN-VEHICLE TIME - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif J == APPROACH_BUS or (J == APPROACH_FEEDER_BUS and I == FRONT_END): - - if J == APPROACH_FEEDER_BUS: - approach_walktime[t, :, J] = approach_distances[t,:, DIST_TO_FEEDER_BUS, I] * 600.0 / SPDWLK - approach_waittime[t, :, J] = np.expand_dims(fwfdr[Z-1][t], 1) # broadcast - else: - approach_walktime[t,:, J] = approach_distances[t,:, DIST_TO_BUS, I] * 600.0 / SPDWLK - # INCREASE WALK TIME IN CHICAGO CBD - approach_walktime[t & (ZTYPE_Z == 1), :, J] *= 1.20 - approach_waittime[t,:,J] = np.expand_dims(fwbus[Z-1][t],1) # broadcast - for _kt in range(approach_distances.shape[2]): - kt = t & (K == _kt) - approach_drivetime[kt,:, J] = approach_distances[kt,:, _kt, I] / np.expand_dims(SPEEDS[ZTYPE_Z[kt]-1 + 4],1) * 60. # broadcast - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * OVT_IVT_RATIO - + approach_drivetime[t,:, J] - + approach_waittime[t,:,J] * OVT_IVT_RATIO - ) * DRVOT - - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # - # COST COMPUTATIONS FOR APPROACH BUS - # REVISED BY EASH 12/4/93 TO REFLECT CURRENT FARES - # ==== ORIGIN ==== - if (I == FRONT_END): - # FIRST MODE SUBURBAN RAIL - CHECK ZONE TYPE AT ORIGIN - # --- SUBURBAN ORIGIN, PACE BUS --- - s = t & (FM == TransitModeCode_METRA_RAIL) & (ozone_type > 2) - if np.any(s): - # PACE BUS - METRA RAIL, ADDED FARE IS PACE FEEDER BUS FARE - approach_cost[s & (LM == TransitModeCode_METRA_RAIL), :, J] = FEEDER_BUS_BOARDING_FARE - # PACE BUS - METRA RAIL - CTA, NO ADDED FARE, LINKUP > FEEDER BUS - # already zero # approach_cost[s & (LM == TransitModeCode_CTA_RAIL), :, J] = 0 - # PACE BUS - METRA RAIL - PACE, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (LM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - - # --- CHICAGO ORIGIN, CTA BUS --- - s = t & (FM == TransitModeCode_METRA_RAIL) & (ozone_type <= 2) - if np.any(s): - # CTA BUS - METRA RAIL, ADDED FARE IS LINKUP FARE (SINGLE RIDE) - approach_cost[s & (LM == TransitModeCode_METRA_RAIL), :, J] = CTA_CBD_LINK_UP_FARE - # CTA BUS - METRA RAIL - CTA, ADDED FARE IS CTA TRANSFER - approach_cost[s & (LM == TransitModeCode_CTA_RAIL), :, J] = CTA_FIRST_XFER_FARE - # CTA BUS - METRA RAIL - PACE, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (LM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - - # FIRST MODE CTA RAIL - # WHEN THIS IS TRUE A FULL FARE AND TRANSFER HAVE - # BEEN PAID, SO NO ADDED FARE IS NEEDED FOR BUS - - - # ORIGIN OTHER THAN CHICAGO, ADDED FARE IS NOW AN RTA TRANSFER - s = t & (FM < TransitModeCode_CTA_RAIL) & (ozone_type > 2) - if np.any(s): - approach_cost[s, :, J] = PACE_BUS_FIRST_XFER_FARE - - # CHICAGO ORIGIN, ADDED FARE IS CTA TRANSFER - s = t & (FM < TransitModeCode_CTA_RAIL) & (ozone_type <= 2) - if np.any(s): - approach_cost[s, :, J] = CTA_FIRST_XFER_FARE - - TVAR4[t, :, J] += approach_cost[t, :, J] - - - # ==== DESTINATION ==== - else: - # LAST MODE SUBURBAN RAIL - s = t & (LM == TransitModeCode_METRA_RAIL) & (dzone_type > 2) - if np.any(s): - # SUBURBAN DESTINATION, PACE BUS - # METRA RAIL - PACE BUS, ADDED FARE IS PACE FEEDER BUS FARE - approach_cost[s & (FM == TransitModeCode_METRA_RAIL), :, J] = FEEDER_BUS_BOARDING_FARE - # CTA - METRA RAIL - PACE BUS, NO ADDED FARE, LINKUP > FEEDER BUS - # PACE - METRA RAIL - PACE BUS, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (FM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - s = t & (LM == TransitModeCode_METRA_RAIL) & (dzone_type <= 2) - if np.any(s): - # CHICAGO DESTINATION, CTA BUS - # METRA - CTA BUS, ADDED COST IS LINKUP FARE (SINGLE RIDE) - approach_cost[s & (FM == TransitModeCode_METRA_RAIL), :, J] = CTA_CBD_LINK_UP_FARE - # CTA - METRA - CTA BUS, ADDED COST IS CTA TRANSFER - approach_cost[s & (FM == TransitModeCode_CTA_RAIL), :, J] = CTA_FIRST_XFER_FARE - # PACE - METRA - CTA BUS, ADDED COST IS LINKUP MINUS FEEDER BUS - approach_cost[s & (FM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - # ADD CTA TRANSFER IF NOT ALREADY PAID BUT IT WAS USED - s = t & (LM < TransitModeCode_CTA_RAIL) & (dzone_type > 2) - if np.any(s): - approach_cost[s, :, J] = CTA_FIRST_XFER_FARE * ( - (best_approach_mode[s,:, FRONT_END]==APPROACH_BUS) - |(best_approach_mode[s,:, FRONT_END]==APPROACH_FEEDER_BUS) - ) - - TVAR4[t, :, J] += approach_cost[t, :, J] - - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=2(PARK & RIDE) FIRST MODE. PARK & RIDE FOR APPROACH TO RAPID TRANSIT AND SUBURBAN RAIL ROAD - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif (J == APPROACH_PARK_N_RIDE and I == FRONT_END): - approach_drivetime[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] / np.expand_dims(SPEEDS[ZTYPE_Z[t] - 1],1) * 60. # broadcast - approach_walktime[t,:, J] = W2PNR - # APPROACH COST=PER MILE COST + FIXED COST - approach_cost[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] * np.expand_dims(AUTO_OPERATING_COST_BY_ZONETYPE[ZTYPE_Z[t] - 1],1) # broadcast - # OPERATING COST MAY NOT BE LESS THAN 5 CENTS - approach_cost[t,:, J] = np.fmax(approach_cost[t,:, J], 5.0) - - approach_cost[t,:, J] = approach_cost[t,:, J] + AFC1 - # ADD HALF OF THE PARKING COST IF PARK-&-RIDE AVAILABLE - _tz = t&PNRAVL[Z-1] - approach_cost[_tz,:, J] += np.expand_dims(PRCOST[Z-1][_tz],1) / 2 # broadcast - # IF NO PARK-&-RIDE FACILITY AVAILABLE INCREASE WALK TIME - approach_walktime[~_tz,:, J] = 3 * W2PNR - - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * DRVOT * 2.0 - + approach_drivetime[t,:, J] * DRVOT - + approach_cost[t,:, J] - ) - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=3(KISS & RIDE) FIRST MODE. KISS & RIDE FOR APPROACH TO RAPID TRANSIT AND SUBURBAN RAIL ROAD - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif (J == APPROACH_KISS_N_RIDE and I == FRONT_END): - approach_drivetime[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] / np.expand_dims(SPEEDS[ZTYPE_Z[t] - 1],1) * 60. # broadcast - approach_walktime[t,:, J] = W2PNR - approach_cost[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] * np.expand_dims(AUTO_OPERATING_COST_BY_ZONETYPE[ZTYPE_Z[t] - 1],1) # broadcast - approach_cost[t,:, J] = np.fmin(approach_cost[t,:, J], 5.0) - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # ASSUMPTION IS THAT KISS AND RIDE REQUIRES A SPECIAL - # TRIP FROM HOME. DRIVER AND PASSENGER TIME VALUES NOW EQUAL. - # APCOST[J]=APCOST[J]*2.+AFC2+(DRVOT*approach_drivetime[J]*2.)/10 - approach_cost[t,:, J] = approach_cost[t,:, J] * 2. + AFC2 - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * OVT_IVT_RATIO - + approach_drivetime[t,:, J] * 2 # KISSING DRIVER - + approach_drivetime[t,:, J] - ) * DRVOT - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - TVAR4[t,:, J] += approach_cost[t,:, J] - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # EVALUATE APPROACH MODES AND SELECT THE BEST - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # FOLLOWING CODE CHANGED BY EASH 12/6/93 TO REFLECT - # NEW TRIP TYPES - # TPTYPE = 1 HOME PRODUCTIONS TO WORK ATTRACTIONS - # TPTYPE = 2 HOME PRODUCTIONS TO NON-WORK/NON-HOME ATTRACTIONS - # TPTYPE = 3 NON-HOME PRODUCTIONS TO NON-HOME ATTRACTIONS - for J in range(N_APPROACH_MODES): - # NO KISS-&-RIDE FOR NON-WORK TRIPS - if (TPTYPE != HW and J == APPROACH_KISS_N_RIDE): - continue - # NO PARK-AND RIDE OR KISS-&-RIDE AT THE WORK/OTHER - # ATTRACTION END FOR HOME BASED TRIPS - if (TPTYPE != NH and I == BACK_END and (J == APPROACH_PARK_N_RIDE or J == APPROACH_KISS_N_RIDE)): - continue - # NO PARK-&-RIDE OR KISS AND RIDE FOR NON-HOME TO NON-HOME TRIPS - if (TPTYPE == NH and (J == APPROACH_PARK_N_RIDE or J == APPROACH_KISS_N_RIDE)): - continue - # -- FIND LOWEST COST APPROACH - for _i1 in range(TVAR4.shape[0]): - for _i2 in range(TVAR4.shape[1]): - if (TVAR4[_i1, _i2, J] > 0) and (TVAR4[_i1, _i2, J] < TVAR5[_i1, _i2]): - TVAR5[_i1, _i2] = TVAR4[_i1, _i2, J] - best_approach_mode[_i1, _i2, I] = J - best_drivetime[_i1, _i2, I] = approach_drivetime[_i1, _i2, J] + .5 - best_walktime[_i1, _i2, I] = approach_walktime[_i1, _i2, J] + .5 - best_cost[_i1, _i2, I] = approach_cost[_i1, _i2, J] + .5 - best_waittime[_i1, _i2, I] = approach_waittime[_i1, _i2, J] + .5 - - # if trace: - # log.log(trace, f" DIRECTION {I} APPROACH TYPE {J} {APPROACH_MODE_NAMES.get(J)}") - # log.log(trace, f" drivetime {approach_drivetime[:5,:5, J]}") - # log.log(trace, f" walktime {approach_walktime[:5,:5, J]}") - # log.log(trace, f" cost {approach_cost[:5,:5, J]}") - # log.log(trace, f" waittime {approach_waittime[:5,:5,J]}") - # log.log(trace, f" gen cost {TVAR4[:5,:5, J]}") - # if trace: - # log.log(trace, f" DIRECTION {I} BEST APPROACH TYPE {best_approach_mode[:5,I]}") - - - # ADD ORIGIN AND DESTINATION QUANTITIES AND PASS BACK TO TRIPS - - ae_drivetime = best_drivetime[:,:, 0] + best_drivetime[:,:, 1] - ae_walktime = best_walktime[:,:, 0] + best_walktime[:,:, 1] - ae_cost = best_cost[:,:, 0] + best_cost[:,:, 1] - ae_waittime = best_waittime[:,:, 0] + best_waittime[:,:, 1] - - ae_drivetime = ae_drivetime.reshape((vector_len,replication)) - ae_walktime = ae_walktime.reshape((vector_len,replication)) - ae_cost = ae_cost.reshape((vector_len,replication)) - ae_waittime = ae_waittime.reshape((vector_len,replication)) - best_approach_mode = best_approach_mode.reshape((vector_len,replication,N_TRIP_ENDS)) - - out[:,:,0] = ae_drivetime - out[:,:,1] = ae_walktime - out[:,:,2] = ae_cost - out[:,:,3] = ae_waittime - out[:,:,4] = best_approach_mode[:,:,0] - out[:,:,5] = best_approach_mode[:,:,1] - - # return ( - # ae_drivetime, - # ae_walktime, - # ae_cost, - # ae_waittime, - # best_approach_mode, - # ) - -@nb.njit(parallel=True, cache=True) -def transit_approach_parallel( - trapp_struct, - ozone, - dzone, - TPTYPE, - approach_distances, -): - out = np.zeros((ozone.size, approach_distances.shape[1], 6), dtype=np.int32) - slices = ozone.size // 100 + (1 if ozone.size % 100 else 0) - for i in nb.prange(slices): - s = slice(i*100, (i+1)*100) - transit_approach( - trapp_struct, - ozone[s], - dzone[s], - TPTYPE, - approach_distances[s], - out[s], - ) - return ( - out[:, :, 0], - out[:, :, 1], - out[:, :, 2], - out[:, :, 3], - out[:, :, 4:], - ) - -def transit_approach_wrap( - trapp_struct, - ozone, - dzone, - TPTYPE, - approach_distances, -): - out_tuple = transit_approach_parallel( - trapp_struct, - ozone, - dzone, - TPTYPE, - approach_distances, - ) - out = Dict() - out.drivetime = out_tuple[0] - out.walktime = out_tuple[1] - out.cost = out_tuple[2] - out.waittime = out_tuple[3] - out.approach_mode = out_tuple[4] - return out - -#return transit_approach_wrap, transit_approach_distances \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/hh_sampling.py b/src/Mode-Dest-TOD/cmap_modedest/hh_sampling.py deleted file mode 100644 index 72e5486..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/hh_sampling.py +++ /dev/null @@ -1,25 +0,0 @@ -import numpy as np -import pandas as pd -from cmap_modedest.random_states import check_random_generator - - -def sample_hh_from_zone(dh, zone, n_hh, random_state=None, attr=('N_ADULTS', 'N_VEHICLES')): - pool = dh.hh_tabulation.loc[zone] - hhv_types = dh.hhv_types - pool_sum = pool.sum() - if pool_sum: - hhv_prob = pool / pool_sum - else: - # No households in this zone to enumerate, sample from region instead to avoid NaNs - pool = dh.hh_tabulation.sum() - pool_sum = pool.sum() - hhv_prob = pool / pool_sum - prng = check_random_generator(random_state) - draws = prng.choice(624, size=n_hh, p=hhv_prob) - result = pd.DataFrame(-1, dtype=np.int8, columns=attr, index=pd.RangeIndex(n_hh)) - for i, a in enumerate(attr): - if a == 'N_ADULTS': - result.values[:, i] = hhv_types[a].cat.codes.iloc[draws] + 1 - else: - result.values[:, i] = hhv_types[a].cat.codes.iloc[draws] - return result diff --git a/src/Mode-Dest-TOD/cmap_modedest/incomes.py b/src/Mode-Dest-TOD/cmap_modedest/incomes.py deleted file mode 100644 index 08eb695..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/incomes.py +++ /dev/null @@ -1,99 +0,0 @@ -import numpy as np -import pandas as pd -from scipy.stats import lognorm - -from .random_states import check_random_generator - -income_levels_1 = { - 1 : 12_000, # Less than $15,000 - 2 : 20_000, # $15,000 to $24,999 - 3 : 27_500, # $25,000 to $29,999 - 4 : 32_500, # $30,000 to $34,999 - 5 : 42_500, # $35,000 to $49,999 - 6 : 55_000, # $50,000 to $59,999 - 7 : 65_000, # $60,000 to $74,999 - 8 : 85_000, # $75,000 to $99,999 - 9 : 120_000, # $100,000 to $149,999 - 10 : 170_000, # $150,000 or more -} - -income_levels_2 = { - 1 : 25_001, # Less than $30,000 - 2 : 40_001, # $30,000 to $59,999 - 3 : 70_001, # $60,000 to $99,999 - 4 : 125_001, # $100,000 to $149,999 - 5 : 175_001, # $150,000 or more -} - - - -def random_incomes( - median_income, - replications, - random_state=None, - sigma=0.42, - bins=None, - trunc_max=None, - trunc_min=None, -): - """ - Draw random income levels from a log-normal distribution - - Parameters - ---------- - median_income : numeric - replications : int - Size of resulting array - random_state : RandomState - sigma : float, default 0.42 - The standard deviation of the underlying normal distribution. - The default of 0.42 is retained from prior versions of the CMAP - trip-based model, although a bug in that model resulted in a - downward bias in the random draws. - bins : array-like or '5', optional, - If provided, digitize into these bins. - - Returns - ------- - ndarray - """ - random_generator = check_random_generator(random_state) - y = lognorm(sigma, scale=median_income).rvs( - replications, - random_state=random_generator, - ) - # resample from acceptable draws when truncated - if trunc_max is not None: - acceptable = y[(y <= trunc_max)] - acceptable_size = acceptable.size - if acceptable_size == 0: - acceptable = [trunc_max] - swaps = random_generator.choice(acceptable, y.size-acceptable_size) - y[(y > trunc_max)] = swaps - if trunc_min is not None: - acceptable = y[(y >= trunc_min)] - acceptable_size = acceptable.size - if acceptable.size == 0: - acceptable = [trunc_min] - swaps = random_generator.choice(acceptable, y.size-acceptable_size) - y[(y < trunc_min)] = swaps - if bins == '5': - bins = [ - -np.inf, - 30_000, - 60_000, - 100_000, - 150_000, - np.inf, - ] - if bins == '4': - bins = [ - -np.inf, - 30_000, - 60_000, - 150_000, - np.inf, - ] - if bins is not None: - return np.digitize(y, bins) - return y \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/modecodes.py b/src/Mode-Dest-TOD/cmap_modedest/modecodes.py deleted file mode 100644 index 8524a96..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/modecodes.py +++ /dev/null @@ -1,60 +0,0 @@ -import numpy as np -from .addict import Dict - -mode5names = ['AUTO', 'TAXI', 'TNC1', 'TNC2', 'TRANSIT'] -mode5codes = Dict(zip( - mode5names, - np.arange(len(mode5names)) + 1, -)) - -mode7names = ['AUTO', 'TAXI', 'TNC1', 'TNC2', 'TRANSIT', 'WALK', 'BIKE'] -mode7codes = Dict(zip( - mode7names, - np.arange(len(mode7names)) + 1, -)) - -mode9names = ['AUTO', 'HOV2', 'HOV3', 'TAXI', 'TNC1', 'TNC2', 'TRANSIT', 'WALK', 'BIKE'] -mode9codes = Dict(zip( - mode9names, - np.arange(len(mode9names)) + 1, -)) - - -TransitModeCode_CTA_REGULAR_BUS = 4 -TransitModeCode_CTA_EXPRESS_BUS = 5 -TransitModeCode_PACE_BUS = 6 -TransitModeCode_CTA_RAIL = 7 -TransitModeCode_METRA_RAIL = 8 - -N_TRANSIT_MODES = 8 - - -APPROACH_WALK = 0 -APPROACH_BUS = 1 -APPROACH_PARK_N_RIDE = 2 -APPROACH_KISS_N_RIDE = 3 -APPROACH_FEEDER_BUS = 4 - -N_APPROACH_MODES = 5 -APPROACH_MODE_NAMES = { - APPROACH_WALK: 'Walk', - APPROACH_BUS: 'Bus', - APPROACH_PARK_N_RIDE: 'PnR', - APPROACH_KISS_N_RIDE: 'KnR', - APPROACH_FEEDER_BUS: 'Feeder', -} - -DIST_TO_BUS = 0 -DIST_TO_CTA_RAIL = 1 -DIST_TO_METRA = 2 -DIST_TO_FEEDER_BUS = 3 -DIST_TO_PARK_N_RIDE_STATION = 4 - -N_DIST_TO_TYPES = 5 -DIST_TO_NAMES = { - DIST_TO_BUS: 'to Bus', - DIST_TO_CTA_RAIL: 'to El', - DIST_TO_METRA: 'to Metra', - DIST_TO_FEEDER_BUS: 'to Feeder', - DIST_TO_PARK_N_RIDE_STATION: 'to PnR', -} \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/numexpr_patch.py b/src/Mode-Dest-TOD/cmap_modedest/numexpr_patch.py deleted file mode 100644 index 59dd7a5..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/numexpr_patch.py +++ /dev/null @@ -1,31 +0,0 @@ - -# Numexpr's caching sometimes fails on dask multi-threaded - - -class CacheDictSafe(dict): - """ - A dictionary that prevents itself from growing too much. - """ - - def __init__(self, maxentries): - self.maxentries = maxentries - super(CacheDictSafe, self).__init__(self) - - def __setitem__(self, key, value): - # Protection against growing the cache too much - if len(self) > self.maxentries * 2: - # The cache is overflowing, wipe it completely - super(CacheDictSafe, self).clear() - if len(self) > self.maxentries: - # Remove a 10% of (arbitrary) elements from the cache - entries_to_remove = self.maxentries // 10 - for k in list(self.keys())[:entries_to_remove]: - try: - super(CacheDictSafe, self).__delitem__(k) - except KeyError: - pass - super(CacheDictSafe, self).__setitem__(key, value) - - -import numexpr as ne -ne.necompiler._numexpr_cache = CacheDictSafe(256) diff --git a/src/Mode-Dest-TOD/cmap_modedest/parking_costs.py b/src/Mode-Dest-TOD/cmap_modedest/parking_costs.py deleted file mode 100644 index 924b198..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/parking_costs.py +++ /dev/null @@ -1,371 +0,0 @@ -import numpy as np -import pandas as pd -from .random_states import check_random_generator - -# cbd_parking = pd.read_csv( -# filenames.HW_CBDPARK, -# header=None, -# names=['ZoneID', 'CumProb', 'ThresholdPrice', 'SavePrice', 'WalkSeconds'], -# ) -# cbd_parking.CumProb /= 10000. -# # cbd_parking['SumPrice'] = cbd_parking.ThresholdPrice + cbd_parking.SavePrice -# cbd_parking['rownum'] = cbd_parking.groupby(['ZoneID']).cumcount() -# _z = cbd_parking.ZoneID.value_counts().sort_index().index -# CBD_PARKING_ZONES = dict(zip(_z, np.arange(len(_z)))) -# -# -# def decumulate(x): -# x_ = np.array(x) -# x_[1:] -= x[:-1] -# return x_ -# cbd_parking['Prob'] = cbd_parking.groupby("ZoneID")['CumProb'].transform(decumulate) -# cbd_parking['WeightedPrice'] = cbd_parking['Prob'] * cbd_parking['ThresholdPrice'] -# cbd_parking_prices = cbd_parking.set_index(["ZoneID",'rownum']).ThresholdPrice.unstack() -# cbd_parking_price_prob = cbd_parking.set_index(["ZoneID",'rownum']).Prob.unstack() -# -# -# -# -# cbd_parking2 = pd.read_csv( -# filenames.HW_CBDPARK2, -# header=None, -# names=[ -# 'IncomeCeiling', -# 'FreeParkingPct', -# 'TransitPct', -# 'AutoOcc1Pct', -# 'AutoOcc2Pct', -# 'AutoOcc3Pct', -# 'AutoOcc4Pct', -# ], -# ) - - -# def parking_cost_cbd( -# ORIG, -# DEST, -# INCOME, -# HOURS, -# random_state=None, -# ): -# """ -# This function tries to exactly replicate the FORTRAN PRKCBD, right or wrong -# -# Parameters -# ---------- -# ORIG, DEST : int -# TAZ ID for origin, destination -# INCOME : array-like, shape[ITER] -# HOURS : numeric -# Number of hours of parking to pay for -# CBD_PARKING_ZONES : Mapping -# Maps destination zone numbers to CBD parking zone numbers -# random_state -# -# Returns -# ------- -# CAPK, WALK3, INTOCC, BLK, SI : array, shape[ITER] -# parking cost, walktime, vehicle occupancy, blocks walked, savings rate -# """ -# global CBD_PARKING_ZONES -# random_state = check_random_generator(random_state) -# -# ITER = INCOME.shape[0] -# -# J6 = np.zeros(ITER) -# J7 = np.ones(ITER) -# J3 = np.zeros(ITER, dtype=int) -# L = np.zeros(ITER, dtype=int) -# -# RAN2 = random_state.random(size=ITER) -# RAN3 = random_state.random(size=ITER) * 100. # Free Parking randomizer -# RAN4 = random_state.random(size=ITER) -# RAN5 = random_state.random(size=ITER) * 100. # Auto Occupancy randomizer -# -# # ORIG = pd.Series(ORIG) -# # DEST = pd.Series(DEST) -# -# PZONE = CBD_PARKING_ZONES[DEST] -# FREEPRK = np.empty(ITER) -# for j2 in reversed(range(5)): -# k = INCOME 1] = 0 -# J6[J7 == 0] = 1 -# -# VT = INCOME/2400. -# -# # Baseline free parking -# CAPK = np.zeros(ITER, dtype=int) -# WALK3 = np.full(ITER, 3.0) -# HC = np.zeros(ITER) -# SI = np.zeros(ITER) -# WK = np.zeros(ITER) -# BLK = np.zeros(ITER) -# -# paid_parking = (RAN3 > FREEPRK) -# HC[paid_parking] = ( -# J7 * CBDPRK.ThresholdPrice.iloc[0] + # when using first row -# J6 * (HCPT1 + (HCPT2-HCPT1)*(HCPT3-RAN2)/(HCPT3_4)) # when using other rows -# )[paid_parking] -# SI[paid_parking] = CBDPRK.SavePrice[J3].values[paid_parking] -# WK[paid_parking] = np.fmax(CBDPRK.WalkSeconds[J3].values[paid_parking], 180) -# BLK[paid_parking] = SI[paid_parking] / (VT[paid_parking] * WK[paid_parking] / 60.) # BLK IS BLOCKS WALKED -# BLK[paid_parking] = np.clip(BLK[paid_parking], 0.25, 6.0) -# WALK3[paid_parking] = (BLK[paid_parking] * WK[paid_parking]) / 60. -# CAPK[paid_parking] = np.clip(HC[paid_parking] * HOURS - BLK[paid_parking] * SI[paid_parking], 0.0, None) -# -# INTOCC = np.zeros(ITER, dtype=np.int8) -# RAN5 -= cbd_parking2.loc[L, 'AutoOcc1Pct'].values -# INTOCC[(INTOCC==0) & (RAN5 < 0)] = 1 -# RAN5 -= cbd_parking2.loc[L, 'AutoOcc2Pct'].values -# INTOCC[(INTOCC==0) & (RAN5 < 0)] = 2 -# RAN5 -= cbd_parking2.loc[L, 'AutoOcc3Pct'].values -# INTOCC[(INTOCC==0) & (RAN5 < 0)] = 3 -# INTOCC[(INTOCC==0)] = 4 -# -# return CAPK, WALK3, INTOCC, BLK, SI -# - -def parking_cost_v2( - dh, - DEST, - INCOME, - HOURS, - purpose, - random_state=None, -): - - """ - Draw a parking cost from the random distribution in the destination zone. - - Parameters - ---------- - DEST : array-like, shape[ITER] - TAZ ID for destination - INCOME : array-like, shape[ITER] - HOURS : numeric - Number of hours of parking to pay for - random_state - - Returns - ------- - CAPK, WALK3, INTOCC, BLK, SI : array, shape[ITER] - parking cost, walktime, vehicle occupancy, blocks walked, savings rate - """ - global CBD_PARKING_ZONES, cbd_parking_price_prob, cbd_parking_prices - random_state = check_random_generator(random_state) - - DEST = pd.Series(DEST) - ITER = DEST.size - - rand_free_parking = random_state.random(size=ITER) * 100. # Free Parking randomizer - rand_parking_price = random_state.random(size=ITER) # Parking Rate randomizer - RAN5 = random_state.random(size=ITER) * 100. # Auto Occupancy randomizer - - price_probs = dh.cbd_parking_price_prob.reindex(DEST.values) - prices = dh.cbd_parking_prices.reindex(DEST.values) - parking_price_row = np.full(ITER, -1, dtype=np.int8) - for i in range(5): - rand_parking_price -= price_probs.iloc[:,0] - parking_price_row[(parking_price_row < 0) & (rand_parking_price < 0)] = i - - # Assemble the randomly selected parking-price columns into one Series. - # It will have NaN values for zones outside the CBD parking model - parking_price_1 = pd.Series( - prices.values[range(len(parking_price_row)), parking_price_row], - index=DEST.index, - ) - - # Assemble default hourly pricing to use for trips based on zone type - # This Series is len(Zones) not len(Trips) - zonetype_price = dh.m01.zone_type.map(dh.cfg.parking_costs.defaults[purpose]) - - # Fill in NaNs with default values. - parking_price_2 = DEST.map(zonetype_price) - parking_price = parking_price_1.fillna(parking_price_2) - - # Find free parking rate based on income group - income_group = np.zeros(ITER, dtype=int) - FREEPRK = np.zeros(ITER) - for j2 in reversed(range(5)): - k = INCOME 1] = 0 - # J6[J7 == 0] = 1 - # - # VT = INCOME/2400. - # - # # Baseline free parking - # CAPK = np.zeros(ITER, dtype=int) - # WALK3 = np.full(ITER, 3.0) - # HC = np.zeros(ITER) - # SI = np.zeros(ITER) - # WK = np.zeros(ITER) - # BLK = np.zeros(ITER) - # - # paid_parking = (RAN3 > FREEPRK) - # HC[paid_parking] = ( - # J7 * CBDPRK.ThresholdPrice.iloc[0] + # when using first row - # J6 * (HCPT1 + (HCPT2-HCPT1)*(HCPT3-RAN2)/(HCPT3_4)) # when using other rows - # )[paid_parking] - # SI[paid_parking] = CBDPRK.SavePrice[J3].values[paid_parking] - # WK[paid_parking] = np.fmax(CBDPRK.WalkSeconds[J3].values[paid_parking], 180) - # BLK[paid_parking] = SI[paid_parking] / (VT[paid_parking] * WK[paid_parking] / 60.) # BLK IS BLOCKS WALKED - # BLK[paid_parking] = np.clip(BLK[paid_parking], 0.25, 6.0) - # WALK3[paid_parking] = (BLK[paid_parking] * WK[paid_parking]) / 60. - # CAPK[paid_parking] = np.clip(HC[paid_parking] * HOURS - BLK[paid_parking] * SI[paid_parking], 0.0, None) - # - # INTOCC = np.zeros(ITER, dtype=np.int8) - # RAN5 -= cbd_parking2.loc[L, 'AutoOcc1Pct'].values - # INTOCC[(INTOCC==0) & (RAN5 < 0)] = 1 - # RAN5 -= cbd_parking2.loc[L, 'AutoOcc2Pct'].values - # INTOCC[(INTOCC==0) & (RAN5 < 0)] = 2 - # RAN5 -= cbd_parking2.loc[L, 'AutoOcc3Pct'].values - # INTOCC[(INTOCC==0) & (RAN5 < 0)] = 3 - # INTOCC[(INTOCC==0)] = 4 - # - # return CAPK, WALK3, INTOCC, BLK, SI - - -def parking_cost_v3( - dh, - DEST, - HOURS, - purpose, - random_state=None, -): - - """ - Draw a parking cost from the random distribution in the destination zone. - - Parameters - ---------- - dh : DataHandler - DEST : array-like, shape[ITER] - TAZ ID for destination - HOURS : numeric - Number of hours of parking to pay for - purpose : str - Used to determine the default price per hour by zonetype. - - random_state - - Returns - ------- - CAPK, WALK3, INTOCC, BLK, SI : array, shape[ITER] - parking cost, walktime, vehicle occupancy, blocks walked, savings rate - """ - global CBD_PARKING_ZONES, cbd_parking_price_prob, cbd_parking_prices - random_state = check_random_generator(random_state) - - DEST = pd.Series(DEST.reshape(-1)) - ITER = DEST.size - - rand_free_parking = random_state.random(size=ITER) * 100. # Free Parking randomizer - rand_parking_price = random_state.random(size=ITER) # Parking Rate randomizer - - price_probs = dh.cbd_parking_price_prob.reindex(DEST.values) - prices = dh.cbd_parking_prices.reindex(DEST.values) - parking_price_row = np.full(ITER, -1, dtype=np.int8) - for i in range(5): - rand_parking_price -= price_probs.iloc[:,0] - parking_price_row[(parking_price_row < 0) & (rand_parking_price < 0)] = i - - # Assemble the randomly selected parking-price columns into one Series. - # It will have NaN values for zones outside the CBD parking model - parking_price_1 = pd.Series( - prices.values[range(len(parking_price_row)), parking_price_row], - index=DEST.index, - ) - - # Assemble default hourly pricing to use for trips based on zone type - # This Series is len(Zones) not len(Trips) - zonetype_price = dh.m01.zone_type.map(dh.cfg.parking_costs.defaults[purpose]) - - # Fill in NaNs with default values. - parking_price_2 = DEST.map(zonetype_price) - parking_price = parking_price_1.fillna(parking_price_2) - - # Scale up based on number of hours of parking - parking_price *= HOURS - - return parking_price - - -def parking_is_free( - dh, - INCOME, - random_state=None, -): - - """ - Draw a parking cost from the random distribution in the destination zone. - - Parameters - ---------- - dh : DataHandler - INCOME : array-like, shape[ITER] - Income groups for each draw, used to find if parking is actually free - Values are categories 1 to 5 - random_state - - Returns - ------- - paid_parking : array, shape[ITER] - 1 if parking is paid, 0 if free - """ - random_state = check_random_generator(random_state) - rand_free_parking = random_state.random(size=INCOME.size) * 100. # Free Parking randomizer - - # Find free parking rate based on income group - FREEPRK = dh.cbd_parking2.FreeParkingPct.iloc[INCOME-1] - - # random draw if the traveler gets free parking - paid_parking = (rand_free_parking > FREEPRK) - - return paid_parking diff --git a/src/Mode-Dest-TOD/cmap_modedest/purposes.py b/src/Mode-Dest-TOD/cmap_modedest/purposes.py deleted file mode 100644 index 55b0387..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/purposes.py +++ /dev/null @@ -1,60 +0,0 @@ - -purposes5 = ( - 'HBWH', # Home-based Work, High Income - 'HBWL', # Home-based Work, Low Income - 'HBS', # Home-based Shopping - 'HBO', # Home-based Other Purpose Not Enumerated - 'NHB', # Non-home-based -) - -purposes8 = ( - 'HBWH', # Home-based Work, High Income - 'HBWL', # Home-based Work, Low Income - 'HBS', # Home-based Shopping - 'HBO', # Home-based Other Purpose Not Enumerated - 'HBOR', # Home-based Other Purpose Not Enumerated, at a residence - 'NHB', # Non-home-based not shopping - 'NHBS', # Non-home-based shopping - 'NHBR', # Non-home-based, at a residence -) - -purposes3 = ( - 'HW', # Home-based Work - 'HO', # Home-based Other Purpose Not Work - 'NH', # Non-home-based -) - -purposesA = purposes5 - -purposes_to_peaky = dict( - HBWH=1, - HBWL=1, - HBS=0, - HBO=0, - NHB=0, - HBOR=0, - NHBR=0, - NHBS=0, -) - -purposes_to_3 = dict( - HBWH='HW', - HBWL='HW', - HBS='HO', - HBO='HO', - NHB='NH', - HBOR='HO', - NHBR='NH', - NHBS='NH', -) - -purposes_to_5 = dict( - HBWH='HBWH', - HBWL='HBWL', - HBS='HBS', - HBO='HBO', - NHB='NHB', - HBOR='HBO', - NHBR='NHB', - NHBS='NHB', -) \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/random_states.py b/src/Mode-Dest-TOD/cmap_modedest/random_states.py deleted file mode 100644 index 7b76a0e..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/random_states.py +++ /dev/null @@ -1,46 +0,0 @@ -import numbers -import numpy as np - -def check_random_state(seed): - """ - Turn a seed into a numpy RandomState instance - - Parameters - ---------- - seed : None | int | instance of RandomState - If seed is None, return the RandomState singleton used by np.random. - If seed is an int, return a new RandomState instance seeded with seed. - If seed is already a RandomState instance, return it. - Otherwise raise ValueError. - """ - if seed is None or seed is np.random: - return np.random.RandomState() - if isinstance(seed, numbers.Integral): - return np.random.RandomState(seed % 1<<32) - if isinstance(seed, np.random.RandomState): - return seed - raise ValueError('%r cannot be used to seed a numpy.random.RandomState' - ' instance' % seed) - - -def check_random_generator(seed=None): - """ - Create a random generator. - - Parameters - ---------- - seed - - Returns - ------- - np.random.Generator - """ - if seed is None: - raise ValueError("True random seeding disallowed for CMAP trip based model") - try: - return np.random.default_rng(seed) - except TypeError: - if isinstance(seed, np.random.RandomState): - return np.random.default_rng(seed.get_state()[1]) - else: - raise \ No newline at end of file diff --git a/src/Mode-Dest-TOD/cmap_modedest/runtime.py b/src/Mode-Dest-TOD/cmap_modedest/runtime.py deleted file mode 100644 index 4d67614..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/runtime.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import cmap_modedest -from pathlib import Path - -from .data_handlers import DataHandler - - -import cmap_modedest - -log = cmap_modedest.log_to_stderr(level=10) - - -def log_info(*args): - """Short logging function for estimation""" - if len(args) == 1 and isinstance(args[0], str) and args[0][0] == "#": - log.info(args[0]) - else: - s = "\n".join(str(i) for i in args) - s = "\n"+s - log.info(s.replace("\n", "\n ")) - - -def working_dir(*candidate_emme_database_dirs, backfill_uncompressed_skims=False, **kwargs): - for emme_database_dir in candidate_emme_database_dirs: - emme_database_dir = os.path.expanduser(emme_database_dir) - if os.path.exists(emme_database_dir): break - else: - raise FileNotFoundError(candidate_emme_database_dirs) - emme_database_dir = Path(emme_database_dir) - os.makedirs(emme_database_dir/"emmemat", exist_ok=True) # must exist even if empty - log_info("###### Set Directories and Prep Data ######") - dh = DataHandler( - emme_database_dir=emme_database_dir, - cache_dir=emme_database_dir/"cache", - zone_shapefile=emme_database_dir/"data/distr/zone17.shp", - backfill_uncompressed_skims=backfill_uncompressed_skims, - **kwargs, - ) - log_info("Data Handlers Ready") - return dh diff --git a/src/Mode-Dest-TOD/cmap_modedest/skims/__init__.py b/src/Mode-Dest-TOD/cmap_modedest/skims/__init__.py deleted file mode 100644 index 26edd5b..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/skims/__init__.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -import zarr -from pathlib import Path -from .compression import read_compressed_skims, read_uncompressed_skims, write_compressed_skims, write_uncompressed_skims -from ..cmap_logging import getLogger - -def read_skims( - directory, - backfill_compressed_skims=False, - backfill_uncompressed_skims=False, - use_compressed_skims=False, -): - """ - - Parameters - ---------- - directory : Path-like - Where to read skims from, omitting any ".zarr" suffix. - backfill_compressed_skims : bool, default False - Write skims that only appear in the uncompressed directory into the - zarr directory. - backfill_uncompressed_skims : bool, default False - Write skims that only appear in the compressed zarr directory into the - uncompressed directory. - use_compressed_skims : bool, default False - Whether to allow the usage of compressed skims at all. - - Returns - ------- - sh.Dataset - """ - appended_names = [] - skims = None - try: - if use_compressed_skims: - skims = read_compressed_skims(directory) - except zarr.errors.GroupNotFoundError as err: - pass - except FileNotFoundError as err: - backfill_compressed_skims = False - try: - skims, appended_names = read_uncompressed_skims(directory, skims) - except (FileNotFoundError, NotADirectoryError) as err2: - if skims is None: - raise err2 - if backfill_compressed_skims and appended_names: - write_compressed_skims( - skims[appended_names], - os.fspath(Path(directory).with_suffix(".zarr")) - ) - if backfill_uncompressed_skims: - write_uncompressed_skims( - skims, - directory, - ) - - return skims diff --git a/src/Mode-Dest-TOD/cmap_modedest/skims/compression.py b/src/Mode-Dest-TOD/cmap_modedest/skims/compression.py deleted file mode 100644 index fc1a917..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/skims/compression.py +++ /dev/null @@ -1,191 +0,0 @@ -import os -import xarray as xr -import sharrow as sh -import numpy as np -import pandas as pd -import zarr -from pathlib import Path -import logging - -log = logging.getLogger('CMAP') - - -def compress_skim_dir(directory, output="zarr"): - """ - Compress the `emmemat` skims directory using zarr. - - Parameters - ---------- - directory : path to emmemat directory - output : {"zarr.zip", "zarr"} - File format to use for compression. Zarr.zip puts all the - piece in one big zip directory, while plain Zarr uses the - native file system to store a bunch of pieces. Both methods - use the same compression. - - Returns - ------- - Dataset - """ - - if output not in ("zarr", "zarr.zip"): - raise NotImplementedError(output) - - if output == "zarr": - if not os.path.exists(directory+".zarr"): - os.makedirs(directory+".zarr") - elif output == "zarr.zip": - if os.path.exists(directory+".zarr.zip"): - raise FileExistsError(directory+".zarr.zip") - - master = {} - for f in os.walk(directory): - for fi in f[2]: - if ".emx" in fi: - arr = np.fromfile(fi, dtype='f4') - side = int(np.sqrt(arr.size)) - arr = arr.reshape(side, side) - tazrange = pd.RangeIndex(1, side+1) - master[fi.replace(".emx", "")] = xr.DataArray( - arr, - dims=['otaz', 'dtaz'], - coords={'otaz': tazrange, 'dtaz': tazrange} - ) - - master = sh.Dataset(master) - - if output == "zarr": - master.to_zarr(directory+".zarr", mode='a') - elif output == "zarr.zip": - with zarr.ZipStore(directory+".zarr.zip", mode='w') as store: - master.to_zarr(store) - return master - - -def read_uncompressed_skims(directory, dataset=None, overload=True): - """ - Read emmemat skims into a Dataset. - - Parameters - ---------- - directory : Path-like - path to emmemat directory - dataset : Dataset, optional - Append to these skims. Only skims not already available - will be loaded. - overload : bool, default True - Whether to overload existing skims in `dataset`. If False, - the existing skims (generally, those loaded from the compressed - skims) have priority and are retained. If True, any uncompressed - skims have priority and existing data is overwritten in memory. - - Returns - ------- - sh.Dataset - Loaded skims - appended_names : List - Names of uncompressed skims that were added - """ - appended_names = [] - if not os.path.isdir(directory): - raise NotADirectoryError(directory) - if dataset is None: - master = {} - else: - master = dataset - log.info(f'reading uncompressed skims from {directory}') - for f in os.walk(directory): - for fi in f[2]: - if ".emx" in fi and (fi.replace(".emx", "") not in master or overload): - arr = np.memmap(os.path.join(f[0], fi), dtype='f4', mode='c') - side = int(np.sqrt(arr.size)) - arr = arr.reshape(side, side) - tazrange = pd.RangeIndex(1, side+1) - master[fi.replace(".emx", "")] = xr.DataArray( - arr, - dims=['otaz', 'dtaz'], - coords={'otaz': tazrange, 'dtaz': tazrange} - ) - appended_names.append(fi.replace(".emx", "")) - if len(master) == 0: - log.error(f'no uncompressed skims read from {directory}') - raise FileNotFoundError(directory) - log.info(f"{len(appended_names)} uncompressed skims were added to the skims dataset") - return sh.Dataset(master), appended_names - - -def read_compressed_skims(zarr_directory): - """ - Read previously compressed skims. - - Compressed skims must be stored in a directory ending with a .zarr extension. - - Parameters - ---------- - zarr_directory - - Returns - ------- - Dataset - """ - result = None - if zarr_directory is None: - log.warning("no `zarr_directory` given") - raise ValueError("no `zarr_directory` given") - zarr_directory = Path(zarr_directory) - if os.path.isdir(zarr_directory.with_suffix(".zarr")): - log.info(f'reading compressed skims from {zarr_directory.with_suffix(".zarr")}') - result = sh.Dataset.from_zarr(zarr_directory.with_suffix(".zarr")) - elif os.path.isfile(zarr_directory.with_suffix(".zarr.zip")): - log.info(f'reading compressed skims from {zarr_directory.with_suffix(".zarr.zip")}') - result = sh.Dataset.from_zarr(zarr_directory.with_suffix(".zarr.zip")) - if result is not None: - log.info(f"{len(result.data_vars)} compressed skims were added to the skims dataset") - return result - raise FileNotFoundError(zarr_directory) - - -def write_uncompressed_skims(skims, directory, overwrite=False): - """ - Writes the .emx files for EMME in the emmemat directory. - - Parameters - ---------- - skims : Dataset - directory : Path-like - uncompressed skims will go here - overwrite : bool, default False - Whether to overwrite existing uncompressed skims. - """ - os.makedirs(directory, exist_ok=True) - for k in skims: - filename = os.path.join(directory, f"{k}.emx") - if not os.path.exists(filename) or overwrite: - skims[k].values.tofile(filename) - - -def write_compressed_skims(skims, output="emmemat.zarr"): - """ - Compress the `emmemat` skims directory using zarr. - - Parameters - ---------- - directory : path to emmemat directory - output : str, ends with {"zarr.zip", "zarr"} - File format to use for compression. Zarr.zip puts all the - piece in one big zip directory, while plain Zarr uses the - native file system to store a bunch of pieces. Both methods - use the same compression. - """ - known_exts = (".zarr", ".zarr.zip") - if not any(output.endswith(k) for k in known_exts): - raise NotImplementedError(output) - if output.endswith(".zarr"): - skims.to_zarr(output, mode='a') - elif output.endswith(".zarr.zip"): - if os.path.exists(output): - raise FileExistsError(output) - with zarr.ZipStore(output, mode='w') as store: - skims.to_zarr(store) - - diff --git a/src/Mode-Dest-TOD/cmap_modedest/skims/names.py b/src/Mode-Dest-TOD/cmap_modedest/skims/names.py deleted file mode 100644 index 8fdd177..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/skims/names.py +++ /dev/null @@ -1,15 +0,0 @@ -from ..addict import Dict - -skim_names = Dict( - mf44='auto_am_time', - mf45='auto_am_dist', - mf46='auto_md_time', - mf47='auto_md_dist', - mf76='auto_am_time_hov', - mf77='auto_am_dist_hov', -) - -skim_tags = Dict({v:k for k,v in skim_names.items()}) - -skim_names.freeze() -skim_tags.freeze() diff --git a/src/Mode-Dest-TOD/cmap_modedest/time_of_day_model.py b/src/Mode-Dest-TOD/cmap_modedest/time_of_day_model.py deleted file mode 100644 index d04a6fd..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/time_of_day_model.py +++ /dev/null @@ -1,130 +0,0 @@ -import os -from larch.numba import Model, P, X -import yaml -from .addict import Dict - -from .cmap_logging import getLogger, get_worker_log -from .purposes import purposes5 - -time_period_names = ['EA', 'AM1', 'AM2', 'AM3', 'MD', 'PM1', 'PM2', 'PM3'] -time_period_codes = [ 1, 2, 3, 4, 5, 6, 7, 8 ] - -def tod_model_builder( - purpose, - data_co=None, - ch_name=None, - model_parameters=None, -): - from larch.numba import DataFrames - if model_parameters is None: - model_parameters = {} - - d = DataFrames( - co=data_co, - ch=ch_name, - alt_codes=time_period_codes, - alt_names=time_period_names, - av=1, - ) - - tod_model = Model(d) - tod_model.title = f"{purpose} Time of Day Choice" - - for tname, tcode in zip(time_period_names, time_period_codes): - tod_model.utility_co[tcode] = ( - + P(f"ASC_{tname}") - + P.time * X(f"mf46{tcode}") - + P(f"hiredcar_{tname}") * X("mode9 in ('TAXI','TNC1','TNC2')") - ) - if purpose[:2].upper() == "HB": - if purpose.upper() == "HBS": - tod_model.utility_co[tcode] += ( - + P(f"ASC_{tname}_r") * X("paFlip") - # no reverse-trip hired car parameters, insufficient survey data - ) - else: - tod_model.utility_co[tcode] += ( - + P(f"ASC_{tname}_r") * X("paFlip") - + P(f"hiredcar_{tname}_r") * X("mode9 in ('TAXI','TNC1','TNC2')") * X("paFlip") - ) - - tod_model.lock_value('ASC_AM2', 0.0) - tod_model.lock_value('hiredcar_AM2', 0.0) - if purpose.upper() == "HBS": - tod_model.lock_value('ASC_AM2_r', 0.0) - elif purpose[:2].upper() == "HB": - tod_model.lock_value('ASC_AM2_r', 0.0) - tod_model.lock_value('hiredcar_AM2_r', 0.0) - tod_model.set_cap() - - if purpose == 'NHB': - tod_model.set_value('time', -0.02, maximum=-0.02) - - for k,v in model_parameters.items(): - tod_model.set_value(k, v) - - return tod_model - - - - -time_of_day_simulator_global = Dict() - - -def time_of_day_simulator_initialize(dh, cache=True): - global time_of_day_simulator_global - - log = get_worker_log( - os.path.join(dh.filenames.cache_dir, 'logs'), - level=10, - ) - - log.debug(f"time_of_day_simulator_initialize(cache={cache}") - n_zones = dh.n_internal_zones - choice_model_params = dh.choice_model_params - - if len(choice_model_params) == 0: - raise ValueError("no choice_model_params") - - pickle_name = dh.filenames.cache_dir / f"tod_models_{n_zones}.pkl" - tod_param_file = dh.filenames.tod_model_param_file - if tod_param_file and os.path.exists(tod_param_file): - with open(tod_param_file, 'r') as f: - tod_model_params = Dict(yaml.load(f, Loader=yaml.SafeLoader)) # TODO addicty - else: - tod_model_params = Dict() - - if len(time_of_day_simulator_global) == 0: - log.debug("time_of_day_simulator_initialize: preloaded tod_simulator not available") - if os.path.exists(pickle_name): - import cloudpickle - with open(pickle_name, 'rb') as pkl_f: - log.debug("time_of_day_simulator_initialize: loading pickled tod_simulator") - time_of_day_simulator_global = cloudpickle.load(pkl_f) - cache = False - else: - log.debug("time_of_day_simulator_initialize: pickled tod_simulator not available") - - if time_of_day_simulator_global: - log.info("time_of_day_simulator_initialize: using existing tod_simulator") - tod_simulator = time_of_day_simulator_global - else: - log.info("time_of_day_simulator_initialize: creating fresh tod_simulator") - tod_simulator = Dict() - for purpose in purposes5: - tod_simulator[purpose] = tod_model_builder( - purpose=purpose, - model_parameters=tod_model_params.get(purpose, {}), - ) - time_of_day_simulator_global = tod_simulator - - if cache and not os.path.exists(pickle_name): - import cloudpickle - with open(pickle_name, 'wb') as pkl_f: - log.debug("time_of_day_simulator_initialize: pickling tod_simulator for future reload") - cloudpickle.dump( - time_of_day_simulator_global, - pkl_f, - ) - - return tod_simulator diff --git a/src/Mode-Dest-TOD/cmap_modedest/timeperiods.py b/src/Mode-Dest-TOD/cmap_modedest/timeperiods.py deleted file mode 100644 index 3e18d1f..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/timeperiods.py +++ /dev/null @@ -1,51 +0,0 @@ - - -# 1. The ten hour late evening-early morning off-peak period (8:00 p.m. to 6:00 a.m.); -# 2. The shoulder hour preceding the AM peak hour (6:00 to 7:00 a.m.); -# 3. The AM peak two hours (7:00 to 9:00 a.m.); -# 4. The shoulder hour following the AM peak period (9:00 to 10:00 a.m); -# 5. A five hour midday period (10:00 a.m. to 2:00 p.m.); -# 6. The two hour shoulder period preceding the PM peak period (2:00 to 4:00 p.m.); -# 7. The PM peak two hours (4:00 to 6:00 p.m.), and; -# 8. The two hour shoulder period following the PM peak period (6:00 to 8:00 p.m.). - -timeperiod_names = [ - 'NIGHT', - 'AM_PRE', - 'AM_PEAK', - 'AM_POST', - 'MIDDAY', - 'PM_PRE', - 'PM_PEAK', - 'PM_POST', -] - -timeperiods = {i:name for i, name in enumerate(timeperiod_names)} - -hours_by_timeperiod = { - 0: 0, - 1: 0, - 2: 0, - 3: 0, - 4: 0, - 5: 0, - 6: 1, - 7: 2, - 8: 2, - 9: 3, - 10: 4, - 11: 4, - 12: 4, - 13: 4, - 14: 4, - 15: 5, - 16: 5, - 17: 6, - 18: 6, - 19: 7, - 20: 7, - 21: 0, - 22: 0, - 23: 0, -} - diff --git a/src/Mode-Dest-TOD/cmap_modedest/tnc_costs.py b/src/Mode-Dest-TOD/cmap_modedest/tnc_costs.py deleted file mode 100644 index 55a76db..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/tnc_costs.py +++ /dev/null @@ -1,124 +0,0 @@ -import numpy as np -import pandas as pd - -peak_tnc_pricing = { - 'OFFPEAK': 0, - 'PEAK': 1, -} - - -def taxi_cost(dh, auto_time, auto_dist, o_zone, d_zone): - """ - Compute taxi fare. - - A single set of rates (Chicago medallion rates for in-city trips) - is used; fares for taxi trips outside Chicago are close to this - rate and rare enough that more precision is unneeded. - - Parameters - ---------- - auto_time, auto_dist : array-like - - Returns - ------- - fare : array-like - """ - return ( - dh.cfg.taxi.cost.flag_pull - + auto_time * dh.cfg.taxi.cost.per_minute - + auto_dist * dh.cfg.taxi.cost.per_mile - ) - - -def tnc_solo_cost(dh, auto_time, auto_dist, o_zone, d_zone, peak): - """ - Compute the solo rider TNC cost. - - Parameters - ---------- - auto_time, auto_dist : array-like of float - The auto travel time and distance for a set of trips. - Shapes must match. - o_zone, d_zone : pd.Series of int - Zone numbers for origin and destination - Shapes must match `auto_time`. - peak : pd.Series of bool - Whether each trip is peak or offpeak. - Shapes must match `auto_time`. - - Returns - ------- - ndarray - Same shape as inputs - """ - - peak_fare = ( - dh.cfg.tnc.cost.peak.per_minute * auto_time - + dh.cfg.tnc.cost.peak.per_mile * auto_dist - + dh.cfg.tnc.cost.peak.base_fare - ) - peak_fare = np.fmax(peak_fare, dh.cfg.tnc.cost.peak.min_fare) + dh.cfg.tnc.cost.peak.booking_fee - - offpeak_fare = ( - dh.cfg.tnc.cost.offpeak.per_minute * auto_time - + dh.cfg.tnc.cost.offpeak.per_mile * auto_dist - + dh.cfg.tnc.cost.offpeak.base_fare - ) - offpeak_fare = np.fmax(offpeak_fare, dh.cfg.tnc.cost.offpeak.min_fare) + dh.cfg.tnc.cost.offpeak.booking_fee - - cost = peak_fare * peak + offpeak_fare * (1-peak) - for bucket_name, bucket_price in dh.cfg.tnc.surcharge_rates.items(): - if bucket_price: - bucket_applies = ( - np.isin(o_zone, dh.cfg.tnc.surcharge_zones[bucket_name]) - | np.isin(d_zone, dh.cfg.tnc.surcharge_zones[bucket_name]) - ).astype(float) - cost += bucket_applies * bucket_price - return cost - - -def tnc_pool_cost(dh, auto_time, auto_dist, o_zone, d_zone, peak): - """ - Compute the pooled rider TNC cost. - - Parameters - ---------- - auto_time, auto_dist : array-like of float - The auto travel time and distance for a set of trips/ - Shapes must match. - o_zone, d_zone : pd.Series of int - Zone numbers for origin and destination - Shapes must match `auto_time`. - peak : pd.Series of bool - Whether each trip is peak or offpeak. - Shapes must match `auto_time`. - - Returns - ------- - ndarray - Same shape as inputs - """ - - peak_fare = ( - dh.cfg.tnc_pooled.cost.peak.per_minute * auto_time - + dh.cfg.tnc_pooled.cost.peak.per_mile * auto_dist - + dh.cfg.tnc_pooled.cost.peak.base_fare - ) - peak_fare = np.fmax(peak_fare, dh.cfg.tnc_pooled.cost.peak.min_fare) + dh.cfg.tnc_pooled.cost.peak.booking_fee - - offpeak_fare = ( - dh.cfg.tnc_pooled.cost.offpeak.per_minute * auto_time - + dh.cfg.tnc_pooled.cost.offpeak.per_mile * auto_dist - + dh.cfg.tnc_pooled.cost.offpeak.base_fare - ) - offpeak_fare = np.fmax(offpeak_fare, dh.cfg.tnc_pooled.cost.offpeak.min_fare) + dh.cfg.tnc_pooled.cost.offpeak.booking_fee - - cost = peak_fare * peak + offpeak_fare * (1-peak) - for bucket_name, bucket_price in dh.cfg.tnc_pooled.surcharge_rates.items(): - if bucket_price: - bucket_applies = ( - np.isin(o_zone, dh.cfg.tnc_pooled.surcharge_zones[bucket_name]) - | np.isin(d_zone, dh.cfg.tnc_pooled.surcharge_zones[bucket_name]) - ).astype(float) - cost += bucket_applies * bucket_price - return cost diff --git a/src/Mode-Dest-TOD/cmap_modedest/transit_approach.py b/src/Mode-Dest-TOD/cmap_modedest/transit_approach.py deleted file mode 100644 index 349aaee..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/transit_approach.py +++ /dev/null @@ -1,731 +0,0 @@ -import numpy as np -import logging -from .addict import Dict -log = logging.getLogger('CMAP') - -from .ae_distance_sim import simulate_ae_dist -from .random_states import check_random_generator - -# trip types -HW = 'HW' # HOME PRODUCTIONS TO WORK ATTRACTIONS -HO = 'HO' # HOME PRODUCTIONS TO NON-WORK/NON-HOME ATTRACTIONS -NH = 'NH' # NON-HOME PRODUCTIONS TO NON-HOME ATTRACTIONS - -ITER = 50 # NUMBER OF TRIPS USED TO COMPUTE AVERAGE IMPEDANCES - -from .modecodes import ( - APPROACH_WALK, - APPROACH_BUS, - APPROACH_PARK_N_RIDE, - APPROACH_KISS_N_RIDE, - APPROACH_FEEDER_BUS, - N_APPROACH_MODES, - APPROACH_MODE_NAMES, - DIST_TO_BUS, - DIST_TO_CTA_RAIL, - DIST_TO_METRA, - DIST_TO_FEEDER_BUS, - DIST_TO_PARK_N_RIDE_STATION, - N_DIST_TO_TYPES, - TransitModeCode_CTA_RAIL, - TransitModeCode_METRA_RAIL, - TransitModeCode_CTA_EXPRESS_BUS, - TransitModeCode_CTA_REGULAR_BUS, - TransitModeCode_PACE_BUS, -) - - - -FRONT_END = 0 -BACK_END = 1 -N_TRIP_ENDS = 2 - -SPDWLK = 30 -# SPDWLK = SYSTEM-WIDE SPEED OF WALKING, -# DEFAULT IS 30 TENTHS OF A MILE PER HOUR - -SPEEDS = np.array([7, 15, 20, 30, 5, 10, 12, 17]) -# SPEEDS = SPEEDS OF APPROACH AUTO AND BUS BY ZONE AREA TYPE -# AUTO APPROACH SPEEDS: -# ZONE TYPE 1 (CHICAGO CBD) DEFAULT IS 7 MPH -# ZONE TYPE 2 (CHICAGO REMAINDER) DEFAULT IS 15 MPH -# ZONE TYPE 3 (DENSE SUBURB) DEFAULT IS 20 MPH -# ZONE TYPE 4 (SPARSE SUBURB) DEFAULT IS 30 MPH -# BUS APPROACH SPEEDS: -# ZONE TYPE 1 (CHICAGO CBD) DEFAULT IS 5 MPH -# ZONE TYPE 2 (CHICAGO REMAINDER) DEFAULT IS 10 MPH -# ZONE TYPE 3 (DENSE SUBURB) DEFAULT IS 12 MPH -# ZONE TYPE 4 (SPARSE SUBURB) DEFAULT IS 17 MPH - -DRVOT = 14 -# DRVOT = DRIVER'S VALUE OF TIME, DEFAULT IS 14 CENTS/MIN - -OVT_IVT_RATIO = 2.0 - - - -AFC1 = 35 # AUTO FIXED COSTS FOR AUTO DRIVER IN CENTS -AFC2 = 20 # AUTO FIXED COSTS FOR AUTO PASSENGER IN CENTS - -# W2PNR = WALK TIME TO STATION FROM PARK AND RIDE LOT, -# DEFAULT IS 2 MINUTES -W2PNR = 2 - - -def _simulate_approach_distances( - dh, - zone, - attached_mode, - trip_purpose, - trip_end, - out, - random_state=None, -): - """ - - Parameters - ---------- - dh : DataHandler - zone : int - Zone id (1-based) - attached_mode : int - Number for first or last mode (as matches this approach) - trip_purpose : {'HW','HO','NH'} - Trip purpose, used to select DISTR table and possibly filter - approach modes - trip_end : {0,1} - Zero if approach to first mode, one if approach from last mode - out : array-like - Output array must already exist, as a float dtype, - with shape [replications, N_APPROACH_MODES, ] - - """ - if not isinstance(zone, int): - return _simulate_approach_distances_arr( - dh, - zone, - attached_mode, - trip_purpose, - trip_end, - out, - random_state=random_state, - ) - random_state = check_random_generator(random_state) - replication = list(out.shape[:-1]) - distr = dh.distr - if replication[0] == 1: - replication = replication[1:] - for J in range(N_DIST_TO_TYPES): - # OBTAIN APPROACH DISTANCES TO FIVE MODES - if (J == DIST_TO_BUS): - distr_params = distr[trip_purpose].loc[(zone, 'bus')] - elif (J == DIST_TO_CTA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS CTA RAIL - if attached_mode == TransitModeCode_CTA_RAIL: - distr_params = distr[trip_purpose].loc[(zone, 'ctarail')] - else: - distr_params = (999,999,999) - elif (J == DIST_TO_METRA): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - if attached_mode == TransitModeCode_METRA_RAIL: - distr_params = distr[trip_purpose].loc[(zone, 'metra')] - else: - distr_params = (999, 999, 999) - elif (J == DIST_TO_FEEDER_BUS): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - if attached_mode == TransitModeCode_METRA_RAIL: - distr_params = distr[trip_purpose].loc[(zone, 'feederbus')] - else: - distr_params = (999, 999, 999) - elif (J == DIST_TO_PARK_N_RIDE_STATION): - # PARK AND RIDE STATION DISTANCE OBTAINED WHEN TRIP END IS FRONT - if trip_end == FRONT_END: - distr_params = distr[trip_purpose].loc[(zone, 'pnr')] - else: - distr_params = (999, 999, 999) - else: - raise ValueError(J) - if distr_params[2] != 999: - out[...,J] = simulate_ae_dist(*distr_params, replication=replication, random_state=random_state) - else: - out[...,J] = 255.0 - - -def _simulate_approach_distances_arr( - dh, - zone, - attached_mode, - trip_purpose, - trip_end, - out, - random_state=None, -): - """ - - Parameters - ---------- - zone : array-like - Zone id (1-based) - attached_mode : int - Number for first or last mode (as matches this approach) - trip_purpose : {'HW','HO','NH'} - Trip purpose, used to select DISTR table and possibly filter - approach modes - trip_end : {0,1} - Zero if approach to first mode, one if approach from last mode - out : array-like - Output array must already exist, as a float dtype, - with shape [replications, N_APPROACH_MODES, ] - - """ - random_state = check_random_generator(random_state) - replication = list(out.shape[1:-1]) - distr_df = dh.distr[trip_purpose].unstack().loc[zone] - for J in range(N_DIST_TO_TYPES): - # OBTAIN APPROACH DISTANCES TO FIVE MODES - if (J == DIST_TO_BUS): - distr_params = distr_df.xs('bus', level='submode', axis=1).copy() - elif (J == DIST_TO_CTA_RAIL): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS CTA RAIL - distr_params = distr_df.xs('ctarail', level='submode', axis=1).copy() - distr_params.loc[attached_mode != TransitModeCode_CTA_RAIL,:] = 999 - elif (J == DIST_TO_METRA): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_df.xs('metra', level='submode', axis=1).copy() - distr_params.loc[attached_mode != TransitModeCode_METRA_RAIL,:] = 999 - elif (J == DIST_TO_FEEDER_BUS): - # DISTANCE OBTAINED ONLY IF FIRST/LAST MODE IS METRA - distr_params = distr_df.xs('feederbus', level='submode', axis=1).copy() - distr_params.loc[attached_mode != TransitModeCode_METRA_RAIL,:] = 999 - elif (J == DIST_TO_PARK_N_RIDE_STATION): - # PARK AND RIDE STATION DISTANCE OBTAINED WHEN TRIP END IS FRONT - if trip_end == FRONT_END: - distr_params = distr_df.xs('pnr', level='submode', axis=1).copy() - else: - distr_params.loc[:,:] = 999 - else: - raise ValueError(J) - _temp = simulate_ae_dist( - distr_params.p1, - distr_params.p2, - distr_params.p3, - replication=replication, - random_state=random_state, - ) - out[..., J] = _temp - - -# def simulate_approach_distances_222(ozone, dzone, firstmode, lastmode, trip_purpose): -# DOND = np.full([ITER, N_APPROACH_MODES, N_TRIP_ENDS], 255.) -# for I in range(N_TRIP_ENDS): -# -# # C I=1 OBTAIN DISTANCES FOR ORIGIN -# # C I=2 OBTAIN DISTANCES FOR DESTINATION -# if I == FRONT_END: -# Z=ozone -# M=firstmode -# else: -# Z=dzone -# M=lastmode -# -# -# for J in range(N_APPROACH_MODES): -# # C -# # C OBTAIN APPROACH DISTANCES TO FIVE MODES -# DOND[:,J,I]=255. -# -# if (J == APPROACH_WALK): -# distr_params = distr[trip_purpose].loc[(ozone, 3)] -# elif (J == APPROACH_BUS): -# distr_params = distr[trip_purpose].loc[(ozone, 2)] -# elif (J == APPROACH_PARK_N_RIDE): -# distr_params = distr[trip_purpose].loc[(ozone, 1)] -# elif (J == APPROACH_KISS_N_RIDE): -# distr_params = distr[trip_purpose].loc[(ozone, 4)] -# else: # (J == FEEDER_BUS): -# distr_params = distr[trip_purpose].loc[(ozone, 5)] -# -# DOND[:,J,I] = simulate_ae_dist(*distr_params, replication=ITER) -# -# return DOND - - -def _IS_CTA(m): - return ( - m == TransitModeCode_CTA_RAIL - or m == TransitModeCode_CTA_REGULAR_BUS - or m == TransitModeCode_CTA_EXPRESS_BUS - ) - - -from numba import jit, njit, prange - -def transit_approach( - dh, - ozone, - dzone, - TPTYPE, - replication=None, - approach_distances=None, - trace=False, - random_state=None, -): - """ - Replaces TRAPP fortran. - - Parameters - ---------- - dh : DataHandler - ozone, dzone : int or array-like - Zone ID numbers. If array-like, should be arrays of the same shape. - TPTYPE : {'HW', 'HO', 'NH'} - Trip type - replication : int - Number of simulation replications - - Returns - ------- - Dict - Containing: - - drivetime : array of int32, shape [replication] - simulated in vehicle (drive) approach times, in minutes - - walktime : array of int32, shape [replication] - simulated out of vehicle (walk) approach times, in minutes - - cost : array of int32, shape [replication] - simulated approach costs, in cents - - waittime : array of int32, shape [replication] - simulated approach waiting times - - approach_mode : array of int8, shape [replication, 2] - simulated best approach modes - = approach_distances : array of float32, shape [replication, N_DIST_TO_TYPES, N_TRIP_ENDS] - - Notes - ----- - When ozone, dzone are given as arrays, all returned arrays have one extra front - dimension matching these arrays. - - """ - random_state = check_random_generator(random_state or [ozone, dzone]) - - PACE_BUS_BOARDING_FARE = dh.m023.PACE_BUS_BOARDING_FARE - PACE_BUS_FIRST_XFER_FARE = dh.m023.PACE_BUS_FIRST_XFER_FARE - FEEDER_BUS_BOARDING_FARE = dh.m023.FEEDER_BUS_BOARDING_FARE - FEEDER_BUS_CBD_FARE = dh.m023.FEEDER_BUS_CBD_FARE - - CTA_FIRST_XFER_FARE = dh.m023.CTA_FIRST_XFER_FARE - CTA_CBD_LINK_UP_FARE = dh.m023.CTA_CBD_LINK_UP_FARE - - AUTO_OPERATING_COST_BY_ZONETYPE = dh.m023.AUTO_OPERATING_COST_BY_ZONETYPE # AVERAGE OPERATING COST PER MILE FOR AUTO, BY ZONE TYPE - - if replication is None: - replication = ITER - - if trace: - log.log(trace, f"transit_approach({ozone},{dzone},{TPTYPE},{replication})") - - # convert inputs to length-1 vectors if not already vectors - if isinstance(ozone, int): - ozone_ = ozone - ozone = np.array([ozone]) - else: - ozone_ = ozone = np.asanyarray(ozone) - if isinstance(dzone, int): - dzone_ = dzone - dzone = np.array([dzone]) - else: - dzone_ = dzone = np.asanyarray(dzone) - vector_len = ozone.shape[0] - assert vector_len == dzone.shape[0] - - ozone_idx = ozone-1 - dzone_idx = dzone-1 - - m01_df = dh.m01 - ZTYPE = m01_df['zone_type'] # integers 1-4 - if TPTYPE == HW: - fwbus = m01_df['first_wait_bus_peak'] # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr = m01_df['first_wait_feeder_peak'] # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - else: - fwbus = m01_df['first_wait_bus_offpeak'] # FIRST WAIT FOR BUS IN APPROACH SUBMODEL - fwfdr = m01_df['first_wait_feeder_offpeak'] # FIRST WAIT FOR FEEDER BUS IN APPROACH SUBMODEL - PNRAVL = m01_df['pnr_flag'].astype(bool) # park-n-ride available, by zone - PRCOST = m01_df['pnr_parking_cost'] # park-n-ride cost, by zone - - # -- INITIALIZE VALUES -- - approach_cost = np.zeros([vector_len, replication, N_APPROACH_MODES], dtype=np.float32) - approach_waittime = np.zeros([vector_len, replication, N_APPROACH_MODES], dtype=np.float32) - approach_drivetime = np.zeros([vector_len, replication, N_APPROACH_MODES], dtype=np.float32) - approach_walktime = np.zeros([vector_len, replication, N_APPROACH_MODES], dtype=np.float32) - TVAR4 = np.zeros([vector_len, replication, 5], dtype=np.float32) - - best_approach_mode = np.zeros([vector_len*replication, N_TRIP_ENDS], dtype=np.int8) - best_cost = np.zeros([vector_len*replication, N_TRIP_ENDS], dtype=np.int32) - best_waittime = np.zeros([vector_len*replication, N_TRIP_ENDS], dtype=np.int32) - best_walktime = np.zeros([vector_len* replication, N_TRIP_ENDS], dtype=np.int32) - best_drivetime = np.zeros([vector_len* replication, N_TRIP_ENDS], dtype=np.int32) - # - # GET ZONE TYPES - # - ozone_type = ZTYPE.iloc[ozone_idx] - dzone_type = ZTYPE.iloc[dzone_idx] - # - # GET INTERCHANGE ATTRIBUTES - # FM=FIRST MODE,LM=LAST MODE,PM=PRIORITY MODE - # - if TPTYPE == 'HW': - FM = dh.skims.first_mode_peak[ozone_idx, dzone_idx] - LM = dh.skims.last_mode_peak[ozone_idx, dzone_idx] - else: - FM = dh.skims.first_mode_offpeak[ozone_idx, dzone_idx] - LM = dh.skims.last_mode_offpeak[ozone_idx, dzone_idx] - # - # INET TRANSIT NETWORK STORES SOME SUBURBAN BUS LINES (MODE=6) - # AS MODE=5 DUE TO ARRAY SIZE LIMITS. IF MODE=5 AND - # ZONE TYPE NO. 1 IS OUTSIDE OF CHICAGO, THEN CHANGE MODE TO 6. - # - - FM[(FM == 5) & (ozone_type > 2)] = 6 - LM[(LM == 5) & (ozone_type > 2)] = 6 - - # - # GET APPROACH DISTANCES FOR FIRST AND LAST MODES - # - - #### CALL ADIST(ozone,dzone,FM,LM) - if approach_distances is not None: - if replication == 1 and len(approach_distances.shape) == 3: - approach_distances = np.expand_dims(approach_distances, axis=1) - assert approach_distances.shape == (vector_len, replication, N_DIST_TO_TYPES, N_TRIP_ENDS) - else: - approach_distances = np.empty([vector_len, replication, N_DIST_TO_TYPES, N_TRIP_ENDS]) - _simulate_approach_distances( - dh, - ozone_, - attached_mode=FM, - trip_purpose=TPTYPE, - trip_end=0, - out=approach_distances[:,:,:,0], - random_state=random_state, - ) - _simulate_approach_distances( - dh, - dzone_, - attached_mode=LM, - trip_purpose=TPTYPE, - trip_end=1, - out=approach_distances[:,:,:,1], - random_state=random_state, - ) - if trace: - log.log(trace, f" PRODUCTION APPROACH DISTANCES") - log.log(trace, f" to Bus {approach_distances[:5,:5,DIST_TO_BUS,0]}") - log.log(trace, f" to El {approach_distances[:5,:5,DIST_TO_CTA_RAIL,0]}") - log.log(trace, f" to Metra {approach_distances[:5,:5,DIST_TO_METRA,0]}") - log.log(trace, f" to feeder {approach_distances[:5,:5,DIST_TO_FEEDER_BUS,0]}") - log.log(trace, f" to PnR {approach_distances[:5,:5,DIST_TO_PARK_N_RIDE_STATION,0]}") - log.log(trace, f" ATTRACTION APPROACH DISTANCES") - log.log(trace, f" to Bus {approach_distances[:5,:5,DIST_TO_BUS,1]}") - log.log(trace, f" to El {approach_distances[:5,:5,DIST_TO_CTA_RAIL,1]}") - log.log(trace, f" to Metra {approach_distances[:5,:5,DIST_TO_METRA,1]}") - log.log(trace, f" to feeder {approach_distances[:5,:5,DIST_TO_FEEDER_BUS,1]}") - log.log(trace, f" to PnR {approach_distances[:5,:5,DIST_TO_PARK_N_RIDE_STATION,1]}") - - - # CHECK FIRST/LAST MODES AND COMPUTE APPROACH TIME AND COST - # - # ARRAYS approach_walktime,APCOST,approach_drivetime CONTAIN TIME TO WALK,APPROACH COST, - # AND IN-VEHICLE APPROACH TIME RESPECTIVELY. THESE ARRAYS HAVE FIVE - # ELEMENTS FOR FIVE POSSIBLE APPROACH MODES.( 1-WALK,2-BUS, - # 3-PARK & RIDE,4-KISS & RIDE,AND 5-FEEDER BUS) - # - - for I in range(N_TRIP_ENDS): - # I=1 GET VALUES FOR ORIGIN - # I=2 GET VALUES FOR DESTINATION - if (I == FRONT_END): - Z = ozone - M = FM - else: # I == BACK_END - Z = dzone - M = LM - - ZTYPE_Z = ZTYPE[Z].values - - # - # IN THIS CASE WE ARE MAKING THE STATION PARKING COST FOR HOME BASED OTHER AND - # NON-HOME BASED TRIPS EQUAL TO 60 PERCENT OF HOME BASED WORK - # CHANGE MADE 12/8/93 BY GWS NEXT LINE - # IF(TPTYPE.NE.1) PRCOST(Z) = PRCOST(Z) * 0.6 - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # NONWORK PARK AND RIDE PARKING COST IS NOW READ FROM M01. IN MANY - # CASES THE NONWORK PNR COSTS ARE HIGHER THAN WORK DUE TO - # DISCOUNTING OF MONTHLY PARKING FEES. - # - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # SET HIGH STARTING VALUE OF TVAR5 - TVAR5 = np.full([vector_len*replication], 1.E10) - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # IN CALCULATING TVAR4 AND TVAR5 - # IN-VEHICLE TIME = DRVOT = 20 CENTS/MIN - # OUT-OF-VEHICLE TIME = 40 CENTS/MIN - # PASSENGER TIME = 0.5 DRIVER TIME - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # - # FOLLOWING SECTION ADDED BY EASH TO SIMPLIFY LOGIC - # IF M IS BUS (MODE<7) THEN ONLY POSSIBLE APPROACH COST IS TIME TO - # WALK TO BUS. OTHER APPROACH COSTS AND TIMES ARE LINE=HAUL. - t = (M < TransitModeCode_CTA_RAIL) - if np.any(t): - J = APPROACH_WALK - approach_walktime[t,:,J] = approach_distances[t,:, DIST_TO_BUS, I] / SPDWLK * 600. - # INCREASE WALK TIME IN CHICAGO CBD FOR WORK TRIPS - cbd_work = t & (ZTYPE_Z == 1) & (TPTYPE == HW) - approach_walktime[cbd_work,:,J] *= 1.20 - - # if (ZTYPE_Z == 1 and TPTYPE == HW): - # approach_walktime[:, 0] = approach_walktime[:, 0] * 1.20 - TVAR4[t,:, J] = approach_walktime[t,:, 0] * DRVOT * 2.0 - TVAR5.reshape([vector_len,replication])[t,:] = TVAR4[t,:, J] - best_approach_mode.reshape([vector_len,replication,N_TRIP_ENDS])[t,:, I] = 0 - best_drivetime.reshape([vector_len,replication,N_TRIP_ENDS])[t,:, I] = 0 - best_walktime.reshape([vector_len,replication,N_TRIP_ENDS])[t,:, I] = approach_walktime[t,:, 0] + .5 - best_cost.reshape([vector_len,replication,N_TRIP_ENDS])[t,:, I] = 0 - best_waittime.reshape([vector_len,replication,N_TRIP_ENDS])[t,:, I] = 0 - for J in [APPROACH_BUS, APPROACH_PARK_N_RIDE, APPROACH_KISS_N_RIDE, APPROACH_FEEDER_BUS]: - TVAR4[t,:, J] = 0. - approach_cost[t, :, J] = 0. - approach_waittime[t, :, J] = 0. - approach_drivetime[t,:, J] = 0. - approach_walktime[t,:, J] = 0. - - t = (M >= TransitModeCode_CTA_RAIL) - if np.any(t): - # REMAINDER OF SUBROUTINE FOR RAIL TRANSIT/COMMUTER RAIL ONLY - # GET VALUES FOR FIVE ALTERNATIVES - for J in range(5): - TVAR4[t,:, J] = 0. - approach_cost[t, :, J] = 0. - approach_waittime[t,:,J] = 0. - approach_drivetime[t,:, J] = 0. - approach_walktime[t,:, J] = 0. - - K = np.fmax(0, M - 6).astype(int) # 0 for BUS, 1 for CTA RAIL(7-1), 2 for METRA(8-1) - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=0(WALK).COMPUTE WALKING TIME TO FIRST MODE.NO COST OR IN-VEHICLE TIME - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - if J == APPROACH_WALK: - approach_walktime[t,:, J] = approach_distances[t,:, K[t], I] / SPDWLK * 600. - # INCREASE WALK TIME IN CHICAGO CBD FOR WORK TRIPS - cbd_work = t & (ZTYPE_Z == 1) & (TPTYPE == HW) - approach_walktime[cbd_work,:, J] *= 1.20 - # if (ZTYPE_Z == 1 and TPTYPE == HW): - # approach_walktime[:, J] = approach_walktime[:, J] * 1.20 - TVAR4[t,:, J] = approach_walktime[t,:, J] * DRVOT * 2.0 - # ADD APPROACH TIMES AND COSTS - EVERYTHING SHOULD NOW BE IN CENTS - TVAR4[t,:, J] += approach_cost[t, :, J] - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=1(BUS) FIRST MODE. COMPUTE WALKING TIME, COST, AND IN-VEHICLE TIME - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif J == APPROACH_BUS or (J == APPROACH_FEEDER_BUS and I == FRONT_END): - - if J == APPROACH_FEEDER_BUS: - approach_walktime[t,:, J] = approach_distances[t,:, DIST_TO_FEEDER_BUS, I] / SPDWLK * 600. - approach_waittime[t,:,J] = fwfdr[Z][t].values[:,np.newaxis] - else: - approach_walktime[t,:, J] = approach_distances[t,:, DIST_TO_BUS, I] / SPDWLK * 600. - # INCREASE WALK TIME IN CHICAGO CBD - approach_walktime[t & (ZTYPE_Z == 1), :, J] *= 1.20 - approach_waittime[t,:,J] = fwbus[Z][t].values[:,np.newaxis] - approach_drivetime[t,:, J] = approach_distances[t,:, K[t], I] / SPEEDS[ZTYPE_Z[t]-1 + 4, np.newaxis] * 60. - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * OVT_IVT_RATIO - + approach_drivetime[t,:, J] - + approach_waittime[t,:,J] * OVT_IVT_RATIO - ) * DRVOT - - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # - # COST COMPUTATIONS FOR APPROACH BUS - # REVISED BY EASH 12/4/93 TO REFLECT CURRENT FARES - # ==== ORIGIN ==== - if (I == FRONT_END): - # FIRST MODE SUBURBAN RAIL - CHECK ZONE TYPE AT ORIGIN - # --- SUBURBAN ORIGIN, PACE BUS --- - s = t & (FM == TransitModeCode_METRA_RAIL) & (ozone_type > 2) - if np.any(s): - # PACE BUS - METRA RAIL, ADDED FARE IS PACE FEEDER BUS FARE - approach_cost[s & (LM == TransitModeCode_METRA_RAIL), :, J] = FEEDER_BUS_BOARDING_FARE - # PACE BUS - METRA RAIL - CTA, NO ADDED FARE, LINKUP > FEEDER BUS - # already zero # approach_cost[s & (LM == TransitModeCode_CTA_RAIL), :, J] = 0 - # PACE BUS - METRA RAIL - PACE, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (LM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - - # --- CHICAGO ORIGIN, CTA BUS --- - s = t & (FM == TransitModeCode_METRA_RAIL) & (ozone_type <= 2) - if np.any(s): - # CTA BUS - METRA RAIL, ADDED FARE IS LINKUP FARE (SINGLE RIDE) - approach_cost[s & (LM == TransitModeCode_METRA_RAIL), :, J] = CTA_CBD_LINK_UP_FARE - # CTA BUS - METRA RAIL - CTA, ADDED FARE IS CTA TRANSFER - approach_cost[s & (LM == TransitModeCode_CTA_RAIL), :, J] = CTA_FIRST_XFER_FARE - # CTA BUS - METRA RAIL - PACE, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (LM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - - # FIRST MODE CTA RAIL - # WHEN THIS IS TRUE A FULL FARE AND TRANSFER HAVE - # BEEN PAID, SO NO ADDED FARE IS NEEDED FOR BUS - - - # ORIGIN OTHER THAN CHICAGO, ADDED FARE IS NOW AN RTA TRANSFER - s = t & (FM < TransitModeCode_CTA_RAIL) & (ozone_type > 2) - if np.any(s): - approach_cost[s, :, J] = PACE_BUS_FIRST_XFER_FARE - - # CHICAGO ORIGIN, ADDED FARE IS CTA TRANSFER - s = t & (FM < TransitModeCode_CTA_RAIL) & (ozone_type <= 2) - if np.any(s): - approach_cost[s, :, J] = CTA_FIRST_XFER_FARE - - TVAR4[t, :, J] += approach_cost[t, :, J] - - - # ==== DESTINATION ==== - else: - # LAST MODE SUBURBAN RAIL - s = t & (LM == TransitModeCode_METRA_RAIL) & (dzone_type > 2) - if np.any(s): - # SUBURBAN DESTINATION, PACE BUS - # METRA RAIL - PACE BUS, ADDED FARE IS PACE FEEDER BUS FARE - approach_cost[s & (FM == TransitModeCode_METRA_RAIL), :, J] = FEEDER_BUS_BOARDING_FARE - # CTA - METRA RAIL - PACE BUS, NO ADDED FARE, LINKUP > FEEDER BUS - # PACE - METRA RAIL - PACE BUS, ADDED FARE IS LINKUP LESS FEEDER BUS - approach_cost[s & (FM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - s = t & (LM == TransitModeCode_METRA_RAIL) & (dzone_type <= 2) - if np.any(s): - # CHICAGO DESTINATION, CTA BUS - # METRA - CTA BUS, ADDED COST IS LINKUP FARE (SINGLE RIDE) - approach_cost[s & (FM == TransitModeCode_METRA_RAIL), :, J] = CTA_CBD_LINK_UP_FARE - # CTA - METRA - CTA BUS, ADDED COST IS CTA TRANSFER - approach_cost[s & (FM == TransitModeCode_CTA_RAIL), :, J] = CTA_FIRST_XFER_FARE - # PACE - METRA - CTA BUS, ADDED COST IS LINKUP MINUS FEEDER BUS - approach_cost[s & (FM == TransitModeCode_PACE_BUS), :, J] = FEEDER_BUS_CBD_FARE - # ADD CTA TRANSFER IF NOT ALREADY PAID BUT IT WAS USED - s = t & (LM < TransitModeCode_CTA_RAIL) & (dzone_type > 2) - if np.any(s): - approach_cost[s, J] = CTA_FIRST_XFER_FARE * ( - (best_approach_mode[:, FRONT_END]==APPROACH_BUS) - |(best_approach_mode[:, FRONT_END]==APPROACH_FEEDER_BUS) - ) - - TVAR4[t, :, J] += approach_cost[t, :, J] - - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=2(PARK & RIDE) FIRST MODE. PARK & RIDE FOR APPROACH TO RAPID TRANSIT AND SUBURBAN RAIL ROAD - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif (J == APPROACH_PARK_N_RIDE and I == FRONT_END): - approach_drivetime[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] / SPEEDS[ZTYPE_Z[t] - 1, np.newaxis] * 60. - approach_walktime[t,:, J] = W2PNR - # APPROACH COST=PER MILE COST + FIXED COST - approach_cost[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] * AUTO_OPERATING_COST_BY_ZONETYPE[ZTYPE_Z[t] - 1,np.newaxis] - # OPERATING COST MAY NOT BE LESS THAN 5 CENTS - approach_cost[t,:, J] = np.fmax(approach_cost[t,:, J], 5.0) - - approach_cost[t,:, J] = approach_cost[t,:, J] + AFC1 - # ADD HALF OF THE PARKING COST IF PARK-&-RIDE AVAILABLE - _tz = t&PNRAVL[Z] - approach_cost[_tz,:, J] += PRCOST[Z].values[_tz,np.newaxis] / 2 - # IF NO PARK-&-RIDE FACILITY AVAILABLE INCREASE WALK TIME - approach_walktime[~_tz,:, J] = 3 * W2PNR - - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * DRVOT * 2.0 - + approach_drivetime[t,:, J] * DRVOT - + approach_cost[t,:, J] - ) - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # J=3(KISS & RIDE) FIRST MODE. KISS & RIDE FOR APPROACH TO RAPID TRANSIT AND SUBURBAN RAIL ROAD - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - elif (J == APPROACH_KISS_N_RIDE and I == FRONT_END): - approach_drivetime[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] / SPEEDS[ZTYPE_Z[t] - 1, np.newaxis] * 60. - approach_walktime[t,:, J] = W2PNR - approach_cost[t,:, J] = approach_distances[t,:, DIST_TO_PARK_N_RIDE_STATION, I] * AUTO_OPERATING_COST_BY_ZONETYPE[ZTYPE_Z[t] - 1, np.newaxis] - approach_cost[t,:, J] = np.fmin(approach_cost[t,:, J], 5.0) - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - # ASSUMPTION IS THAT KISS AND RIDE REQUIRES A SPECIAL - # TRIP FROM HOME. DRIVER AND PASSENGER TIME VALUES NOW EQUAL. - # APCOST[J]=APCOST[J]*2.+AFC2+(DRVOT*approach_drivetime[J]*2.)/10 - approach_cost[t,:, J] = approach_cost[t,:, J] * 2. + AFC2 - TVAR4[t,:, J] = ( - approach_walktime[t,:, J] * OVT_IVT_RATIO - + approach_drivetime[t,:, J] * 2 # KISSING DRIVER - + approach_drivetime[t,:, J] - ) * DRVOT - # ******************* RWE CHANGE FOR I290 AUGUST-SEPT 2009 ************ - TVAR4[t,:, J] += approach_cost[t,:, J] - - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # EVALUATE APPROACH MODES AND SELECT THE BEST - # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - # FOLLOWING CODE CHANGED BY EASH 12/6/93 TO REFLECT - # NEW TRIP TYPES - # TPTYPE = 1 HOME PRODUCTIONS TO WORK ATTRACTIONS - # TPTYPE = 2 HOME PRODUCTIONS TO NON-WORK/NON-HOME ATTRACTIONS - # TPTYPE = 3 NON-HOME PRODUCTIONS TO NON-HOME ATTRACTIONS - for J in range(N_APPROACH_MODES): - # NO KISS-&-RIDE FOR NON-WORK TRIPS - if (TPTYPE != HW and J == APPROACH_KISS_N_RIDE): - continue - # NO PARK-AND RIDE OR KISS-&-RIDE AT THE WORK/OTHER - # ATTRACTION END FOR HOME BASED TRIPS - if (TPTYPE != NH and I == BACK_END and (J == APPROACH_PARK_N_RIDE or J == APPROACH_KISS_N_RIDE)): - continue - # NO PARK-&-RIDE OR KISS AND RIDE FOR NON-HOME TO NON-HOME TRIPS - if (TPTYPE == NH and (J == APPROACH_PARK_N_RIDE or J == APPROACH_KISS_N_RIDE)): - continue - # -- FIND LOWEST COST APPROACH - TVAR4_J = TVAR4[:,:, J].reshape(-1) - low_cost = (TVAR4_J < TVAR5) & (TVAR4_J > 0) - TVAR5[low_cost] = TVAR4_J[low_cost] - best_approach_mode[low_cost, I] = J - best_drivetime[low_cost, I] = approach_drivetime.reshape([-1,N_APPROACH_MODES])[low_cost, J] + .5 - best_walktime[low_cost, I] = approach_walktime.reshape([-1,N_APPROACH_MODES])[low_cost, J] + .5 - best_cost[low_cost, I] = approach_cost.reshape([-1,N_APPROACH_MODES])[low_cost, J] + .5 - best_waittime[low_cost, I] = approach_waittime.reshape([-1,N_APPROACH_MODES])[low_cost,J] + .5 - if trace: - log.log(trace, f" DIRECTION {I} APPROACH TYPE {J} {APPROACH_MODE_NAMES.get(J)}") - log.log(trace, f" drivetime {approach_drivetime[:5,:5, J]}") - log.log(trace, f" walktime {approach_walktime[:5,:5, J]}") - log.log(trace, f" cost {approach_cost[:5,:5, J]}") - log.log(trace, f" waittime {approach_waittime[:5,:5,J]}") - log.log(trace, f" gen cost {TVAR4[:5,:5, J]}") - if trace: - log.log(trace, f" DIRECTION {I} BEST APPROACH TYPE {best_approach_mode[:5,I]}") - - - # ADD ORIGIN AND DESTINATION QUANTITIES AND PASS BACK TO TRIPS - - ae_drivetime = best_drivetime[:, 0] + best_drivetime[:, 1] - ae_walktime = best_walktime[:, 0] + best_walktime[:, 1] - ae_cost = best_cost[:, 0] + best_cost[:, 1] - ae_waittime = best_waittime[:, 0] + best_waittime[:, 1] - - if not isinstance(ozone_, int): - ae_drivetime = ae_drivetime.reshape([vector_len,replication]) - ae_walktime = ae_walktime.reshape([vector_len,replication]) - ae_cost = ae_cost.reshape([vector_len,replication]) - ae_waittime = ae_waittime.reshape([vector_len,replication]) - best_approach_mode = best_approach_mode.reshape([vector_len,replication,N_TRIP_ENDS]) - approach_distances = approach_distances.reshape([vector_len, replication, N_DIST_TO_TYPES, N_TRIP_ENDS]) - - out = Dict() - out.drivetime = ae_drivetime - out.walktime = ae_walktime - out.cost = ae_cost - out.waittime = ae_waittime - out.approach_mode = best_approach_mode - out.approach_distances = approach_distances - return out - diff --git a/src/Mode-Dest-TOD/cmap_modedest/transit_skim_convolution.py b/src/Mode-Dest-TOD/cmap_modedest/transit_skim_convolution.py deleted file mode 100644 index 1ce0d25..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/transit_skim_convolution.py +++ /dev/null @@ -1,265 +0,0 @@ -import os -import numpy as np -import xarray as xr -# from array import * -from .addict import Dict - -import logging -log = logging.getLogger("CMAP") - -def skim_convol( - dh, - peak=True, - cutoff=0.4, - zone_types=None, -): - """ - Perform matrix convolution of transit skims. - - This function is based on the original TRANSIT_SKIM_FINAL_MATRICES1.PY - - Parameters - ---------- - dh : DataHandler - peak : bool, default True - Whether to process the peak or offpeak skims. - cutoff : float, default 0.4 - Park-and-ride skim routing is ignored if the transit generalized - cost exceeds this fraction of the congested drive-to-destination - cost. This prevents, for example, transit paths where the traveler - drives a long distance to a park-and-ride lot, then boards transit - for a short hop to the final destination. - New for the 2020 model update: When the final destination is in the - Chicago CBD, this cutoff is ignored when there is no valid non-PnR - path, so the traveler is permitted to drive unlimited distances to - access outlying transit (generally outlying Metra stations). - zone_types : array-like, optional - The zone type codes for zones in the model, used to filter for - Chicago CBD zones to apply the new cutoff rules. If not given, the - zone types are loaded from the package-default M01 HW file (see - m01_handler for details). - - """ - report_dir = dh.filenames.emme_database_dir / "report" - os.makedirs(report_dir, exist_ok=True) - - if peak: - # -- Input Matrix Numbers -- - inputmtx = Dict( - auto =44, ##0 AM peak hwy time matrix (mf44) - fmode=803, ##1 skimmed first mode (mf803) - pmode=804, ##2 skimmed priority mode (mf804) - lmode=805, ##3 skimmed last mode (mf805) - inveh=808, ##4 skimmed in-vehicle minutes (mf808) - trnfr=809, ##5 skimmed transfer link minutes (mf809) - twait=810, ##6 skimmed total wait minutes (mf810) - fwait=811, ##7 skimmed first wait minutes (mf811) - afare=818, ##8 skimmed final average fare (mf818) - cghwy=819, ##9 congested hwy generalized cost matrix (mf819) - tcost=820, #10 indexed transit generalized cost (mf820) - kzone=821, #11 intermediate zone matrix (mf821) - ) - # -- Output Matrix Numbers -- - outputmtx = Dict( - mfinvehi=822, ###0 indexed in-vehicle minutes (mf822) - mftrnfri=823, ###1 indexed walk transfer minutes (mf823) - mftwaiti=824, ###2 indexed total wait minutes (mf824) - mffwaiti=825, ###3 indexed first wait minutes (mf825) - mfafarei=828, ###4 indexed final average fare (mf828) - mffmodei=829, ###5 indexed first mode (mf829) - mfpmodei=830, ###6 indexed priority mode (mf830) - mflmodei=831, ###7 indexed last mode (mf831) - mfacosti=832, ###8 indexed auto generalized cost (mf832) - mfautrni=833, ###9 indexed auto min. to transit (mf833) - mfratioi=834, ##10 indexed transit/auto only (mf834) - ) - else: - # -- Input Matrix Numbers -- - inputmtx = Dict( - auto =46, ### midday hwy time matrix (mf46) - fmode=903, ### skimmed first mode (mf903) - pmode=904, ### skimmed priority mode (mf904) - lmode=905, ### skimmed last mode (mf905) - inveh=908, ### skimmed in-vehicle minutes (mf908) - trnfr=909, ### skimmed transfer link minutes (mf909) - twait=910, ### skimmed total wait minutes (mf910) - fwait=911, ### skimmed first wait minutes (mf911) - afare=918, ### skimmed final average fare (mf918) - cghwy=919, ### congested hwy generalized cost matrix (mf919) - tcost=920, ### indexed transit generalized cost (mf920) - kzone=921, ### intermediate zone matrix (mf921) - ) - # -- Output Matrix Numbers -- - outputmtx = Dict( - mfinvehi=922, ### indexed in-vehicle minutes (mf922) - mftrnfri=923, ### indexed walk transfer minutes (mf923) - mftwaiti=924, ### indexed total wait minutes (mf924) - mffwaiti=925, ### indexed first wait minutes (mf925) - mfafarei=928, ### indexed final average fare (mf928) - mffmodei=929, ### indexed first mode (mf929) - mfpmodei=930, ### indexed priority mode (mf930) - mflmodei=931, ### indexed last mode (mf931) - mfacosti=932, ### indexed auto generalized cost (mf932) - mfautrni=933, ### indexed auto min. to transit (mf933) - mfratioi=934, ### indexed transit/auto only (mf934) - ) - - # -- Input Matrices -- - # mfauto = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[0]) + ".emx" ) - # mffmode = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[1]) + ".emx" ) - # mfpmode = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[2]) + ".emx" ) - # mflmode = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[3]) + ".emx" ) - # mfinveh = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[4]) + ".emx" ) - # mftrnfr = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[5]) + ".emx" ) - # mftwait = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[6]) + ".emx" ) - # mffwait = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[7]) + ".emx" ) - # mfafare = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[8]) + ".emx" ) - # mfcghwy = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[9]) + ".emx" ) - # mftcost = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[10]) + ".emx" ) - # mfkzone = os.path.join(emmemat_in_dir, "mf" + str(inputmtx[11]) + ".emx" ) - # # -- Output Matrices -- - # if emmemat_out_dir: - # mfinvehi = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[0]) + ".emx" ) - # mftrnfri = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[1]) + ".emx" ) - # mftwaiti = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[2]) + ".emx" ) - # mffwaiti = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[3]) + ".emx" ) - # mfafarei = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[4]) + ".emx" ) - # mffmodei = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[5]) + ".emx" ) - # mfpmodei = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[6]) + ".emx" ) - # mflmodei = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[7]) + ".emx" ) - # mfacosti = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[8]) + ".emx" ) - # mfautrni = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[9]) + ".emx" ) - # mfratioi = os.path.join(emmemat_out_dir, "mf" + str(outputmtx[10]) + ".emx" ) - - # -- Others -- - stats = os.path.join(report_dir, f"transit_skim_stats{8 if peak else 9}.txt") - - if os.path.exists(stats): - os.remove(stats) - - # --------------------------------------------------------------- - # Store matrix values in arrays. - # --------------------------------------------------------------- - # -- Input Matrices -- - auto = dh.skims.raw[f"mf{inputmtx.auto }"].values.astype(np.float32).reshape(-1) # np.fromfile(mfauto, dtype='f4') ## -- float, 4 bytes - kzone = dh.skims.raw[f"mf{inputmtx.kzone}"].values.astype(np.float32).reshape(-1) - tcost = dh.skims.raw[f"mf{inputmtx.tcost}"].values.astype(np.float32).reshape(-1) - inveh = dh.skims.raw[f"mf{inputmtx.inveh}"].values.astype(np.float32).reshape(-1) - trnfr = dh.skims.raw[f"mf{inputmtx.trnfr}"].values.astype(np.float32).reshape(-1) - twait = dh.skims.raw[f"mf{inputmtx.twait}"].values.astype(np.float32).reshape(-1) - fwait = dh.skims.raw[f"mf{inputmtx.fwait}"].values.astype(np.float32).reshape(-1) - afare = dh.skims.raw[f"mf{inputmtx.afare}"].values.astype(np.float32).reshape(-1) - fmode = dh.skims.raw[f"mf{inputmtx.fmode}"].values.astype(np.float32).reshape(-1) - pmode = dh.skims.raw[f"mf{inputmtx.pmode}"].values.astype(np.float32).reshape(-1) - lmode = dh.skims.raw[f"mf{inputmtx.lmode}"].values.astype(np.float32).reshape(-1) - cghwy = dh.skims.raw[f"mf{inputmtx.cghwy}"].values.astype(np.float32).reshape(-1) - - mcent = int(np.sqrt(auto.shape[0])) - - if zone_types is None: - zone_types = dh.m01.zone_type.values - assert zone_types.size <= mcent - cbd_zone_indexes = np.where(zone_types == 1)[0] - dzone_inside_cbd = np.zeros([mcent,mcent], dtype=bool) - dzone_inside_cbd[:,cbd_zone_indexes] = True - dzone_inside_cbd = dzone_inside_cbd.reshape(-1) - - ## -- create leg1 (p-k) indices - indxloc = np.arange(mcent*mcent) ## -- array of consecutive numbers representing element index values - leg1pt1 = np.floor_divide(indxloc,mcent) * mcent ## -- portion of element index defining origin zone (division results in integer value) - leg1indx = np.add(leg1pt1,kzone.astype('i4')-1,dtype='i4') ## -- add portion of element index defining destination zone - log.info( - f"Kzone 1-1: {kzone[0]}, Index 1-1: {leg1indx[0]}, " - f"Kzone 121-2: {kzone[437882]}, Index 121-2: {leg1indx[437882]} \n" - ) - - ## -- create leg2 (k-q) indices - leg2pt1 = np.multiply(kzone.astype('i4')-1,mcent) - leg2pt2 = np.mod(indxloc,mcent) - leg2indx = np.add(leg2pt1,leg2pt2,dtype='i4') - log.info( - f"Kzone 1-1: {kzone[0]}, Index 1-1: {leg2indx[0]}, " - f"Kzone 121-2: {kzone[437882]}, Index 121-2: {leg2indx[437882]} \n" - ) - - # --------------------------------------------------------------- - # Create indexed matrices. - # --------------------------------------------------------------- - log.debug(f"Create indexed matrices") - autoval = np.where(kzone>0, auto [leg1indx], kzone) ## -- hwy time matrix - tcostval = np.where(kzone>0, tcost[leg1indx], kzone) ## -- indexed transit generalized cost - invehval = np.where(kzone>0, inveh[leg2indx], kzone) ## -- skimmed in-vehicle minutes - trnfrval = np.where(kzone>0, trnfr[leg2indx], kzone) ## -- skimmed transfer link minutes - twaitval = np.where(kzone>0, twait[leg2indx], kzone) ## -- skimmed total wait minutes - fwaitval = np.where(kzone>0, fwait[leg2indx], kzone) ## -- skimmed first wait minutes - afareval = np.where(kzone>0, afare[leg2indx], kzone) ## -- skimmed final average fare - fmodeval = np.where(kzone>0, fmode[leg2indx], kzone) ## -- skimmed first mode - pmodeval = np.where(kzone>0, pmode[leg2indx], kzone) ## -- skimmed priority mode - lmodeval = np.where(kzone>0, lmode[leg2indx], kzone) ## -- skimmed last mode - threshold= np.where(cghwy>0, np.divide(tcostval,cghwy), cghwy) ## -- ratio of indexed transit cost to auto only cost - - log.debug(f"Swap original matrix value back in if the threshold exceeds the cutoff value") - # -- Swap original matrix value back in if the threshold exceeds the cutoff value - swap = (threshold>cutoff) - # -- NEW 12/2020: but keep the park-and-ride indexed values if the destination zone - # is inside the CBD and the original values are invalid - prevent_swap = (dzone_inside_cbd) & (inveh > 999) - swap &= ~prevent_swap - autoval = np.where(swap, 0, autoval) - tcostval = np.where(swap, 0, tcostval) - invehval = np.where(swap, inveh, invehval) - trnfrval = np.where(swap, trnfr, trnfrval) - twaitval = np.where(swap, twait, twaitval) - fwaitval = np.where(swap, fwait, fwaitval) - afareval = np.where(swap, afare, afareval) - fmodeval = np.where(swap, fmode, fmodeval) - pmodeval = np.where(swap, pmode, pmodeval) - lmodeval = np.where(swap, lmode, lmodeval) - - - # --------------------------------------------------------------- - # Write final matrix values into files. - # --------------------------------------------------------------- - # -- Arrays to write out - mtxlist = { - outputmtx.mfinvehi: invehval, ###0 - outputmtx.mftrnfri: trnfrval, ###1 - outputmtx.mftwaiti: twaitval, ###2 - outputmtx.mffwaiti: fwaitval, ###3 - outputmtx.mfafarei: afareval, ###4 - outputmtx.mffmodei: fmodeval, ###5 - outputmtx.mfpmodei: pmodeval, ###6 - outputmtx.mflmodei: lmodeval, ###7 - outputmtx.mfacosti: tcostval, ###8 - outputmtx.mfautrni: autoval, ###9 - outputmtx.mfratioi: threshold, ##10 - } - with open(stats, 'a') as outFl: - for mf_num, vals in mtxlist.items(): - arr = dh.skims.raw[f"mf{mf_num}"] = xr.DataArray( - vals.reshape([mcent, mcent]), - dims=['otaz', 'dtaz'], - coords=dh.skims.raw.indexes, - ) - log.info(f"mf{mf_num} computed") - outFl.write(f"mf{mf_num} computed.\n") - # arr = arr.values.reshape(-1) - # arr_statistics = ( - # f"\t-- Minimum = {min(arr):.4f}\n" - # f"\t-- Maximum = {max(arr):0.4f}\n" - # f"\t-- Mean = {sum(arr) / len(arr):0.4f}\n" - # f"\t-- Sum = {sum(arr):0.4f}\n\n" - # ) - # outFl.write(arr_statistics) - # log.info(arr_statistics) - - revised_skims = dh.skims.raw[[f"mf{mf_num}" for mf_num in mtxlist.keys()]] - revised_skims.to_zarr( - dh.skims.filename - if os.path.splitext(dh.skims.filename) == ".zarr" else - dh.skims.filename.with_suffix(".zarr"), - mode='a', - ) - - - log.info("-- TRANSIT SKIM MATRICES CREATED --") diff --git a/src/Mode-Dest-TOD/cmap_modedest/util.py b/src/Mode-Dest-TOD/cmap_modedest/util.py deleted file mode 100644 index 74d322a..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/util.py +++ /dev/null @@ -1,138 +0,0 @@ -import os -import gc as _gc -import timeit -try: - import resource -except ModuleNotFoundError: - resource = None -import time -import numpy as np -import pandas as pd -try: - import psutil -except: - psutil = None - -# nano micro milli kilo mega giga tera peta exa zeta yotta -tiers = ['n', 'µ', 'm', '', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] - - -def si_units(x, kind='B', f="{:.3g} {}{}"): - tier = 3 - shift = 1024 if kind=='B' else 1000 - if x > 0: - while x > 1024 and tier < len(tiers): - x /= shift - tier += 1 - while x < 1 and tier >= 0: - x *= shift - tier -= 1 - return f.format(x,tiers[tier],kind) - - -class MemoryUsage: - - def __init__(self): - self.memory_history = [0,] - self.max_memory_history = [0,] - self.pid = os.getpid() # the current process identifier, to track memory usage - if psutil is None: - raise ModuleNotFoundError("pstil") - self.check() - - def check(self, silent=False, gc=False, time_checkpoint=None): - if gc: - _gc.collect() - now_memory = psutil.Process(self.pid).memory_info().rss - if resource: - max_memory = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss - marginal_max = max_memory - self.max_memory_history[-1] - else: - max_memory = None - marginal_max = None - marginal_usage = now_memory - self.memory_history[-1] - if time_checkpoint: - time_note = si_units(time.time()-time_checkpoint, kind='s') + ": " - else: - time_note = "" - if not silent: - print(f"{time_note}Net {si_units(marginal_usage)}, Total {si_units(now_memory)}") - self.memory_history.append(now_memory) - self.max_memory_history.append(max_memory) - - def __enter__(self): - _gc.collect() - _gc.disable() - self._context_start_time = time.time() - self.check(silent=True, gc=False) - - def __exit__(self, exc_type, exc_val, exc_tb): - self.check(time_checkpoint=self._context_start_time) - _gc.enable() - _gc.collect() - - -resource_usage = MemoryUsage() - - -def start_memory_tracing(): - '''More intensive memory tracing''' - import tracemalloc - tracemalloc.start() - - -def stop_memory_tracing(): - import tracemalloc - tracemalloc.stop() - - -def ping_memory_tracing(): - import tracemalloc - current, peak = tracemalloc.get_traced_memory() - print(f"Current memory usage is {si_units(current)}; Peak was {si_units(peak)}") - - -def timing(stmt, setup='pass', repeat=10, globals=None, quiet=False): - t = timeit.Timer( - stmt, - setup=setup, - globals=globals, - ) - n, duration = t.autorange() - timings = np.asarray([duration]+t.repeat(repeat-1, n)) / n - _mean = si_units(np.mean(timings), 's') - _std = si_units(np.std(timings), 's') - _min = si_units(min(timings), 's') - _max = si_units(max(timings), 's') - if not quiet: - if n > 1: - print(f"{_mean} ± {_std} per loop (mean ± std of {repeat} runs, {n} loops each), {_min} to {_max}") - else: - print(f"{_mean} ± {_std} per run (mean ± std of {repeat} runs), {_min} to {_max}") - return timings - - -def search_path(*paths): - """Search and return the first path that exists.""" - from pathlib import Path - for pth in paths: - if os.path.exists(pth): - return Path(pth) - pth = os.path.expanduser(pth) - if os.path.exists(pth): - return Path(pth) - pth = os.path.expandvars(pth) - if os.path.exists(pth): - return Path(pth) - - -from contextlib import contextmanager - -@contextmanager -def profiler(): - from pyinstrument import Profiler - profiler = Profiler() - profiler.start() - yield - profiler.stop() - print(profiler.output_text(unicode=True, color=True)) diff --git a/src/Mode-Dest-TOD/cmap_modedest/validation.py b/src/Mode-Dest-TOD/cmap_modedest/validation.py deleted file mode 100644 index 6286e43..0000000 --- a/src/Mode-Dest-TOD/cmap_modedest/validation.py +++ /dev/null @@ -1,96 +0,0 @@ -import pandas as pd -import numpy as np -from pathlib import Path -import dask.dataframe as dd -from .modecodes import mode9codes, mode9names - - -def attach_superdistricts_to_trip_table(dh, trip_table): - if isinstance(trip_table, dd.DataFrame): - trip_table = trip_table.compute() - if 'o_zone' not in trip_table.columns: - trip_table = trip_table.reset_index() - if 'o_district' not in trip_table: - zone_info = pd.read_csv( - dh.filenames.zone_districts, - index_col=0, - ) - trip_table['o_district'] = trip_table['o_zone'].map(zone_info.district) - trip_table['d_district'] = trip_table['d_zone'].map(zone_info.district) - if 'o_superdistrict' not in trip_table: - super_districts = dh.cfg.super_districts - trip_table['o_superdistrict'] = trip_table['o_district'].map(super_districts) - trip_table['d_superdistrict'] = trip_table['d_district'].map(super_districts) - return trip_table - -def superdistrict_flow_summary(dh, trip_table, dimensions): - trip_table = attach_superdistricts_to_trip_table(dh, trip_table) - - summary_table = trip_table.groupby([ - *dimensions, - "o_superdistrict", - "d_superdistrict", - ])['trips'].sum().unstack(-1).fillna(0) - - z = slice(None) - summary_output = [] - - for k in dh.cfg.super_district_flow_summaries: - v1, v2 = k.split("-") - temp = ( - summary_table - .loc[(*tuple([z]*len(dimensions)), list(v1)), list(v2)] - .sum(1) - .groupby(summary_table.index.names[:-1]) - .sum() - .rename(k) - ) - if v1 != v2: - temp = temp.add( - summary_table - .loc[(*tuple([z]*len(dimensions)), list(v2)), list(v1)] - .sum(1) - .groupby(summary_table.index.names[:-1]) - .sum(), - fill_value=0, - ).rename(k) - summary_output.append(temp) - - return pd.concat(summary_output, axis=1).fillna(0) - - -def to_excel(df, *args, **kwargs): - if isinstance(df, dd.DataFrame): - df = df.compute() - return df.to_excel(*args, **kwargs) - -def validation_aggregation(dh, trips, to_dir=None): - - if to_dir is None: - to_dir = dh.filenames.cache_dir - to_dir = Path(to_dir) - - if isinstance(trips, dd.DataFrame): - trips = trips.compute() - - trips = attach_superdistricts_to_trip_table(dh, trips) - internal_trips = trips.query("o_superdistrict != 'X'").query("d_superdistrict != 'X'") - - agg1 = internal_trips.groupby(['purpose', 'mode', 'hh_autos'])[['trips']].sum().unstack(-1) - agg2 = internal_trips.groupby(['purpose', 'mode', 'hh_inc5'])[['trips']].sum().unstack(-1) - agg3 = internal_trips.groupby(['purpose', 'mode', 'timeperiod'])[['trips']].sum().unstack(-1) - agg4 = superdistrict_flow_summary(dh, trips, ['purpose', 'mode']).T - agg4.index.name = 'segments' - agg5 = agg4.unstack().reset_index().pivot(index=['purpose', 'segments'], columns='mode') - agg5.columns = pd.MultiIndex.from_arrays([ - agg5.columns.get_level_values(1), - mode9names, - ], names=['modecode', 'modename']) - agg5pct = agg5.div(agg5.sum(1), axis=0).style.format("{:.2%}") - - with pd.ExcelWriter(to_dir / 'validation_data.xlsx', engine='xlsxwriter') as writer: - to_excel(agg1, writer, sheet_name='Autos', merge_cells=False) - to_excel(agg2, writer, sheet_name='Incomes', merge_cells=False) - to_excel(agg3, writer, sheet_name='TimePeriod', merge_cells=False) - to_excel(agg4, writer, sheet_name='FlowsByPurp&Mode', merge_cells=False) - to_excel(agg5pct, writer, sheet_name='FlowsByPurp&Mode%', merge_cells=False) diff --git a/src/Mode-Dest-TOD/nesting-tree.png b/src/Mode-Dest-TOD/nesting-tree.png deleted file mode 100644 index 148f406..0000000 Binary files a/src/Mode-Dest-TOD/nesting-tree.png and /dev/null differ diff --git a/src/Mode-Dest-TOD/requirements.txt b/src/Mode-Dest-TOD/requirements.txt deleted file mode 100644 index cb569c0..0000000 --- a/src/Mode-Dest-TOD/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy -scipy -pandas -addict>=2.2 -larch diff --git a/src/Mode-Dest-TOD/setup.py b/src/Mode-Dest-TOD/setup.py deleted file mode 100644 index 26db817..0000000 --- a/src/Mode-Dest-TOD/setup.py +++ /dev/null @@ -1,62 +0,0 @@ -""" -CMAP Trip-based Model Code -""" - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -# To use a consistent encoding -from codecs import open -import os -import re - -here = os.path.abspath(os.path.dirname(__file__)) - -def version(path): - """Obtain the packge version from a python file e.g. pkg/__init__.py - See . - """ - with open(os.path.join(here, path), encoding='utf-8') as f: - version_file = f.read() - version_match = re.search(r"""^__version__ = ['"]([^'"]*)['"]""", - version_file, re.M) - if version_match: - return version_match.group(1) - raise RuntimeError("Unable to find version string.") - -VERSION = version('cmap_modedest/__init__.py') - -# Get the long description from the README file -with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - -with open('requirements.txt') as f: - requirements_lines = f.readlines() -install_requires = [r.strip() for r in requirements_lines] - -setup( - name='cmap_modedest', - version=VERSION, - - description='CMAP Trip-based model', - long_description=long_description, - - url='https://github.com/CMAP-REPOS/cmap_trip-based_model', - - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=find_packages(exclude=['contrib', 'docs', 'tests']), - - # List run-time dependencies here. These will be installed by pip when - # your project is installed. For an analysis of "install_requires" vs pip's - # requirements files see: - # https://packaging.python.org/en/latest/requirements.html - - install_requires=install_requires, - - entry_points={ - "console_scripts": [ - "cmap_modedest = cmap_modedest.__main__:main" - ] - }, - -) diff --git a/src/Mode-Dest-TOD/sharrow/.idea/sharrow_lite.iml b/src/Mode-Dest-TOD/sharrow/.idea/sharrow_lite.iml deleted file mode 100644 index 32effd1..0000000 --- a/src/Mode-Dest-TOD/sharrow/.idea/sharrow_lite.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/Mode-Dest-TOD/sharrow/LICENSE b/src/Mode-Dest-TOD/sharrow/LICENSE deleted file mode 100644 index 7026335..0000000 --- a/src/Mode-Dest-TOD/sharrow/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2021, Jeffrey Newman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/Mode-Dest-TOD/sharrow/README.md b/src/Mode-Dest-TOD/sharrow/README.md deleted file mode 100644 index 285f345..0000000 --- a/src/Mode-Dest-TOD/sharrow/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# sharrow - -This pre-release library is independently developed from the CMAP trip-based model, -and is included here to ensure that the CMAP model links against the correct version. \ No newline at end of file diff --git a/src/Mode-Dest-TOD/sharrow/requirements.txt b/src/Mode-Dest-TOD/sharrow/requirements.txt deleted file mode 100644 index 25ff221..0000000 --- a/src/Mode-Dest-TOD/sharrow/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy>=1.19 -pandas>=1.2 -pyarrow>=3.0.0 -xarray>=0.17.0 -numba>=0.53 diff --git a/src/Mode-Dest-TOD/sharrow/setup.py b/src/Mode-Dest-TOD/sharrow/setup.py deleted file mode 100644 index 6fac007..0000000 --- a/src/Mode-Dest-TOD/sharrow/setup.py +++ /dev/null @@ -1,64 +0,0 @@ - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -# To use a consistent encoding -from codecs import open -from os import path -import os -import re -from setuptools import setup, find_packages - -def version(path): - """Obtain the packge version from a python file e.g. pkg/__init__.py - See . - """ - here = os.path.abspath(os.path.dirname(__file__)) - with open(os.path.join(here, path), encoding='utf-8') as f: - version_file = f.read() - version_match = re.search(r"""^__version__ = ['"]([^'"]*)['"]""", - version_file, re.M) - if version_match: - return version_match.group(1) - raise RuntimeError("Unable to find version string.") - -VERSION = version('sharrow/__init__.py') - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - -with open('requirements.txt') as f: - requirements_lines = f.readlines() -install_requires = [r.strip() for r in requirements_lines] - -setup( - name='sharrow', - version=VERSION, - - description='shared data formats for transportation modeling', - long_description=long_description, - - # The project's main homepage. - url='https://github.com/jpn--/sharrow', - - # Author details - author='Jeffrey Newman', - author_email='jeff@newman.me', - - # Choose your license - license='GPLv3', - - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - 'Programming Language :: Python :: 3.9', - ], - - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=find_packages(exclude=['contrib', 'docs', 'tests']), - - install_requires=install_requires, - -) diff --git a/src/Mode-Dest-TOD/sharrow/sharrow/__init__.py b/src/Mode-Dest-TOD/sharrow/sharrow/__init__.py deleted file mode 100644 index d168061..0000000 --- a/src/Mode-Dest-TOD/sharrow/sharrow/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -__version__ = "2021.4" - -import os -from .interface import SharedData -from .dataset import Dataset -from .local_dir import local_cache -from .tables import concat_tables, Table -from xarray import DataArray - -try: - _pro = int(os.environ.get("SHARROW_PRO", "1")) -except: - _pro = True - -if _pro: - try: - from sharrow_pro import * - except ImportError: - pass diff --git a/src/Mode-Dest-TOD/sharrow/sharrow/dataset.py b/src/Mode-Dest-TOD/sharrow/sharrow/dataset.py deleted file mode 100644 index 612ad8c..0000000 --- a/src/Mode-Dest-TOD/sharrow/sharrow/dataset.py +++ /dev/null @@ -1,457 +0,0 @@ -import numpy as np -import xarray as xr -import pandas as pd - - -def one_based(n): - return pd.RangeIndex(1, n + 1) - - -def zero_based(n): - return pd.RangeIndex(0, n) - - -class Dataset(xr.Dataset): - - __slots__ = () - - def update(self, other): - super().update(other) - if isinstance(other, Dataset): - match_names = self.match_names - match_names.update(other.match_names) - self.match_names = match_names - return self # deprecated return for consistency until xarray 0.19 - - @classmethod - def from_table( - cls, tbl, index_name="index", index=None, - ): - """ - Convert a pyarrow.Table into an xarray.Dataset - - Parameters - ---------- - tbl : Table - Table from which to use data and indices. - index_name : str, default 'index' - This name will be given to the default dimension index, if - none is given. Ignored if `index` is given explicitly. - index : Index-like, optional - Use this index instead of a default RangeIndex. - - Returns - ------- - New Dataset. - """ - if len(set(tbl.column_names)) != len(tbl.column_names): - raise ValueError("cannot convert Table with non-unique columns") - if index is None: - index = pd.RangeIndex(len(tbl), name=index_name) - else: - if len(index) != len(tbl): - raise ValueError( - f"length of index ({len(index)}) does not match length of table ({len(tbl)})" - ) - if isinstance(index, pd.MultiIndex) and not index.is_unique: - raise ValueError( - "cannot attach a non-unique MultiIndex and convert into xarray" - ) - arrays = [ - (tbl.column_names[n], np.asarray(tbl.column(n))) - for n in range(len(tbl.column_names)) - ] - result = cls() - if isinstance(index, pd.MultiIndex): - dims = tuple( - name if name is not None else "level_%i" % n - for n, name in enumerate(index.names) - ) - for dim, lev in zip(dims, index.levels): - result[dim] = (dim, lev) - else: - index_name = index.name if index.name is not None else "index" - dims = (index_name,) - result[index_name] = (dims, index) - - result._set_numpy_data_from_dataframe(index, arrays, dims) - return result - - @classmethod - def from_omx( - cls, omx, index_names=("otaz", "dtaz"), indexes="one-based", renames=None, - ): - # handle both larch.OMX and openmatrix.open_file versions - if "larch" in type(omx).__module__: - omx_data = omx.data - omx_shape = omx.shape - else: - omx_data = omx.root["data"] - omx_shape = omx.shape() - - arrays = {} - if renames is None: - for k in omx_data._v_children: - arrays[k] = omx_data[k][:] - elif isinstance(renames, dict): - for new_k, old_k in renames.items(): - arrays[new_k] = omx_data[old_k][:] - else: - for k in renames: - arrays[k] = omx_data[k][:] - d = { - "dims": index_names, - "data_vars": {k: {"dims": index_names, "data": arrays[k]} for k in arrays}, - } - if indexes == "one-based": - indexes = { - index_names[0]: one_based(omx_shape[0]), - index_names[1]: one_based(omx_shape[1]), - } - elif indexes == "zero-based": - indexes = { - index_names[0]: zero_based(omx_shape[0]), - index_names[1]: zero_based(omx_shape[1]), - } - if indexes is not None: - d["coords"] = { - index_name: {"dims": index_name, "data": index} - for index_name, index in indexes.items() - } - return cls.from_dict(d) - - @classmethod - def from_amx( - cls, amx, index_names=("otaz", "dtaz"), indexes="one-based", renames=None, - ): - arrays = {} - if renames is None: - for k in amx.list_matrices(): - arrays[k] = amx[k][:] - elif isinstance(renames, dict): - for new_k, old_k in renames.items(): - arrays[new_k] = amx[old_k] - else: - for k in renames: - arrays[k] = amx[k] - d = { - "dims": index_names, - "data_vars": {k: {"dims": index_names, "data": arrays[k]} for k in arrays}, - } - if indexes == "one-based": - indexes = {index_names[i]: "1" for i in range(len(index_names))} - elif indexes == "zero-based": - indexes = {index_names[i]: "0" for i in range(len(index_names))} - if isinstance(indexes, (list, tuple)): - indexes = dict(zip(index_names, indexes)) - if isinstance(indexes, dict): - for n, i in enumerate(index_names): - if indexes.get(i) == "1": - indexes[i] = one_based(amx.shape[n]) - elif indexes.get(i) == "0": - indexes[i] = zero_based(amx.shape[n]) - if indexes is not None: - d["coords"] = { - index_name: {"dims": index_name, "data": index} - for index_name, index in indexes.items() - } - return cls.from_dict(d) - - @classmethod - def from_zarr(cls, store, *args, **kwargs): - return cls(xr.open_zarr(store, *args, **kwargs)) - - def to_zarr(self, *args, **kwargs): - """ - Write dataset contents to a zarr group. - - Parameters - ---------- - store : MutableMapping, str or Path, optional - Store or path to directory in file system. If given with a - ".zarr.zip" extension, and keyword arguments limited to 'mode' and - 'compression', then a ZipStore will be created, populated, and then - immediately closed. - chunk_store : MutableMapping, str or Path, optional - Store or path to directory in file system only for Zarr array chunks. - Requires zarr-python v2.4.0 or later. - mode : {"w", "w-", "a", None}, optional - Persistence mode: "w" means create (overwrite if exists); - "w-" means create (fail if exists); - "a" means override existing variables (create if does not exist). - If ``append_dim`` is set, ``mode`` can be omitted as it is - internally set to ``"a"``. Otherwise, ``mode`` will default to - `w-` if not set. - synchronizer : object, optional - Zarr array synchronizer. - group : str, optional - Group path. (a.k.a. `path` in zarr terminology.) - encoding : dict, optional - Nested dictionary with variable names as keys and dictionaries of - variable specific encodings as values, e.g., - ``{"my_variable": {"dtype": "int16", "scale_factor": 0.1,}, ...}`` - compute : bool, optional - If True write array data immediately, otherwise return a - ``dask.delayed.Delayed`` object that can be computed to write - array data later. Metadata is always updated eagerly. - consolidated : bool, optional - If True, apply zarr's `consolidate_metadata` function to the store - after writing metadata. - append_dim : hashable, optional - If set, the dimension along which the data will be appended. All - other dimensions on overriden variables must remain the same size. - region : dict, optional - Optional mapping from dimension names to integer slices along - dataset dimensions to indicate the region of existing zarr array(s) - in which to write this dataset's data. For example, - ``{'x': slice(0, 1000), 'y': slice(10000, 11000)}`` would indicate - that values should be written to the region ``0:1000`` along ``x`` - and ``10000:11000`` along ``y``. - - Two restrictions apply to the use of ``region``: - - - If ``region`` is set, _all_ variables in a dataset must have at - least one dimension in common with the region. Other variables - should be written in a separate call to ``to_zarr()``. - - Dimensions cannot be included in both ``region`` and - ``append_dim`` at the same time. To create empty arrays to fill - in with ``region``, use a separate call to ``to_zarr()`` with - ``compute=False``. See "Appending to existing Zarr stores" in - the reference documentation for full details. - compression : int, optional - Only used for ".zarr.zip" files. By default zarr uses blosc - compression for chunks, so adding another layer of compression here - is typically redundant. - - References - ---------- - https://zarr.readthedocs.io/ - - Notes - ----- - Zarr chunking behavior: - If chunks are found in the encoding argument or attribute - corresponding to any DataArray, those chunks are used. - If a DataArray is a dask array, it is written with those chunks. - If not other chunks are found, Zarr uses its own heuristics to - choose automatic chunk sizes. - """ - if ( - len(args) == 1 - and isinstance(args[0], str) - and args[0].endswith(".zarr.zip") - ): - if {"compression", "mode"}.issuperset(kwargs.keys()): - import zarr - - with zarr.ZipStore(args[0], **kwargs) as store: - self.to_zarr(store) - return - return super().to_zarr(*args, **kwargs) - - def iat(self, *, _names=None, _load=False, _index_name=None, **idxs): - loaders = {} - if _index_name is None: - _index_name = "index" - for k, v in idxs.items(): - loaders[k] = xr.DataArray(v, dims=[_index_name]) - if _names: - ds = self[_names] - else: - ds = self - if _load: - ds = ds.load() - return ds.isel(**loaders) - - def at(self, *, _names=None, _load=False, _index_name=None, **idxs): - loaders = {} - if _index_name is None: - _index_name = "index" - for k, v in idxs.items(): - loaders[k] = xr.DataArray(v, dims=[_index_name]) - if _names: - ds = self[_names] - else: - ds = self - if _load: - ds = ds.load() - return ds.sel(**loaders) - - def at_df(self, df): - """ - Extract values by label on the coordinates indicated by columns of a DataFrame. - - Parameters - ---------- - df : pd.DataFrame or Mapping[str, array-like] - The columns (or keys) of `df` should match the named dimensions of - this Dataset. The resulting extracted DataFrame will have one row - per row of `df`, columns matching the data variables in this dataset, - and each value is looked up by the labels. - - Returns - ------- - pd.DataFrame - """ - result = self.at(**df).reset_coords(drop=True).to_dataframe() - if isinstance(df, pd.DataFrame): - result.index = df.index - return result - - def iat_df(self, df): - """ - Extract values by position on the coordinates indicated by columns of a DataFrame. - - Parameters - ---------- - df : pd.DataFrame or Mapping[str, array-like] - The columns (or keys) of `df` should match the named dimensions of - this Dataset. The resulting extracted DataFrame will have one row - per row of `df`, columns matching the data variables in this dataset, - and each value is looked up by the positions. - - Returns - ------- - pd.DataFrame - """ - result = self.iat(**df).reset_coords(drop=True).to_dataframe() - if isinstance(df, pd.DataFrame): - result.index = df.index - return result - - def select_and_rename(self, name_dict=None, **names): - """ - Select and rename variables from this Dataset - - Parameters - ---------- - name_dict, **names: dict - The keys or keyword arguments give the current names of the - variables that will be selected out of this Dataset. The values - give the new names of the same variables in the resulting Dataset. - - Returns - ------- - Dataset - """ - if name_dict is None: - name_dict = names - else: - name_dict.update(names) - return self[list(name_dict.keys())].rename(name_dict) - - def squash_index(self, indexes_dict=None, *, set_match_names=True, **indexes): - if indexes_dict is None: - indexes_dict = indexes - else: - indexes_dict.update(indexes) - ds = self.reset_index(list(indexes_dict.keys()), drop=True) - ds = ds.rename(**indexes_dict) - if set_match_names: - ds = ds.set_match_names({v: v for v in indexes_dict.values()}) - return ds - - def _repr_html_(self): - html = super()._repr_html_() - html = html.replace("xarray.Dataset", "sharrow.Dataset") - return html - - def __repr__(self): - r = super().__repr__() - r = r.replace("xarray.Dataset", "sharrow.Dataset") - return r - - @property - def match_names(self): - """ - A mapping - - If a match_name target begins with an '@', the match is a dynamic - match, where the particular index-position values are created based - on data in the main or other source[s]. This allows for match columns - that do not exist yet, including columns where the key column exists - but is a label-based or offset-based match that needs to be processed - into index-position values. - - """ - result = {} - for k in self.attrs.keys(): - if k.startswith("match_names_"): - result[k[12:]] = self.attrs.get(k) - for k in self.indexes.keys(): - if k not in result: - result[k] = None - return result - - @match_names.setter - def match_names(self, names): - if names is None: - existing_match_name_keys = list(self.match_names.keys()) - for k in existing_match_name_keys: - del self.attrs[k] - return - if isinstance(names, str): - dims = list(self.dims.keys()) - assert len(dims) == 1 - names = {dims[0]: names} - for k in names.keys(): - if k not in self.dims: - raise ValueError(f"'{k}' not in dims") - for k, v in names.items(): - if v is not None: - self.attrs[f"match_names_{k}"] = v - elif f"match_names_{k}" in self.attrs: - del self.attrs[f"match_names_{k}"] - - def set_match_names(self, names): - """ - Create a copy of this dataset with the given match_names for flowing. - - Parameters - ---------- - names : Sequence[str] or Mapping[str,str] - - Returns - ------- - sharrow.shared.Dataset - """ - result = self.copy() - result.match_names = names - return result - - def keep_dims(self, keep_dims, *, errors="raise"): - """ - Keep only certain dimensions and associated variables from this dataset. - - Parameters - ---------- - keep_dims : hashable or iterable of hashable - Dimension or dimensions to keep. - errors : {"raise", "ignore"}, optional - If 'raise' (default), raises a ValueError error if any of the - dimensions passed are not in the dataset. If 'ignore', any given - labels that are in the dataset are dropped and no error is raised. - - Returns - ------- - obj : Dataset - The dataset without the given dimensions (or any variables - containing those dimensions) - errors : {"raise", "ignore"}, optional - If 'raise' (default), raises a ValueError error if - any of the dimensions passed are not - in the dataset. If 'ignore', any given dimensions that are in the - dataset are dropped and no error is raised. - """ - if isinstance(keep_dims, str): - keep_dims = {keep_dims} - else: - keep_dims = set(keep_dims) - all_dims = set(self.dims) - if errors == "raise": - missing_dims = keep_dims - all_dims - if missing_dims: - raise ValueError( - "Dataset does not contain the dimensions: %s" % missing_dims - ) - return self.drop_dims([i for i in all_dims if i not in keep_dims]) diff --git a/src/Mode-Dest-TOD/sharrow/sharrow/interface.py b/src/Mode-Dest-TOD/sharrow/sharrow/interface.py deleted file mode 100644 index f8fcd92..0000000 --- a/src/Mode-Dest-TOD/sharrow/sharrow/interface.py +++ /dev/null @@ -1,90 +0,0 @@ -import os -import sys -import importlib -import hashlib -import base64 -import pandas as pd -import pyarrow as pa -import xarray as xr - -from .dataset import Dataset - - -class SharedData: - def __init__( - self, main=None, extra_funcs=(), extra_vars=None, **datasets, - ): - """ - SharedData establishes a domain to evaluate data flows. - - Parameters - ---------- - main : Dataset or Table or DataFrame or Sequence[str], optional - This is the main set of data that defines this object. - Only the main data can be replaced with similarly formatted - other data when flowing results. - **datasets : Dict[str, Dataset] - Other `Dataset` inputs for flowing data can be provided. - The flow closes on any other data (i.e. it is immutable and cannot - be replaced when flowing). Although "main" can be certain non-Dataset - types (i.e. a DataFrame or a Table), datasets must be - given as `Dataset` objects with appropriate `match_names` set. - """ - self.main = main - self.datasets = datasets - try: - from sharrow_pro import Table - except ImportError: - table_types = (pa.Table,) - else: - table_types = (pa.Table, Table) - for k in self.datasets: - arr = self.datasets[k] - if not isinstance(arr, Dataset): - if isinstance(arr, pd.DataFrame): - arr = Dataset.from_dataframe(arr) - elif isinstance(arr, table_types): - arr = Dataset.from_table(arr) - elif isinstance(arr, xr.Dataset): - arr = Dataset(arr) - self.datasets[k] = arr - - def setup_flow( - self, definition_spec, cache_dir, name, dtype="float32", - ): - """ - - Parameters - ---------- - definition_spec : Dict[str,str] - Gives the names and definitions for the columns to - create in our generated table. - - Returns - ------- - module - """ - if not os.path.isdir(cache_dir): - raise NotADirectoryError(cache_dir) - if not os.path.isdir(os.path.join(cache_dir, name)): - raise ModuleNotFoundError(name) - if not os.path.isfile(os.path.join(cache_dir, name, "__init__.py")): - raise ModuleNotFoundError(name) - - sys.path.insert(0, str(cache_dir)) - importlib.invalidate_caches() - module = importlib.import_module(name) - sys.path = sys.path[1:] - module.set_shared_data(**self.datasets) - - if definition_spec and hasattr(module, 'defs_hash'): - defs_hash = hashlib.md5() - for k, v in definition_spec.items(): - defs_hash.update(k.encode("utf8")) - defs_hash.update(v.encode("utf8")) - if module.defs_hash != (base64.b32encode(defs_hash.digest())).decode(): - raise ValueError( - "definitions are not consistent with precompiled data flows" - ) - - return module diff --git a/src/Mode-Dest-TOD/sharrow/sharrow/local_dir.py b/src/Mode-Dest-TOD/sharrow/sharrow/local_dir.py deleted file mode 100644 index cc40ffd..0000000 --- a/src/Mode-Dest-TOD/sharrow/sharrow/local_dir.py +++ /dev/null @@ -1,6 +0,0 @@ -import os -import inspect - - -def local_cache(dirname="__sc"): - return os.path.join(os.path.dirname(inspect.stack()[1][1]), dirname,) diff --git a/src/Mode-Dest-TOD/sharrow/sharrow/logging.py b/src/Mode-Dest-TOD/sharrow/sharrow/logging.py deleted file mode 100644 index c3bb39f..0000000 --- a/src/Mode-Dest-TOD/sharrow/sharrow/logging.py +++ /dev/null @@ -1,142 +0,0 @@ -import logging -import sys -from contextlib import contextmanager -import time - -LOGGER_NAME = "SHARROW" -FILE_LOG_FORMAT = "%(name)s.%(levelname)s: %(message)s" -CONSOLE_LOG_FORMAT = "[%(asctime)s] %(name)s.%(levelname)s: %(message)s" -DEFAULT_LOG_LEVEL = logging.DEBUG - - -def timesize_single(t): - if t < 60: - return f"{t:.2f}s" - elif t < 3600: - return f"{t / 60:.2f}m" - elif t < 86400: - return f"{t / 3600:.2f}h" - else: - return f"{t / 86400:.2f}d" - - -def timesize_stack(t): - if t < 60: - return f"{t:.2f}s" - elif t < 3600: - return f"{t // 60:.0f}m {timesize_stack(t % 60)}" - elif t < 86400: - return f"{t // 3600:.0f}h {timesize_stack(t % 3600)}" - else: - return f"{t // 86400:.0f}d {timesize_stack(t % 86400)}" - - -def log_to_console(level=None): - if level is None: - level = DEFAULT_LOG_LEVEL - - logger = logging.getLogger(LOGGER_NAME) - - # avoid creation of multiple stream handlers for logging to console - for entry in logger.handlers: - if (isinstance(entry, logging.StreamHandler)) and ( - entry.formatter._fmt == CONSOLE_LOG_FORMAT - ): - return logger - - console_handler = logging.StreamHandler(stream=sys.stderr) - console_handler.setLevel(level) - console_handler.setFormatter(logging.Formatter(CONSOLE_LOG_FORMAT)) - logger.addHandler(console_handler) - if level < logger.getEffectiveLevel(): - logger.setLevel(level) - - return logger - - -def log_to_file(filename, level=None): - if level is None: - level = DEFAULT_LOG_LEVEL - - logger = logging.getLogger(LOGGER_NAME) - - # avoid creation of multiple file handlers for logging to the same file - for entry in logger.handlers: - if (isinstance(entry, logging.FileHandler)) and ( - entry.baseFilename == filename - ): - return logger - - file_handler = logging.FileHandler(filename) - file_handler.setLevel(level) - file_handler.setFormatter(logging.Formatter(FILE_LOG_FORMAT)) - logger.addHandler(file_handler) - - return logger - - -logger = log = log_to_console() - - -@contextmanager -def timing_log(label=""): - start_time = time.time() - log.critical(f"