Renumbering nodes in the network
In several circumstances it might be necessary to renumber the nodes in the network entirely or a sub-set of them.
The renumberNodes() method allows to undertake this operation, requiring the following arguments:
- The network name (for example, stored in the variable named network_name), after connecting to the database (db).
- The list of current node numbers.
- The list of new node numbers in the same sequence.
The below script provides and example when passing a subset
of existing nodes for renumbering, and obtaining the full list through a Python
dictionary.
current_node_numbers = [1, 2, 3, 4, 5, 6, 7] new_node_numbers = [7, 6, 5, 4, 3, 2, 1] nodes_renum_dict = dict() for node_old, node_new in zip(current_node_numbers, new_node_numbers): nodes_renum_dict[node_old] = node_new lua_expr = "value(node.n)" current_nodes = db.valueForNodes(network_name, lua_expr) current_nodes_list = [] new_nodes_list = [] for node in current_nodes: current_nodes_list.append(node.n) try: new_nodes_list.append(nodes_renum_dict[node.n]) except: # in case of error, when the key is not in the dictionary new_nodes_list.append(node.n) # uses the current node number db.renumberNodes(network_name, current_nodes_list, new_nodes_list)
When using this method, the user should consider that the network will be modified and saved with the new numbering pattern.