Skip to content

Commit

Permalink
for benefit cost, calculate travel time instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Ennazus committed Jun 19, 2015
1 parent 985ced4 commit 0753e75
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions scripts/summarize/benefit_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# this should be a run or config parameter
model_dir = 'C:/soundcast615/'

h5_base_file = 'outputs/daysim_outputs3.h5'
h5_base_file = 'outputs/daysim_outputs.h5'
h5_base_name = 'Base'
h5_scen_file = 'outputs/daysim_outputs1.h5'
h5_scen_file = 'outputs/daysim_outputs2040luv.h5'
h5_scen_name = 'Scenario'
report_output_location = 'outputs/benefits_zone.csv'
report_output_location = 'outputs/time_zone.csv'
guidefile = 'scripts/summarize/CatVarDict.xlsx'
zone_dim = 4050 #hard code should be in the config
zone_dim = 4000 #hard code should be in the config
#output

##################################
Expand All @@ -41,60 +41,61 @@
dtaz_base = np.asarray(trips_base["dtaz"])
dtaz_base = dtaz_base.astype('int')

vot_base = np.asarray(trips_base["vot"])
#vot_base = np.asarray(trips_base["vot"])
time_base = np.asarray(trips_base["travtime"])
cost_base =vot_base*time_base
#cost_base =vot_base*time_base

otaz_scen = np.asarray(trips_scen["otaz"])
otaz_scen = otaz_scen.astype('int')

dtaz_scen = np.asarray(trips_scen["dtaz"])
dtaz_scen = dtaz_base.astype('int')
dtaz_scen = dtaz_scen.astype('int')

vot_scen = np.asarray(trips_scen["vot"])
#vot_scen = np.asarray(trips_scen["vot"])
time_scen = np.asarray(trips_scen["travtime"])
cost_scen =vot_scen*time_scen
#cost_scen =vot_scen*time_scen


trip_base_matrix = np.zeros((zone_dim,zone_dim), np.float64)
cost_base_matrix= np.zeros((zone_dim,zone_dim), np.float64)
time_base_matrix= np.zeros((zone_dim,zone_dim), np.float64)
trip_scen_matrix = np.zeros((zone_dim,zone_dim), np.float64)
cost_scen_matrix= np.zeros((zone_dim,zone_dim), np.float64)
time_scen_matrix= np.zeros((zone_dim,zone_dim), np.float64)

# Fill up the base matrices from the arrays of data because they will be faster to work with
for trip in range (0, len(otaz_base)):
for trip in range (0, len(otaz_base)-1):
this_otaz = otaz_base[trip]
this_dtaz = dtaz_base[trip]
this_cost = cost_base[trip]
this_time = time_base[trip]
trip_base_matrix [this_otaz, this_dtaz] = trip_base_matrix[this_otaz, this_dtaz] + 1
cost_base_matrix [this_otaz, this_dtaz] = cost_base_matrix[this_otaz, this_dtaz] + this_cost
time_base_matrix [this_otaz, this_dtaz] = time_base_matrix[this_otaz, this_dtaz] + this_time

# Fill up the scenario matrices
for trip in range (0, len(otaz_scen)):
this_otaz = otaz_scen[trip]
this_dtaz = dtaz_scen[trip]
this_cost = cost_scen[trip]
for trip_s in range (0, len(otaz_scen)-1):
this_otaz = otaz_scen[trip_s]
this_dtaz = dtaz_scen[trip_s]
this_time = time_scen[trip_s]
trip_scen_matrix [this_otaz, this_dtaz] = trip_scen_matrix[this_otaz, this_dtaz] + 1
cost_scen_matrix [this_otaz, this_dtaz] = cost_scen_matrix[this_otaz, this_dtaz] + this_cost
time_scen_matrix [this_otaz, this_dtaz] = time_scen_matrix[this_otaz, this_dtaz] + this_time

cost_diff = (cost_scen_matrix - cost_base_matrix)
trips_total = (trip_scen_matrix + trip_base_matrix)/2
time_diff = (time_scen_matrix - time_base_matrix)
trips_total = (trip_scen_matrix + trip_base_matrix)

benefit_matrix = cost_diff*trips_total
avg_time_diff_matrix = time_diff/trips_total
avg_time_diff_matrix[np.isnan(avg_time_diff_matrix)] =0

taz_labels = np.array(range(1, zone_dim + 1))

#benefits by origin:
bens_by_origin = np.nansum(benefit_matrix , axis = 1, dtype=np.float64)
time_by_origin = np.mean(avg_time_diff_matrix, axis = 1, dtype=np.float64)

#benefits by destination:
bens_by_destination = np.nansum(benefit_matrix, axis = 0, dtype=np.float64)
time_by_destination = np.mean(avg_time_diff_matrix, axis = 0, dtype=np.float64)

#combine arrays:
all_colls = zip(taz_labels,bens_by_origin, bens_by_destination)
all_colls = zip(taz_labels,time_by_origin, time_by_destination)

#convert to dataframe
results = pd.DataFrame(data=all_colls, columns=['taz','origin_benefit', 'destination_benefit'])
results = pd.DataFrame(data=all_colls, columns=['taz','origin_time_diff', 'destination_time_diff'])

results.to_csv(report_output_location)

Expand Down

0 comments on commit 0753e75

Please sign in to comment.