def node_time_depth(tree, min_branch_length=None, max_tree_height='tree'):
    '\n    Returns a dictionary mapping nodes in the specified tree to their depth\n    in the specified tree (from the root direction). If min_branch_len is\n    provided, it specifies the minimum length of each branch. If not specified,\n    default to 1.\n    '
    if (min_branch_length is None):
        min_branch_length = {u: 1 for u in range(tree.tree_sequence.num_nodes)}
    time_node_map = collections.defaultdict(list)
    current_depth = 0
    depth = {}
    if (max_tree_height == 'tree'):
        for u in tree.nodes():
            time_node_map[tree.time(u)].append(u)
        for t in sorted(time_node_map.keys()):
            for u in time_node_map[t]:
                for v in tree.children(u):
                    current_depth = max(current_depth, (depth[v] + min_branch_length[v]))
            for u in time_node_map[t]:
                depth[u] = current_depth
            current_depth += 2
        for root in tree.roots:
            current_depth = max(current_depth, (depth[root] + min_branch_length[root]))
    else:
        assert (max_tree_height == 'ts')
        ts = tree.tree_sequence
        for node in ts.nodes():
            time_node_map[node.time].append(node.id)
        node_edges = collections.defaultdict(list)
        for edge in ts.edges():
            node_edges[edge.parent].append(edge)
        for t in sorted(time_node_map.keys()):
            for u in time_node_map[t]:
                for edge in node_edges[u]:
                    v = edge.child
                    current_depth = max(current_depth, (depth[v] + min_branch_length[v]))
            for u in time_node_map[t]:
                depth[u] = current_depth
            current_depth += 2
    return (depth, current_depth)
Returns a dictionary mapping nodes in the specified tree to their depth
in the specified tree (from the root direction). If min_branch_len is
provided, it specifies the minimum length of each branch. If not specified,
default to 1.
def node_time_depth(tree, min_branch_length=None, max_tree_height='tree'):
    '\n    Returns a dictionary mapping nodes in the specified tree to their depth\n    in the specified tree (from the root direction). If min_branch_len is\n    provided, it specifies the minimum length of each branch. If not specified,\n    default to 1.\n    '
    if (min_branch_length is None):
        min_branch_length = {u: 1 for u in range(tree.tree_sequence.num_nodes)}
    time_node_map = collections.defaultdict(list)
    current_depth = 0
    depth = {}
    if (max_tree_height == 'tree'):
        for u in tree.nodes():
            time_node_map[tree.time(u)].append(u)
        for t in sorted(time_node_map.keys()):
            for u in time_node_map[t]:
                for v in tree.children(u):
                    current_depth = max(current_depth, (depth[v] + min_branch_length[v]))
            for u in time_node_map[t]:
                depth[u] = current_depth
            current_depth += 2
        for root in tree.roots:
            current_depth = max(current_depth, (depth[root] + min_branch_length[root]))
    else:
        assert (max_tree_height == 'ts')
        ts = tree.tree_sequence
        for node in ts.nodes():
            time_node_map[node.time].append(node.id)
        node_edges = collections.defaultdict(list)
        for edge in ts.edges():
            node_edges[edge.parent].append(edge)
        for t in sorted(time_node_map.keys()):
            for u in time_node_map[t]:
                for edge in node_edges[u]:
                    v = edge.child
                    current_depth = max(current_depth, (depth[v] + min_branch_length[v]))
            for u in time_node_map[t]:
                depth[u] = current_depth
            current_depth += 2
    return (depth, current_depth)