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
11 changes: 9 additions & 2 deletions activitysim/abm/models/joint_tour_frequency_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ def joint_tour_frequency_composition(
# - 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
# FIXME: not all models are guaranteed to have PNUM
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
3 changes: 3 additions & 0 deletions activitysim/abm/models/joint_tour_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def joint_tour_participation_candidates(joint_tours, persons_merged):
# if this happens, participant_id may not be unique
# channel random seeds will overlap at MAX_PARTICIPANT_PNUM (probably not a big deal)
# and estimation infer will fail
if "PNUM" not in candidates.columns:
# create a PNUM column that just numbers the candidates for assignment of participant_id
candidates["PNUM"] = candidates.groupby("household_id").cumcount() + 1
assert (
candidates.PNUM.max() < MAX_PARTICIPANT_PNUM
), f"max persons.PNUM ({candidates.PNUM.max()}) > MAX_PARTICIPANT_PNUM ({MAX_PARTICIPANT_PNUM})"
Expand Down
6 changes: 6 additions & 0 deletions activitysim/abm/tables/vehicles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def vehicles(state: workflow.State, households: pd.DataFrame):
"""

# initialize vehicles table
if "auto_ownership" not in households.columns:
# grab the proto_households table instead
# this is called when running disaggregate accessibilities and the vehicles table is used in the logsum calculation
households = state.get_table("proto_households")
households.index.name = "household_id"

vehicles = households.loc[households.index.repeat(households["auto_ownership"])]
vehicles = vehicles.reset_index()[["household_id"]]

Expand Down
Loading