    def __recompose_and_apply_mask(self, j, state, params):
        """
        Recompose the precipitation field from cascades and apply the precipitation mask.
        """
        state["precip_decomp"][j]["cascade_levels"] = [
            state["precip_cascades"][j][i][-1, :]
            for i in range(params["n_cascade_levels"])
        ]

        if params["domain"] == "spatial":
            state["precip_decomp"][j]["cascade_levels"] = np.stack(
                state["precip_decomp"][j]["cascade_levels"]
            )

        precip_forecast = params["recomp_method"](state["precip_decomp"][j])

        if params["domain"] == "spectral":
            precip_forecast = state["fft_objs"][j].irfft2(precip_forecast)

        # Apply the precipitation mask
        if params["mask_method"] is not None:
            precip_forecast = self.__apply_precipitation_mask(
                precip_forecast, j, state, params
            )

        # Adjust the CDF of the forecast to match the observed precipitation field
        if params["probmatching_method"] == "cdf":
            precip_forecast = probmatching.nonparam_match_empirical_cdf(
                precip_forecast, params["precip"]
            )
        # Adjust the mean of the forecast to match the observed mean
        elif params["probmatching_method"] == "mean":
            mask = precip_forecast >= params["precip_thr"]
            mu_fct = np.mean(precip_forecast[mask])
            precip_forecast[mask] = precip_forecast[mask] - mu_fct + params["mu_0"]

        # Update the mask for incremental method
        if params["mask_method"] == "incremental":
            state["mask_prec"][j] = nowcast_utils.compute_dilated_mask(
                precip_forecast >= params["precip_thr"],
                params["struct"],
                params["mask_rim"],
            )

        # Apply the domain mask (set masked areas to NaN)
        precip_forecast[params["domain_mask"]] = np.nan

        return precip_forecast
Recompose the precipitation field from cascades and apply the precipitation mask.
pysteps/nowcasts/steps.py