def dump_tables_to_tskit(pop):
node_view = np.array(pop.tables.nodes, copy=True)<EOL>node_view['<STR_LIT:time>'] -= node_view['<STR_LIT:time>'].max()<EOL>node_view['<STR_LIT:time>'][np.where(node_view['<STR_LIT:time>'] != <NUM_LIT:0.0>)[<NUM_LIT:0>]] *= -<NUM_LIT:1.0><EOL>edge_view = np.array(pop.tables.edges, copy=False)<EOL>mut_view = np.array(pop.tables.mutations, copy=False)<EOL>tc = tskit.TableCollection(pop.tables.genome_length)<EOL>_initializePopulationTable(node_view, tc)<EOL>node_to_individual = _initializeIndividualTable(pop, tc)<EOL>individual = [-<NUM_LIT:1> for i in range(len(node_view))]<EOL>for k, v in node_to_individual.items():<EOL><INDENT>individual[k] = v<EOL><DEDENT>flags = [<NUM_LIT:1>]*<NUM_LIT:2>*pop.N + [<NUM_LIT:0>]*(len(node_view) - <NUM_LIT:2>*pop.N)<EOL>for i in pop.tables.preserved_nodes:<EOL><INDENT>flags[i] = <NUM_LIT:1><EOL><DEDENT>tc.nodes.set_columns(flags=flags, time=node_view['<STR_LIT:time>'],<EOL>population=node_view['<STR_LIT>'],<EOL>individual=individual)<EOL>tc.edges.set_columns(left=edge_view['<STR_LIT:left>'],<EOL>right=edge_view['<STR_LIT:right>'],<EOL>parent=edge_view['<STR_LIT>'],<EOL>child=edge_view['<STR_LIT>'])<EOL>mpos = np.array([pop.mutations[i].pos for i in mut_view['<STR_LIT:key>']])<EOL>ancestral_state = np.zeros(len(mut_view), dtype=np.int8)+ord('<STR_LIT:0>')<EOL>ancestral_state_offset = np.arange(len(mut_view)+<NUM_LIT:1>, dtype=np.uint32)<EOL>tc.sites.set_columns(position=mpos,<EOL>ancestral_state=ancestral_state,<EOL>ancestral_state_offset=ancestral_state_offset)<EOL>derived_state = np.zeros(len(mut_view), dtype=np.int8)+ord('<STR_LIT:1>')<EOL>md, mdo = _generate_mutation_metadata(pop)<EOL>tc.mutations.set_columns(site=np.arange(len(mpos), dtype=np.int32),<EOL>node=mut_view['<STR_LIT>'],<EOL>derived_state=derived_state,<EOL>derived_state_offset=ancestral_state_offset,<EOL>metadata=md,<EOL>metadata_offset=mdo)<EOL>return tc.tree_sequence()<EOL>
Converts fwdpy11.TableCollection to an
tskit.TreeSequence