def test_bootstrap_vwmp_sig50_similar_vwmp(PM_da_control_3d): sig = 50 actual = varweighted_mean_period_threshold(PM_da_control_3d, iterations=ITERATIONS, sig=sig).drop_vars("quantile") expected = varweighted_mean_period(PM_da_control_3d) xr.testing.assert_allclose(actual, expected, atol=2, rtol=0.5)
def test_bootstrap_vwmp_sig50_similar_vwmp(control_3d_NA): ds = control_3d_NA bootstrap = 5 sig = 50 actual = varweighted_mean_period_threshold(ds, bootstrap=bootstrap, sig=sig).drop( 'quantile' ) expected = varweighted_mean_period(ds) xr.testing.assert_allclose(actual, expected, atol=2, rtol=0.5)
def vwmp_bootstrap(control, l=100, bootstrap=10, sig=99): """Bootstrap variance weighted mean period from control. Masked areas are non-significant. Rejected at 1-sig% level.""" from climpred.bootstrap import varweighted_mean_period_threshold d = [] for _ in range(int(bootstrap / 5)): r = np.random.randint(0, control.time.size - l) d.append(varweighted_mean_period(control.isel(time=slice(r, r + l)))) data = xr.concat(d, 'bootstrap') data['lon'] = control.lon data['lat'] = control.lat vwmp = data.mean('bootstrap') threshold = varweighted_mean_period_threshold( control, sig=sig, bootstrap=bootstrap) threshold['lon'] = control.lon threshold['lat'] = control.lat vwmp = vwmp.where(vwmp > threshold) vwmp.name = 'Period [years]' return vwmp