Skip to content

Commit

Permalink
Merge branch 'release/0.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Oct 20, 2023
2 parents b7108c1 + 25671e9 commit 558b553
Show file tree
Hide file tree
Showing 11 changed files with 1,203 additions and 305 deletions.
1 change: 1 addition & 0 deletions climetlab/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def f(**kwargs):
f = normalize_grib_keys(f)
f = normalize("param", "variable-list(mars)")(f)
f = normalize("date", "date-list(%Y%m%d)")(f)
f = normalize("hdate", "date-list(%Y%m%d)")(f)
f = normalize("area", "bounding-box(list)")(f)
f = normalize("levelist", "int-list")(f)
kwargs = f(**kwargs)
Expand Down
24 changes: 18 additions & 6 deletions climetlab/indexing/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,31 @@ def __init__(

# Sort the source according to their
# internal_args = reduce(operator.add, [Separator.split(a) for a in args], [])
# for i in ds:
# print(i)
# print("before")
# print(ds[0])
# print(ds[1])
# print(ds[2])
# print(ds[3])
self.source = ds.order_by(*args, remapping=remapping)
del ds
# print("after")
# print(self.source[0])
# print(self.source[1])
# print(self.source[2])
# print(self.source[3])

# Get a mapping of user names to unique values
# With possible reduce dimentionality if the user use 'level+param'
self.user_coords = ds.unique_values(*names, remapping=remapping)

print(f"{self.user_coords=}")
self.user_coords = self.source.unique_values(*names, remapping=remapping)

self.user_shape = tuple(len(v) for k, v in self.user_coords.items())

if math.prod(self.user_shape) != len(self.source):
details = []
for k, v in self.user_coords.items():
details.append(f"{k=}, {len(v)}, {v}")
for key, v in self.user_coords.items():
details.append(f"{key=} ({len(v)}) {v}")
assert not isinstance(
self.source, str
), f"Not expecting a str here ({self.source})"
Expand All @@ -94,7 +105,7 @@ def __init__(
msg = (
f"Shape {self.user_shape} [{math.prod(self.user_shape):,}]"
+ f" does not match number of available fields {len(self.source):,}. "
+ f"Difference: {len(self.source)-math.prod(self.user_shape):,}"
+ f"Difference: {len(self.source)-math.prod(self.user_shape):,}\n"
+ "\n".join(details)
)
raise ValueError(msg)
Expand Down Expand Up @@ -157,6 +168,7 @@ def __getitem__(self, indexes):
user_shape = self.user_shape
for x in itertools.product(*coords):
i = coords_to_index(x, user_shape)
assert isinstance(i, int), i
dataset_indexes.append(i)

ds = self.source[tuple(dataset_indexes)]
Expand Down
Loading

0 comments on commit 558b553

Please sign in to comment.