diff --git a/docs/activity_plans.md b/docs/activity_plans.md index fb7514ac..570aec1a 100644 --- a/docs/activity_plans.md +++ b/docs/activity_plans.md @@ -135,4 +135,5 @@ This is resulting some difficult to follow logic (e.g., [][pam.activity.Plan.fil ## Plan cropping The [`pam.operations.cropping`](reference/pam/operations/cropping.md) module allows to spatially subset populations, by simplifying plan components that take place outside the "core" area. Any activities or legs that do not affect that core area are removed from the agents' plans, and agents with fully-external plans are removed from the population. -Examples of using the module can be found in the [][plan-cropping] notebook. \ No newline at end of file +Examples of using the module can be found in the [][plan-cropping] notebook. +Plan cropping now features basic logging on the input and then output population, quantifying the changes in agent and households as a result of the cropping. \ No newline at end of file diff --git a/src/pam/operations/cropping.py b/src/pam/operations/cropping.py index b0e82c70..7fd8a8ca 100644 --- a/src/pam/operations/cropping.py +++ b/src/pam/operations/cropping.py @@ -23,18 +23,25 @@ def simplify_population( # remove empty person-plans and households remove_persons = [] + track_those_removed = [] for hid, pid, person in population.people(): if len(person.plan) == 1 and person.plan.day[0].act == "external": remove_persons.append((hid, pid)) + track_those_removed.append({"hid": hid, "pid": pid}) for hid, pid in remove_persons: del population[hid].people[pid] + print(len(remove_persons), "persons to be removed") + remove_hhs = [ hid for hid in population.households if len(population.households[hid].people) == 0 ] for hid in remove_hhs: del population.households[hid] + print(len(remove_hhs), "households to be removed") + print("After simplification", population.stats) + def simplify_external_plans( plan: Plan,