Skip to content

Commit 6a553fc

Browse files
dhenslejpn--
andauthored
PNUM hard-coded and Vehicle table creation bug fix (#953)
* minor fixes for SimOR development * blacken * Using PNUM if available in JTFC Required to maintain backwards compatibility in tour indexes in SANDAG models --------- Co-authored-by: Jeffrey Newman <[email protected]>
1 parent 58dc347 commit 6a553fc

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

activitysim/abm/models/joint_tour_frequency_composition.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,15 @@ def joint_tour_frequency_composition(
146146
# - but we don't know the tour participants yet
147147
# - so we arbitrarily choose the first person in the household
148148
# - to be point person for the purpose of generating an index and setting origin
149-
# FIXME: not all models are guaranteed to have PNUM
150-
temp_point_persons = persons.loc[persons.PNUM == 1]
149+
if "PNUM" in persons.columns:
150+
temp_point_persons = persons.loc[persons.PNUM == 1]
151+
else:
152+
# if PNUM is not available, we can still get the first person in the household
153+
temp_point_persons = (
154+
persons.sort_index() # ensure stable ordering
155+
.groupby("household_id", as_index=False)
156+
.first()
157+
)
151158
temp_point_persons["person_id"] = temp_point_persons.index
152159
temp_point_persons = temp_point_persons.set_index("household_id")
153160
temp_point_persons = temp_point_persons[["person_id", "home_zone_id"]]

activitysim/abm/models/joint_tour_participation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def joint_tour_participation_candidates(joint_tours, persons_merged):
6060
# if this happens, participant_id may not be unique
6161
# channel random seeds will overlap at MAX_PARTICIPANT_PNUM (probably not a big deal)
6262
# and estimation infer will fail
63+
if "PNUM" not in candidates.columns:
64+
# create a PNUM column that just numbers the candidates for assignment of participant_id
65+
candidates["PNUM"] = candidates.groupby("household_id").cumcount() + 1
6366
assert (
6467
candidates.PNUM.max() < MAX_PARTICIPANT_PNUM
6568
), f"max persons.PNUM ({candidates.PNUM.max()}) > MAX_PARTICIPANT_PNUM ({MAX_PARTICIPANT_PNUM})"

activitysim/abm/tables/vehicles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def vehicles(state: workflow.State, households: pd.DataFrame):
2929
"""
3030

3131
# initialize vehicles table
32+
if "auto_ownership" not in households.columns:
33+
# grab the proto_households table instead
34+
# this is called when running disaggregate accessibilities and the vehicles table is used in the logsum calculation
35+
households = state.get_table("proto_households")
36+
households.index.name = "household_id"
37+
3238
vehicles = households.loc[households.index.repeat(households["auto_ownership"])]
3339
vehicles = vehicles.reset_index()[["household_id"]]
3440

0 commit comments

Comments
 (0)