From 3c5d5b559c592740c79ef544565398c8780f34e1 Mon Sep 17 00:00:00 2001 From: davide-f Date: Mon, 13 Mar 2023 11:50:11 +0100 Subject: [PATCH] Add fix nan --- atlite/convert.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/atlite/convert.py b/atlite/convert.py index 29fe7731..121f4999 100644 --- a/atlite/convert.py +++ b/atlite/convert.py @@ -805,7 +805,10 @@ def hydro( matrix = cutout.indicatormatrix(basins.shapes) # compute the average surface runoff in each basin - matrix_normalized = matrix / matrix.sum(axis=1) + # Fix NaN and Inf values to 0.0 to avoid numerical issues + matrix_normalized = np.nan_to_num( + matrix / matrix.sum(axis=1), nan=0.0, posinf=0.0, neginf=0.0 + ) runoff = cutout.runoff( matrix=matrix_normalized, index=basins.shapes.index,