def test_vet_cost_function():
    """
    Test that the vet cost_function computation gives always the same result
    with the same input.

    Useful to test if the parallelization in VET produce undesired results.
    """

    from pysteps.motion import vet

    ideal_motion, precip_obs = _create_observations(
        reference_field.copy(), "linear_y", num_times=2
    )

    mask_2d = np.ma.getmaskarray(precip_obs).any(axis=0).astype("int8")

    returned_values = np.zeros(20)

    for i in range(20):
        returned_values[i] = vet.vet_cost_function(
            ideal_motion.ravel(),  # sector_displacement_1d
            precip_obs.data,  # input_images
            ideal_motion.shape[1:],  # blocks_shape (same as 2D grid)
            mask_2d,  # Mask
            1e6,  # smooth_gain
            debug=False,
        )

    tolerance = 1e-12
    errors = np.abs(returned_values - returned_values[0])
    # errors should contain all zeros
    assert (errors < tolerance).any()
    assert (returned_values[0] - 1548250.87627097) < 0.001
Test that the vet cost_function computation gives always the same result
with the same input.

Useful to test if the parallelization in VET produce undesired results.
pysteps/tests/test_motion.py