Skip to content

Commit fa25905

Browse files
authored
Fix finite mask calculation and handle NaN values
Replace finite mask calculation to handle NaN values and update data accordingly.
1 parent 5dcbcf3 commit fa25905

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

pyfesom2/diagnostics.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):
7676
data = data.where(data < threshhold, 1)
7777
data = data.where(data > threshhold)
7878

79-
finite_mask = data.squeeze().values
79+
finite_mask = np.isfinite(data.squeeze().values)
8080

8181
ext = (data[:, hemis_mask & finite_mask] * mesh.lump2[hemis_mask & finite_mask]).sum(axis=1)
8282
da = xr.DataArray(
@@ -86,8 +86,9 @@ def ice_ext(data, mesh, hemisphere="N", threshhold=0.15, attrs={}):
8686

8787
else:
8888
logger.debug(data)
89-
finite_mask = data.squeeze()
90-
i, j = np.where(data < 0.15)
89+
finite_mask = np.isfinite(data.squeeze())
90+
data = np.where(~finite_mask, 0, data) # replace nan values by 0s
91+
i, j = np.where(data < threshhold)
9192
data[:] = 1
9293
data[i, j] = 0
9394
ext = (data[:, hemis_mask & finite_mask] * mesh.lump2[hemis_mask & finite_mask]).sum(axis=1)

0 commit comments

Comments
 (0)