Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ def joint_tour_frequency(
# - but we don't know the tour participants yet
# - so we arbitrarily choose the first person in the household
# - to be point person for the purpose of generating an index and setting origin
temp_point_persons = persons.loc[persons.PNUM == 1]
if "PNUM" in persons.columns:
temp_point_persons = persons.loc[persons.PNUM == 1]
else:
# if PNUM is not available, we can still get the first person in the household
temp_point_persons = (
persons.sort_index() # ensure stable ordering
.groupby("household_id", as_index=False)
.first()
)
temp_point_persons["person_id"] = temp_point_persons.index
temp_point_persons = temp_point_persons.set_index("household_id")
temp_point_persons = temp_point_persons[["person_id", "home_zone_id"]]
Expand Down
26 changes: 18 additions & 8 deletions activitysim/abm/models/joint_tour_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,24 @@ def joint_tour_participation(
PARTICIPANT_COLS = ["tour_id", "household_id", "person_id"]
participants = candidates[participate][PARTICIPANT_COLS].copy()

# assign participant_num
# FIXME do we want something smarter than the participant with the lowest person_id?
participants["participant_num"] = (
participants.sort_values(by=["tour_id", "person_id"])
.groupby("tour_id")
.cumcount()
+ 1
)
if estimator:
# In estimation mode, use participant_num from survey data to preserve consistency
# with the original survey data. ActivitySim treats participant_num=1 as the tour
# leader, so the joint tour in the tour table will be associated with the tour
# leader's person_id. We merge participant_num from survey data using the
# participant_id as the join key to ensure the correct tour leader is identified.
participants["participant_num"] = survey_participants_df.reindex(
participants.index
)["participant_num"]
else:
# assign participant_num
# FIXME do we want something smarter than the participant with the lowest person_id?
participants["participant_num"] = (
participants.sort_values(by=["tour_id", "person_id"])
.groupby("tour_id")
.cumcount()
+ 1
)

state.add_table("joint_tour_participants", participants)

Expand Down