Coverage for tests/continuous/flip_flop_test_data.py: 100%
53 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-02-28 12:51 +1100
« prev ^ index » next coverage.py v7.3.2, created at 2024-02-28 12:51 +1100
1"""
2Test data for tests.continuous.flip_flop in scores
3"""
4import numpy as np
5import xarray as xr
7"""
8Test data for flip_flop_index and related functions
9"""
10DATA_FFI_1D_6 = xr.DataArray([20, 50, 60, 30, 10, 20], coords=[("letter", ["a", "b", "c", "d", "e", "f"])])
11DATA_FFI_1D_6_WITH_NAN = xr.DataArray([20, 50, 60, 30, np.nan, 20], coords=[("letter", ["a", "b", "c", "d", "e", "f"])])
12DATA_FFI_2D_6 = xr.DataArray(
13 [[20, 50, 60, 30, 10, 20], [20, 50, 60, 30, np.nan, 20]],
14 coords=[("number", [1, 2]), ("letter", ["a", "b", "c", "d", "e", "f"])],
15)
17DATA_FFI_1D_6_ABC = xr.DataArray([20, 50, 60], coords=[("letter", ["a", "b", "c"])])
18DATA_FFI_1D_6_BCD = xr.DataArray([50, 60, 30], coords=[("letter", ["b", "c", "d"])])
19DATA_FFI_1D_6_ACEF = xr.DataArray([20, 60, 10, 20], coords=[("letter", ["a", "c", "e", "f"])])
20DATA_FFI_1D_6_WITH_NAN_ACE = xr.DataArray([20, 60, np.nan], coords=[("letter", ["a", "c", "e"])])
21DATA_FFI_3D = xr.DataArray(
22 [
23 [[np.pi, 0, 2 * np.pi], [np.nan, 3.4, -100]],
24 [[-20, -40, -10], [0.5, 0.6, 0.1]],
25 ],
26 coords=[
27 ("fruit", ["apple", "pear"]),
28 ("number", [1, 2]),
29 ("letter", ["a", "b", "c"]),
30 ],
31)
32DATA_FFI_3D_DIR = xr.DataArray(
33 [
34 [[10, 350, 20], [np.nan, 90, 100]],
35 [[0, 240, 300], [100, 0, 200]],
36 ],
37 coords=[
38 ("fruit", ["apple", "pear"]),
39 ("number", [1, 2]),
40 ("letter", ["a", "b", "c"]),
41 ],
42)
43DATA_FFI_2X2X4 = xr.DataArray(
44 [
45 [[-5, 3, 2.5, 1], [np.nan, -4, 9, 4]],
46 [[3.14, 0, 6.28, 10], [-2, -3, 0, -5]],
47 ],
48 coords=[("char", ["a", "b"]), ("bool", [True, False]), ("int", [1, 2, 3, 4])],
49)
50DATA_FFI_2X2X4_DIR = xr.DataArray(
51 [
52 [[350, 30, 60, 10], [np.nan, 40, 190, 100]],
53 [[300, 270, 200, 190], [120, 300, 10, 50]],
54 ],
55 coords=[("char", ["a", "b"]), ("bool", [True, False]), ("int", [1, 2, 3, 4])],
56)
58"""
59Test data for flip_flop_index
60"""
61EXP_FFI_CASE8 = xr.DataArray(
62 [[np.pi, np.nan], [20, 0.1]],
63 coords=[("fruit", ["apple", "pear"]), ("number", [1, 2])],
64)
65EXP_FFI_CASE9 = xr.DataArray(
66 [[20.0, np.nan], [60.0, 80.0]],
67 coords=[("fruit", ["apple", "pear"]), ("number", [1, 2])],
68)
71"""
72Test data for flip_flop_index_subsets
73"""
74DICT_FFI_SUB_CASE4 = {
75 "zero": ["b", "c", "d"],
76 "one": ["e", "a", "c"],
77 "two": ["a", "c", "e"],
78}
80EXP_FFI_SUB_CASE0 = xr.DataArray(12.5, attrs={"sampling_dim": "letter"})
81EXP_FFI_SUB_CASE1 = xr.DataArray(np.nan, attrs={"sampling_dim": "letter"})
82EXP_FFI_SUB_CASE2 = xr.DataArray(
83 [12.5, np.nan],
84 dims=["number"],
85 coords={"number": [1, 2]},
86 attrs={"sampling_dim": "letter"},
87)
88EXP_FFI_SUB_CASE3 = xr.DataArray(np.pi, attrs={"sampling_dim": "pi"})
90EXP_FFI_SUB_CASE4 = xr.Dataset(
91 {"back_to_front": xr.DataArray(0.0)},
92 attrs={"sampling_dim": "letter", "selections": {"back_to_front": ["e", "a", "c"]}},
93)
94EXP_FFI_SUB_CASE5 = xr.Dataset(
95 {
96 "zero": xr.DataArray([10.0, 10.0], dims=["number"], coords={"number": [1, 2]}),
97 "one": xr.DataArray([0.0, np.nan], dims=["number"], coords={"number": [1, 2]}),
98 "two": xr.DataArray([40.0, np.nan], dims=["number"], coords={"number": [1, 2]}),
99 },
100 attrs={"sampling_dim": "letter", "selections": DICT_FFI_SUB_CASE4},
101)
102EXP_FFI_SUB_CASE6 = xr.Dataset(
103 {"banana": xr.DataArray([25.0, np.nan], dims=["number"], coords={"number": [1, 2]})},
104 attrs={"sampling_dim": "letter", "selections": {"banana": ["a", "c", "e", "f"]}},
105)
106EXP_FFI_SUB_CASE7 = xr.Dataset(
107 {"banana": EXP_FFI_CASE8},
108 attrs={"sampling_dim": "letter", "selections": {"banana": ["a", "b", "c"]}},
109)
110EXP_FFI_SUB_CASE8 = xr.Dataset(
111 {"irrational": xr.DataArray(np.pi)},
112 attrs={"sampling_dim": "pi", "selections": {"irrational": [np.e, np.pi, 3.14]}},
113)
114EXP_FFI_SUB_CASE9 = xr.Dataset(
115 {
116 "one": xr.DataArray(
117 [[0.5, np.nan], [3.14, 1]],
118 coords=[("char", ["a", "b"]), ("bool", [True, False])],
119 ),
120 "two": xr.DataArray(
121 [[0.0, 5.0], [0.0, 3.0]],
122 coords=[("char", ["a", "b"]), ("bool", [True, False])],
123 ),
124 },
125 attrs={"sampling_dim": "int", "selections": {"one": [1, 2, 3], "two": [2, 3, 4]}},
126)
127EXP_FFI_SUB_CASE10 = xr.Dataset(
128 {
129 "3letters": xr.DataArray([40.0, np.nan], dims=["number"], coords={"number": [1, 2]}),
130 "4letters": xr.DataArray([25.0, np.nan], dims=["number"], coords={"number": [1, 2]}),
131 },
132 attrs={
133 "sampling_dim": "letter",
134 "selections": {"3letters": ["a", "c", "e"], "4letters": ["a", "c", "e", "f"]},
135 },
136)
139"""
140Test data for encompassing_sector_size
141"""
142ESS = xr.DataArray(
143 data=[
144 [[10, 20, 30, 40], [50, 150, 200, 250], [0, 90, 180, 270]],
145 [[np.nan, 20, 30, 40], [np.nan, np.nan, np.nan, np.nan], [90, 90, 90, 90]],
146 ],
147 dims=["i", "j", "k"],
148 coords={"i": [1, 2], "j": [1, 2, 3], "k": [1, 2, 3, 4]},
149)
150EXP_ESS_DIM_K = xr.DataArray(
151 data=[[30, 200, 270], [np.nan, np.nan, 0]],
152 dims=["i", "j"],
153 coords={"i": [1, 2], "j": [1, 2, 3]},
154)
155EXP_ESS_DIM_K_SKIPNA = xr.DataArray(
156 data=[[30, 200, 270], [20.0, np.nan, 0]],
157 dims=["i", "j"],
158 coords={"i": [1, 2], "j": [1, 2, 3]},
159)
160EXP_ESS_DIMS_J_AND_K = xr.DataArray(data=[120, np.nan], dims=["i"], coords={"i": [1, 2]})
161EXP_ESS_DIM_K_1J = xr.DataArray(data=[[30], [np.nan]], dims=["i", "j"], coords={"i": [1, 2], "j": [1]})
164ENC_SIZE_NP_TESTS_SKIPNA = [
165 # only 2 angles. answer is for skipna=True [2nd tuple element]
166 (
167 [0, 90, 90, 90, 90],
168 90,
169 ),
170 (
171 [0, 45, 0, 0, 0],
172 45,
173 ),
174 (
175 [0, 45, 44, 42, 44],
176 45,
177 ),
178 (
179 [90, 90, 89, 88, 90],
180 2,
181 ),
182 ## other
183 ([0, 0, 0, 45, 90], 90),
184 ([0, 360, 720, 45, 90], 90),
185 ([0, 1, 5, 45, 90], 90),
186 ([0, 85, 88, 89, 90], 90),
187 ([0, np.nan, 179, np.nan, np.nan], 179),
188 ([0, 30, 179, np.nan, np.nan], 179),
189 ([0, 30, 181, np.nan, np.nan], 181),
190 ([30, 0, np.nan, 181, 3], 181),
191 ([np.nan, 1, np.nan, 182, 3], 181),
192 ([np.nan, np.nan, np.nan, np.nan, np.nan], np.nan),
193]
194ENC_SIZE_NP_TESTS_NOSKIPNA = []
195for test, ans in ENC_SIZE_NP_TESTS_SKIPNA:
196 if np.nan in test:
197 ENC_SIZE_NP_TESTS_NOSKIPNA.append(
198 (
199 test,
200 np.nan,
201 )
202 )
203 else:
204 ENC_SIZE_NP_TESTS_NOSKIPNA.append(
205 (
206 test,
207 ans,
208 )
209 )
211ENC_SIZE_3D_TEST_AXIS2 = np.array(
212 [
213 [
214 [0, 30, 181, np.nan],
215 [3, 3, 3, 3],
216 ], # <= this is an individual testcase.
217 [
218 [0, 30, 179, 0],
219 [np.nan, np.nan, np.nan, np.nan],
220 ],
221 ]
222)
224ENC_SIZE_3D_ANSW_AXIS2_SKIPNA = np.array(
225 [
226 [
227 181,
228 0,
229 ],
230 [
231 179,
232 np.nan,
233 ],
234 ]
235)
236ENC_SIZE_3D_ANSW_AXIS2_NOSKIPNA = np.array(
237 [
238 [
239 np.nan,
240 0,
241 ],
242 [
243 179,
244 np.nan,
245 ],
246 ]
247)
248ENC_SIZE_3D_TEST_AXIS0 = ENC_SIZE_3D_TEST_AXIS2.swapaxes(0, 2)
249ENC_SIZE_3D_ANSW_AXIS0_SKIPNA = ENC_SIZE_3D_ANSW_AXIS2_SKIPNA.swapaxes(0, 1)
250ENC_SIZE_3D_ANSW_AXIS0_NOSKIPNA = ENC_SIZE_3D_ANSW_AXIS2_NOSKIPNA.swapaxes(0, 1)
253"""
254Test data for flipflipindex_proportion_exceeding
255"""
256EXP_FFI_PE_NONE = xr.Dataset(
257 {
258 "one": xr.DataArray([1, 2 / 3, 0], coords=[("threshold", [0, 1, 5])]),
259 "two": xr.DataArray([1, 0.5, 0.25], coords=[("threshold", [0, 1, 5])]),
260 },
261 attrs={"sampling_dim": "int", "selections": {"one": [1, 2, 3], "two": [2, 3, 4]}},
262)
263EXP_FFI_PE_CHAR = xr.Dataset(
264 {
265 "one": xr.DataArray(
266 [[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]],
267 coords=[("char", ["a", "b"]), ("threshold", [0, 1, 5])],
268 ),
269 "two": xr.DataArray(
270 [[1, 0.5, 0.5], [1, 0.5, 0]],
271 coords=[("char", ["a", "b"]), ("threshold", [0, 1, 5])],
272 ),
273 },
274 attrs={"sampling_dim": "int", "selections": {"one": [1, 2, 3], "two": [2, 3, 4]}},
275)
276EXP_FFI_PE_CHARBOOL = xr.Dataset(
277 {
278 "one": xr.DataArray(
279 [[[1, 0, 0], [np.nan, np.nan, np.nan]], [[1, 1, 0], [1, 1, 0]]],
280 coords=[
281 ("char", ["a", "b"]),
282 ("bool", [True, False]),
283 ("threshold", [0, 1, 5]),
284 ],
285 ),
286 "two": xr.DataArray(
287 [[[1.0, 0.0, 0.0], [1.0, 1.0, 1.0]], [[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]]],
288 coords=[
289 ("char", ["a", "b"]),
290 ("bool", [True, False]),
291 ("threshold", [0, 1, 5]),
292 ],
293 ),
294 },
295 attrs={"sampling_dim": "int", "selections": {"one": [1, 2, 3], "two": [2, 3, 4]}},
296)
297EXP_FFI_PE_CHARBOOL_DIR = xr.Dataset(
298 {
299 "one": xr.DataArray(
300 [
301 [[1.0, 0.0, 0.0], [np.nan, np.nan, np.nan]],
302 [[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]],
303 ],
304 coords=[
305 ("char", ["a", "b"]),
306 ("bool", [True, False]),
307 ("threshold", [0, 50, 100]),
308 ],
309 ),
310 "two": xr.DataArray(
311 [[[1.0, 0.0, 0.0], [1.0, 1.0, 0.0]], [[1.0, 0.0, 0.0], [1.0, 0.0, 0.0]]],
312 coords=[
313 ("char", ["a", "b"]),
314 ("bool", [True, False]),
315 ("threshold", [0, 50, 100]),
316 ],
317 ),
318 },
319 attrs={"sampling_dim": "int", "selections": {"one": [1, 2, 3], "two": [2, 3, 4]}},
320)