bmtool 0.7.0.6.4__py3-none-any.whl → 0.7.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bmtool/debug/commands.py CHANGED
@@ -1,14 +1,20 @@
1
- import click
2
- import logging
3
1
  import os
4
2
 
5
- from clint.textui import puts, colored, indent
3
+ import click
4
+ from clint.textui import colored
5
+
6
6
 
7
- @click.group('debug')
8
- @click.option('-c', '--config', type=click.Path(), default='./simulation_config.json', help='Configuration file to use, default: "simulation_config.json"')
7
+ @click.group("debug")
8
+ @click.option(
9
+ "-c",
10
+ "--config",
11
+ type=click.Path(),
12
+ default="./simulation_config.json",
13
+ help='Configuration file to use, default: "simulation_config.json"',
14
+ )
9
15
  @click.pass_context
10
16
  def cli(ctx, config, no_display):
11
- config_path = os.path.abspath(os.path.expanduser(config)).replace("\\","/")
17
+ config_path = os.path.abspath(os.path.expanduser(config)).replace("\\", "/")
12
18
 
13
19
  if not os.path.exists(config_path):
14
20
  click.echo(colored.red("Config file not found: " + config))
@@ -17,4 +23,4 @@ def cli(ctx, config, no_display):
17
23
 
18
24
 
19
25
  if __name__ == "__main__":
20
- cli()
26
+ cli()
bmtool/debug/debug.py CHANGED
@@ -7,6 +7,6 @@ python -m bmtool.debug
7
7
 
8
8
  """
9
9
 
10
- if __name__ == '__main__':
10
+ if __name__ == "__main__":
11
11
  parser = util.get_argparse(use_description)
12
- util.verify_parse(parser)
12
+ util.verify_parse(parser)
bmtool/graphs.py CHANGED
@@ -1,13 +1,13 @@
1
1
  import networkx as nx
2
2
  import pandas as pd
3
+
3
4
  import bmtool.util.util as u
4
- import pandas as pd
5
5
 
6
6
 
7
7
  def generate_graph(config, source, target):
8
8
  """
9
9
  Generate a NetworkX graph from BMTK network configuration.
10
-
10
+
11
11
  Parameters:
12
12
  -----------
13
13
  config : str
@@ -16,14 +16,14 @@ def generate_graph(config, source, target):
16
16
  Network name for source nodes.
17
17
  target : str
18
18
  Network name for target nodes.
19
-
19
+
20
20
  Returns:
21
21
  --------
22
22
  nx.DiGraph
23
- A directed graph representing the network with nodes containing
23
+ A directed graph representing the network with nodes containing
24
24
  position and population information.
25
25
  """
26
- nodes,edges = u.load_nodes_edges_from_config(config)
26
+ nodes, edges = u.load_nodes_edges_from_config(config)
27
27
  nodes_source = nodes[source]
28
28
  nodes_target = nodes[target]
29
29
  if source != target:
@@ -31,7 +31,7 @@ def generate_graph(config, source, target):
31
31
  nodes = pd.concat([nodes_source, nodes_target])
32
32
  else:
33
33
  nodes = nodes[source]
34
- edge_to_grap = source+"_to_"+target
34
+ edge_to_grap = source + "_to_" + target
35
35
  edges = edges[edge_to_grap]
36
36
 
37
37
  # Create an empty graph
@@ -39,14 +39,19 @@ def generate_graph(config, source, target):
39
39
 
40
40
  # Add nodes to the graph with their positions and labels
41
41
  for index, node_data in nodes.iterrows():
42
- G.add_node(index, pos=(node_data['pos_x'], node_data['pos_y'], node_data['pos_z']), label=node_data['pop_name'])
42
+ G.add_node(
43
+ index,
44
+ pos=(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"]),
45
+ label=node_data["pop_name"],
46
+ )
43
47
 
44
48
  # Add edges to the graph
45
49
  for _, row in edges.iterrows():
46
- G.add_edge(row['source_node_id'], row['target_node_id'])
50
+ G.add_edge(row["source_node_id"], row["target_node_id"])
47
51
 
48
52
  return G
49
53
 
54
+
50
55
  # import plotly.graph_objects as go
51
56
  # def plot_graph(Graph=None,show_edges = False,title = None):
52
57
  # """
@@ -54,7 +59,7 @@ def generate_graph(config, source, target):
54
59
  # Graph: A Graph object
55
60
  # show_edges: Boolean to show edges in graph plot
56
61
  # title: A string for the title of the graph
57
-
62
+
58
63
  # """
59
64
 
60
65
  # # Extract node positions
@@ -120,7 +125,7 @@ def generate_graph(config, source, target):
120
125
 
121
126
  # if title == None:
122
127
  # title = '3D plot'
123
-
128
+
124
129
  # fig = go.Figure(data=graph_prop,
125
130
  # layout=go.Layout(
126
131
  # title=title,
@@ -144,19 +149,19 @@ def generate_graph(config, source, target):
144
149
  def export_node_connections_to_csv(Graph, filename):
145
150
  """
146
151
  Generate a CSV file with node type and all incoming connections that node has.
147
-
152
+
148
153
  Parameters:
149
154
  -----------
150
155
  Graph : nx.DiGraph
151
156
  A directed graph object from NetworkX.
152
157
  filename : str
153
158
  Path and filename for the output CSV file (must end in .csv).
154
-
159
+
155
160
  Returns:
156
161
  --------
157
162
  None
158
163
  The function saves the results to the specified CSV file.
159
-
164
+
160
165
  Notes:
161
166
  ------
162
167
  The resulting CSV file will have the node label as the first column,
@@ -169,18 +174,20 @@ def export_node_connections_to_csv(Graph, filename):
169
174
  for node in Graph.nodes():
170
175
  # Initialize a dictionary to store the outgoing connections for the current node
171
176
  connections = {}
172
- node_label = Graph.nodes[node]['label']
177
+ node_label = Graph.nodes[node]["label"]
173
178
 
174
179
  # Iterate over each presuccessor (ingoing neighbor) of the current node
175
180
  for successor in Graph.predecessors(node):
176
181
  # Get the label of the successor node
177
- successor_label = Graph.nodes[successor]['label']
182
+ successor_label = Graph.nodes[successor]["label"]
178
183
 
179
184
  # Increment the connection count for the current node and successor label
180
- connections[f'{successor_label} incoming Connections'] = connections.get(f'{successor_label} incoming Connections', 0) + 1
185
+ connections[f"{successor_label} incoming Connections"] = (
186
+ connections.get(f"{successor_label} incoming Connections", 0) + 1
187
+ )
181
188
 
182
189
  # Add the connections information for the current node to the dictionary
183
- connections['Node Label'] = node_label
190
+ connections["Node Label"] = node_label
184
191
  node_connections[node] = connections
185
192
 
186
193
  # Convert the dictionary to a DataFrame
@@ -188,8 +195,8 @@ def export_node_connections_to_csv(Graph, filename):
188
195
 
189
196
  # Reorder columns so that 'Node Label' is the leftmost column
190
197
  cols = df.columns.tolist()
191
- cols = ['Node Label'] + [col for col in cols if col != 'Node Label']
198
+ cols = ["Node Label"] + [col for col in cols if col != "Node Label"]
192
199
  df = df[cols]
193
200
 
194
201
  # Write the DataFrame to a CSV file
195
- df.to_csv(filename)
202
+ df.to_csv(filename)
bmtool/manage.py CHANGED
@@ -1,22 +1,17 @@
1
1
  import click
2
- import logging
3
- import os
2
+ from clint.textui import colored
4
3
 
5
- from clint.textui import puts, colored, indent
6
-
7
- from .debug import commands as debug_commands
8
4
  from . import plot_commands
5
+ from .debug import commands as debug_commands
9
6
  from .util import commands as util_commands
10
7
 
8
+
11
9
  @click.group()
12
- @click.option('--verbose', is_flag=True, default=False, help='Verbose printing')
10
+ @click.option("--verbose", is_flag=True, default=False, help="Verbose printing")
13
11
  @click.pass_context
14
12
  def cli(ctx, verbose):
15
-
16
-
17
-
18
13
  if verbose:
19
- click.echo(colored.green('Verbose printing mode is on.'))
14
+ click.echo(colored.green("Verbose printing mode is on."))
20
15
 
21
16
  ctx_obj = {}
22
17
  ctx_obj["verbose"] = verbose
@@ -29,4 +24,4 @@ cli.add_command(plot_commands.cli)
29
24
  cli.add_command(util_commands.cli)
30
25
 
31
26
  if __name__ == "__main__":
32
- cli()
27
+ cli()