Skip to content

Commit

Permalink
Better error message when thinning non lat/lon fields
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Jun 18, 2024
1 parent 2299d36 commit 1150845
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/anemoi/datasets/data/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ def __init__(self, forward, thinning, method):
self.thinning = thinning
self.method = method

latitudes = forward.latitudes.reshape(forward.field_shape)
longitudes = forward.longitudes.reshape(forward.field_shape)
shape = forward.field_shape
if len(shape) != 2:
raise ValueError("Thinning only works latitude/longitude fields")

latitudes = forward.latitudes.reshape(shape)
longitudes = forward.longitudes.reshape(shape)
latitudes = latitudes[::thinning, ::thinning].flatten()
longitudes = longitudes[::thinning, ::thinning].flatten()

Expand Down
6 changes: 5 additions & 1 deletion src/anemoi/datasets/data/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ def resolution(self):

@property
def field_shape(self):
return tuple(self.z.attrs["field_shape"])
try:
return tuple(self.z.attrs["field_shape"])
except KeyError:
LOG.warning("No 'field_shape' in %r, assuming 1D fields", self)
return (self.shape[-1],)

@property
def frequency(self):
Expand Down

0 comments on commit 1150845

Please sign in to comment.