Skip to content

Commit 91c5515

Browse files
authored
Fix recipe_carvalhais14nat.yml to avoid the usage of vars() inside a function (#4170)
1 parent 59d7736 commit 91c5515

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

  • esmvaltool/diag_scripts/land_carbon_cycle

esmvaltool/diag_scripts/land_carbon_cycle/shared.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,11 @@ def _apply_common_mask(*args):
2121
------
2222
an array with size of nargs x common size of all input arrays
2323
"""
24-
nargs = len(args)
25-
for arg_ in range(nargs):
26-
_dat = args[arg_]
27-
vars()["dat_mask" + str(arg_)] = np.ones(np.shape(_dat))
28-
vars()["dat_mask_inv" + str(arg_)] = np.ma.masked_invalid(_dat).mask
29-
vars()["dat_mask" + str(arg_)][vars()["dat_mask_inv" + str(arg_)]] = 0
30-
dat_mask = vars()["dat_mask0"]
31-
for arg_ in range(nargs):
32-
dat_mask = dat_mask * vars()["dat_mask" + str(arg_)]
33-
mask_where = np.ma.getmask(np.ma.masked_less(dat_mask, 1.0))
34-
odat = []
35-
for arg_ in range(nargs):
36-
_dat = args[arg_].astype(np.float64)
37-
_dat[mask_where] = np.nan
38-
odat = np.append(odat, np.ma.masked_invalid(_dat))
39-
odat = odat.reshape(nargs, _dat.shape[0], _dat.shape[1])
24+
odat = np.stack(args, axis=0)
25+
odat = np.ma.masked_array(odat, dtype=np.float64)
26+
odat = np.ma.masked_invalid(odat)
27+
mask = np.ma.getmaskarray(odat).any(axis=0, keepdims=True)
28+
odat = np.ma.masked_where(np.broadcast_to(mask, odat.shape), odat)
4029
return odat
4130

4231

0 commit comments

Comments
 (0)