Skip to content

Commit

Permalink
More verbosity (#102)
Browse files Browse the repository at this point in the history
* More verbosity
  • Loading branch information
b8raoult authored Oct 26, 2024
1 parent c436520 commit f3574f1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Keep it human-readable, your future self will thank you!
- Bugfix in `auto_adjust`
- Fixed precommit CI errors
- Improve tests
- More verbosity

### Added

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@

project = "Anemoi"

author = "ECMWF"
author = "Anemoi contributors"

year = datetime.datetime.now().year
if year == 2024:
years = "2024"
else:
years = "2024-%s" % (year,)

copyright = "%s, ECMWF" % (years,)
copyright = "%s, Anemoi contributors" % (years,)


try:
Expand Down
33 changes: 24 additions & 9 deletions src/anemoi/datasets/data/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,35 @@ def __init__(self, forward, thinning, method):
self.thinning = thinning
self.method = method

shape = forward.field_shape
if len(shape) != 2:
raise ValueError("Thinning only works latitude/longitude fields")
if thinning is not None:

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

mask = [lat in latitudes and lon in longitudes for lat, lon in zip(forward.latitudes, forward.longitudes)]
mask = np.array(mask, dtype=bool)
# Make a copy, so we read the data only once from zarr
forward_latitudes = forward.latitudes.copy()
forward_longitudes = forward.longitudes.copy()

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

# TODO: This is not very efficient

mask = [lat in latitudes and lon in longitudes for lat, lon in zip(forward_latitudes, forward_longitudes)]
mask = np.array(mask, dtype=bool)
else:
mask = None

super().__init__(forward, mask)

def mutate(self) -> Dataset:
if self.thinning is None:
return self.forward.mutate()
return super().mutate()

def tree(self):
return Node(self, [self.forward.tree()], thinning=self.thinning, method=self.method)

Expand Down
9 changes: 9 additions & 0 deletions src/anemoi/datasets/data/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ def label(self):
return "zarr*"


QUIET = set()


def zarr_lookup(name, fail=True):

if name.endswith(".zarr") or name.endswith(".zip"):
Expand All @@ -413,6 +416,9 @@ def zarr_lookup(name, fail=True):
config = load_config()["datasets"]

if name in config["named"]:
if name not in QUIET:
LOG.info("Opening `%s` as `%s`", name, config["named"][name])
QUIET.add(name)
return config["named"][name]

tried = []
Expand All @@ -426,6 +432,9 @@ def zarr_lookup(name, fail=True):
if z is not None:
# Cache for next time
config["named"][name] = full
if name not in QUIET:
LOG.info("Opening `%s` as `%s`", name, full)
QUIET.add(name)
return full
except zarr.errors.PathNotFoundError:
pass
Expand Down

0 comments on commit f3574f1

Please sign in to comment.