def dynamic_sp_comm_view(self, type_viz='consumption', random_state=None): """ Same as :py:meth:`dynamic_view` but the species nodes are grouped by the communities they belong to. Communities are obtained using the Louvain algorithm. Parameters ---------- type_viz: str Type of visualization. It can be `consumption` to see how species are being consumed or `production` to see how the species are being produced. random_state: int Seed used by the random generator in community detection Returns ------- dict A Dictionary Object with all nodes and edges information that can be converted into Cytoscape.js JSON to be visualized """ self.type_viz = type_viz self.sp_graph = PysbStaticViz(self.model).species_graph() hf.add_louvain_communities(self.sp_graph, all_levels=False, random_state=random_state) self.sp_graph.graph['nsims'] = self.nsims self.sp_graph.graph['tspan'] = self.tspan.tolist() self._add_edge_node_dynamics() data = from_networkx(self.sp_graph) return data
def sp_comm_louvain_hierarchy_view(self, random_state=None): """ Use the Louvain algorithm https://en.wikipedia.org/wiki/Louvain_Modularity for community detection to find groups of nodes that are densely connected. It generates the data of all the intermediate clusters obtained during the Louvain algorithm generate to create a network with compound nodes that hold the communities. Parameters ========== random_state : int, optional Random state seed use by the community detection algorithm, by default None Returns ------- dict A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network. """ graph = self.species_graph() hf.add_louvain_communities(graph, all_levels=True, random_state=random_state) data = from_networkx(graph) return data