11#
22# MIT License
33#
4- # Copyright (c) 2018-2023 Tskit Developers
4+ # Copyright (c) 2018-2024 Tskit Developers
55# Copyright (c) 2017 University of Oxford
66#
77# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -3368,7 +3368,7 @@ def simplify(
33683368 function and ``u`` is the ID of a node in the input table, then
33693369 ``a[u]`` is the ID of this node in the output table. For any node ``u``
33703370 that is not mapped into the output tables, this mapping will equal
3371- ``-1``.
3371+ ``tskit.NULL`` (`` -1``) .
33723372
33733373 Tables operated on by this function must: be sorted (see
33743374 :meth:`TableCollection.sort`), have children be born strictly after their
@@ -3377,6 +3377,18 @@ def simplify(
33773377 requirements to specify a valid tree sequence (but the resulting tables
33783378 will).
33793379
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+
33803392 .. seealso::
33813393 This is identical to :meth:`TreeSequence.simplify` but acts *in place* to
33823394 alter the data in this :class:`TableCollection`. Please see the
0 commit comments