Created
December 14, 2019 15:50
-
-
Save paulopperman/d605f229f62d027d2964762776224b36 to your computer and use it in GitHub Desktop.
an inelegant script to melt state origin/destination data into files for SUMO model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# an inelegant script to melt state data into files for SUMO model | |
import pandas as pd | |
def build_od_list(od_file): | |
od = pd.read_csv(od_file, header=None, index_col=0) | |
od.columns = od.index | |
# clean matrix | |
od = od.drop(index=[589, 594], columns=[589, 594]) # drop ODs that aren't in the network bounds | |
# remove invalid bridge to bridge traffic | |
for m in [1,2,3]: | |
for n in [1,2,3]: | |
od.loc[m,n] = 0 | |
# melt dataframe | |
mat=[] | |
for idx, row in od.iterrows(): | |
for i, r in row.iteritems(): | |
mat.append([idx, i, r]) | |
df = pd.DataFrame(mat) | |
return df | |
# Home Based Non-Work Auto | |
build_od_list('Update Data/Update Data/15OD/HBNWAUTO15.csv').to_csv('OD_Lists/hbnwauto15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBNWAUTO25.csv').to_csv('OD_Lists/hbnwauto25.txt', sep='\t', header=None, index=None) | |
# Home Based Non-Work Drive to Bus | |
build_od_list('Update Data/Update Data/15OD/HBNWDRV2BUS15.csv').to_csv('OD_Lists/hbnwdrv2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBNWDRV2BUS25.csv').to_csv('OD_Lists/hbnwdrv2bus25.txt', sep='\t', header=None, index=None) | |
# Home Based Non-Work Drive to Train | |
build_od_list('Update Data/Update Data/15OD/HBNWDRV2TRN15.csv').to_csv('OD_Lists/hbnwdrv2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBNWDRV2TRN25.csv').to_csv('OD_Lists/hbnwdrv2trn25.txt', sep='\t', header=None, index=None) | |
# Home Based Non-Work Walk to Bus | |
build_od_list('Update Data/Update Data/15OD/HBNWWK2BUS15.csv').to_csv('OD_Lists/hbnwwk2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBNWWK2BUS25.csv').to_csv('OD_Lists/hbnwwk2bus25.txt', sep='\t', header=None, index=None) | |
# Home Based Non-Work Walk to Train | |
build_od_list('Update Data/Update Data/15OD/HBNWWK2TRN15.csv').to_csv('OD_Lists/hbnwwk2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBNWWK2TRN25.csv').to_csv('OD_Lists/hbnwwk2trn25.txt', sep='\t', header=None, index=None) | |
# Home Based Work Auto | |
build_od_list('Update Data/Update Data/15OD/HBWAUTO15.csv').to_csv('OD_Lists/hbwauto15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBWAUTO25.csv').to_csv('OD_Lists/hbwauto25.txt', sep='\t', header=None, index=None) | |
# Home Based Work Drive to Bus | |
build_od_list('Update Data/Update Data/15OD/HBWDRV2BUS15.csv').to_csv('OD_Lists/hbwdrv2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBWDRV2BUS25.csv').to_csv('OD_Lists/hbwdrv2bus25.txt', sep='\t', header=None, index=None) | |
# Home Based Work Drive to Train | |
build_od_list('Update Data/Update Data/15OD/HBWDRV2TRN15.csv').to_csv('OD_Lists/hbwdrv2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBWDRV2TRN25.csv').to_csv('OD_Lists/hbwdrv2trn25.txt', sep='\t', header=None, index=None) | |
# Home Based Work Walk to Bus | |
build_od_list('Update Data/Update Data/15OD/HBWWK2BUS15.csv').to_csv('OD_Lists/hbwwk2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBWWK2BUS25.csv').to_csv('OD_Lists/hbwwk2bus25.txt', sep='\t', header=None, index=None) | |
# Home Based Work Walk to Train | |
build_od_list('Update Data/Update Data/15OD/HBWWK2TRN15.csv').to_csv('OD_Lists/hbwwk2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/HBWWK2TRN25.csv').to_csv('OD_Lists/hbwwk2trn25.txt', sep='\t', header=None, index=None) | |
# Non-Home Based Auto | |
build_od_list('Update Data/Update Data/15OD/NHBAUTO15.csv').to_csv('OD_Lists/nhbauto15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/NHBAUTO25.csv').to_csv('OD_Lists/nhbauto25.txt', sep='\t', header=None, index=None) | |
# Non-Home Based Drive to Bus | |
build_od_list('Update Data/Update Data/15OD/NHBDRV2BUS15.csv').to_csv('OD_Lists/nhbdrv2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/NHBDRV2BUS25.csv').to_csv('OD_Lists/nhbdrv2bus25.txt', sep='\t', header=None, index=None) | |
# Non-Home Based Drive to Train | |
build_od_list('Update Data/Update Data/15OD/NHBDRV2TRN15.csv').to_csv('OD_Lists/nhbdrv2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/NHBDRV2TRN25.csv').to_csv('OD_Lists/nhbdrv2trn25.txt', sep='\t', header=None, index=None) | |
# Non-Home Based Walk to Bus | |
build_od_list('Update Data/Update Data/15OD/NHBWK2BUS15.csv').to_csv('OD_Lists/nhbwk2bus15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/NHBWK2BUS25.csv').to_csv('OD_Lists/nhbwk2bus25.txt', sep='\t', header=None, index=None) | |
# Non-Home Based Walk to Train | |
build_od_list('Update Data/Update Data/15OD/NHBWK2TRN15.csv').to_csv('OD_Lists/nhbwk2trn15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/NHBWK2TRN25.csv').to_csv('OD_Lists/nhbwk2trn25.txt', sep='\t', header=None, index=None) | |
# Trucks | |
build_od_list('Update Data/Update Data/15OD/TRUCK15.csv').to_csv('OD_Lists/truck15.txt', sep='\t', header=None, index=None) | |
build_od_list('Update Data/Update Data/25OD/TRUCK25.csv').to_csv('OD_Lists/truck25.txt', sep='\t', header=None, index=None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment