From fa40b0431a5df82b59dcff1f33bb86c4bf3eff9d Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Mon, 18 Mar 2024 18:47:01 +0000 Subject: [PATCH] accumulations --- ecml_tools/create/functions/steps/rename.py | 12 ++++++++---- ecml_tools/create/input.py | 2 +- ecml_tools/create/loaders.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ecml_tools/create/functions/steps/rename.py b/ecml_tools/create/functions/steps/rename.py index d0bd589..a184f83 100644 --- a/ecml_tools/create/functions/steps/rename.py +++ b/ecml_tools/create/functions/steps/rename.py @@ -7,6 +7,8 @@ # nor does it submit to any jurisdiction. # +import re + from climetlab.indexing.fieldset import FieldArray @@ -30,12 +32,13 @@ class RenamedFieldFormat: def __init__(self, field, format): self.field = field self.format = format + self.bits = re.findall(r"{(\w+)}", format) def metadata(self, key): value = self.field.metadata(key) - # print('✅✅✅✅✅✅✅✅✅ ====> ', key, value, self.format) if "{" + key + "}" in self.format: - return self.format.format(**{key: value}) + bits = {b: self.field.metadata(b) for b in self.bits} + return self.format.format(**bits) return value def __getattr__(self, name): @@ -43,7 +46,8 @@ def __getattr__(self, name): def execute(context, input, what="param", **kwargs): - if "{" in what: - return FieldArray([RenamedFieldFormat(fs, what) for fs in input]) + # print('🍍🍍🍍🍍🍍🍍🍍🍍🍍🍍🍍🍍🍍 ==========', kwargs) + if what in kwargs: + return FieldArray([RenamedFieldFormat(fs, kwargs[what]) for fs in input]) return FieldArray([RenamedFieldMapping(fs, what, kwargs) for fs in input]) diff --git a/ecml_tools/create/input.py b/ecml_tools/create/input.py index 34f1967..13caf48 100644 --- a/ecml_tools/create/input.py +++ b/ecml_tools/create/input.py @@ -852,7 +852,7 @@ def step_factory(config, context, action_path, previous_step): raise ValueError(f"Unknown step {key}") cls = FunctionStepAction args = [key] + args - print("========", args) + # print("========", args) return cls(context, action_path, previous_step, *args, **kwargs) diff --git a/ecml_tools/create/loaders.py b/ecml_tools/create/loaders.py index a70a1c7..32a1438 100644 --- a/ecml_tools/create/loaders.py +++ b/ecml_tools/create/loaders.py @@ -366,7 +366,7 @@ def load(self): LOG.info(f" -> Skipping {igroup} total={len(self.groups)} (already done)") continue self.print(f" -> Processing {igroup} total={len(self.groups)}") - print("========", group) + # print("========", group) assert isinstance(group[0], datetime.datetime), group result = self.input.select(dates=group)