summaryrefslogtreecommitdiff
path: root/lib/utils.py
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2024-01-12 15:28:17 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2024-01-12 15:28:17 +0100
commit94865648210a69544b049acf54991eba35d92c18 (patch)
treeb343d1e88b1eedf66f0fe1fdfa54360114aaddbf /lib/utils.py
parent5d6f965c656466b99457fd3fea80183f2e81fa43 (diff)
add --filter-observations
Diffstat (limited to 'lib/utils.py')
-rw-r--r--lib/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index 40d8b69..4282a14 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -580,6 +580,23 @@ def shift_param_in_aggregate(aggregate, parameters, parameter_shift):
)
+def filter_aggregate_by_observation(aggregate, observation_filter):
+ if observation_filter is None:
+ return
+ to_pop = dict()
+ for name in aggregate.keys():
+ to_pop[name] = list()
+ for attribute in aggregate[name]["attributes"]:
+ if (name, attribute) not in observation_filter:
+ to_pop[name].append(attribute)
+ for name, attributes in to_pop.items():
+ for attribute in attributes:
+ aggregate[name]["attributes"].remove(attribute)
+ aggregate[name].pop(attribute)
+ if len(aggregate[name]["attributes"]) == 0:
+ aggregate.pop(name)
+
+
def filter_aggregate_by_param(aggregate, parameters, parameter_filter):
"""
Remove entries which do not have certain parameter values from `aggregate`.