Skip to content

Commit

Permalink
Fix cor in plot (#141)
Browse files Browse the repository at this point in the history
* update the corr value when denominator is zero

* format surrogate.py with oitnb
  • Loading branch information
FariborzDaneshvar-NOAA authored Apr 11, 2024
1 parent 6b235c3 commit 71804ad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ensembleperturbation/plotting/surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def corrcoef(O, P):
OD2 = ((O - MO) ** 2).sum()
PDOD = ((P - MP) * (O - MO)).sum()
corr = PDOD / (PD2 * OD2) ** 0.5
if numpy.isnan(corr.values):
if (PDOD == 0) & (PD2 == 0) & (OD2 == 0):
corr.values = 1.0 # 0/0: perfect correlation
elif (PD2 == 0) or (OD2 == 0):
corr.values = 0.0 # No./0: no-correlation
return corr

# correlation coefficient
Expand Down

0 comments on commit 71804ad

Please sign in to comment.