Skip to content

Commit

Permalink
Fix wrong type when passing slope as float (#308)
Browse files Browse the repository at this point in the history
* Use int(scale) match variable type in _get_kernel

* Add test for float slope and timesteps
  • Loading branch information
aitaten committed Sep 11, 2022
1 parent bf323e2 commit 44038db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pysteps/nowcasts/lagrangian_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def forecast(
# Compute exceedance probabilities using a neighborhood approach
precip_forecast = (precip_forecast >= threshold).astype(float)
for i, timestep in enumerate(timesteps):
scale = timestep * slope
scale = int(timestep * slope)
if scale == 0:
continue
kernel = _get_kernel(scale)
Expand Down
19 changes: 19 additions & 0 deletions pysteps/tests/test_nowcasts_lagrangian_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ def test_numerical_example():
assert np.allclose(fct, ref)


def test_numerical_example_with_float_slope_and_float_list_timesteps():
""""""
precip = np.zeros((20, 20))
precip[5:10, 5:10] = 1
velocity = np.zeros((2, *precip.shape))
timesteps = [1.0, 2.0, 5.0, 12.0]
thr = 0.5
slope = 1.0 # pixels / timestep

# compute probability forecast
fct = forecast(precip, velocity, timesteps, thr, slope=slope)

assert fct.ndim == 3
assert fct.shape[0] == len(timesteps)
assert fct.shape[1:] == precip.shape
assert fct.max() <= 1.0
assert fct.min() >= 0.0


def test_real_case():
""""""
pytest.importorskip("cv2")
Expand Down

0 comments on commit 44038db

Please sign in to comment.