

def get_tree_str(f, where='/', max_depth=(- 1), print_class=True, print_size=True, print_percent=True, print_shape=False, print_compression=False, print_total=True, sort_by=None, use_si_units=False):
    '\n    Generate the ASCII string representing the tree structure, and the summary\n    info (if requested)\n    '
    root = f.get_node(where)
    root._g_check_open()
    start_depth = root._v_depth
    if (max_depth < 0):
        max_depth = os.sys.maxint
    b2h = bytes2human(use_si_units)
    total_in_mem = 0
    total_on_disk = 0
    total_items = 0
    in_mem = defaultdict((lambda : 0.0))
    on_disk = defaultdict((lambda : 0.0))
    leaf_count = defaultdict((lambda : 0))
    ref_count = defaultdict((lambda : 0))
    ref_idx = defaultdict((lambda : 0))
    hl_addresses = defaultdict((lambda : None))
    hl_targets = defaultdict((lambda : ''))
    stack = deque(root)
    leaves = deque()
    while stack:
        node = stack.pop()
        if isinstance(node, tables.link.Link):
            leaves.append(node)
            continue
        path = ref_idx._v_pathname
        (addr, rc) = node._get_obj_info()
        ref_count[addr] += 1
        ref_idx[path] = ref_count[addr]
        hl_addresses[path] = addr
        if isinstance(node, tables.Leaf):
            if (ref_count[addr] == 1):
                try:
                    m = node.size_in_memory
                    d = node.size_on_disk
                    in_mem[path] += m
                    on_disk[path] += d
                    leaf_count[path] += 1
                    total_in_mem += m
                    total_on_disk += d
                    total_items += 1
                    hl_targets[addr] = path
                except NotImplementedError as e:
                    warnings.warn(e.message)
            leaves.append(node)
        elif isinstance(node, tables.Group):
            if (ref_count[addr] == 1):
                stack.extend(list(node._v_children.values()))
                hl_targets[addr] = path
            else:
                leaves.append(node)
    pretty = {
        
    }
    stack = leaves
    while stack:
        node = stack.pop()
        path = node._v_pathname
        parent = node._v_parent
        parent_path = parent._v_pathname
        in_mem[parent_path] += in_mem[path]
        on_disk[parent_path] += on_disk[path]
        leaf_count[parent_path] += leaf_count[path]
        depth = (node._v_depth - start_depth)
        if (not (depth > max_depth)):
            name = node._v_name
            if print_class:
                name += (' (%s)' % node.__class__.__name__)
            labels = []
            pct = ((100 * on_disk[path]) / total_on_disk)
            if (ref_count[hl_addresses[path]] > 1):
                name += (', addr=%i, ref=%i/%i' % (hl_addresses[path], ref_idx[path], ref_count[hl_addresses[path]]))
            if isinstance(node, tables.link.Link):
                labels.append(('softlink --> %s' % node.target))
            elif (ref_idx[path] > 1):
                labels.append(('hardlink --> %s' % hl_targets[hl_addresses[path]]))
            elif isinstance(node, (tables.Array, tables.Table)):
                if print_size:
                    sizestr = ('mem=%s, disk=%s' % (b2h(in_mem[path]), b2h(on_disk[path])))
                    if print_percent:
                        sizestr += (' [%4.1f%%]' % pct)
                    labels.append(sizestr)
                if print_shape:
                    labels.append(('shape=%s' % repr(node.shape)))
                if print_compression:
                    lib = node.filters.complib
                    level = node.filters.complevel
                    if level:
                        compstr = ('%s(%i)' % (lib, level))
                    else:
                        compstr = 'None'
                    labels.append(('compression=%s' % compstr))
            elif (depth == max_depth):
                itemstr = ('... %i leaves' % leaf_count[path])
                if print_size:
                    itemstr += (', mem=%s, disk=%s' % (b2h(in_mem[path]), b2h(on_disk[path])))
                if print_percent:
                    itemstr += (' [%4.1f%%]' % pct)
                labels.append(itemstr)
            if (path not in pretty):
                pretty.update({
                    path: PrettyTree(),
                })
            pretty[path].name = name
            pretty[path].labels = labels
            if (sort_by == 'size'):
                pretty[path].sort_by = (- pct)
            elif (sort_by == 'name'):
                pretty[path].sort_by = node._v_name
            elif (path is '/'):
                pretty[path].sort_by = 0
            else:
                pretty[path].sort_by = list(parent._v_children.values()).index(node)
            if (path is not '/'):
                if (parent_path not in pretty):
                    pretty.update({
                        parent_path: PrettyTree(),
                    })
                pretty[parent_path].add_child(pretty[path])
        if ((node is not root) and (parent not in stack)):
            stack.appendleft(parent)
    out_str = (('\n' + ('-' * 60)) + ('\n' * 2))
    out_str += (str(pretty[root._v_pathname]) + ('\n' * 2))
    if print_total:
        avg_ratio = (float(total_on_disk) / total_in_mem)
        fsize = os.stat(f.filename).st_size
        out_str += (('-' * 60) + '\n')
        out_str += ('Total branch leaves:    %i\n' % total_items)
        out_str += ('Total branch size:      %s in memory, %s on disk\n' % (b2h(total_in_mem), b2h(total_on_disk)))
        out_str += ('Mean compression ratio: %.2f\n' % avg_ratio)
        out_str += ('HDF5 file size:         %s\n' % b2h(fsize))
        out_str += (('-' * 60) + '\n')
    return out_str

dataset/ETHPy150Open PyTables/PyTables/tables/scripts/pttree.py get_tree_str/VarMisuse@242/350 `node`->`ref_idx`