Skip to content

Commit

Permalink
fix scaling of IE trips based on study area
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekyadav26 committed Jul 27, 2023
1 parent f8f86f2 commit f0135f3
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions abm/src/main/python/dataExporter/abmScenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -2760,8 +2760,32 @@ def ie(self) -> pd.DataFrame:
dtype={"hh_id": "int32",
"transponder": "bool"})

input_hh = pd.read_csv(
os.path.join(self.scenario_path, "input", "households.csv"),
usecols=["hhid",
"taz"],
dtype={"hhid": "int64",
"taz": "int64"})

rsm_zones = pd.read_csv(
os.path.join(self.scenario_path, "input", "taz_crosswalk.csv"))

dict_clusters = dict(zip(rsm_zones["taz"], rsm_zones["cluster_id"]))

input_hh["taz"] = input_hh["taz"].map(dict_clusters)
input_hh['scale_factor'] = 1/self.properties["rsmSamplingRate"]

study_area_file = os.path.join(self.scenario_path, "input", "study_area.csv")

if os.path.exists(study_area_file):
df = pd.read_csv(study_area_file)
study_area_taz = set(df['taz'])
rsm_zone = set(rsm_zones.loc[rsm_zones['taz'].isin(study_area_taz), 'cluster_id'])
input_hh.loc[input_hh['taz'].isin(rsm_zone), 'scale_factor'] = 1

# if household has a transponder then all trips can use it
trips = trips.merge(hh, left_on="hhID", right_on="hh_id")
trips = trips.merge(input_hh, left_on="hhID", right_on="hhid", how="left")

# apply exhaustive field mappings where applicable
mappings = {
Expand Down Expand Up @@ -2838,9 +2862,10 @@ def ie(self) -> pd.DataFrame:

sampling_rate = self.properties["rsmSamplingRate"]
trips["weightTrip"] = pd.Series(
np.select(conditions, choices, default=1) / (sampling_rate*sampling_rate),
np.select(conditions, choices, default=1), #/ (sampling_rate*sampling_rate),
dtype="float32")
trips["weightPersonTrip"] = 1 / (sampling_rate*sampling_rate)
trips["weightTrip"] = trips["weightTrip"]*trips['scale_factor']
trips["weightPersonTrip"] = trips['scale_factor'] #1 / (sampling_rate*sampling_rate)
trips["weightPersonTrip"] = trips["weightPersonTrip"].astype("float32")

# rename columns to standard/generic ABM naming conventions
Expand Down

0 comments on commit f0135f3

Please sign in to comment.