pySTEPS / pysteps

Python framework for short-term ensemble prediction systems.
https://pysteps.github.io/
BSD 3-Clause "New" or "Revised" License
466 stars 168 forks source link

Incorrect output from decluster when n=1 #194

Closed jleinonen closed 3 years ago

jleinonen commented 3 years ago

Description

The function pysteps.utils.cleansing.decluster returns the first output with an incorrect shape in the specific case of n==1.

How to reproduce

import numpy as np
from pysteps.utils.cleansing import decluster

X = np.array([[0.0, 0.0]]) # ndim==2
V = np.array([[1.0, 1.0]]) # ndim==2
(X_dec, V_dec) = decluster(X, V, 20)
print(X_dec, V_dec)
print(X_dec.ndim)
print(V_dec.ndim)

Prints:

[0. 0.] [[1. 1.]]
1
2

Expected output

According to the documentation of the decluster function:

    Returns
    -------
    out: tuple of ndarrays
        A two-element tuple (``out_coord``, ``output_array``) containing the
        declustered coordinates (l, d) and input array (l, m), where *l* is
        the new number of samples with *l* <= *n*.

That is, both outputs should have ndim==2 even in the edge case of n==1.

Notes

I didn't examine this throughly, but this may mean that pysteps.motion.lukaskanade.dense_lucaskanade does something funny when exactly one motion vector is found by the sparse motion vector search. See call to decluster here: https://github.com/pySTEPS/pysteps/blob/e2c3484ef234e3ef1ac8f1f11b1e64bc6911f35c/pysteps/motion/lucaskanade.py#L273

dnerini commented 3 years ago

Hi @jleinonen and thanks for the detailed description - I'll have a look into it!