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

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Feb 5, 2024
1 parent ba7b650 commit fac9909
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ecml_tools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def __repr__(self):
return self.__class__.__name__ + "()"

def _get_tuple(self, n):
raise NotImplementedError(f"Tuple not supported: {n} (class {self.__class__.__name__})")
raise NotImplementedError(
f"Tuple not supported: {n} (class {self.__class__.__name__})"
)


class Source:
Expand Down Expand Up @@ -769,6 +771,21 @@ def check_same_variables(self, d1, d2):
def __len__(self):
return len(self.datasets[0])

def _get_tuple(self, n):

p = (n[0], slice(None), n[2:])
result = [d[p] for d in self.datasets]

print([type(s) for s in p], p)
print(self.shape, [r.shape for r in result])

raise NotImplementedError()

result = np.concatenate(result)
# result = np.stack(result)

return result[n[1]]

def _get_slice(self, s):
return np.stack([self[i] for i in range(*s.indices(self._len))])

Expand Down
9 changes: 9 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def __init__(self, ds):
self.ds = ds
self.np = ds[:] # Numpy array

assert self.ds.shape == self.np.shape

def __getitem__(self, index):
assert (self.ds[index] == self.np[index]).all()

Expand All @@ -199,6 +201,13 @@ def slices(ds, start=None, end=None, step=None):
t[::step]

t[0:10, :, 0]
t[:, 0:3, 0]
t[:, :, 0]
t[0:10, 0:3, 0]
t[:, :, :]

# t[:,(1,3),:]
# t[:,(1,3)]

if ds.shape[2] > 1: # Ensemble dimension
t[0:10, :, (0, 1)]
Expand Down

0 comments on commit fac9909

Please sign in to comment.