Skip to content

Commit

Permalink
simple logging for cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
gac55 committed Oct 15, 2024
1 parent c8bff76 commit 787c7c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/activity_plans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
7 changes: 7 additions & 0 deletions src/pam/operations/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 787c7c4

Please sign in to comment.