Skip to content

Commit

Permalink
Refactor tests for spatialscores
Browse files Browse the repository at this point in the history
  • Loading branch information
dnerini committed Oct 24, 2019
1 parent fa9cb1c commit b8025a6
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions pysteps/tests/test_spatialscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@
from pysteps.tests.helpers import get_precipitation_fields
from pysteps.verification import spatialscores

try:
import pywt

PYWT_IMPORTED = True
except ImportError:
PYWT_IMPORTED = False

R = get_precipitation_fields(num_prev_files=1, return_raw=True)
test_data = [(R[0], R[1], "FSS", [1], [10], None, 0.85161531)]
if PYWT_IMPORTED:
test_data.append((R[0], R[1], "BMSE", [1], None, "Haar", 0.99989651))

test_data = [
(R[0], R[1], "FSS", [1], [10], None, 0.85161531),
(R[0], R[1], "BMSE", [1], None, "Haar", 0.99989651),
]

@pytest.mark.parametrize(
"X_f, X_o, name, thrs, scales, wavelet, expected", test_data
)
def test_intensity_scale(X_f, X_o, name, thrs, scales, wavelet, expected):
"""Test the intensity_scale."""
if name == "BMSE":
pytest.importorskip("pywt")

assert_array_almost_equal(
spatialscores.intensity_scale(X_f, X_o, name, thrs, scales, wavelet)[
0
Expand All @@ -33,18 +29,26 @@ def test_intensity_scale(X_f, X_o, name, thrs, scales, wavelet, expected):


R = get_precipitation_fields(num_prev_files=3, return_raw=True)
test_data = [(R[:2], R[2:], "FSS", [1], [10], None, 0.85062658)]
if PYWT_IMPORTED:
test_data.append((R[:2], R[2:], "BMSE", [1], None, "Haar", 0.99985691))

test_data = [
(R[:2], R[2:], "FSS", [1], [10], None),
(R[:2], R[2:], "BMSE", [1], None, "Haar"),
]

@pytest.mark.parametrize(
"R1, R2, name, thrs, scales, wavelet, expected", test_data
"R1, R2, name, thrs, scales, wavelet", test_data
)
def test_intensity_scale_methods(
R1, R2, name, thrs, scales, wavelet, expected
R1, R2, name, thrs, scales, wavelet
):
"""Test the intensity_scale merge."""
if name == "BMSE":
pytest.importorskip("pywt")

# expected reult
int = spatialscores.intensity_scale_init(name, thrs, scales, wavelet)
spatialscores.intensity_scale_accum(int, R1[0], R1[1])
spatialscores.intensity_scale_accum(int, R2[0], R2[1])
expected = spatialscores.intensity_scale_compute(int)[0][0]

# init
int_1 = spatialscores.intensity_scale_init(name, thrs, scales, wavelet)
Expand Down

0 comments on commit b8025a6

Please sign in to comment.