def test_PredictionEnsemble_smooth_None( perfectModelEnsemble_initialized_control_1d_ym_cftime, ): """Test that PredictionEnsemble.smooth(None) does nothing.""" pm = perfectModelEnsemble_initialized_control_1d_ym_cftime pm_smoothed = pm.smooth(None) assert_PredictionEnsemble(pm, pm_smoothed)
def test_PerfectModelEnsemble_plus_broadcast(PM_ds_initialized_3d, operator): """Test that PerfectModelEnsemble math operator (+-*/) other also broadcasts correctly.""" he = PerfectModelEnsemble(PM_ds_initialized_3d) operator = eval(operator) # minimal adding an offset or like multiplying area he2 = operator( he, xr.ones_like(PM_ds_initialized_3d.isel(init=1, lead=1, drop=True))) he3 = operator(he, 1) assert_PredictionEnsemble(he2, he3)
def test_PredictionEnsemble_map_dim_or(hindcast_hist_obs_1d): """Tests that PredictionEnsemble allows dim0_or_dim1 as kwargs without UserWarning.""" with pytest.warns(None): # no warnings he_or = hindcast_hist_obs_1d.map(rm_poly, dim="init_or_time", deg=2) assert he_or != hindcast_hist_obs_1d with pytest.warns(UserWarning) as record: # triggers warnings he_chained = hindcast_hist_obs_1d.map(rm_poly, dim="init", deg=2).map( rm_poly, dim="time", deg=2 ) assert he_chained != hindcast_hist_obs_1d assert len(record) == 3 # for init, uninit and obs for r in record: assert "Error due to " in str(r.message) assert_PredictionEnsemble(he_or, he_chained)
def test_PerfectModelEnsemble_area_weighted_mean(PM_ds_initialized_3d): """Test area weighted mean PerfectModelEnsemble.""" he = PerfectModelEnsemble(PM_ds_initialized_3d) # fake area area = np.cos(PM_ds_initialized_3d.lat) + 1 spatial_dims = [ d for d in PM_ds_initialized_3d.dims if d not in CLIMPRED_DIMS ] # PredictionEnsemble doesnt like other data_vars he_self_spatial_mean = (he * area).sum(spatial_dims) / area.sum() # weighted requires Dataset area = area.to_dataset(name="area") he_xr_spatial_mean = he.weighted(area).mean(spatial_dims) assert_PredictionEnsemble(he_self_spatial_mean, he_xr_spatial_mean, how="allclose", rtol=0.03, atol=0.05)
def test_HindcastEnsemble_area_weighted_mean(hind_ds_initialized_3d): """Test area weighted mean HindcastEnsemble.""" he = HindcastEnsemble(hind_ds_initialized_3d) # fake area area = hind_ds_initialized_3d["TAREA"] spatial_dims = [ d for d in hind_ds_initialized_3d.dims if d not in CLIMPRED_DIMS ] # PredictionEnsemble doesnt like other data_vars he_self_spatial_mean = (he * area).sum(spatial_dims) / area.sum() # weighted requires Dataset area = area.to_dataset(name="area") he_xr_spatial_mean = he.weighted(area).mean(spatial_dims) assert_PredictionEnsemble(he_self_spatial_mean, he_xr_spatial_mean, how="allclose", rtol=0.03, atol=0.05)