def test_persistence_lead0_lead1(hind_ds_initialized_1d, hind_ds_initialized_1d_lead0, reconstruction_ds_1d): """ Checks that compute persistence returns the same results with a lead-0 and lead-1 framework. """ res1 = compute_persistence(hind_ds_initialized_1d, reconstruction_ds_1d, metric='rmse') res2 = compute_persistence(hind_ds_initialized_1d_lead0, reconstruction_ds_1d, metric='rmse') assert (res1.SST.values == res2.SST.values).all()
def test_compute_persistence_ds1d_not_nan( PM_ds_initialized_1d, PM_ds_control_1d, metric ): """ Checks that there are no NaNs on persistence forecast of 1D time series. """ if metric == "contingency": metric_kwargs = { "forecast_category_edges": category_edges, "observation_category_edges": category_edges, "score": "accuracy", } else: metric_kwargs = {} actual = ( compute_persistence( PM_ds_initialized_1d, PM_ds_control_1d, metric=metric, alignment="same_inits", **metric_kwargs ) # .isnull() # .any() ) print(actual.tos) actual = actual.isnull().any() for var in actual.data_vars: assert not actual[var], actual[var]
def test_compute_persistence_lead0_lead1( PM_da_initialized_1d, PM_da_initialized_1d_lead0, PM_da_control_1d, metric ): """ Checks that persistence forecast results are identical for a lead 0 and lead 1 setup """ res1 = compute_persistence( PM_da_initialized_1d, PM_da_control_1d, metric=metric, alignment="same_inits" ) res2 = compute_persistence( PM_da_initialized_1d_lead0, PM_da_control_1d, metric=metric, alignment="same_inits", ) assert (res1.values == res2.values).all()
def test_persistence(hind_da_initialized_1d, reconstruction_da_1d, metric): """ Checks that compute persistence works without breaking. """ res = compute_persistence(hind_da_initialized_1d, reconstruction_da_1d, metric=metric) assert not res.isnull().any() # check persistence metadata assert res.attrs['metric'] == metric assert res.attrs['skill_calculated_by_function'] == 'compute_persistence' assert 'number of members' not in res.attrs
def test_compute_persistence_add_attrs(PM_ds_initialized_1d, PM_ds_control_1d, metric): """ Checks that there are no NaNs on persistence forecast of 1D time series. """ attrs = (compute_persistence( PM_ds_initialized_1d, PM_ds_control_1d, metric=metric, alignment="same_inits", )).attrs assert (attrs["prediction_skill"] == "calculated by climpred https://climpred.readthedocs.io/") assert attrs["skill_calculated_by_function"] == "compute_persistence" assert "number of members" not in attrs assert attrs["metric"] == metric
def test_compute_persistence_ds1d_not_nan( PM_ds_initialized_1d, PM_ds_control_1d, metric ): """ Checks that there are no NaNs on persistence forecast of 1D time series. """ actual = ( compute_persistence( PM_ds_initialized_1d, PM_ds_control_1d, metric=metric, alignment='same_inits', ) .isnull() .any() ) for var in actual.data_vars: assert not actual[var]
def test_compute_persistence_add_attrs(PM_ds_initialized_1d, PM_ds_control_1d, metric): """ Checks that there are no NaNs on persistence forecast of 1D time series. """ attrs = ( compute_persistence( PM_ds_initialized_1d, PM_ds_control_1d, metric=metric, alignment='same_inits', ) ).attrs assert ( attrs['prediction_skill'] == 'calculated by climpred https://climpred.readthedocs.io/' ) assert attrs['skill_calculated_by_function'] == 'compute_persistence' assert 'number of members' not in attrs assert attrs['metric'] == metric
def test_persistence(hind_da_initialized_1d, reconstruction_da_1d, metric): """ Checks that compute persistence works without breaking. """ if metric == "contingency": metric_kwargs = { "forecast_category_edges": category_edges, "observation_category_edges": category_edges, "score": "accuracy", } else: metric_kwargs = {} res = compute_persistence( hind_da_initialized_1d, reconstruction_da_1d, metric=metric, **metric_kwargs ) assert not res.isnull().any() # check persistence metadata assert res.attrs["metric"] == metric assert res.attrs["skill_calculated_by_function"] == "compute_persistence" assert "number of members" not in res.attrs