def test_nowcast_main_loop(
    timesteps, ensemble, num_ensemble_members, velocity_perturbations
):
    """Test the nowcast_main_loop function."""
    precip = get_precipitation_fields(
        num_prev_files=2,
        num_next_files=0,
        return_raw=False,
        metadata=False,
        upscale=2000,
    )
    precip = precip.filled()

    oflow_method = motion.get_method("LK")
    velocity = oflow_method(precip)

    precip = precip[-1]

    state = {"input": precip}
    extrap_method = "semilagrangian"

    def func(state, params):
        if not ensemble:
            precip_out = state["input"]
        else:
            precip_out = state["input"][np.newaxis, :]

        return precip_out, state

    nowcast_utils.nowcast_main_loop(
        precip,
        velocity,
        state,
        timesteps,
        extrap_method,
        func,
        ensemble=ensemble,
        num_ensemble_members=num_ensemble_members,
    )
Test the nowcast_main_loop function.
pysteps/tests/test_nowcasts_utils.py