Skip to content
Snippets Groups Projects
Commit 96948a92 authored by Felix Kleinert's avatar Felix Kleinert
Browse files

update statistics test (simplistic)

parent 2f8a4e34
Branches
Tags
7 merge requests!353add developments to release v1.5.0,!352Resolve "release v1.5.0",!351Lukas issue337 bug ci pipeline fails for docs,!350Resolve "upgrade code to TensorFlow V2",!342Include sample-uncertainty to wrf workflow,!337Resolve "Test Set Sample Uncertainty in PostProcessing",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
......@@ -4,7 +4,8 @@ import pytest
import xarray as xr
from mlair.helpers.statistics import standardise, standardise_inverse, standardise_apply, centre, centre_inverse, \
centre_apply, apply_inverse_transformation, min_max, min_max_inverse, min_max_apply, log, log_inverse, log_apply
centre_apply, apply_inverse_transformation, min_max, min_max_inverse, min_max_apply, log, log_inverse, log_apply, \
create_single_bootstrap_realization, calculate_average, create_n_bootstrap_realizations
lazy = pytest.lazy_fixture
......@@ -221,3 +222,47 @@ class TestLog:
data_ref, opts = log(data_orig, dim)
data_test = log_apply(data_orig, opts["mean"], opts["std"])
assert np.testing.assert_array_almost_equal(data_ref, data_test) is None
class TestCreateSingleBootstrapRealization:
@pytest.fixture
def data(self):
return xr.DataArray(np.array(range(20)).reshape(2 , -1).T,
dims={'time': range(10), 'model': ['m1', 'm2']},
coords={'time': range(10), 'model': ['m1', 'm2']})
def test_create_single_bootstrap_realization(self, data):
np.random.seed(42)
proc_data = create_single_bootstrap_realization(data, "time")
assert isinstance(proc_data, xr.DataArray)
assert (proc_data.coords['time'].values == np.array([6, 3, 7, 4, 6, 9, 2, 6, 7, 4])).all()
# check if all time index values of proc_data are from data
assert np.in1d(proc_data.indexes['time'].values, data.indexes['time'].values).all()
def test_calculate_average(self, data):
assert isinstance(data, xr.DataArray)
assert calculate_average(data) == data.mean()
assert (calculate_average(data, axis=0) == data.mean(axis=0)).all()
def test_create_n_bootstrap_realizations(self, data):
boot_data = create_n_bootstrap_realizations(data, dim_name_time='time', dim_name_model='model',
n_boots=1000, dim_name_boots='boots')
assert isinstance(boot_data, xr.DataArray)
assert boot_data.shape == (1000, 2)
boot_data = create_n_bootstrap_realizations(data.sel(model='m1').squeeze(), dim_name_time='time',
dim_name_model='model', n_boots=1000, dim_name_boots='boots')
assert isinstance(boot_data, xr.DataArray)
assert boot_data.shape == (1000,)
class TestCalculateAverage:
pass
class TestCreateNBootstrapRealizations:
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment