Skip to content

Commit

Permalink
fix: add utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
JPXKQX committed Dec 12, 2024
1 parent 3b89b82 commit 202765c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/anemoi/utils/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,15 @@ def register_buffer(self, *, caller, name, persistent=False):
assert '__' not in name, name
for k, array in self.arrays.items():
caller.register_buffer(f'{name}__{k}', array, persistent=persistent)


def define_anemoi_tensor(data: dict, sources: list[str], indices: dict) -> TorchNestedAnemoiTensor:
import torch

tt = {}
for name in sources:
valid_values_mask = ~torch.isnan(data[name]).any((0, 2))
tt[name] = data[name][:, valid_values_mask][..., indices[name]]

return TorchNestedAnemoiTensor(tt)

0 comments on commit 202765c

Please sign in to comment.