Skip to content

Commit

Permalink
Logging - write hid and pid of removed agents to a csv for inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
gac55 committed Sep 7, 2024
1 parent d388e82 commit 30cdca5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/pam/operations/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pam.activity import Activity, Leg, Plan
from pam.core import Population
from pam.variables import END_OF_DAY, START_OF_DAY
import pandas as pd


def simplify_population(
Expand All @@ -18,22 +19,24 @@ def simplify_population(
) -> None:
"""Simplify external plans across a population."""
# simplify plans
pre_stats = population.stats

for hid, pid, person in population.people():
simplify_external_plans(person.plan, boundary, snap_to_boundary, rename_external_activities)

# remove empty person-plans and households
remove_persons = []

track_those_removed = []

print("Before simplification",population.stats)

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("After simplification",population.stats)
# print("List of persons to remove:", remove_persons)
print(len(remove_persons), " persons to be removed")
print(len(remove_persons), "persons to be removed")

remove_hhs = [
hid for hid in population.households if len(population.households[hid].people) == 0
Expand All @@ -44,14 +47,10 @@ def simplify_population(
for hid in remove_hhs:
del population.households[hid]

gc_dict = {"remove_persons": remove_persons,
"remove_hhs": remove_hhs,
"population_stats_before": pre_stats,
"population_stats_after": population.stats,
}
# gc_dict.to_json(".json")
print("After simplification",population.stats)

pd.DataFrame(track_those_removed).to_csv("/mnt/efs/population/SE_v1_2040_developments_20240819_40wfh_hhsize_iter3_gc/combined/cropping_logs.csv")

print(population.stats)


def simplify_external_plans(
Expand Down

0 comments on commit 30cdca5

Please sign in to comment.