code: def _check_input_as_first_level_model(
      second_level_input, none_confounds
  ):
      """Check that all all first level models are valid.
  
      - must have been fit
      - must all have a subject label in case confounds are passed
      - must all have the same affine / shape
        (checking all against those of the first model)
  
      """
      ref_affine = None
      ref_shape = None
  
      for model_idx, first_level in enumerate(second_level_input):
          if (
              first_level.labels_ is None
              or first_level.results_ is None
          ):
              raise ValueError(
                  f"Model {first_level.subject_label} "
                  f"at index {model_idx} has not been fit yet."
              )
          if not none_confounds and first_level.subject_label is None:
              raise ValueError(
                  "In case confounds are provided, "
                  "first level objects need to provide "
                  "the attribute 'subject_label' to match rows appropriately.\n"
                  f"Model at idx {model_idx} does not provide it. "
                  "To set it, you can do first_level.subject_label = '01'"
              )
  
          affine = None
          shape = None
          if first_level.mask_img is not None:
              if isinstance(first_level.mask_img, NiftiMasker):
                  affine = first_level.mask_img.affine_
                  shape = first_level.mask_img.mask_img_.shape
              elif isinstance(first_level.mask_img, Nifti1Image):
                  affine = first_level.mask_img.affine
                  shape = first_level.mask_img.shape
  
          # take as reference the first values we found
          if ref_affine is None:
              ref_affine = affine
          if ref_shape is None:
              ref_shape = shape
  
          if (
              ref_affine is not None
              and abs(affine - ref_affine).max() > INF
          ):
              raise ValueError(
                  "All first level models must have the same affine.\n"
                  f"Model {first_level.subject_label} "
                  f"at index {model_idx} has a different affine "
                  "from the previous ones."
              )
  
          if shape != ref_shape:
              raise ValueError(
                  "All first level models must have the same shape.\n"
                  f"Model {first_level.subject_label} "
                  f"at index {model_idx} has a different shape "
                  "from the previous ones."
              )
  
imports: import sys
  import time
  from warnings import warn
  import numpy
  import pandas
  from joblib import Memory
  from nibabel import Nifti1Image
  from sklearn.base import clone
  from nilearn._utils import fill_doc, stringify_path
  from nilearn._utils.niimg_conversions import check_niimg
  from nilearn.glm._base import BaseGLM
  from nilearn.glm.contrasts import compute_contrast, expression_to_contrast_vector
  from nilearn.glm.first_level import FirstLevelModel, run_glm
  from nilearn.glm.first_level.design_matrix import make_second_level_design_matrix
  from nilearn.glm.regression import RegressionResults, SimpleRegressionResults
  from nilearn.image import mean_img
  from nilearn.maskers import NiftiMasker
  from nilearn.mass_univariate import permuted_ols
label_desc: Use image node_id 7 for calling a global function with example usage: _check_input_as_first_level_model(second_level_input, none_confounds) without return types