    def __determine_weights_per_component(self, worker_state):
        """
        Compute blending weights for each component based on the selected method
        ('bps' or 'spn'). Weights are determined for both full blending and
        model-only scenarios, accounting for correlations and covariance.
        """
        # Weights following the bps method. These are needed for the velocity
        # weights prior to the advection step. If weights method spn is
        # selected, weights will be overwritten with those weights prior to
        # blending step.
        # weight = [(extr_field, n_model_fields, noise), n_cascade_levels, ...]
        worker_state.weights = calculate_weights_bps(
            worker_state.rho_final_blended_forecast
        )

        # The model only weights
        if self.__config.weights_method == "bps":
            # Determine the weights of the components without the extrapolation
            # cascade, in case this is no data or outside the mask.
            worker_state.weights_model_only = calculate_weights_bps(
                worker_state.rho_final_blended_forecast[1:, :]
            )
        elif self.__config.weights_method == "spn":
            # Only the weights of the components without the extrapolation
            # cascade will be determined here. The full set of weights are
            # determined after the extrapolation step in this method.
            if (
                self.__config.blend_nwp_members
                and worker_state.precip_models_cascades_timestep.shape[0] > 1
            ):
                worker_state.weights_model_only = np.zeros(
                    (
                        worker_state.precip_models_cascades_timestep.shape[0] + 1,
                        self.__config.n_cascade_levels,
                    )
                )
                for i in range(self.__config.n_cascade_levels):
                    # Determine the normalized covariance matrix (containing)
                    # the cross-correlations between the models
                    covariance_nwp_models = np.corrcoef(
                        np.stack(
                            [
                                worker_state.precip_models_cascades_timestep[
                                    n_model, i, :, :
                                ].flatten()
                                for n_model in range(
                                    worker_state.precip_models_cascades_timestep.shape[
                                        0
                                    ]
                                )
                            ]
                        )
                    )
                    # Determine the weights for this cascade level
                    worker_state.weights_model_only[:, i] = calculate_weights_spn(
                        correlations=worker_state.rho_final_blended_forecast[1:, i],
                        covariance=covariance_nwp_models,
                    )
            else:
                # Same as correlation and noise is 1 - correlation
                worker_state.weights_model_only = calculate_weights_bps(
                    worker_state.rho_final_blended_forecast[1:, :]
                )
        else:
            raise ValueError(
                "Unknown weights method %s: must be 'bps' or 'spn'"
                % self.__config.weights_method
            )
Compute blending weights for each component based on the selected method
('bps' or 'spn'). Weights are determined for both full blending and
model-only scenarios, accounting for correlations and covariance.
pysteps/blending/steps.py