Many functions return a 2d list with a complex data type in each cell.
    For instance, grids representing environments have a set of resources,
    while reading in multiple data files at once will yield a list
    containing the values for that cell from each file. In order to visualize
    these data types it is helpful to summarize the more complex data types
    with a single number. For instance, you might want to take the length
    of a resource set to see how many resource types are present. Alternately,
    you might want to take the mode of a list to see the most common phenotype
    in a cell.

    This function facilitates this analysis by calling the given aggregation
    function (agg) on each cell of the given grid and returning the result.

    agg - A function indicating how to summarize grid contents. Default: len.

def agg_grid(grid, agg=None):
    """
    Many functions return a 2d list with a complex data type in each cell.
    For instance, grids representing environments have a set of resources,
    while reading in multiple data files at once will yield a list
    containing the values for that cell from each file. In order to visualize
    these data types it is helpful to summarize the more complex data types
    with a single number. For instance, you might want to take the length
    of a resource set to see how many resource types are present. Alternately,
    you might want to take the mode of a list to see the most common phenotype
    in a cell.

    This function facilitates this analysis by calling the given aggregation
    function (agg) on each cell of the given grid and returning the result.

    agg - A function indicating how to summarize grid contents. Default: len.
    """
    grid = deepcopy(grid)

    if agg is None:
        if type(grid[0][0]) is list and type(grid[0][0][0]) is str:
            agg = string_avg
        else:
            agg = mode

    for i in range(len(grid)):
        for j in range(len(grid[i])):
            grid[i][j] = agg(grid[i][j])

    return grid