1
1
#
2
2
# MIT License
3
3
#
4
- # Copyright (c) 2018-2023 Tskit Developers
4
+ # Copyright (c) 2018-2024 Tskit Developers
5
5
# Copyright (c) 2017 University of Oxford
6
6
#
7
7
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -3368,7 +3368,7 @@ def simplify(
3368
3368
function and ``u`` is the ID of a node in the input table, then
3369
3369
``a[u]`` is the ID of this node in the output table. For any node ``u``
3370
3370
that is not mapped into the output tables, this mapping will equal
3371
- ``-1``.
3371
+ ``tskit.NULL`` (`` -1``) .
3372
3372
3373
3373
Tables operated on by this function must: be sorted (see
3374
3374
:meth:`TableCollection.sort`), have children be born strictly after their
@@ -3377,6 +3377,18 @@ def simplify(
3377
3377
requirements to specify a valid tree sequence (but the resulting tables
3378
3378
will).
3379
3379
3380
+ .. note::
3381
+ To invert the returned ``node_map``, that is, to obtain a reverse
3382
+ mapping from the node ID in the output table to the node ID in
3383
+ the input table, you can use::
3384
+
3385
+ rev_map = np.zeros_like(node_map, shape=simplified_ts.num_nodes)
3386
+ kept = node_map != tskit.NULL
3387
+ rev_map[node_map[kept]] = np.arange(len(node_map))[kept]
3388
+
3389
+ In this case, no elements of the ``rev_map`` array will be set to
3390
+ ``tskit.NULL``.
3391
+
3380
3392
.. seealso::
3381
3393
This is identical to :meth:`TreeSequence.simplify` but acts *in place* to
3382
3394
alter the data in this :class:`TableCollection`. Please see the
0 commit comments