    def __initialize_precipitation_mask(self):
        """
        Initialize the precipitation mask and handle different mask methods (sprog, incremental).
        """
        self.__state.precip_forecast = [[] for _ in range(self.__config.n_ens_members)]

        if self.__config.probmatching_method == "mean":
            self.__params.precipitation_mean = np.mean(
                self.__precip[-1, :, :][
                    self.__precip[-1, :, :] >= self.__config.precip_threshold
                ]
            )
        else:
            self.__params.precipitation_mean = None

        if self.__config.mask_method is not None:
            self.__state.mask_precip = (
                self.__precip[-1, :, :] >= self.__config.precip_threshold
            )

            if self.__config.mask_method == "sprog":
                # Compute the wet area ratio and the precipitation mask
                self.__params.wet_area_ratio = np.sum(self.__state.mask_precip) / (
                    self.__precip.shape[1] * self.__precip.shape[2]
                )
                self.__state.precip_mask = [
                    self.__state.precip_cascades[0][i].copy()
                    for i in range(self.__config.n_cascade_levels)
                ]
                self.__state.precip_mask_decomposed = self.__state.precip_decomposed[
                    0
                ].copy()

            elif 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
                self.__params.structuring_element = generate_binary_structure(2, 1)
                # Expand the structuring element based on mask factor and timestep
                n = mask_f * self.__config.timestep / self.__config.kmperpixel
                self.__params.structuring_element = iterate_structure(
                    self.__params.structuring_element, int((n - 1) / 2.0)
                )
                # Compute and apply the dilated mask for each ensemble member
                self.__state.mask_precip = nowcast_utils.compute_dilated_mask(
                    self.__state.mask_precip,
                    self.__params.structuring_element,
                    self.__params.mask_rim,
                )
                self.__state.mask_precip = [
                    self.__state.mask_precip.copy()
                    for _ in range(self.__config.n_ens_members)
                ]
        else:
            self.__state.mask_precip = None

        if self.__config.noise_method is None and self.__state.precip_mask is None:
            self.__state.precip_mask = [
                self.__state.precip_cascades[0][i].copy()
                for i in range(self.__config.n_cascade_levels)
            ]
        print("Precipitation mask initialized successfully.")
Initialize the precipitation mask and handle different mask methods (sprog, incremental).
pysteps/nowcasts/steps.py