def blend_cascades(cascades_norm, weights):
    """Calculate blended normalized cascades using STEPS weights following eq.
    10 in :cite:`BPS2006`.

    Parameters
    ----------
    cascades_norm : array-like
      Array of shape [number_components + 1, scale_level, ...]
      with the cascade for each component (NWP, nowcasts, noise) and scale level,
      obtained by calling a method implemented in pysteps.blending.utils.stack_cascades

    weights : array-like
      An array of shape [number_components + 1, scale_level, ...]
      containing the weights to be used in this routine
      for each component plus noise, scale level, and optionally [y, x]
      dimensions, obtained by calling a method implemented in
      pysteps.blending.steps.calculate_weights

    Returns
    -------
    combined_cascade : array-like
      An array of shape [scale_level, y, x]
      containing per scale level (cascade) the weighted combination of
      cascades from multiple components (NWP, nowcasts and noise) to be used
      in STEPS blending.
    """
    # check inputs
    if isinstance(cascades_norm, (list, tuple)):
        cascades_norm = np.stack(cascades_norm)

    if isinstance(weights, (list, tuple)):
        weights = np.asarray(weights)

    # check weights dimensions match number of sources
    num_sources = cascades_norm.shape[0]
    num_sources_klevels = cascades_norm.shape[1]
    num_weights = weights.shape[0]
    num_weights_klevels = weights.shape[1]

    if num_weights != num_sources:
        raise ValueError(
            "dimension mismatch between cascades and weights.\n"
            "weights dimension must match the number of components in cascades.\n"
            f"number of models={num_sources}, number of weights={num_weights}"
        )
    if num_weights_klevels != num_sources_klevels:
        raise ValueError(
            "dimension mismatch between cascades and weights.\n"
            "weights cascade levels dimension must match the number of cascades in cascades_norm.\n"
            f"number of cascade levels={num_sources_klevels}, number of weights={num_weights_klevels}"
        )

    # cascade_norm component, scales, y, x
    # weights component, scales, ....
    # Reshape weights to make the calculation possible with numpy
    all_c_wn = weights.reshape(num_weights, num_weights_klevels, 1, 1) * cascades_norm
    combined_cascade = np.sum(all_c_wn, axis=0)
    # combined_cascade [scale, ...]
    return combined_cascade
Calculate blended normalized cascades using STEPS weights following eq.
10 in :cite:`BPS2006`.

Parameters
----------
cascades_norm : array-like
Array of shape [number_components + 1, scale_level, ...]
with the cascade for each component (NWP, nowcasts, noise) and scale level,
obtained by calling a method implemented in pysteps.blending.utils.stack_cascades

weights : array-like
An array of shape [number_components + 1, scale_level, ...]
containing the weights to be used in this routine
for each component plus noise, scale level, and optionally [y, x]
dimensions, obtained by calling a method implemented in
pysteps.blending.steps.calculate_weights

Returns
-------
combined_cascade : array-like
An array of shape [scale_level, y, x]
containing per scale level (cascade) the weighted combination of
cascades from multiple components (NWP, nowcasts and noise) to be used
in STEPS blending.
pysteps/blending/utils.py