Skip to content

Commit

Permalink
Better support for notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Nov 29, 2024
1 parent 77c7894 commit 82431b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
23 changes: 11 additions & 12 deletions src/anemoi/inference/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,11 @@ def constant_forcings_inputs(self, context, input_state):
remaining_mask = [i for i, _ in remaining]
remaining = [name for _, name in remaining]

result.append(
context.create_constant_coupled_forcings(
remaining,
remaining_mask,
)
)
forcing = context.create_constant_coupled_forcings(remaining, remaining_mask)

if forcing is not None:
# SimpleRunner does not support dynamic forcings
result.append(forcing)

return result

Expand Down Expand Up @@ -676,12 +675,12 @@ def dynamic_forcings_inputs(self, context, input_state):
remaining_mask = [i for i, _ in remaining]
remaining = [name for _, name in remaining]

result.append(
context.create_dynamic_coupled_forcings(
remaining,
remaining_mask,
)
)
forcing = context.create_dynamic_coupled_forcings(remaining, remaining_mask)

if forcing is not None:
# SimpleRunner does not support dynamic forcings
result.append(forcing)

return result

def boundary_forcings_inputs(self, context, input_state):
Expand Down
4 changes: 1 addition & 3 deletions src/anemoi/inference/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ def add_initial_forcings_to_input_state(self, input_state):
# TODO: Check for user provided forcings

for source in self.constant_forcings_inputs:
if source is None:
# When the constants are already in the input state
continue
LOG.info("Constant forcings input: %s %s (%s)", source, source.variables, dates)
arrays = source.load_forcings(input_state, dates)
for name, forcing in zip(source.variables, arrays):
Expand Down Expand Up @@ -362,6 +359,7 @@ def add_dynamic_forcings_to_input_tensor(self, input_tensor_torch, state, date,
# batch is always 1

for source in self.dynamic_forcings_inputs:

forcings = source.load_forcings(state, [date]) # shape: (variables, dates, values)

forcings = np.squeeze(forcings, axis=1) # Drop the dates dimension
Expand Down
11 changes: 11 additions & 0 deletions src/anemoi/inference/runners/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@ def create_dynamic_computed_forcings(self, variables, mask):
return result

def create_constant_coupled_forcings(self, variables, mask):
# This runner does not support coupled forcings
# there are supposed to be already in the state dictionary
# of managed by the user.
LOG.warning("Coupled forcings are not supported by this runner: %s", variables)
return None

def create_dynamic_coupled_forcings(self, variables, mask):
# This runner does not support coupled forcings
# there are supposed to be already in the state dictionary
# of managed by the user.
LOG.warning("Coupled forcings are not supported by this runner: %s", variables)
return None

0 comments on commit 82431b2

Please sign in to comment.