code: def write_granular_summary(
      dataset_name: str,
      granular_sections: Dict[
          str, Union[pandas.DataFrame, Dict[str, pandas.DataFrame]]
      ],
      out_dir: str,
  ):
      def _format_section(df):
          return df.rename(columns=COLUMN_RENAMES)[
              ANNOTATION_COLUMN_ORDER
          ]
  
      out_path = os.path.join(
          out_dir, f"{dataset_name}_summary_granular.csv"
      )
      with open(out_path, "w") as f:
          # baselines
          formatted_section = _format_section(
              granular_sections["baselines"]
          )
          f.write(formatted_section.to_csv())
          # ROSCOE scores, by section
          for section in (
              "ROSCOE-SA",
              "ROSCOE-SS",
              "ROSCOE-LI",
              "ROSCOE-LC",
          ):
              if section in {"ROSCOE-SA", "ROSCOE-SS"}:
                  for model in MODELS:
                      formatted_section = _format_section(
                          granular_sections[section][model].loc[
                              ROSCOE_SECTIONS[section]
                          ]
                      )
                      f.write(f"{section} - {model}\n")
                      f.write(formatted_section.to_csv(header=False))
              else:
                  formatted_section = _format_section(
                      granular_sections[section].loc[
                          ROSCOE_SECTIONS[section]
                      ]
                  )
                  f.write(f"{section}\n")
                  f.write(formatted_section.to_csv(header=False))
  
      print(
          f"Granular summary of {dataset_name} written to: {out_path}"
      )
  
imports: import argparse
  from collections import defaultdict
  import csv
  import math
  import os
  import pathlib
  from typing import Dict, Iterable, List, Optional, Set, Tuple, Union
  import pandas
  from projects.roscoe.meta_evaluation.correlations import Analyzer
  from projects.roscoe.score import ROSCOE_SA, ROSCOE_SS, ROSCOE_LI, ROSCOE_LC, SUPERVISED_SCORES, UNSUPERVISED_SCORES
  from projects.roscoe.utils import assert_all_elements_same_length, ordered_union, split_list
  from projects.roscoe.meta_evaluation.table_file_writing import ANNOTATION_COLUMN_ORDER, COLUMN_RENAMES, MODELS, ROSCOE_SECTIONS, STEP_COLUMN_RENAMES, section_rows, write_every_dataset_summary_table_tex, write_every_dataset_final_summary_table_tex, write_granular_summary_tex
label_desc: Use image node_id 26 for calling a global function with example usage: write_granular_summary(dataset_name, granular_sections, out_dir) and returns: df