def percolation_graph(graph, spanning_cluster=True):
ret = dict()<EOL>ret['<STR_LIT>'] = graph<EOL>ret['<STR_LIT>'] = bool(spanning_cluster)<EOL>if spanning_cluster:<EOL><INDENT>spanning_auxiliary_node_attributes = nx.get_node_attributes(<EOL>graph, '<STR_LIT>'<EOL>)<EOL>ret['<STR_LIT>'] = spanning_auxiliary_node_attributes<EOL>auxiliary_nodes = spanning_auxiliary_node_attributes.keys()<EOL>if not list(auxiliary_nodes):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>spanning_sides = list(set(spanning_auxiliary_node_attributes.values()))<EOL>if len(spanning_sides) != <NUM_LIT:2>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>ret['<STR_LIT>'] = spanning_sides<EOL>ret['<STR_LIT>'] = nx.get_edge_attributes(<EOL>graph, '<STR_LIT>'<EOL>)<EOL><DEDENT>if spanning_cluster:<EOL><INDENT>perc_graph = graph.subgraph(<EOL>[<EOL>node for node in graph.nodes_iter()<EOL>if '<STR_LIT>' not in graph.node[node]<EOL>]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>perc_graph = graph<EOL><DEDENT>ret['<STR_LIT>'] = perc_graph<EOL>ret['<STR_LIT>'] = nx.number_of_nodes(perc_graph)<EOL>ret['<STR_LIT>'] = nx.number_of_edges(perc_graph)<EOL>return ret<EOL>
Prepare the (internal) percolation graph from a given graph

Helper function to prepare the given graph for spanning cluster detection
(if required).
Basically it strips off the auxiliary nodes and edges again.
It also returns fundamental graph quantitities (number of nodes and edges).

Parameters
----------
graph
spanning_cluster

Returns
-------
ret : tuple