NOC-MSM / pyBDY

pyBDY: a Python based regional NEMO model configuration toolbox.
GNU General Public License v3.0
7 stars 7 forks source link

runtime warnings #76

Closed jdha closed 2 years ago

jdha commented 2 years ago

./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] *

jdha commented 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

jdha commented 2 years ago

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

jdha commented 2 years ago

proposed solution: c = np.where(b!=0., a/b, 0.)

jdha commented 2 years ago

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

jdha commented 2 years ago

to remove the runtime warning:

c=np.zeros_like(b)
ind=c>0.
c[ind] = np.nansum(a*d, axis=2)[ind] / b[ind]