Skip to content

Commit

Permalink
missing
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Feb 29, 2024
1 parent f3aadae commit 8945a41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 57 deletions.
32 changes: 8 additions & 24 deletions ecml_tools/create/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def __init__(self, *args, **kwargs):
self[key] = DictObj(value)
continue
if isinstance(value, list):
self[key] = [
DictObj(item) if isinstance(item, dict) else item for item in value
]
self[key] = [DictObj(item) if isinstance(item, dict) else item for item in value]
continue

def __getattr__(self, attr):
Expand Down Expand Up @@ -128,31 +126,21 @@ def __init__(self, config, *args, **kwargs):
if "config_format_version" not in self:
# Should be changed to 2
self.config_format_version = 1
print(
f"Setting config_format_version={self.config_format_version} because it was not provided."
)
print(f"Setting config_format_version={self.config_format_version} because it was not provided.")

if self.config_format_version != 2:
raise ValueError(
"Config format has changed. Must provide config with format version >= 2."
)
raise ValueError("Config format has changed. Must provide config with format version >= 2.")

if "dates" in self.output:
raise ValueError("Obsolete: Dates should not be provided in output config.")

# deprecated/obsolete
if "order" in self.output:
raise ValueError(
f"Do not use 'order'. Use order_by instead. {list(self.keys())}"
)
raise ValueError(f"Do not use 'order'. Use order_by instead. {list(self.keys())}")
if "loops" in self:
raise ValueError(
f"Do not use 'loops'. Use dates instead. {list(self.keys())}"
)
raise ValueError(f"Do not use 'loops'. Use dates instead. {list(self.keys())}")
if "loop" in self:
raise ValueError(
f"Do not use 'loop'. Use dates instead. {list(self.keys())}"
)
raise ValueError(f"Do not use 'loop'. Use dates instead. {list(self.keys())}")

self.normalise()

Expand Down Expand Up @@ -186,9 +174,7 @@ def normalise(self):
if k == statistics_axis_name:
statistics_axis = i

assert (
statistics_axis >= 0
), f"{self.output.statistics} not in {list(self.output.order_by.keys())}"
assert statistics_axis >= 0, f"{self.output.statistics} not in {list(self.output.order_by.keys())}"

self.statistics_names = self.output.order_by[statistics_axis_name]

Expand All @@ -205,9 +191,7 @@ def check_dict_value_and_set(self, dic, key, value):
if key in dic:
if dic[key] == value:
return
raise ValueError(
f"Cannot use {key}={dic[key]} with {self.purpose} purpose. Must use {value}."
)
raise ValueError(f"Cannot use {key}={dic[key]} with {self.purpose} purpose. Must use {value}.")
print(f"Setting {key}={value} because purpose={self.purpose}")
dic[key] = value

Expand Down
42 changes: 9 additions & 33 deletions ecml_tools/create/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ def sort(old_dic):
params_steps = sort(params_steps)
params_levels = sort(params_levels)

return dict(
param_level=params_levels, param_step=params_steps, area=area, grid=grid
)
return dict(param_level=params_levels, param_step=params_steps, area=area, grid=grid)


class Coords:
Expand All @@ -162,14 +160,7 @@ def _build_coords(self):
ensembles_key = list(from_config.keys())[2]

if isinstance(from_config[variables_key], (list, tuple)):
assert all(
[
v == w
for v, w in zip(
from_data[variables_key], from_config[variables_key]
)
]
), (
assert all([v == w for v, w in zip(from_data[variables_key], from_config[variables_key])]), (
from_data[variables_key],
from_config[variables_key],
)
Expand Down Expand Up @@ -413,9 +404,7 @@ def __init__(self, context, action_path, dates, action):
assert isinstance(action, Action), type(action)
self.action = action

self.args, self.kwargs = substitute(
context, (self.action.args, self.action.kwargs)
)
self.args, self.kwargs = substitute(context, (self.action.args, self.action.kwargs))

def _trace_datasource(self, *args, **kwargs):
return f"{self.action.name}({shorten(self.dates)})"
Expand All @@ -428,9 +417,7 @@ def datasource(self):
args, kwargs = resolve(self.context, (self.args, self.kwargs))

try:
return self.action.function(
FunctionContext(self), self.dates, *args, **kwargs
)
return self.action.function(FunctionContext(self), self.dates, *args, **kwargs)
except Exception:
LOG.error(f"Error in {self.action.function.__name__}", exc_info=True)
raise
Expand Down Expand Up @@ -525,9 +512,7 @@ def metadata(self, key):
new_value = new_dt.isoformat()
return new_value
if key in ["date", "time", "step", "hdate"]:
raise NotImplementedError(
f"metadata {key} not implemented when shifting dates"
)
raise NotImplementedError(f"metadata {key} not implemented when shifting dates")
return value

def __getattr__(self, name):
Expand Down Expand Up @@ -555,9 +540,7 @@ def function(self):
def __repr__(self):
content = ""
content += ",".join([self._short_str(a) for a in self.args])
content += " ".join(
[self._short_str(f"{k}={v}") for k, v in self.kwargs.items()]
)
content += " ".join([self._short_str(f"{k}={v}") for k, v in self.kwargs.items()])
content = self._short_str(content)
return super().__repr__(_inline_=content, _indent_=" ")

Expand All @@ -568,10 +551,7 @@ def _trace_select(self, dates):
class ActionWithList(Action):
def __init__(self, context, action_path, *configs):
super().__init__(context, action_path, *configs)
self.actions = [
action_factory(c, context, action_path + [str(i)])
for i, c in enumerate(configs)
]
self.actions = [action_factory(c, context, action_path + [str(i)]) for i, c in enumerate(configs)]

def __repr__(self):
content = "\n".join([str(i) for i in self.actions])
Expand All @@ -584,9 +564,7 @@ def __init__(self, context, action_path, *configs):
assert len(configs) > 1, configs
current = action_factory(configs[0], context, action_path + ["0"])
for i, c in enumerate(configs[1:]):
current = step_factory(
c, context, action_path + [str(i + 1)], previous_step=current
)
current = step_factory(c, context, action_path + [str(i + 1)], previous_step=current)
self.last_step = current

@trace_select
Expand Down Expand Up @@ -789,9 +767,7 @@ def action_factory(config, context, action_path):
if not isinstance(config, dict):
raise ValueError(f"Invalid input config {config}")
if len(config) != 1:
raise ValueError(
f"Invalid input config. Expecting dict with only one key, got {list(config.keys())}"
)
raise ValueError(f"Invalid input config. Expecting dict with only one key, got {list(config.keys())}")

config = deepcopy(config)
key = list(config.keys())[0]
Expand Down

0 comments on commit 8945a41

Please sign in to comment.