From 7f7b181bf786c5b418ebf75759b0e093f994bfce Mon Sep 17 00:00:00 2001 From: Mikko Partio Date: Fri, 29 Nov 2024 17:30:44 +0200 Subject: [PATCH] Fix division-by-zero when computing statistics for a single-time dataset (#142) When calculating sample indices, make sure that at least one sample is included. --- src/anemoi/datasets/data/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anemoi/datasets/data/dataset.py b/src/anemoi/datasets/data/dataset.py index 185cf29..0cb4295 100644 --- a/src/anemoi/datasets/data/dataset.py +++ b/src/anemoi/datasets/data/dataset.py @@ -469,7 +469,7 @@ def _compute_constant_fields_from_a_few_samples(self): sample_count = min(4, len(indices)) count = len(indices) - p = slice(0, count, count // (sample_count - 1)) + p = slice(0, count, count // max(1, sample_count - 1)) samples = list(range(*p.indices(count))) samples.append(count - 1) # Add last