Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pysteps/blending/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def __check_inputs(self):
self.__params.filter_kwargs = deepcopy(self.__config.filter_kwargs)

if self.__config.noise_kwargs is None:
self.__params.noise_kwargs = dict()
self.__params.noise_kwargs = {"win_fun": "tukey"}
else:
self.__params.noise_kwargs = deepcopy(self.__config.noise_kwargs)

Expand Down Expand Up @@ -1092,16 +1092,31 @@ def transform_to_lagrangian(precip, i):

self.__precip_models = np.stack(temp_precip_models)

if self.__params.noise_kwargs["win_fun"] is not None:
tapering = utils.tapering.compute_window_function(
self.__precip.shape[1],
self.__precip.shape[2],
self.__params.noise_kwargs["win_fun"],
)
else:
Comment thread
dnerini marked this conversation as resolved.
Outdated
tapering = np.ones((self.__precip.shape[1], self.__precip.shape[2]))

tapering_mask = tapering == 0.0
masked_precip = self.__precip.copy()
masked_precip[:, tapering_mask] = np.nanmin(self.__precip)
masked_precip_models = self.__precip_models.copy()
masked_precip_models[:, :, tapering_mask] = np.nanmin(self.__precip_models)

# Check for zero input fields in the radar and NWP data.
self.__params.zero_precip_radar = blending.utils.check_norain(
self.__precip,
masked_precip,
self.__config.precip_threshold,
self.__config.norain_threshold,
)
# The norain fraction threshold used for nwp is the default value of 0.0,
# since nwp does not suffer from clutter.
self.__params.zero_precip_model_fields = blending.utils.check_norain(
self.__precip_models,
masked_precip_models,
self.__config.precip_threshold,
self.__config.norain_threshold,
)
Expand Down
3 changes: 1 addition & 2 deletions pysteps/tests/test_nowcasts_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pysteps import io, motion, nowcasts, verification
from pysteps.tests.helpers import get_precipitation_fields


steps_arg_names = (
"n_ens_members",
"n_cascade_levels",
Expand All @@ -22,7 +21,7 @@
steps_arg_values = [
(5, 6, 2, None, None, "spatial", 3, 1.30),
(5, 6, 2, None, None, "spatial", [3], 1.30),
(5, 6, 2, "incremental", None, "spatial", 3, 7.31),
(5, 6, 2, "incremental", None, "spatial", 3, 7.32),
(5, 6, 2, "sprog", None, "spatial", 3, 8.4),
(5, 6, 2, "obs", None, "spatial", 3, 8.37),
(5, 6, 2, None, "cdf", "spatial", 3, 0.60),
Expand Down
16 changes: 7 additions & 9 deletions pysteps/utils/tapering.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def compute_window_function(m, n, func, **kwargs):
Array of shape (m, n) containing the tapering weights.
"""
X, Y = np.meshgrid(np.arange(n), np.arange(m))
R = np.sqrt((X - int(n / 2)) ** 2 + (Y - int(m / 2)) ** 2)
R = np.sqrt(((X / n) - 0.5) ** 2 + ((Y / m) - 0.5) ** 2)

if func == "hann":
return _hann(R)
Expand All @@ -108,26 +108,24 @@ def _compute_mask_distances(mask):

def _hann(R):
W = np.ones_like(R)
N = min(R.shape[0], R.shape[1])
mask = R > int(N / 2)
mask = R > 0.5

W[mask] = 0.0
W[~mask] = 0.5 * (1.0 - np.cos(2.0 * np.pi * (R[~mask] + int(N / 2)) / N))
W[~mask] = 0.5 * (1.0 - np.cos(2.0 * np.pi * (R[~mask] + 0.5)))

return W


def _tukey(R, alpha):
W = np.ones_like(R)
N = min(R.shape[0], R.shape[1])

mask1 = R < int(N / 2)
mask2 = R > int(N / 2) * (1.0 - alpha)
mask1 = R < 0.5
mask2 = R > 0.5 * (1.0 - alpha)
mask = np.logical_and(mask1, mask2)
W[mask] = 0.5 * (
1.0 + np.cos(np.pi * (R[mask] / (alpha * 0.5 * N) - 1.0 / alpha + 1.0))
1.0 + np.cos(np.pi * (R[mask] / (alpha * 0.5) - 1.0 / alpha + 1.0))
)
mask = R >= int(N / 2)
mask = R >= 0.5
W[mask] = 0.0

return W
Expand Down