Commit c3a22383 authored by lukas leufen's avatar lukas leufen

new tests implemented

parent 25db784d
Pipeline #50920 passed with stages
in 7 minutes and 20 seconds
from mlair.configuration.defaults import *
class TestGetDefaults:
def test_get_defaults(self):
defaults = get_defaults()
assert isinstance(defaults, dict)
assert all(map(lambda k: k in defaults.keys(), ["DEFAULT_STATIONS", "DEFAULT_BATCH_SIZE", "DEFAULT_PLOT_LIST"]))
assert all(map(lambda x: x.startswith("DEFAULT"), defaults.keys()))
class TestAllDefaults:
def test_training_parameters(self):
assert DEFAULT_CREATE_NEW_MODEL is True
assert DEFAULT_TRAIN_MODEL is True
assert DEFAULT_FRACTION_OF_TRAINING == 0.8
assert DEFAULT_EXTREME_VALUES is None
assert DEFAULT_EXTREMES_ON_RIGHT_TAIL_ONLY is False
assert DEFAULT_PERMUTE_DATA is False
assert DEFAULT_BATCH_SIZE == int(256 * 2)
assert DEFAULT_EPOCHS == 20
def test_data_handler_parameters(self):
assert DEFAULT_STATIONS == ['DEBW107', 'DEBY081', 'DEBW013', 'DEBW076', 'DEBW087']
assert DEFAULT_VAR_ALL_DICT == {'o3': 'dma8eu', 'relhum': 'average_values', 'temp': 'maximum',
'u': 'average_values',
'v': 'average_values', 'no': 'dma8eu', 'no2': 'dma8eu',
'cloudcover': 'average_values',
'pblheight': 'maximum'}
assert DEFAULT_NETWORK == "AIRBASE"
assert DEFAULT_STATION_TYPE == "background"
assert DEFAULT_VARIABLES == DEFAULT_VAR_ALL_DICT.keys()
assert DEFAULT_START == "1997-01-01"
assert DEFAULT_END == "2017-12-31"
assert DEFAULT_WINDOW_HISTORY_SIZE == 13
assert DEFAULT_OVERWRITE_LOCAL_DATA is False
assert isinstance(DEFAULT_TRANSFORMATION, TransformationClass)
assert DEFAULT_TRANSFORMATION.inputs.transform_method == "standardise"
assert DEFAULT_TRANSFORMATION.targets.transform_method == "standardise"
assert DEFAULT_TARGET_VAR == "o3"
assert DEFAULT_TARGET_DIM == "variables"
assert DEFAULT_WINDOW_LEAD_TIME == 3
assert DEFAULT_DIMENSIONS == {"new_index": ["datetime", "Stations"]}
assert DEFAULT_TIME_DIM == "datetime"
assert DEFAULT_INTERPOLATION_METHOD == "linear"
assert DEFAULT_INTERPOLATION_LIMIT == 1
def test_subset_parameters(self):
assert DEFAULT_TRAIN_START == "1997-01-01"
assert DEFAULT_TRAIN_END == "2007-12-31"
assert DEFAULT_TRAIN_MIN_LENGTH == 90
assert DEFAULT_VAL_START == "2008-01-01"
assert DEFAULT_VAL_END == "2009-12-31"
assert DEFAULT_VAL_MIN_LENGTH == 90
assert DEFAULT_TEST_START == "2010-01-01"
assert DEFAULT_TEST_END == "2017-12-31"
assert DEFAULT_TEST_MIN_LENGTH == 90
assert DEFAULT_TRAIN_VAL_MIN_LENGTH == 180
assert DEFAULT_USE_ALL_STATIONS_ON_ALL_DATA_SETS is True
def test_hpc_parameters(self):
assert DEFAULT_HPC_HOST_LIST == ["jw", "hdfmlc"]
assert DEFAULT_HPC_LOGIN_LIST == ["ju", "hdfmll"]
def test_postprocessing_parameters(self):
assert DEFAULT_EVALUATE_BOOTSTRAPS is True
assert DEFAULT_CREATE_NEW_BOOTSTRAPS is False
assert DEFAULT_NUMBER_OF_BOOTSTRAPS == 20
assert DEFAULT_PLOT_LIST == ["PlotMonthlySummary", "PlotStationMap", "PlotClimatologicalSkillScore",
"PlotTimeSeries", "PlotCompetitiveSkillScore", "PlotBootstrapSkillScore",
"PlotConditionalQuantiles", "PlotAvailability"]
......@@ -3,7 +3,9 @@ import pandas as pd
import pytest
import xarray as xr
from mlair.helpers.statistics import standardise, standardise_inverse, standardise_apply, centre, centre_inverse, centre_apply, \
from mlair.helpers.statistics import DataClass, TransformationClass
from mlair.helpers.statistics import standardise, standardise_inverse, standardise_apply, centre, centre_inverse, \
centre_apply, \
apply_inverse_transformation
lazy = pytest.lazy_fixture
......@@ -113,3 +115,50 @@ class TestCentre:
data = centre_apply(data_orig, mean)
mean_expected = np.array([2, -5, 10]) - np.array([2, 10, 3])
assert np.testing.assert_almost_equal(data.mean(dim), mean_expected, decimal=1) is None
class TestDataClass:
def test_init(self):
dc = DataClass()
assert all([obj is None for obj in [dc.data, dc.mean, dc.std, dc.max, dc.min, dc.transform_method, dc._method]])
def test_init_values(self):
dc = DataClass(data=12, mean=2, std="test", max=23.4, min=np.array([3]), transform_method="f")
assert dc.data == 12
assert dc.mean == 2
assert dc.std == "test"
assert dc.max == 23.4
assert np.testing.assert_array_equal(dc.min, np.array([3])) is None
assert dc.transform_method == "f"
assert dc._method is None
def test_as_dict(self):
dc = DataClass(std=23)
dc._method = "f(x)"
assert dc.as_dict() == {"data": None, "mean": None, "std": 23, "max": None, "min": None,
"transform_method": None}
class TestTransformationClass:
def test_init(self):
tc = TransformationClass()
assert hasattr(tc, "inputs")
assert isinstance(tc.inputs, DataClass)
assert hasattr(tc, "targets")
assert isinstance(tc.targets, DataClass)
assert tc.inputs.mean is None
assert tc.targets.std is None
def test_init_values(self):
tc = TransformationClass(inputs_mean=1, inputs_std=2, inputs_method="f", targets_mean=3, targets_std=4,
targets_method="g")
assert tc.inputs.mean == 1
assert tc.inputs.std == 2
assert tc.inputs.transform_method == "f"
assert tc.inputs.max is None
assert tc.targets.mean == 3
assert tc.targets.std == 4
assert tc.targets.transform_method == "g"
assert tc.inputs.min is None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment