code: def block_covariances(X, blocks, estimator="cov", **kwds):
      """Compute block diagonal covariance.
  
      Calculates block diagonal matrices where each block is a covariance
      matrix of a subset of channels.
      Block sizes are passed as a list of integers and can vary. The sum
      of block sizes must equal the number of channels in X.
  
      Parameters
      ----------
      X : ndarray, shape (n_matrices, n_channels, n_times)
          Multi-channel time-series.
      blocks: list of int
          List of block sizes.
      estimator : string, default='scm'
          Covariance matrix estimator, see
          :func:`pyriemann.utils.covariance.covariances`.
      **kwds : optional keyword parameters
          Any further parameters are passed directly to the covariance estimator.
  
      Returns
      -------
      covmats : ndarray, shape (n_matrices, n_channels, n_channels)
          Block diagonal covariance matrices.
      """
      est = _check_cov_est_function(estimator)
      n_matrices, n_channels, n_times = X.shape
  
      if np.sum(blocks) != n_channels:
          raise ValueError(
              "Sum of individual block sizes "
              "must match number of channels of X."
          )
  
      covmats = np.empty((n_matrices, n_channels, n_channels))
      for i in range(n_matrices):
          blockcov, idx_start = [], 0
          for j in blocks:
              blockcov.append(
                  est(X[i, idx_start : idx_start + j, :], **kwds)
              )
              idx_start += j
          covmats[i] = block_diag(*tuple(blockcov))
  
      return covmats
  
imports: import warnings
  from functools import wraps
  import numpy
  from scipy.linalg import block_diag
  from scipy.stats import chi2
  from sklearn.covariance import oas, ledoit_wolf, fast_mcd
  from .distance import distance_mahalanobis
  from .test import is_square, is_real_type
label_desc: Use image node_id 15 for calling a global function with example usage: block_covariances(X, blocks, estimator) and returns: covmats