From 94865648210a69544b049acf54991eba35d92c18 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Fri, 12 Jan 2024 15:28:17 +0100 Subject: add --filter-observations --- lib/cli.py | 6 ++++++ lib/utils.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/cli.py b/lib/cli.py index 273f86b..f9341f8 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -522,6 +522,12 @@ def add_standard_arguments(parser): "All other measurements (including those where it is None, that is, has not been set yet) are discarded. " "Note that this may remove entire function calls from the model.", ) + parser.add_argument( + "--filter-observation", + metavar=":[,:...]", + type=str, + help="Only consider measurements of ", + ) parser.add_argument( "--ignore-param", metavar="[,,...]", 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`. -- cgit v1.2.3