code: def _get_s_matrix(X):
      """Determine the summation "S" matrix.
  
      Reconciliation methods require the S matrix, which is defined by the
      structure of the hierarchy only. The S matrix is inferred from the input
      multi-index of the forecasts and is used to sum bottom-level forecasts
      appropriately.
  
      Please refer to [1]_ for further information.
  
      Parameters
      ----------
      X :  Panel of mtype pd_multiindex_hier
  
      Returns
      -------
      s_matrix : pd.DataFrame with rows equal to the number of unique nodes in
          the hierarchy, and columns equal to the number of bottom level nodes only,
          i.e. with no aggregate nodes. The matrix indexes is inherited from the
          input data, with the time level removed.
  
      References
      ----------
      .. [1] https://otexts.com/fpp3/hierarchical.html
      """
      # get bottom level indexes
      bl_inds = (
          X.loc[~(X.index.get_level_values(level=-2).isin(["__total"]))]
          .index.droplevel(level=-1)
          .unique()
      )
      # get all level indexes
      al_inds = X.droplevel(level=-1).index.unique()
  
      # set up matrix
      s_matrix = pd.DataFrame(
          [
              [0.0 for i in range(len(bl_inds))]
              for i in range(len(al_inds))
          ],
          index=al_inds,
      )
      s_matrix.columns = bl_inds
  
      # now insert indicator for bottom level
      for i in s_matrix.columns:
          s_matrix.loc[s_matrix.index == i, i] = 1.0
  
      # now for each unique column add aggregate indicator
      for i in s_matrix.columns:
          if s_matrix.index.nlevels > 1:
              # replace index with totals -> ("nodeA", "__total")
              agg_ind = list(i)[::-1]
              for j in range(len(agg_ind)):
                  agg_ind[j] = "__total"
                  # insert indicator
                  s_matrix.loc[tuple(agg_ind[::-1]), i] = 1.0
          else:
              s_matrix.loc["__total", i] = 1.0
  
      # drop new levels not present in original matrix
      s_matrix = s_matrix.loc[s_matrix.index.isin(al_inds)]
  
      return s_matrix
  
imports: import numpy
  import pandas
  from numpy.linalg import inv
  from sktime.transformations.base import BaseTransformer
  from sktime.transformations.hierarchical.aggregate import _check_index_no_total
  from sktime.utils.warnings import warn
label_desc: Use image node_id 1 for calling a global function with example usage: _get_s_matrix(X) and returns: s_matrix