@@ -2101,7 +2101,7 @@ def get_num_tracked_samples(self, u=None):
2101
2101
2102
2102
def num_tracked_samples (self , u = None ):
2103
2103
"""
2104
- Returns the number of samples in the set specified in the
2104
+ Returns the numpy of samples in the set specified in the
2105
2105
``tracked_samples`` parameter of the :meth:`TreeSequence.trees` method
2106
2106
underneath the specified node. If the input node is not specified,
2107
2107
return the total number of tracked samples in the tree.
@@ -2116,15 +2116,51 @@ def num_tracked_samples(self, u=None):
2116
2116
u = self .virtual_root if u is None else u
2117
2117
return self ._ll_tree .get_num_tracked_samples (u )
2118
2118
2119
- # TODO document these traversal arrays
2120
- # https://github.com/tskit-dev/tskit/issues/1788
2121
2119
def preorder (self , u = NULL ):
2120
+ """
2121
+ Returns a numpy array of node ids in preorder
2122
+ <https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)>. If the node u
2123
+ is specified the traversal is rooted at this node (and it will be the first
2124
+ element in the returned array). Otherwise, all nodes reachable from the tree
2125
+ roots will be returned. See :ref:tutorials:sec_analysing_trees_traversals for
2126
+ examples.
2127
+
2128
+ :param int u: If specified, return all nodes in the subtree rooted at u
2129
+ (including u) in traversal order.
2130
+ :return: Array of node ids
2131
+ :rtype: numpy.ndarray (dtype=np.int32)
2132
+ """
2122
2133
return self ._ll_tree .get_preorder (u )
2123
2134
2124
2135
def postorder (self , u = NULL ):
2136
+ """
2137
+ Returns a numpy array of node ids in postorder
2138
+ <https://en.wikipedia.org/wiki/Tree_traversal##Post-order_(LRN)>. If the node u
2139
+ is specified the traversal is rooted at this node (and it will be the first
2140
+ element in the returned array). Otherwise, all nodes reachable from the tree
2141
+ roots will be returned. See :ref:tutorials:sec_analysing_trees_traversals for
2142
+ examples.
2143
+
2144
+ :param int u: If specified, return all nodes in the subtree rooted at u
2145
+ (including u) in traversal order.
2146
+ :return: Array of node ids
2147
+ :rtype: numpy.ndarray (dtype=np.int32)
2148
+ """
2125
2149
return self ._ll_tree .get_postorder (u )
2126
2150
2127
2151
def timeasc (self , u = NULL ):
2152
+ """
2153
+ Returns a numpy array of node ids. Starting at `u`, returns the reachable
2154
+ descendant nodes in order of increasing time (most recent first), falling back
2155
+ to increasing ID if times are equal. Also see
2156
+ :ref:`tutorials:sec_analysing_trees_traversals` for examples of how to use
2157
+ traversals.
2158
+
2159
+ :param int u: If specified, return all nodes in the subtree rooted at u
2160
+ (including u) in traversal order.
2161
+ :return: Array of node ids
2162
+ :rtype: numpy.ndarray (dtype=np.int32)
2163
+ """
2128
2164
nodes = self .preorder (u )
2129
2165
is_virtual_root = u == self .virtual_root
2130
2166
time = self .tree_sequence .tables .nodes .time
@@ -2138,6 +2174,18 @@ def timeasc(self, u=NULL):
2138
2174
return nodes [order ]
2139
2175
2140
2176
def timedesc (self , u = NULL ):
2177
+ """
2178
+ Returns a numpy array of node ids. Starting at `u`, returns the reachable
2179
+ descendant nodes in order of decreasing time (least recent first), falling back
2180
+ to decreasing ID if times are equal. Also see
2181
+ :ref:`tutorials:sec_analysing_trees_traversals` for examples of how to use
2182
+ traversals.
2183
+
2184
+ :param int u: If specified, return all nodes in the subtree rooted at u
2185
+ (including u) in traversal order.
2186
+ :return: Array of node ids
2187
+ :rtype: numpy.ndarray (dtype=np.int32)
2188
+ """
2141
2189
return self .timeasc (u )[::- 1 ]
2142
2190
2143
2191
def _preorder_traversal (self , root ):
0 commit comments