code: def _generate_model_metadata(out_file, model):
      """Generate a sidecar JSON file containing model metadata.
  
      .. versionadded:: 0.9.2
  
      Parameters
      ----------
      out_file : :obj:`str`
          Output JSON filename, to be created by the function.
      model : :obj:`~nilearn.glm.first_level.FirstLevelModel` or
              :obj:`~nilearn.glm.second_level.SecondLevelModel`
          First- or second-level model from which to save outputs.
      """
      # Define which FirstLevelModel attributes are BIDS compliant and which
      # should be bundled in a new "ModelParameters" field.
      DATA_ATTRIBUTES = [
          "t_r",
      ]
      PARAMETER_ATTRIBUTES = [
          "drift_model",
          "hrf_model",
          "standardize",
          "high_pass",
          "target_shape",
          "signal_scaling",
          "drift_order",
          "scaling_axis",
          "smoothing_fwhm",
          "target_affine",
          "slice_time_ref",
          "fir_delays",
      ]
      ATTRIBUTE_RENAMING = {
          "t_r": "RepetitionTime",
      }
  
      # Fields for the top level of the dictionary
      DATA_ATTRIBUTES.sort()
      data_attributes = {
          attr_name: getattr(model, attr_name)
          for attr_name in DATA_ATTRIBUTES
          if hasattr(model, attr_name)
      }
      data_attributes = {
          ATTRIBUTE_RENAMING.get(k, k): v
          for k, v in data_attributes.items()
      }
  
      # Fields for a nested section of the dictionary
      # The ModelParameters field is an ad-hoc way to retain useful info.
      PARAMETER_ATTRIBUTES.sort()
      model_attributes = {
          attr_name: getattr(model, attr_name)
          for attr_name in PARAMETER_ATTRIBUTES
          if hasattr(model, attr_name)
      }
      model_attributes = {
          ATTRIBUTE_RENAMING.get(k, k): v
          for k, v in model_attributes.items()
      }
  
      model_metadata = {
          "Description": "A statistical map generated by Nilearn.",
          **data_attributes,
          "ModelParameters": model_attributes,
      }
  
      with open(out_file, "w") as f_obj:
          json.dump(model_metadata, f_obj, indent=4, sort_keys=True)
  
file_path: nilearn/nilearn/interfaces/bids/glm.py
imports: import json
  import os
  import warnings
  import numpy
  from nilearn import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: _generate_model_metadata(out_file, model) without return types