Skip to content

Commit

Permalink
Merge branch 'develop' into setup_model
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishKuls committed Oct 16, 2024
2 parents de4472f + 7c4ecaa commit a3f664a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
47 changes: 44 additions & 3 deletions tm2py/acceptance/canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Canonical:
canonical_dict: dict
canonical_file: str
scenario_dict: dict
scenario_file: str

census_2010_to_maz_crosswalk_df: pd.DataFrame

Expand All @@ -19,6 +21,7 @@ class Canonical:

standard_to_emme_node_crosswalk_df: pd.DataFrame
pems_to_link_crosswalk_df: pd.DataFrame
taz_to_district_df: pd.DataFrame

ALL_DAY_WORD = "daily"
WALK_ACCESS_WORD = "Walk"
Expand Down Expand Up @@ -64,18 +67,25 @@ def _load_configs(self):
with open(self.canonical_file, "r", encoding="utf-8") as toml_file:
self.canonical_dict = toml.load(toml_file)

with open(self.scenario_file, "r", encoding="utf-8") as toml_file:
self.scenario_dict = toml.load(toml_file)



return

def __init__(
self, canonical_file: str, on_board_assign_summary: bool = False
self, canonical_file: str, scenario_file: str = None, on_board_assign_summary: bool = False
) -> None:
self.canonical_file = canonical_file
self.scenario_file = scenario_file
self._load_configs()
self._make_canonical_agency_names_dict()
self._make_canonical_station_names_dict()
self._read_standard_to_emme_transit()
self._make_tm2_to_gtfs_mode_crosswalk()
self._read_standard_transit_to_survey_crosswalk()
self._make_simulated_maz_data()

if not on_board_assign_summary:
self._make_census_maz_crosswalk()
Expand All @@ -84,6 +94,37 @@ def __init__(

return

def _make_simulated_maz_data(self):
in_file = self.scenario_dict["scenario"]["maz_landuse_file"]

df = pd.read_csv(in_file)

index_file = os.path.join("inputs", "landuse", "mtc_final_network_zone_seq.csv")

index_df = pd.read_csv(index_file)
join_df = index_df.rename(columns={"N": "MAZ_ORIGINAL"})[
["MAZ_ORIGINAL", "MAZSEQ"]
].copy()

self.simulated_maz_data_df = pd.merge(
df,
join_df,
how="left",
on="MAZ_ORIGINAL",
)

self._make_taz_district_crosswalk()

return

def _make_taz_district_crosswalk(self):

df = self.simulated_maz_data_df[["TAZ_ORIGINAL", "DistID"]].copy()
df = df.rename(columns={"TAZ_ORIGINAL": "taz", "DistID": "district"})
self.taz_to_district_df = df.drop_duplicates().reset_index(drop=True)

return

def _make_canonical_agency_names_dict(self):
file_root = self.canonical_dict["remote_io"]["crosswalk_folder_root"]
in_file = self.canonical_dict["crosswalks"]["canonical_agency_names_file"]
Expand Down Expand Up @@ -243,8 +284,8 @@ def _read_pems_to_link_crosswalk(self) -> pd.DataFrame:
in_file = self.canonical_dict["crosswalks"]["pems_station_to_tm2_links_file"]

df = pd.read_csv(os.path.join(file_root, in_file))

df = df[["station", "A", "B"]]
df["station_id"] = df["station"].astype(str) + "_" + df["direction"]
df = df[["station_id", "A", "B"]]

self.pems_to_link_crosswalk_df = df

Expand Down
4 changes: 2 additions & 2 deletions tm2py/acceptance/observed.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ def _make_district_to_district_transit_flows_by_technology(self):
o_df = self.reduced_transit_spatial_flow_df.copy()
o_df = o_df[o_df["time_period"] == "am"].copy()

tm2_district_dict = self.c.taz_to_district_df.set_index("taz_tm2")[
"district_tm2"
tm2_district_dict = self.c.taz_to_district_df.set_index("taz")[
"district"
].to_dict()
o_df["orig_district"] = o_df["orig_taz"].map(tm2_district_dict)
o_df["dest_district"] = o_df["dest_taz"].map(tm2_district_dict)
Expand Down
10 changes: 4 additions & 6 deletions tm2py/acceptance/simulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Simulated:
transit_access_mode_dict = {}
transit_mode_dict = {}

taz_to_district_df: pd.DataFrame

simulated_boardings_df: pd.DataFrame
simulated_home_work_flows_df: pd.DataFrame
Expand Down Expand Up @@ -136,7 +135,6 @@ def reduce_on_board_assignment_boardings(self, time_period_list: list = ["am"]):

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()
Expand Down Expand Up @@ -356,7 +354,7 @@ def _reduce_simulated_home_work_flows(self):
b_df = (
pd.merge(
df[["HHID", "HomeMGRA", "WorkLocation"]].copy(),
self.simulated_maz_data_df[["MAZSEQ", "CountyName"]].copy(),
self.c.simulated_maz_data_df[["MAZSEQ", "CountyName"]].copy(),
how="left",
left_on="HomeMGRA",
right_on="MAZSEQ",
Expand All @@ -368,7 +366,7 @@ def _reduce_simulated_home_work_flows(self):
c_df = (
pd.merge(
b_df,
self.simulated_maz_data_df[["MAZSEQ", "CountyName"]].copy(),
self.c.simulated_maz_data_df[["MAZSEQ", "CountyName"]].copy(),
how="left",
left_on="WorkLocation",
right_on="MAZSEQ",
Expand Down Expand Up @@ -725,7 +723,7 @@ def _reduce_simulated_zero_vehicle_households(self):
a_df = (
pd.merge(
self.simulated_zero_vehicle_hhs_df,
self.simulated_maz_data_df[["MAZ_ORIGINAL", "MAZSEQ"]],
self.c.simulated_maz_data_df[["MAZ_ORIGINAL", "MAZSEQ"]],
left_on="maz",
right_on="MAZSEQ",
how="left",
Expand Down Expand Up @@ -1074,7 +1072,7 @@ def _make_dataframe_from_omx(self, input_mtx: omx, core_name: str):
return df

def _make_district_to_district_transit_summaries(self):
taz_district_dict = self.taz_to_district_df.set_index("taz")[
taz_district_dict = self.c.taz_to_district_df.set_index("taz")[
"district"
].to_dict()

Expand Down

0 comments on commit a3f664a

Please sign in to comment.