def _get_table_counts(sheet, num_section):
    """
    Loop through sheet metadata and count how many of each table type is needed at each index.
    Example: 'paleo 1' needs {'2 measurement tables', '1 model table, with 1 summary, 1 ensemble, and 3 distributions'}
    :param dict sheet: Sheet metadata
    :param dict num_section: Rolling number counts of table types for each index.
    :return:
    """
    tt = sheet["table_type"]
    idx_pc = sheet["idx_pc"]
    idx_table = sheet["idx_table"]
    idx_model = sheet["idx_model"]

    # Have we started counters for this idx model yet??
    if idx_pc not in num_section:
        # No, create the counters and start tracking table counts
        num_section[idx_pc] = {"ct_meas": 0, "ct_model": 0, "ct_in_model": {}}

    # Compare indices to get the highest index number for this table type
    # If we have a higher number model index, then increment out models count

    try:
        # Is this a ens, dist, or summary table?
        if idx_model:
            # Yes it is.

            # Is this model idx higher than ours?
            if idx_model > num_section[idx_pc]["ct_model"]:
                # Yes. Now, we have N number of model tables.
                num_section[idx_pc]["ct_model"] = idx_model

            # Have we started counters for this idx model yet??
            if idx_model not in num_section[idx_pc]["ct_in_model"]:
                # No, create the counters and start tracking table counts.
                num_section[idx_pc]["ct_in_model"][idx_model] = {"ct_ens": 0, "ct_sum": 0, "ct_dist": 0}
    except Exception as e:
        logger_excel.debug("excel: get_table_counts: error incrementing model counts, ".format(e))

    # Incrementer!
    # For the given table type, track the highest index number.
    # That number is how many tables we need to make of that type.  Ex. 'measurement4', we need to make 4 empty tables
    try:
        if tt == "measurement":
            # Is this meas table a higher idx?
            if idx_table > num_section[idx_pc]["ct_meas"]:
                # Yes, set this idx to the counter.
                num_section[idx_pc]["ct_meas"] = idx_table
        elif tt == "distribution":
            # Is this dist table a higher idx?
            if idx_table > num_section[idx_pc]["ct_in_model"][idx_model]["ct_dist"]:
                # Yes, set this idx to the counter.
                num_section[idx_pc]["ct_in_model"][idx_model]["ct_dist"] = idx_table
        elif tt == "summary":
            # Summary tables are not indexed. Only one per table.
            num_section[idx_pc]["ct_in_model"][idx_model]["ct_sum"] = 1
        elif tt == "ensemble":
            # Ensemble tables are not indexed. Only one per table.
            num_section[idx_pc]["ct_in_model"][idx_model]["ct_ens"] = 1
    except Exception as e:
        logger_excel.debug("excel: get_table_counts: error incrementing table count".format(e))

    return num_section