Skip to content

Commit

Permalink
Update simulated.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vamerlynck committed Oct 20, 2023
1 parent 5eaebcb commit a72eb07
Showing 1 changed file with 35 additions and 45 deletions.
80 changes: 35 additions & 45 deletions tm2py/acceptance/simulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,31 @@ def __init__(

def _validate(self):

self._make_transit_mode_dict()
self._make_simulated_maz_data()

self._read_standard_transit_stops()
self._read_standard_transit_shapes()
self._read_standard_transit_routes()
self._read_standard_node()

self._read_transit_demand()
self._make_transit_technology_in_vehicle_table_from_skims()
self._make_district_to_district_transit_summaries()

self._reduce_simulated_transit_boardings()
self._reduce_simulated_transit_shapes()
self._reduce_simulated_home_work_flows()
self._reduce_simulated_zero_vehicle_households()
self._reduce_simulated_station_to_station()
self._reduce_simulated_rail_access_summaries()

assert sorted(
self.simulated_home_work_flows_df.residence_county.unique().tolist()
) == sorted(self.c.county_names_list)
assert sorted(
self.simulated_home_work_flows_df.work_county.unique().tolist()
) == sorted(self.c.county_names_list)
# self._make_transit_mode_dict()
# self._make_simulated_maz_data()

# self._read_standard_transit_stops()
# self._read_standard_transit_shapes()
# self._read_standard_transit_routes()
# self._read_standard_node()

# self._read_transit_demand()
# self._make_transit_technology_in_vehicle_table_from_skims()
# self._make_district_to_district_transit_summaries()

# self._reduce_simulated_transit_boardings()
# self._reduce_simulated_transit_shapes()
# self._reduce_simulated_home_work_flows()
# self._reduce_simulated_zero_vehicle_households()
# self._reduce_simulated_station_to_station()
# self._reduce_simulated_rail_access_summaries()

# assert sorted(
# self.simulated_home_work_flows_df.residence_county.unique().tolist()
# ) == sorted(self.c.county_names_list)
# assert sorted(
# self.simulated_home_work_flows_df.work_county.unique().tolist()
# ) == sorted(self.c.county_names_list)

self._reduce_simulated_roadway_assignment_outcomes()

Expand Down Expand Up @@ -365,7 +365,7 @@ def _reduce_simulated_rail_access_summaries(self):
for time_period in self.model_time_periods:

df = pd.read_csv(
os.path.join(file_root, "trn", file_prefix + time_period + ".csv"),
os.path.join(file_root, "output_summaries", file_prefix + time_period + ".csv"),
dtype={"stop_name": str, "mdesc": str},
low_memory=False,
)
Expand Down Expand Up @@ -509,7 +509,7 @@ def _reduce_simulated_station_to_station(self):
):
input_file_name = os.path.join(
root_dir,
"trn",
"output_summaries",
f"{operator}_station_to_station_{path}_{time_period}.txt",
)
file = open(input_file_name, "r")
Expand Down Expand Up @@ -575,7 +575,7 @@ def _reduce_simulated_transit_boardings(self):
for time_period in self.model_time_periods:

df = pd.read_csv(
os.path.join(file_root, file_prefix + time_period + ".csv")
os.path.join(file_root, output_summaries, file_prefix + time_period + ".csv")
)
df["time_period"] = time_period
c_df = c_df.append(df)
Expand Down Expand Up @@ -908,8 +908,8 @@ def _read_transit_demand(self):
"KNR_TRN_WLK",
"WLK_TRN_KNR",
]
dem_dir = os.path.join(self.scenario_dict["scenario"]["root_dir"], "demand_matrices")

#dem_dir = os.path.join(self.scenario_dict["scenario"]["root_dir"], "demand_matrices")
dem_dir = '//corp.pbwan.net/us/CentralData/DCCLDA00/Standard/sag/projects/MTC/Acceptance_Criteria/temp/temp_acceptance/demand_matrices'

out_df = pd.DataFrame()
for time_period in self.model_time_periods:
Expand Down Expand Up @@ -961,9 +961,6 @@ def _make_dataframe_from_omx(self, input_mtx: omx, column_name: str):

def _make_district_to_district_transit_summaries(self):




taz_district_dict = self.c.taz_to_district_df.set_index("taz_tm1")[
"district_tm1"
].to_dict()
Expand Down Expand Up @@ -1019,7 +1016,7 @@ def _reduce_simulated_traffic_flow(self):

file_root = self.scenario_dict["scenario"]["root_dir"]
time_of_day_df = pd.DataFrame()


for time_period in self.model_time_periods:

Expand All @@ -1034,7 +1031,7 @@ def _reduce_simulated_traffic_flow(self):
df["time_period"] = time_period
time_of_day_df = time_of_day_df.append(
df
) # one file with selected vars for all the time periods
)

time_of_day_df["simulated_flow_auto"] = time_of_day_df[
["@flow_da", "@flow_sr2", "@flow_sr3","@flow_dato","@flow_sr2t", "@flow_sr3t"]
Expand All @@ -1054,16 +1051,16 @@ def _reduce_simulated_traffic_flow(self):
all_day_df = (
time_of_day_df.groupby(
["model_link_id"]
) # summarize all timeperiod flow variables to daily
)
.sum()
.reset_index()
)
all_day_df["time_period"] = self.c.ALL_DAY_WORD

# combine

out_df = pd.concat([time_of_day_df, all_day_df], axis="rows", ignore_index=True)

# remove unneeded columns

out_df = out_df[
[
"model_link_id",
Expand All @@ -1073,8 +1070,6 @@ def _reduce_simulated_traffic_flow(self):
"simulated_flow",
]
]

out_df.to_csv(os.path.join(file_root, out_file))

self.simulated_traffic_flow_df = out_df

Expand Down Expand Up @@ -1152,11 +1147,6 @@ def _reduce_simulated_roadway_assignment_outcomes(self):
"@useclass": "useclass",
"@capacity": "capacity",
"@lanes": "lanes",
#"@flow_da": "flow_da",
#"@flow_sr2": "flow_s2",
#"@flow_sr3": "flow_s3",
#"@flow_lrgt": "flow_lrgt",
#"@flow_trk": "flow_trk",
}
)

Expand Down

0 comments on commit a72eb07

Please sign in to comment.