Esempio n. 1
0
    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
Esempio n. 2
0
    def dynamic_sp_view(self, type_viz='consumption'):
        """
        Generates a dictionary with the model dynamics data that can be converted in the Cytoscape.js JSON format

        Parameters
        ----------
        type_viz : str
            Type of the dynamic visualization, it can be 'consumption' or 'production'

        Examples
        --------
        >>> from pysb.examples.earm_1_0 import model
        >>> from pysb.simulator import ScipyOdeSimulator
        >>> import pyvipr.pysb_viz.dynamic_viz as viz
        >>> import numpy as np
        >>> tspan = np.linspace(0, 20000)
        >>> sim = ScipyOdeSimulator(model, tspan).run()
        >>> dyn_viz = viz.PysbDynamicViz(sim)
        >>> data = dyn_viz.dynamic_sp_view()

        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()
        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
Esempio n. 3
0
    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
Esempio n. 4
0
    def dynamic_sp_comp_view(self, type_viz='consumption'):
        """
        Same as :py:meth:`dynamic_view` but the species nodes are grouped
        by the compartments they belong to

        """
        self.type_viz = type_viz
        self.sp_graph = PysbStaticViz(self.model).compartments_data_graph()
        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
Esempio n. 5
0
    def sp_view(self):
        """
        Generate a dictionary that contains the species network information

        Returns
        -------
        dict
            A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary
            contains all the information (nodes,edges, positions) to generate a cytoscapejs network.
        """
        graph = self.species_graph()
        data = from_networkx(graph)
        return data
Esempio n. 6
0
    def nx_function_view(self, nx_function, **kwargs):

        self.network.graph['name'] = ''
        result = nx_function(self.network, **kwargs)
        if nx_function.__name__ == 'girvan_newman':
            top_level_communities = next(result)
        else:
            top_level_communities = result

        top_level_communities = {
            idx: 'c_{0}'.format(comm)
            for comm, nodes in enumerate(top_level_communities)
            for idx in nodes
        }
        cnodes = set(top_level_communities.values())

        self.network.add_nodes_from(cnodes, NodeType='community')
        nx.set_node_attributes(self.network, top_level_communities, 'parent')
        json = from_networkx(self.network)
        return json
Esempio n. 7
0
    def dynamic_sp_view(self, type_viz='consumption'):
        """
        Generates a dictionary with the model dynamics data that can be converted in the Cytoscape.js JSON format

        Parameters
        ----------
        type_viz : str
            Type of the dynamic visualization, it can be 'consumption' or 'production'

        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 = TelluriumStaticViz(self.model).species_graph()
        self.sp_graph.graph['nsims'] = 1
        self.sp_graph.graph['tspan'] = self.y['time'].tolist()
        self._add_edge_node_dynamics()
        data = from_networkx(self.sp_graph)
        return data
Esempio n. 8
0
 def sp_comm_asyn_fluidc_view(self, k, max_iter=100, seed=None):
     graph = self.species_graph()
     hf.add_asyn_fluidc(graph, k, max_iter, seed)
     data = from_networkx(graph)
     return data
Esempio n. 9
0
 def sp_comm_girvan_newman_view(self):
     graph = self.species_graph()
     hf.add_girvan_newman(graph)
     data = from_networkx(graph)
     return data
Esempio n. 10
0
 def sp_comm_label_propagation_view(self):
     graph = self.species_graph()
     hf.add_label_propagation_communities(graph)
     data = from_networkx(graph)
     return data
Esempio n. 11
0
 def sp_comm_asyn_lpa_view(self, random_state=None):
     graph = self.species_graph()
     hf.add_asyn_lpa_communities(graph, seed=random_state)
     data = from_networkx(graph)
     return data
Esempio n. 12
0
 def sp_comm_greedy_view(self):
     graph = self.species_graph()
     hf.add_greedy_modularity_communities(graph)
     data = from_networkx(graph)
     return data
Esempio n. 13
0
 def network_static_view(self):
     self.network.graph['name'] = ''
     json = from_networkx(self.network)
     return json
Esempio n. 14
0
 def dynamic_network_view(self):
     # This is necessary because the javascript part chooses to render
     # a static or dynamic visualization depending on the name
     # of the function.
     data = from_networkx(self.network)
     return data