Skip to content

Commit

Permalink
Fix weights in nested noise (#320)
Browse files Browse the repository at this point in the history
* Convert grid index to km

* Add test for nested noise
  • Loading branch information
dnerini committed Jan 25, 2023
1 parent c9bd687 commit 4065c88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pysteps/noise/fftgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ def initialize_nonparam_2d_nested_filter(field, gridres=1.0, **kwargs):
x0 = (
Idxinext[n, 1] - Idxinext[n, 0]
) / 2.0 # TODO: consider y dimension, too
merge_weights = 1 / (1 + np.exp(-k * (1 / freq_grid - x0)))
merge_weights = 1 / (
1 + np.exp(-k * (1 / freq_grid - x0 * gridres))
)
newfilter *= 1 - merge_weights

# perform the weighted average of previous and new fourier filters
Expand Down
13 changes: 13 additions & 0 deletions pysteps/tests/test_noise_fftgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ def test_noise_nonparam_2d_ssft_filter():

assert isinstance(out, np.ndarray)
assert out.shape == PRECIP.shape


def test_noise_nonparam_2d_nested_filter():

fft_filter = fftgenerators.initialize_nonparam_2d_nested_filter(PRECIP)

assert isinstance(fft_filter, dict)
assert all([key in fft_filter for key in ["field", "input_shape"]])

out = fftgenerators.generate_noise_2d_ssft_filter(fft_filter)

assert isinstance(out, np.ndarray)
assert out.shape == PRECIP.shape

0 comments on commit 4065c88

Please sign in to comment.