Skip to content

Commit 767c1fd

Browse files
Merge pull request #278 from davide-f/fix_normalization
Add fix nan
2 parents 343ce31 + 3c5d5b5 commit 767c1fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

atlite/convert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,10 @@ def hydro(
799799

800800
matrix = cutout.indicatormatrix(basins.shapes)
801801
# compute the average surface runoff in each basin
802-
matrix_normalized = matrix / matrix.sum(axis=1)
802+
# Fix NaN and Inf values to 0.0 to avoid numerical issues
803+
matrix_normalized = np.nan_to_num(
804+
matrix / matrix.sum(axis=1), nan=0.0, posinf=0.0, neginf=0.0
805+
)
803806
runoff = cutout.runoff(
804807
matrix=matrix_normalized,
805808
index=basins.shapes.index,

0 commit comments

Comments
 (0)