From 3690b0e24bfca0fa7a5ce3c095f76fba75092d4f Mon Sep 17 00:00:00 2001 From: rakow Date: Mon, 9 Oct 2023 14:31:02 +0200 Subject: [PATCH] option to filter persons with invalid trips --- matsim/scenariogen/data/run_create_ref_data.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/matsim/scenariogen/data/run_create_ref_data.py b/matsim/scenariogen/data/run_create_ref_data.py index 6043f12..fbf4ecd 100644 --- a/matsim/scenariogen/data/run_create_ref_data.py +++ b/matsim/scenariogen/data/run_create_ref_data.py @@ -71,7 +71,7 @@ def default_person_filter(df): return df[df.present_on_day & (df.reporting_day <= 4)] -def create(survey_dirs, transform_persons): +def create(survey_dirs, transform_persons, filter_persons_with_invalid_trips=True): """ Create reference data from survey data. """ all_hh, all_persons, all_trips = read_all(survey_dirs) @@ -84,9 +84,12 @@ def create(survey_dirs, transform_persons): # TODO: configurable attributes persons["age_group"] = pd.cut(persons.age, [0, 18, 66, np.inf], labels=["0 - 17", "18 - 65", "65+"], right=False) - invalid = set(all_trips[~all_trips.valid].p_id) + # Filter persons, if they have at least one invalid trip + if filter_persons_with_invalid_trips: + invalid = set(all_trips[~all_trips.valid].p_id) + persons = persons[~persons.index.isin(invalid)] - persons = persons[~persons.index.isin(invalid)] + # TODO: only filter inviduall trips if invalid trips = all_trips.drop(columns=["hh_id"]).join(persons, on="p_id", how="inner")