Skip to content

Commit

Permalink
Merge pull request #278 from davide-f/fix_normalization
Browse files Browse the repository at this point in the history
Add fix nan
  • Loading branch information
FabianHofmann authored May 2, 2023
2 parents 343ce31 + 3c5d5b5 commit 767c1fd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion atlite/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,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,
Expand Down

0 comments on commit 767c1fd

Please sign in to comment.