Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More prints during dataset creation #181

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/anemoi/datasets/create/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ def load_result(self, result):
# There is one cube to load for each result.
dates = list(result.group_of_dates)

LOG.debug(f"Loading cube for {len(dates)} dates")

cube = result.get_cube()
shape = cube.extended_user_shape
dates_in_data = cube.user_coords["valid_datetime"]
Expand Down Expand Up @@ -645,12 +647,14 @@ def dates_to_indexes(dates, all_dates):
indexes = dates_to_indexes(self.dates, dates_in_data)

array = ViewCacheArray(self.data_array, shape=shape, indexes=indexes)
LOG.info(f"Loading array shape={shape}, indexes={len(indexes)}")
self.load_cube(cube, array)

stats = compute_statistics(array.cache, self.variables_names, allow_nans=self._get_allow_nans())
self.tmp_statistics.write(indexes, stats, dates=dates_in_data)

LOG.info("Flush data array")
array.flush()
LOG.info("Flushed data array")

def _get_allow_nans(self):
config = self.main_config
Expand Down
7 changes: 5 additions & 2 deletions src/anemoi/datasets/create/statistics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import socket

import numpy as np
import tqdm
from anemoi.utils.provenance import gather_provenance_info

from ..check import check_data_values
Expand Down Expand Up @@ -134,7 +135,7 @@ def check_variance(x, variables_names, minimum, maximum, mean, count, sums, squa

def compute_statistics(array, check_variables_names=None, allow_nans=False):
"""Compute statistics for a given array, provides minimum, maximum, sum, squares, count and has_nans as a dictionary."""

LOG.info(f"Computing statistics for {array.shape} array")
nvars = array.shape[1]

LOG.debug(f"Stats {nvars}, {array.shape}, {check_variables_names}")
Expand All @@ -149,7 +150,7 @@ def compute_statistics(array, check_variables_names=None, allow_nans=False):
maximum = np.zeros(stats_shape, dtype=np.float64)
has_nans = np.zeros(stats_shape, dtype=np.bool_)

for i, chunk in enumerate(array):
for i, chunk in tqdm.tqdm(enumerate(array), delay=1, total=array.shape[0], desc="Computing statistics"):
values = chunk.reshape((nvars, -1))

for j, name in enumerate(check_variables_names):
Expand All @@ -166,6 +167,8 @@ def compute_statistics(array, check_variables_names=None, allow_nans=False):
count[i] = np.sum(~np.isnan(values), axis=1)
has_nans[i] = np.isnan(values).any()

LOG.info(f"Statistics computed for {nvars} variables.")

return {
"minimum": minimum,
"maximum": maximum,
Expand Down
Loading