-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_misc.py
132 lines (116 loc) · 3.89 KB
/
test_misc.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# -*- mode: python; coding: utf-8 -*-
#
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# All rights reserved.
# https://github.com/btschwertfeger
#
"""Module implementing even more tests"""
from __future__ import annotations
import logging
import re
from typing import Any
import numpy as np
import pytest
from cmethods import adjust
from cmethods.distribution import (
detrended_quantile_mapping,
quantile_delta_mapping,
quantile_mapping,
)
from cmethods.scaling import delta_method, linear_scaling, variance_scaling
def test_not_implemented_errors(
datasets: dict,
caplog: Any,
) -> None:
caplog.set_level(logging.INFO)
with (
pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' not available for linear_scaling."),
),
pytest.warns(UserWarning, match="Do not call linear_scaling"),
):
linear_scaling(obs=[], simh=[], simp=[], kind="/")
with (
pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' not available for variance_scaling."),
),
pytest.warns(UserWarning, match="Do not call variance_scaling"),
):
variance_scaling(obs=[], simh=[], simp=[], kind="/")
with (
pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' not available for delta_method. "),
),
pytest.warns(UserWarning, match="Do not call delta_method"),
):
delta_method(obs=[], simh=[], simp=[], kind="/")
with (
pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' for quantile_mapping is not available."),
),
pytest.warns(UserWarning, match="Do not call quantile_mapping"),
):
quantile_mapping(
obs=np.array(datasets["+"]["obsh"][:, 0, 0]),
simh=np.array(datasets["+"]["simh"][:, 0, 0]),
simp=np.array(datasets["+"]["simp"][:, 0, 0]),
kind="/",
n_quantiles=100,
)
with pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' for detrended_quantile_mapping is not available."),
):
detrended_quantile_mapping(
obs=np.array(datasets["+"]["obsh"][:, 0, 0]),
simh=np.array(datasets["+"]["simh"][:, 0, 0]),
simp=np.array(datasets["+"]["simp"][:, 0, 0]),
kind="/",
n_quantiles=100,
)
with (
pytest.raises(
NotImplementedError,
match=re.escape(r"kind='/' not available for quantile_delta_mapping."),
),
pytest.warns(UserWarning, match="Do not call quantile_delta_mapping"),
):
quantile_delta_mapping(
obs=np.array(datasets["+"]["obsh"][:, 0, 0]),
simh=np.array(datasets["+"]["simh"][:, 0, 0]),
simp=np.array(datasets["+"]["simp"][:, 0, 0]),
kind="/",
n_quantiles=100,
)
def test_adjust_failing_dqm(datasets: dict) -> None:
with pytest.raises(
ValueError,
match=r"This function is not available for detrended quantile mapping. "
"Please use cmethods.CMethods.detrended_quantile_mapping",
):
adjust(
method="detrended_quantile_mapping",
obs=datasets["+"]["obsh"][:, 0, 0],
simh=datasets["+"]["simh"][:, 0, 0],
simp=datasets["+"]["simp"][:, 0, 0],
kind="/",
n_quantiles=100,
)
def test_adjust_failing_no_group_for_distribution(datasets: dict) -> None:
with pytest.raises(
ValueError,
match=r"Can't use group for distribution based methods.",
):
adjust(
method="quantile_mapping",
obs=datasets["+"]["obsh"][:, 0, 0],
simh=datasets["+"]["simh"][:, 0, 0],
simp=datasets["+"]["simp"][:, 0, 0],
kind="/",
n_quantiles=100,
group="time.month",
)