-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_config.py
110 lines (84 loc) · 3.23 KB
/
test_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# standalone imports
from lib.logger_config import log
from lib.color import Style
'''
Module providing classes and functions related to the tests. It contains:
- get_config_of_current_test: return configuration
of the test matching the string passed as argument
- class WelchsTest: define properties of Welch's t-test
- class EmissionsTest: define properties of emission test
- class FldcorTest: define properties of field correlation test
- class RmseTest: define properties of
normalize root mean square error test
- class threshold_prop: contains the properties of a testmetric
e.g. color, threshold or significance level
J.Jucker 12.2020 (C2SM)
'''
def get_config_of_current_test(testname):
if testname == 'welch':
config = WelchsTest()
elif testname == 'emi':
config = EmissionsTest()
elif testname == 'fldcor':
config = FldcorTest()
elif testname == 'rmse':
config = RmseTest()
else:
log.error('Test {} does not exist'.format(testname))
return config
class WelchsTest:
def __init__(self):
self.name = 'welch'
self.ref_name = 'glob_means'
self.metric = 'p-value [%]'
self.metric_threshold = [
threshold_prop('very low', 1, 'DarkRed'),
threshold_prop('low', 5, 'Red'),
threshold_prop('middle', 10, 'Orange'),
threshold_prop('high', 100, 'Green')]
class EmissionsTest:
def __init__(self):
self.name = 'emi'
self.ref_name = 'emis'
self.metric = 'relative deviation [%]'
self.metric_threshold = [
threshold_prop('high', 0.01, 'Green'),
threshold_prop('middle', 0.1, 'Orange'),
threshold_prop('low', 1, 'Red'),
threshold_prop('very low', 100, 'DarkRed')]
class FldcorTest:
def __init__(self):
self.name = 'pattern_correlation'
self.ref_name = 'fldcor'
self.metric = 'R^2'
self.metric_threshold = [
threshold_prop('very low', 0.98, 'DarkRed'),
threshold_prop('low', 0.985, 'Red'),
threshold_prop('middle', 0.99, 'Orange'),
threshold_prop('high', 1, 'Green')]
class RmseTest:
def __init__(self):
self.name = 'rmse'
self.ref_name = 'rmse'
self.metric = 'normalized RMSE'
self.metric_threshold = [
threshold_prop('high', 0.03, 'Green'),
threshold_prop('middle', 0.07, 'Orange'),
threshold_prop('low', 0.15, 'Red'),
threshold_prop('very low', 0.99, 'DarkRed')]
class threshold_prop:
'''Properties linked to the metrics threshold'''
def __init__(self, lev, metric_threshold, color_var):
# defining color text
dict_col = {'Red': Style.RED, 'DarkRed': Style.RED_HIGHL,
'Orange':Style.ORANGE,'Green': Style.GREEN}
try:
self.col_txt = dict_col[color_var]
except KeyError:
log.warning('No text color associated with {} - '
'setting to BLACK'.format(color_var))
self.col_txt = Style.BLACK
# other properties
self.level = lev
self.p_thresh = metric_threshold
self.col_graph = color_var