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

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Nov 15, 2023
1 parent e4eeb08 commit 7b2dfa1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions ecml_tools/create/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ def n_iter_loops(self):

@property
def first_cube(self):
return self.first_cube_creator.to_cube()
return self.first_lazycube.to_cube()

@property
def first_cube_creator(self):
def first_lazycube(self):
for loop in self.loops:
for cube_creator in loop.iterate():
return cube_creator
for lazycube in loop.iterate():
return lazycube

@cached_property
def chunking(self):
Expand Down Expand Up @@ -521,7 +521,7 @@ def n_iter_loops(self):

def iterate(self):
for items in itertools.product(*self.values.values()):
yield CubeCreator(
yield LazyCube(
inputs=self.applies_to_inputs,
vars=dict(zip(self.values.keys(), items)),
loop_config=self.config,
Expand All @@ -531,7 +531,7 @@ def iterate(self):

@property
def first(self):
return CubeCreator(
return LazyCube(
inputs=self.applies_to_inputs,
vars={k: lst[0] for k, lst in self.values.items() if lst},
loop_config=self.config,
Expand All @@ -557,11 +557,11 @@ def _info(self):
)

def get_datetimes(self):
# merge datetimes from all cubecreators and check there are no duplicates
# merge datetimes from all lazycubes and check there are no duplicates
datetimes = set()

for i in self.iterate():
assert isinstance(i, CubeCreator), i
assert isinstance(i, LazyCube), i
new = i.get_datetimes()

duplicates = datetimes.intersection(set(new))
Expand All @@ -579,7 +579,7 @@ class DuplicateDateTimeError(ValueError):
pass


class CubeCreator:
class LazyCube:
def __init__(self, inputs, vars, loop_config, output, partial=False):
self._loop_config = loop_config
self._vars = vars
Expand All @@ -594,7 +594,7 @@ def length(self):
return 1

def __repr__(self) -> str:
out = f"CubeCreator ({self.length}):\n"
out = f"LazyCube ({self.length}):\n"
out += f" loop_config: {self._loop_config}"
out += f" vars: {self._vars}\n"
out += " Inputs:\n"
Expand Down
8 changes: 4 additions & 4 deletions ecml_tools/create/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,22 @@ def __init__(self, parts, parent, print=print):
self.filter = CubesFilter(parts=parts, total=total)

def write(self):
for icube, cubecreator in enumerate(self.parent.input_handler.iter_cubes()):
for icube, lazycube in enumerate(self.parent.input_handler.iter_cubes()):
if not self.filter(icube):
continue
if self.registry.get_flag(icube):
LOG.info(f" -> Skipping {icube} total={self.n_cubes} (already done)")
continue

self.print(f" -> Processing i={icube} total={self.n_cubes}")
self.write_cube(cubecreator, icube)
self.write_cube(lazycube, icube)

@property
def variables_names(self):
return self.parent.main_config.get_variables_names()

def write_cube(self, cubecreator, icube):
cube = cubecreator.to_cube()
def write_cube(self, lazycube, icube):
cube = lazycube.to_cube()

shape = cube.extended_user_shape
chunks = cube.chunking(self.output_config.chunking)
Expand Down

0 comments on commit 7b2dfa1

Please sign in to comment.