コード例 #1
0
    def import_nodes(self,
                     nodes_file_name,
                     node_types_file_name,
                     population=None):
        sonata_file = sonata.File(data_files=nodes_file_name,
                                  data_type_files=node_types_file_name)
        if sonata_file.nodes is None:
            raise Exception('nodes file {} does not have any nodes.'.format(
                nodes_file_name))

        populations = sonata_file.nodes.populations
        if len(populations) == 1:
            node_pop = populations[0]
        elif population is None:
            raise Exception('The nodes file {} contains multiple populations.'.
                            format(nodes_file_name) +
                            'Please specify population parameter.')
        else:
            for pop in populations:
                if pop.name == population:
                    node_pop = pop
                    break
            else:
                raise Exception(
                    'Nodes file {} does not contain population {}.'.format(
                        nodes_file_name, population))

        for node_type_props in node_pop.node_types_table:
            self._add_node_type(node_type_props)

        for node in node_pop:
            self._node_id_gen.remove_id(node.node_id)
            self._nodes.append(
                Node(node.node_id, node.group_props,
                     node.node_type_properties))
コード例 #2
0
    def import_nodes(self, nodes_file_name, node_types_file_name):
        nodes_network = TabularNetwork.load_nodes(
            nodes_file=nodes_file_name, node_types_file=node_types_file_name)
        for node_type_id, node_type_props in nodes_network.node_types_table.items(
        ):
            self._add_node_type(node_type_props)

        nodes = []
        for n in nodes_network:
            self._node_id_gen.remove_id(n.gid)
            self._nodes.append(Node(n.gid, n.node_props, n.node_type_props))