    def __prepare_forecast_loop(self):
        """
        Initialize variables and structures needed for the forecast loop, including
        displacement tracking, mask parameters, noise handling, FFT objects, and
        extrapolation scaling for nowcasting.
        """
        # Empty arrays for the previous displacements and the forecast cascade
        self.__state.previous_displacement = np.stack(
            [None for j in range(self.__config.n_ens_members)]
        )
        self.__state.previous_displacement_noise_cascade = np.stack(
            [None for j in range(self.__config.n_ens_members)]
        )
        self.__state.previous_displacement_prob_matching = np.stack(
            [None for j in range(self.__config.n_ens_members)]
        )
        self.__state.final_blended_forecast = [
            [] for j in range(self.__config.n_ens_members)
        ]

        if self.__config.mask_method == "incremental":
            # get mask parameters
            self.__params.mask_rim = self.__params.mask_kwargs.get("mask_rim", 10)
            mask_f = self.__params.mask_kwargs.get("mask_f", 1.0)
            # initialize the structuring element
            struct = generate_binary_structure(2, 1)
            # iterate it to expand it nxn
            n = mask_f * self.__config.timestep / self.__config.kmperpixel
            self.__params.struct = iterate_structure(struct, int((n - 1) / 2.0))
        else:
            self.__params.mask_rim, self.__params.struct = None, None

        if self.__config.noise_method is None:
            self.__state.final_blended_forecast_non_perturbed = [
                self.__state.precip_cascades[0][i].copy()
                for i in range(self.__config.n_cascade_levels)
            ]
        else:
            self.__state.final_blended_forecast_non_perturbed = None

        self.__params.fft_objs = []
        for i in range(self.__config.n_ens_members):
            self.__params.fft_objs.append(
                utils.get_method(
                    self.__config.fft_method,
                    shape=self.__state.precip_cascades.shape[-2:],
                )
            )

        # initizalize the current and previous extrapolation forecast scale for the nowcasting component
        # phi1 / (1 - phi2), see BPS2004
        self.__state.rho_extrap_cascade_prev = np.repeat(
            1.0, self.__params.PHI.shape[0]
        )
        self.__state.rho_extrap_cascade = self.__params.PHI[:, 0] / (
            1.0 - self.__params.PHI[:, 1]
        )
Initialize variables and structures needed for the forecast loop, including
displacement tracking, mask parameters, noise handling, FFT objects, and
extrapolation scaling for nowcasting.
pysteps/blending/steps.py