From 30cdca5cef335624bf82101d5ed5490bb6d9e1dd Mon Sep 17 00:00:00 2001 From: Gerard Casey Date: Sat, 7 Sep 2024 08:57:41 +0100 Subject: [PATCH] Logging - write hid and pid of removed agents to a csv for inspection --- src/pam/operations/cropping.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pam/operations/cropping.py b/src/pam/operations/cropping.py index 53beacf3..8a72474f 100644 --- a/src/pam/operations/cropping.py +++ b/src/pam/operations/cropping.py @@ -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( @@ -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 @@ -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(