Skip to content

Commit c8ebc2d

Browse files
authored
Test fft-generators (#213)
* Add basic tests for fft noise gen * Fix example * Aesthetics
1 parent 21192cb commit c8ebc2d

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

examples/plot_noise_generators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Generation of stochastic noise
44
==============================
55
6-
This example script shows how to run the stochastic noise field generators
6+
This example script shows how to run the stochastic noise field generators
77
included in pysteps.
88
99
These noise fields are used as perturbation terms during an extrapolation
10-
nowcast in order to represent the uncertainty in the evolution of the rainfall
10+
nowcast in order to represent the uncertainty in the evolution of the rainfall
1111
field.
1212
"""
1313

@@ -67,7 +67,7 @@
6767

6868
# Compute the observed and fitted 1D PSD
6969
L = np.max(Fp["input_shape"])
70-
if L % 2 == 0:
70+
if L % 2 == 1:
7171
wn = np.arange(0, int(L / 2) + 1)
7272
else:
7373
wn = np.arange(0, int(L / 2))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import numpy as np
2+
3+
from pysteps.noise import fftgenerators
4+
from pysteps.tests.helpers import get_precipitation_fields
5+
6+
7+
PRECIP = get_precipitation_fields(
8+
num_prev_files=0,
9+
num_next_files=0,
10+
return_raw=False,
11+
metadata=False,
12+
upscale=2000,
13+
)
14+
PRECIP = PRECIP.filled()
15+
16+
17+
def test_noise_param_2d_fft_filter():
18+
19+
fft_filter = fftgenerators.initialize_param_2d_fft_filter(PRECIP)
20+
21+
assert isinstance(fft_filter, dict)
22+
assert all([key in fft_filter for key in ["field", "input_shape", "model", "pars"]])
23+
24+
out = fftgenerators.generate_noise_2d_fft_filter(fft_filter)
25+
26+
assert isinstance(out, np.ndarray)
27+
assert out.shape == PRECIP.shape
28+
29+
30+
def test_noise_nonparam_2d_fft_filter():
31+
32+
fft_filter = fftgenerators.initialize_nonparam_2d_fft_filter(PRECIP)
33+
34+
assert isinstance(fft_filter, dict)
35+
assert all([key in fft_filter for key in ["field", "input_shape"]])
36+
37+
out = fftgenerators.generate_noise_2d_fft_filter(fft_filter)
38+
39+
assert isinstance(out, np.ndarray)
40+
assert out.shape == PRECIP.shape
41+
42+
43+
def test_noise_nonparam_2d_ssft_filter():
44+
45+
fft_filter = fftgenerators.initialize_nonparam_2d_ssft_filter(PRECIP)
46+
47+
assert isinstance(fft_filter, dict)
48+
assert all([key in fft_filter for key in ["field", "input_shape"]])
49+
50+
out = fftgenerators.generate_noise_2d_ssft_filter(fft_filter)
51+
52+
assert isinstance(out, np.ndarray)
53+
assert out.shape == PRECIP.shape

0 commit comments

Comments
 (0)