Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
accumulations
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Mar 18, 2024
1 parent 7fecf48 commit fa40b04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions ecml_tools/create/functions/steps/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# nor does it submit to any jurisdiction.
#

import re

from climetlab.indexing.fieldset import FieldArray


Expand All @@ -30,20 +32,22 @@ 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):
return getattr(self.field, 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])
2 changes: 1 addition & 1 deletion ecml_tools/create/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ecml_tools/create/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa40b04

Please sign in to comment.