-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_zarr_dask_compatibility.py
98 lines (85 loc) · 2.52 KB
/
test_zarr_dask_compatibility.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
# -*- mode: python; coding: utf-8 -*-
#
# Copyright (C) 2024 Benjamin Thomas Schwertfeger
# All rights reserved.
# https://github.com/btschwertfeger
#
from typing import Any
import pytest
import xarray as xr
from cmethods import adjust
from cmethods.types import XRData_t
from .helper import is_3d_rmse_better
GROUP: str = "time.month"
N_QUANTILES: int = 100
@pytest.mark.parametrize(
("method", "kind"),
[
("linear_scaling", "+"),
("linear_scaling", "*"),
("variance_scaling", "+"),
("delta_method", "+"),
("delta_method", "*"),
],
)
def test_3d_scaling_zarr(
datasets_from_zarr: xr.Dataset,
method: str,
kind: str,
dask_cluster: Any, # noqa: ARG001
) -> None:
variable: str = "tas" if kind == "+" else "pr" # noqa: PLR2004
obsh: xr.DataArray = datasets_from_zarr[kind]["obsh"][variable]
obsp: xr.DataArray = datasets_from_zarr[kind]["obsp"][variable]
simh: xr.DataArray = datasets_from_zarr[kind]["simh"][variable]
simp: xr.DataArray = datasets_from_zarr[kind]["simp"][variable]
result: XRData_t = adjust(
method=method,
obs=obsh,
simh=simh,
simp=simp,
kind=kind,
)
assert isinstance(result, XRData_t)
assert is_3d_rmse_better(result=result[variable], obsp=obsp, simp=simp)
# grouped
result = adjust(
method=method,
obs=obsh,
simh=simh,
simp=simp,
kind=kind,
group=GROUP,
)
assert isinstance(result, XRData_t)
assert is_3d_rmse_better(result=result[variable], obsp=obsp, simp=simp)
@pytest.mark.parametrize(
("method", "kind"),
[
("quantile_mapping", "+"),
("quantile_mapping", "*"),
("quantile_delta_mapping", "+"),
("quantile_delta_mapping", "*"),
],
)
def test_3d_distribution_zarr(
datasets_from_zarr: dict,
method: str,
kind: str,
dask_cluster: Any, # noqa: ARG001
) -> None:
variable: str = "tas" if kind == "+" else "pr" # noqa: PLR2004
obsh: XRData_t = datasets_from_zarr[kind]["obsh"][variable]
obsp: XRData_t = datasets_from_zarr[kind]["obsp"][variable]
simh: XRData_t = datasets_from_zarr[kind]["simh"][variable]
simp: XRData_t = datasets_from_zarr[kind]["simp"][variable]
result: XRData_t = adjust(
method=method,
obs=obsh,
simh=simh,
simp=simp,
kind=kind,
n_quantiles=N_QUANTILES,
)
assert isinstance(result, XRData_t)
assert is_3d_rmse_better(result=result[variable], obsp=obsp, simp=simp)