diff --git a/activitysim/abm/models/joint_tour_frequency_composition.py b/activitysim/abm/models/joint_tour_frequency_composition.py index b9f801eb5..1fffd892a 100644 --- a/activitysim/abm/models/joint_tour_frequency_composition.py +++ b/activitysim/abm/models/joint_tour_frequency_composition.py @@ -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"]] diff --git a/activitysim/abm/models/joint_tour_participation.py b/activitysim/abm/models/joint_tour_participation.py index 4e834fc62..47bc2b8ff 100644 --- a/activitysim/abm/models/joint_tour_participation.py +++ b/activitysim/abm/models/joint_tour_participation.py @@ -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})" diff --git a/activitysim/abm/tables/vehicles.py b/activitysim/abm/tables/vehicles.py index c998c9abe..36f13b0cc 100644 --- a/activitysim/abm/tables/vehicles.py +++ b/activitysim/abm/tables/vehicles.py @@ -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"]]