Skip to content
Snippets Groups Projects
Select Git revision
  • 3dd830afe560273e66eb6f7db92ea273973bddcd
  • master default protected
  • enxhi_issue460_remove_TOAR-I_access
  • michael_issue459_preprocess_german_stations
  • sh_pollutants
  • develop protected
  • release_v2.4.0
  • michael_issue450_feat_load-ifs-data
  • lukas_issue457_feat_set-config-paths-as-parameter
  • lukas_issue454_feat_use-toar-statistics-api-v2
  • lukas_issue453_refac_advanced-retry-strategy
  • lukas_issue452_bug_update-proj-version
  • lukas_issue449_refac_load-era5-data-from-toar-db
  • lukas_issue451_feat_robust-apriori-estimate-for-short-timeseries
  • lukas_issue448_feat_load-model-from-path
  • lukas_issue447_feat_store-and-load-local-clim-apriori-data
  • lukas_issue445_feat_data-insight-plot-monthly-distribution
  • lukas_issue442_feat_bias-free-evaluation
  • lukas_issue444_feat_choose-interp-method-cams
  • 414-include-crps-analysis-and-other-ens-verif-methods-or-plots
  • lukas_issue384_feat_aqw-data-handler
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.0 protected
  • v2.1.0 protected
  • Kleinert_etal_2022_initial_submission
  • v2.0.0 protected
  • v1.5.0 protected
  • v1.4.0 protected
  • v1.3.0 protected
  • v1.2.1 protected
  • v1.2.0 protected
  • v1.1.0 protected
  • IntelliO3-ts-v1.0_R1-submit
  • v1.0.0 protected
  • v0.12.2 protected
  • v0.12.1 protected
  • v0.12.0 protected
  • v0.11.0 protected
  • v0.10.0 protected
  • IntelliO3-ts-v1.0_initial-submit
41 results

test_bootstraps.py

Blame
  • test_bootstraps.py 2.76 KiB
    
    from src.data_handling.bootstraps import BootStraps
    
    import pytest
    import os
    
    import numpy as np
    
    
    class TestBootstraps:
    
        @pytest.fixture
        def path(self):
            path = os.path.join(os.path.dirname(__file__), "data")
            if not os.path.exists(path):
                os.makedirs(path)
            return path
    
        @pytest.fixture
        def boot_no_init(self, path):
            obj = object.__new__(BootStraps)
            super(BootStraps, obj).__init__()
            obj.number_bootstraps = 50
            obj.bootstrap_path = path
            return obj
    
        def test_valid_bootstrap_file(self, path, boot_no_init):
            station = "TESTSTATION"
            variables = "var1_var2_var3"
            window = 5
            # empty case
            assert len(os.listdir(path)) == 0
            assert boot_no_init.valid_bootstrap_file(station, variables, window) == (False, 50)
            # different cases, where files with bigger range are existing
            os.mknod(os.path.join(path, f"{station}_{variables}_hist5_nboots50_shuffled.dat"))
            assert boot_no_init.valid_bootstrap_file(station, variables, window) == (True, None)
            os.mknod(os.path.join(path, f"{station}_{variables}_hist5_nboots100_shuffled.dat"))
            assert boot_no_init.valid_bootstrap_file(station, variables, window) == (True, None)
            os.mknod(os.path.join(path, f"{station}_{variables}_hist10_nboots50_shuffled.dat"))
            os.mknod(os.path.join(path, f"{station}1_{variables}_hist10_nboots50_shuffled.dat"))
            assert boot_no_init.valid_bootstrap_file(station, variables, window) == (True, None)
            #  need to reload data and therefore remove not fitting files for this station
            assert boot_no_init.valid_bootstrap_file(station, variables, 20) == (False, 100)
            assert len(os.listdir(path)) == 1
            # reload because expanded boot number
            os.mknod(os.path.join(path, f"{station}_{variables}_hist5_nboots50_shuffled.dat"))
            boot_no_init.number_bootstraps = 60
            assert boot_no_init.valid_bootstrap_file(station, variables, window) == (False, 60)
            assert len(os.listdir(path)) == 1
            # reload because of expanded window size, but use maximum boot number from file names
            os.mknod(os.path.join(path, f"{station}_{variables}_hist5_nboots60_shuffled.dat"))
            boot_no_init.number_bootstraps = 50
            assert boot_no_init.valid_bootstrap_file(station, variables, 20) == (False, 60)
    
        def test_shuffle_single_variale(self, boot_no_init):
            data = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]])
            res = boot_no_init.shuffle_single_variable(data)
            assert res.shape == data.shape
            assert res.max() == data.max()
            assert res.min() == data.min()
            assert set(np.unique(res)).issubset({1, 2, 3})
    
        def test_create_shuffled_data(self):
            pass