code: def granular_summary(
      correls_by_model: Dict[str, pandas.DataFrame],
      pvals_by_model: Dict[str, pandas.DataFrame],
  ):
      columns = [
          "newOverall",
          "newCoherent",
          "any_newExtraUselessInfo",
          "any_newIntermediateFactualInfo",
          "any_newDroppableStep",
          "newMissingStep",
          "any_newContradictContext",
          "any_newWorldKnowledge",
          "any_newLogicalDeduction",
          "any_newMathError",
          "any_newGrammar",
      ]
  
      summary_sections = {}
      pval_sections = {}
      for model, correls_df in correls_by_model.items():
          seq_lvl_columns = correls_df[columns]
          pval_seq_lvl_columns = pvals_by_model[model][columns]
  
          baseline_score_names = (
              EXTRA_REPORTED_BASELINES + REPORTED_BASELINES
          )
          summary_sections["baselines"] = seq_lvl_columns.loc[
              baseline_score_names
          ].astype(float)
          pval_sections["baselines"] = pval_seq_lvl_columns.loc[
              baseline_score_names
          ]
  
          data = []
          row_titles = []
          for agg_score, group_scores in ROSCOE_SECTIONS.items():
              # some models don't have all scores; don't use those to aggregate
              if not all(
                  g in seq_lvl_columns[c]
                  for g in group_scores
                  for c in columns
              ):
                  continue
  
              group_scores_df = seq_lvl_columns.loc[
                  group_scores
              ].astype(float)
              sig_group_scores_df = group_scores_df[
                  pval_seq_lvl_columns.loc[group_scores] < 0.05
              ]
  
              # get aggregate score correlation per annotation
              group_summary_correlations = (
                  sig_group_scores_df.max().tolist()
              )
              data.append(group_summary_correlations)
              row_titles.append(agg_score)
  
              for score in group_scores:
                  if score in row_titles:
                      continue
                  data.append(group_scores_df.loc[score].tolist())
                  row_titles.append(score)
  
          model_df = pandas.DataFrame(
              data=data,
              index=row_titles,
              columns=columns,
          )
  
          for emb_section in ("ROSCOE-SA", "ROSCOE-SS"):
              section_df = model_df.loc[section_rows(emb_section)]
              if emb_section not in summary_sections:
                  summary_sections[emb_section] = {}
                  pval_sections[emb_section] = {}
              summary_sections[emb_section][model] = section_df
              pval_sections[emb_section][
                  model
              ] = pval_seq_lvl_columns.loc[ROSCOE_SECTIONS[emb_section]]
  
          summary_sections["ROSCOE-LI"] = model_df.loc[
              section_rows("ROSCOE-LI")
          ]
          pval_sections["ROSCOE-LI"] = pval_seq_lvl_columns.loc[
              ROSCOE_SECTIONS["ROSCOE-LI"]
          ]
          summary_sections["ROSCOE-LC"] = model_df.loc[
              section_rows("ROSCOE-LC")
          ]
          pval_sections["ROSCOE-LC"] = pval_seq_lvl_columns.loc[
              ROSCOE_SECTIONS["ROSCOE-LC"]
          ]
  
      return summary_sections, pval_sections
  
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 25 for calling a global function with example usage: granular_summary(correls_by_model, pvals_by_model) and returns: summary_sections,  pval_sections