Closed jdha closed 2 years ago
Division by zero within matrices.
This appears to be
A
/ B
where some element-wise occurrences of 0/0
Cleaner to index non-zero numbers prior to execution
Looking at where nan_ind and dist_fac!=0.
in the benchmark shows that there is only a /0
when there is land in the bdy array. One option would be to replace the 0. in dict_fac
with np.nan
so no warnings are thrown
proposed solution:
c = np.where(b!=0., a/b, 0.)
actually that still gives a runtime warning:
RuntimeWarning: invalid value encountered in true_divide
as a/b is still calculated
one option would be to use:
np.errstate(invalid='ignore', divide='ignore')
but not ideal
to remove the runtime warning:
c=np.zeros_like(b)
ind=c>0.
c[ind] = np.nansum(a*d, axis=2)[ind] / b[ind]
./nemo_bdy_extr_tm3.py:673: RuntimeWarning: invalid value encountered in true_divide dst_bdy = (np.nansum(sc_bdy[vn,:,:,:] dist_wei, 2) / ./nemo_bdy_extr_tm3.py:683: RuntimeWarning: invalid value encountered in true_divide dst_bdy_2 = (np.nansum(sc_bdy[vn+1,:,:,:] dist_wei, 2) / ./nemo_bdy_extr_tm3.py:698: RuntimeWarning: invalid value encountered in true_divide dst_bdy = (np.nansum(dst_bdy.flatten('F')[self.id_121] *