bmtool 0.7.7__py3-none-any.whl → 0.7.8__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.

Potentially problematic release.


This version of bmtool might be problematic. Click here for more details.

@@ -1,9 +1,16 @@
1
1
  """
2
- Want to be able to take multiple plot names in and plot them all at the same time, to save time
3
- https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue
2
+ Connection visualization module for BMTK models.
3
+
4
+ This module provides functions to visualize connectivity matrices from BMTK simulations,
5
+ including total connections, percent connectivity, connection probabilities, convergence,
6
+ divergence, and gap junctions.
7
+
8
+ See Also:
9
+ https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue
4
10
  """
5
11
  import re
6
12
  import statistics
13
+ from typing import Dict, List, Optional, Tuple, Union
7
14
 
8
15
  import matplotlib
9
16
  import matplotlib.cm as cmx
@@ -17,27 +24,24 @@ from neuron import h
17
24
 
18
25
  from ..util import util
19
26
 
20
- use_description = """
21
-
22
- Plot BMTK models easily.
23
-
24
- python -m bmtool.plot
25
- """
26
-
27
-
28
27
  def is_notebook() -> bool:
29
28
  """
30
29
  Detect if code is running in a Jupyter notebook environment.
31
30
 
32
- Returns:
33
- --------
31
+ Returns
32
+ -------
34
33
  bool
35
34
  True if running in a Jupyter notebook, False otherwise.
36
35
 
37
- Notes:
38
- ------
36
+ Notes
37
+ -----
39
38
  This is used to determine whether to call plt.show() explicitly or
40
39
  rely on Jupyter's automatic display functionality.
40
+
41
+ Examples
42
+ --------
43
+ >>> if is_notebook():
44
+ ... plt.show()
41
45
  """
42
46
  try:
43
47
  shell = get_ipython().__class__.__name__
@@ -52,52 +56,65 @@ def is_notebook() -> bool:
52
56
 
53
57
 
54
58
  def total_connection_matrix(
55
- config=None,
56
- title=None,
57
- sources=None,
58
- targets=None,
59
- sids=None,
60
- tids=None,
61
- no_prepend_pop=False,
62
- save_file=None,
63
- synaptic_info="0",
64
- include_gap=True,
65
- ):
59
+ config: str,
60
+ title: Optional[str] = None,
61
+ sources: Optional[str] = None,
62
+ targets: Optional[str] = None,
63
+ sids: Optional[str] = None,
64
+ tids: Optional[str] = None,
65
+ no_prepend_pop: bool = False,
66
+ save_file: Optional[str] = None,
67
+ synaptic_info: str = "0",
68
+ include_gap: bool = True,
69
+ ) -> None:
66
70
  """
67
71
  Generate a plot displaying total connections or other synaptic statistics.
68
72
 
69
- Parameters:
70
- -----------
73
+ Parameters
74
+ ----------
71
75
  config : str
72
76
  Path to a BMTK simulation config file.
73
77
  title : str, optional
74
78
  Title for the plot. If None, a default title will be used.
75
- sources : str
79
+ sources : str, optional
76
80
  Comma-separated string of network names to use as sources.
77
- targets : str
81
+ targets : str, optional
78
82
  Comma-separated string of network names to use as targets.
79
83
  sids : str, optional
80
84
  Comma-separated string of source node identifiers to filter.
81
85
  tids : str, optional
82
86
  Comma-separated string of target node identifiers to filter.
83
87
  no_prepend_pop : bool, optional
84
- If True, don't display population name before sid or tid in the plot.
88
+ If True, don't display population name before sid or tid in the plot. Default is False.
85
89
  save_file : str, optional
86
90
  Path to save the plot. If None, plot is not saved.
87
91
  synaptic_info : str, optional
88
- Type of information to display:
92
+ Type of information to display. Options:
89
93
  - '0': Total connections (default)
90
94
  - '1': Mean and standard deviation of connections
91
95
  - '2': All synapse .mod files used
92
96
  - '3': All synapse .json files used
93
97
  include_gap : bool, optional
94
98
  If True, include gap junctions and chemical synapses in the analysis.
95
- If False, only include chemical synapses.
99
+ If False, only include chemical synapses. Default is True.
96
100
 
97
- Returns:
98
- --------
101
+ Returns
102
+ -------
99
103
  None
100
- The function generates and displays a plot.
104
+
105
+ Raises
106
+ ------
107
+ Exception
108
+ If config is not defined or sources/targets are not defined.
109
+
110
+ Examples
111
+ --------
112
+ >>> total_connection_matrix(
113
+ ... config='config.json',
114
+ ... sources='PN',
115
+ ... targets='LN',
116
+ ... title='PN to LN Connections'
117
+ ... )
101
118
  """
102
119
  if not config:
103
120
  raise Exception("config not defined")
@@ -138,35 +155,75 @@ def total_connection_matrix(
138
155
  plot_connection_info(
139
156
  text, num, source_labels, target_labels, title, syn_info=synaptic_info, save_file=save_file
140
157
  )
141
- return
142
158
 
143
159
 
144
160
  def percent_connection_matrix(
145
- config=None,
146
- nodes=None,
147
- edges=None,
148
- title=None,
149
- sources=None,
150
- targets=None,
151
- sids=None,
152
- tids=None,
153
- no_prepend_pop=False,
154
- save_file=None,
155
- method="total",
156
- include_gap=True,
157
- return_dict = False
158
- ):
161
+ config: str,
162
+ nodes: Optional[pd.DataFrame] = None,
163
+ edges: Optional[pd.DataFrame] = None,
164
+ title: Optional[str] = None,
165
+ sources: Optional[str] = None,
166
+ targets: Optional[str] = None,
167
+ sids: Optional[str] = None,
168
+ tids: Optional[str] = None,
169
+ no_prepend_pop: bool = False,
170
+ save_file: Optional[str] = None,
171
+ method: str = "total",
172
+ include_gap: bool = True,
173
+ return_dict: bool = False,
174
+ ) -> Optional[Dict]:
159
175
  """
160
- Generates a plot showing the percent connectivity of a network
161
- config: A BMTK simulation config
162
- sources: network name(s) to plot
163
- targets: network name(s) to plot
164
- sids: source node identifier
165
- tids: target node identifier
166
- no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
167
- method: what percent to displace on the graph 'total','uni',or 'bi' for total connections, unidirectional connections or bidirectional connections
168
- save_file: If plot should be saved
169
- include_gap: Determines if connectivity shown should include gap junctions + chemical synapses. False will only include chemical
176
+ Generates a plot showing the percent connectivity of a network.
177
+
178
+ Parameters
179
+ ----------
180
+ config : str
181
+ Path to a BMTK simulation config file.
182
+ nodes : pd.DataFrame, optional
183
+ Pre-loaded node data. If None, will be loaded from config.
184
+ edges : pd.DataFrame, optional
185
+ Pre-loaded edge data. If None, will be loaded from config.
186
+ title : str, optional
187
+ Title for the plot. If None, a default title will be used.
188
+ sources : str, optional
189
+ Comma-separated string of network name(s) to plot.
190
+ targets : str, optional
191
+ Comma-separated string of network name(s) to plot.
192
+ sids : str, optional
193
+ Comma-separated string of source node identifier(s) to filter.
194
+ tids : str, optional
195
+ Comma-separated string of target node identifier(s) to filter.
196
+ no_prepend_pop : bool, optional
197
+ If True, population name is not displayed before sid or tid in the plot. Default is False.
198
+ save_file : str, optional
199
+ Path to save the plot. If None, plot is not saved.
200
+ method : str, optional
201
+ Method for calculating percent connectivity. Options: 'total', 'uni', 'bi'.
202
+ Default is 'total'.
203
+ include_gap : bool, optional
204
+ If True, include gap junctions in analysis. If False, only include chemical synapses.
205
+ Default is True.
206
+ return_dict : bool, optional
207
+ If True, return connection information as a dictionary. Default is False.
208
+
209
+ Returns
210
+ -------
211
+ dict, optional
212
+ Dictionary containing connection information if return_dict=True, None otherwise.
213
+
214
+ Raises
215
+ ------
216
+ Exception
217
+ If config is not defined or sources/targets are not defined.
218
+
219
+ Examples
220
+ --------
221
+ >>> result = percent_connection_matrix(
222
+ ... config='config.json',
223
+ ... sources='PN',
224
+ ... targets='LN',
225
+ ... return_dict=True
226
+ ... )
170
227
  """
171
228
  if not config:
172
229
  raise Exception("config not defined")
@@ -199,36 +256,85 @@ def percent_connection_matrix(
199
256
  title = "Percent Connectivity"
200
257
 
201
258
  if return_dict:
202
- dict = plot_connection_info(text, num, source_labels, target_labels, title, save_file=save_file, return_dict=return_dict)
203
- return dict
259
+ result_dict = plot_connection_info(
260
+ text, num, source_labels, target_labels, title, save_file=save_file, return_dict=return_dict
261
+ )
262
+ return result_dict
204
263
  else:
205
264
  plot_connection_info(text, num, source_labels, target_labels, title, save_file=save_file)
206
- return
207
265
 
208
266
 
209
267
  def probability_connection_matrix(
210
- config=None,
211
- nodes=None,
212
- edges=None,
213
- title=None,
214
- sources=None,
215
- targets=None,
216
- sids=None,
217
- tids=None,
218
- no_prepend_pop=False,
219
- save_file=None,
220
- dist_X=True,
221
- dist_Y=True,
222
- dist_Z=True,
223
- bins=8,
224
- line_plot=False,
225
- verbose=False,
226
- include_gap=True,
227
- ):
268
+ config: str,
269
+ nodes: Optional[pd.DataFrame] = None,
270
+ edges: Optional[pd.DataFrame] = None,
271
+ title: Optional[str] = None,
272
+ sources: Optional[str] = None,
273
+ targets: Optional[str] = None,
274
+ sids: Optional[str] = None,
275
+ tids: Optional[str] = None,
276
+ no_prepend_pop: bool = False,
277
+ save_file: Optional[str] = None,
278
+ dist_X: bool = True,
279
+ dist_Y: bool = True,
280
+ dist_Z: bool = True,
281
+ bins: int = 8,
282
+ line_plot: bool = False,
283
+ verbose: bool = False,
284
+ include_gap: bool = True,
285
+ ) -> None:
228
286
  """
229
- Generates probability graphs
230
- need to look into this more to see what it does
231
- needs model_template to be defined to work
287
+ Generates probability graphs showing connectivity as a function of distance.
288
+
289
+ Parameters
290
+ ----------
291
+ config : str
292
+ Path to a BMTK simulation config file.
293
+ nodes : pd.DataFrame, optional
294
+ Pre-loaded node data. If None, will be loaded from config.
295
+ edges : pd.DataFrame, optional
296
+ Pre-loaded edge data. If None, will be loaded from config.
297
+ title : str, optional
298
+ Title for the plot. If None, a default title will be used.
299
+ sources : str, optional
300
+ Comma-separated string of network name(s) to plot.
301
+ targets : str, optional
302
+ Comma-separated string of network name(s) to plot.
303
+ sids : str, optional
304
+ Comma-separated string of source node identifier(s) to filter.
305
+ tids : str, optional
306
+ Comma-separated string of target node identifier(s) to filter.
307
+ no_prepend_pop : bool, optional
308
+ If True, population name is not displayed before sid or tid. Default is False.
309
+ save_file : str, optional
310
+ Path to save the plot. If None, plot is not saved.
311
+ dist_X : bool, optional
312
+ If True, include X distance in calculations. Default is True.
313
+ dist_Y : bool, optional
314
+ If True, include Y distance in calculations. Default is True.
315
+ dist_Z : bool, optional
316
+ If True, include Z distance in calculations. Default is True.
317
+ bins : int, optional
318
+ Number of distance bins for the probability calculation. Default is 8.
319
+ line_plot : bool, optional
320
+ If True, plot lines instead of bars. Default is False.
321
+ verbose : bool, optional
322
+ If True, print debugging information. Default is False.
323
+ include_gap : bool, optional
324
+ If True, include gap junctions in analysis. Default is True.
325
+
326
+ Returns
327
+ -------
328
+ None
329
+
330
+ Raises
331
+ ------
332
+ Exception
333
+ If config is not defined or sources/targets are not defined.
334
+
335
+ Notes
336
+ -----
337
+ This function needs model_template to be defined to work properly.
232
338
  """
233
339
  if not config:
234
340
  raise Exception("config not defined")
@@ -277,9 +383,9 @@ def probability_connection_matrix(
277
383
  for x in range(num_src):
278
384
  for y in range(num_tar):
279
385
  ns = data[x][y]["ns"]
280
- bins = data[x][y]["bins"]
386
+ bins_data = data[x][y]["bins"]
281
387
 
282
- XX = bins[:-1]
388
+ XX = bins_data[:-1]
283
389
  YY = ns[0] / ns[1]
284
390
 
285
391
  if line_plot:
@@ -305,37 +411,74 @@ def probability_connection_matrix(
305
411
  st = fig.suptitle(tt, fontsize=14)
306
412
  fig.text(0.5, 0.04, "Target", ha="center")
307
413
  fig.text(0.04, 0.5, "Source", va="center", rotation="vertical")
308
- notebook = is_notebook
414
+ notebook = is_notebook()
309
415
  if not notebook:
310
416
  fig.show()
311
417
 
312
- return
313
-
314
418
 
315
419
  def convergence_connection_matrix(
316
- config=None,
317
- title=None,
318
- sources=None,
319
- targets=None,
320
- sids=None,
321
- tids=None,
322
- no_prepend_pop=False,
323
- save_file=None,
324
- convergence=True,
325
- method="mean+std",
326
- include_gap=True,
327
- return_dict=None,
328
- ):
420
+ config: str,
421
+ title: Optional[str] = None,
422
+ sources: Optional[str] = None,
423
+ targets: Optional[str] = None,
424
+ sids: Optional[str] = None,
425
+ tids: Optional[str] = None,
426
+ no_prepend_pop: bool = False,
427
+ save_file: Optional[str] = None,
428
+ convergence: bool = True,
429
+ method: str = "mean+std",
430
+ include_gap: bool = True,
431
+ return_dict: Optional[bool] = None,
432
+ ) -> Optional[Dict]:
329
433
  """
330
- Generates connection plot displaying convergence data
331
- config: A BMTK simulation config
332
- sources: network name(s) to plot
333
- targets: network name(s) to plot
334
- sids: source node identifier
335
- tids: target node identifier
336
- no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
337
- save_file: If plot should be saved
338
- method: 'mean','min','max','stdev' or 'mean+std' connvergence plot
434
+ Generates connection plot displaying synaptic convergence data.
435
+
436
+ Parameters
437
+ ----------
438
+ config : str
439
+ Path to a BMTK simulation config file.
440
+ title : str, optional
441
+ Title for the plot. If None, a default title will be used.
442
+ sources : str, optional
443
+ Comma-separated string of network name(s) to plot.
444
+ targets : str, optional
445
+ Comma-separated string of network name(s) to plot.
446
+ sids : str, optional
447
+ Comma-separated string of source node identifier(s) to filter.
448
+ tids : str, optional
449
+ Comma-separated string of target node identifier(s) to filter.
450
+ no_prepend_pop : bool, optional
451
+ If True, population name is not displayed before sid or tid. Default is False.
452
+ save_file : str, optional
453
+ Path to save the plot. If None, plot is not saved.
454
+ convergence : bool, optional
455
+ If True, compute convergence; if False, compute divergence. Default is True.
456
+ method : str, optional
457
+ Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'.
458
+ Default is 'mean+std'.
459
+ include_gap : bool, optional
460
+ If True, include gap junctions in analysis. Default is True.
461
+ return_dict : bool, optional
462
+ If True, return connection information as a dictionary. Default is None.
463
+
464
+ Returns
465
+ -------
466
+ dict, optional
467
+ Dictionary containing connection information if return_dict=True, None otherwise.
468
+
469
+ Raises
470
+ ------
471
+ Exception
472
+ If config is not defined or sources/targets are not defined.
473
+
474
+ Examples
475
+ --------
476
+ >>> result = convergence_connection_matrix(
477
+ ... config='config.json',
478
+ ... sources='PN',
479
+ ... targets='LN',
480
+ ... method='mean+std'
481
+ ... )
339
482
  """
340
483
  if not config:
341
484
  raise Exception("config not defined")
@@ -358,29 +501,68 @@ def convergence_connection_matrix(
358
501
 
359
502
 
360
503
  def divergence_connection_matrix(
361
- config=None,
362
- title=None,
363
- sources=None,
364
- targets=None,
365
- sids=None,
366
- tids=None,
367
- no_prepend_pop=False,
368
- save_file=None,
369
- convergence=False,
370
- method="mean+std",
371
- include_gap=True,
372
- return_dict=None,
373
- ):
504
+ config: str,
505
+ title: Optional[str] = None,
506
+ sources: Optional[str] = None,
507
+ targets: Optional[str] = None,
508
+ sids: Optional[str] = None,
509
+ tids: Optional[str] = None,
510
+ no_prepend_pop: bool = False,
511
+ save_file: Optional[str] = None,
512
+ convergence: bool = False,
513
+ method: str = "mean+std",
514
+ include_gap: bool = True,
515
+ return_dict: Optional[bool] = None,
516
+ ) -> Optional[Dict]:
374
517
  """
375
- Generates connection plot displaying divergence data
376
- config: A BMTK simulation config
377
- sources: network name(s) to plot
378
- targets: network name(s) to plot
379
- sids: source node identifier
380
- tids: target node identifier
381
- no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
382
- save_file: If plot should be saved
383
- method: 'mean','min','max','stdev', and 'mean+std' for divergence plot
518
+ Generates connection plot displaying synaptic divergence data.
519
+
520
+ Parameters
521
+ ----------
522
+ config : str
523
+ Path to a BMTK simulation config file.
524
+ title : str, optional
525
+ Title for the plot. If None, a default title will be used.
526
+ sources : str, optional
527
+ Comma-separated string of network name(s) to plot.
528
+ targets : str, optional
529
+ Comma-separated string of network name(s) to plot.
530
+ sids : str, optional
531
+ Comma-separated string of source node identifier(s) to filter.
532
+ tids : str, optional
533
+ Comma-separated string of target node identifier(s) to filter.
534
+ no_prepend_pop : bool, optional
535
+ If True, population name is not displayed before sid or tid. Default is False.
536
+ save_file : str, optional
537
+ Path to save the plot. If None, plot is not saved.
538
+ convergence : bool, optional
539
+ If True, compute convergence; if False, compute divergence. Default is False.
540
+ method : str, optional
541
+ Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'.
542
+ Default is 'mean+std'.
543
+ include_gap : bool, optional
544
+ If True, include gap junctions in analysis. Default is True.
545
+ return_dict : bool, optional
546
+ If True, return connection information as a dictionary. Default is None.
547
+
548
+ Returns
549
+ -------
550
+ dict, optional
551
+ Dictionary containing connection information if return_dict=True, None otherwise.
552
+
553
+ Raises
554
+ ------
555
+ Exception
556
+ If config is not defined or sources/targets are not defined.
557
+
558
+ Examples
559
+ --------
560
+ >>> result = divergence_connection_matrix(
561
+ ... config='config.json',
562
+ ... sources='PN',
563
+ ... targets='LN',
564
+ ... method='mean+std'
565
+ ... )
384
566
  """
385
567
  if not config:
386
568
  raise Exception("config not defined")
@@ -430,7 +612,7 @@ def divergence_connection_matrix(
430
612
  else:
431
613
  title = title + "Synaptic Divergence"
432
614
  if return_dict:
433
- dict = plot_connection_info(
615
+ result_dict = plot_connection_info(
434
616
  syn_info,
435
617
  data,
436
618
  source_labels,
@@ -439,35 +621,66 @@ def divergence_connection_matrix(
439
621
  save_file=save_file,
440
622
  return_dict=return_dict,
441
623
  )
442
- return dict
624
+ return result_dict
443
625
  else:
444
626
  plot_connection_info(
445
627
  syn_info, data, source_labels, target_labels, title, save_file=save_file
446
628
  )
447
- return
448
629
 
449
630
 
450
631
  def gap_junction_matrix(
451
- config=None,
452
- title=None,
453
- sources=None,
454
- targets=None,
455
- sids=None,
456
- tids=None,
457
- no_prepend_pop=False,
458
- save_file=None,
459
- method="convergence",
460
- ):
632
+ config: str,
633
+ title: Optional[str] = None,
634
+ sources: Optional[str] = None,
635
+ targets: Optional[str] = None,
636
+ sids: Optional[str] = None,
637
+ tids: Optional[str] = None,
638
+ no_prepend_pop: bool = False,
639
+ save_file: Optional[str] = None,
640
+ method: str = "convergence",
641
+ ) -> None:
461
642
  """
462
643
  Generates connection plot displaying gap junction data.
463
- config: A BMTK simulation config
464
- sources: network name(s) to plot
465
- targets: network name(s) to plot
466
- sids: source node identifier
467
- tids: target node identifier
468
- no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
469
- save_file: If plot should be saved
470
- type:'convergence' or 'percent' connections
644
+
645
+ Parameters
646
+ ----------
647
+ config : str
648
+ Path to a BMTK simulation config file.
649
+ title : str, optional
650
+ Title for the plot. If None, a default title will be used.
651
+ sources : str, optional
652
+ Comma-separated string of network name(s) to plot.
653
+ targets : str, optional
654
+ Comma-separated string of network name(s) to plot.
655
+ sids : str, optional
656
+ Comma-separated string of source node identifier(s) to filter.
657
+ tids : str, optional
658
+ Comma-separated string of target node identifier(s) to filter.
659
+ no_prepend_pop : bool, optional
660
+ If True, population name is not displayed before sid or tid. Default is False.
661
+ save_file : str, optional
662
+ Path to save the plot. If None, plot is not saved.
663
+ method : str, optional
664
+ Method for computing gap junction statistics. Options: 'convergence', 'percent'.
665
+ Default is 'convergence'.
666
+
667
+ Returns
668
+ -------
669
+ None
670
+
671
+ Raises
672
+ ------
673
+ Exception
674
+ If config is not defined, sources/targets are not defined, or method is invalid.
675
+
676
+ Examples
677
+ --------
678
+ >>> gap_junction_matrix(
679
+ ... config='config.json',
680
+ ... sources='PN',
681
+ ... targets='LN',
682
+ ... method='convergence'
683
+ ... )
471
684
  """
472
685
  if not config:
473
686
  raise Exception("config not defined")
@@ -497,28 +710,34 @@ def gap_junction_matrix(
497
710
  method=method,
498
711
  )
499
712
 
500
- def filter_rows(syn_info, data, source_labels, target_labels):
713
+ def filter_rows(
714
+ syn_info: np.ndarray,
715
+ data: np.ndarray,
716
+ source_labels: List,
717
+ target_labels: List,
718
+ ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, List]:
501
719
  """
502
720
  Filters out rows in a connectivity matrix that contain only NaN or zero values.
503
721
 
504
- This function is used to clean up connection matrices by removing rows that have no meaningful data,
505
- which helps create more informative visualizations of network connectivity.
722
+ This function is used to clean up connection matrices by removing rows that have
723
+ no meaningful data, which helps create more informative visualizations of network connectivity.
506
724
 
507
- Parameters:
508
- -----------
509
- syn_info : numpy.ndarray
725
+ Parameters
726
+ ----------
727
+ syn_info : np.ndarray
510
728
  Array containing synaptic information corresponding to the data matrix.
511
- data : numpy.ndarray
512
- 2D matrix containing connectivity data with rows representing sources and columns representing targets.
729
+ data : np.ndarray
730
+ 2D matrix containing connectivity data with rows representing sources
731
+ and columns representing targets.
513
732
  source_labels : list
514
733
  List of labels for the source populations corresponding to rows in the data matrix.
515
734
  target_labels : list
516
735
  List of labels for the target populations corresponding to columns in the data matrix.
517
736
 
518
- Returns:
519
- --------
737
+ Returns
738
+ -------
520
739
  tuple
521
- A tuple containing the filtered (syn_info, data, source_labels, target_labels) with invalid rows removed.
740
+ A tuple containing (syn_info, data, source_labels, target_labels) with invalid rows removed.
522
741
  """
523
742
  # Identify rows with all NaN or all zeros
524
743
  valid_rows = ~np.all(np.isnan(data), axis=1) & ~np.all(data == 0, axis=1)
@@ -530,7 +749,12 @@ def gap_junction_matrix(
530
749
 
531
750
  return new_syn_info, new_data, new_source_labels, target_labels
532
751
 
533
- def filter_rows_and_columns(syn_info, data, source_labels, target_labels):
752
+ def filter_rows_and_columns(
753
+ syn_info: np.ndarray,
754
+ data: np.ndarray,
755
+ source_labels: List,
756
+ target_labels: List,
757
+ ) -> Tuple[np.ndarray, np.ndarray, List, List]:
534
758
  """
535
759
  Filters out both rows and columns in a connectivity matrix that contain only NaN or zero values.
536
760
 
@@ -538,21 +762,22 @@ def gap_junction_matrix(
538
762
  then transposing the matrix and removing columns with no data (by treating them as rows).
539
763
  This creates a cleaner, more informative connectivity matrix visualization.
540
764
 
541
- Parameters:
542
- -----------
543
- syn_info : numpy.ndarray
765
+ Parameters
766
+ ----------
767
+ syn_info : np.ndarray
544
768
  Array containing synaptic information corresponding to the data matrix.
545
- data : numpy.ndarray
546
- 2D matrix containing connectivity data with rows representing sources and columns representing targets.
769
+ data : np.ndarray
770
+ 2D matrix containing connectivity data with rows representing sources
771
+ and columns representing targets.
547
772
  source_labels : list
548
773
  List of labels for the source populations corresponding to rows in the data matrix.
549
774
  target_labels : list
550
775
  List of labels for the target populations corresponding to columns in the data matrix.
551
776
 
552
- Returns:
553
- --------
777
+ Returns
778
+ -------
554
779
  tuple
555
- A tuple containing the filtered (syn_info, data, source_labels, target_labels) with both
780
+ A tuple containing (syn_info, data, source_labels, target_labels) with both
556
781
  invalid rows and columns removed.
557
782
  """
558
783
  # Filter rows first
@@ -595,75 +820,101 @@ def gap_junction_matrix(
595
820
  elif method == "percent":
596
821
  title += " Percent Connectivity"
597
822
  plot_connection_info(syn_info, data, source_labels, target_labels, title, save_file=save_file)
598
- return
599
823
 
600
824
 
601
825
  def connection_histogram(
602
- config=None,
603
- nodes=None,
604
- edges=None,
605
- sources=[],
606
- targets=[],
607
- sids=[],
608
- tids=[],
609
- no_prepend_pop=True,
610
- synaptic_info="0",
611
- source_cell=None,
612
- target_cell=None,
613
- include_gap=True,
614
- ):
826
+ config: str,
827
+ nodes: Optional[pd.DataFrame] = None,
828
+ edges: Optional[pd.DataFrame] = None,
829
+ sources: Optional[str] = None,
830
+ targets: Optional[str] = None,
831
+ sids: Optional[str] = None,
832
+ tids: Optional[str] = None,
833
+ no_prepend_pop: bool = True,
834
+ synaptic_info: str = "0",
835
+ source_cell: Optional[str] = None,
836
+ target_cell: Optional[str] = None,
837
+ include_gap: bool = True,
838
+ ) -> None:
615
839
  """
616
- Generates histogram of number of connections individual cells in a population receieve from another population
617
- config: A BMTK simulation config
618
- sources: network name(s) to plot
619
- targets: network name(s) to plot
620
- sids: source node identifier
621
- tids: target node identifier
622
- no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
623
- source_cell: where connections are coming from
624
- target_cell: where connections on coming onto
625
- save_file: If plot should be saved
840
+ Generates histogram of the number of connections individual cells receive from another population.
841
+
842
+ Parameters
843
+ ----------
844
+ config : str
845
+ Path to a BMTK simulation config file.
846
+ nodes : pd.DataFrame, optional
847
+ Pre-loaded node data. If None, will be loaded from config.
848
+ edges : pd.DataFrame, optional
849
+ Pre-loaded edge data. If None, will be loaded from config.
850
+ sources : str, optional
851
+ Comma-separated string of network name(s) to plot as sources.
852
+ targets : str, optional
853
+ Comma-separated string of network name(s) to plot as targets.
854
+ sids : str, optional
855
+ Comma-separated string of source node identifier(s) to filter by.
856
+ tids : str, optional
857
+ Comma-separated string of target node identifier(s) to filter by.
858
+ no_prepend_pop : bool, optional
859
+ If True, population name is not prepended to sid or tid. Default is True.
860
+ synaptic_info : str, optional
861
+ Type of synaptic information to display. Default is '0'.
862
+ source_cell : str, optional
863
+ Specific source cell type to plot connections from.
864
+ target_cell : str, optional
865
+ Specific target cell type to plot connections onto.
866
+ include_gap : bool, optional
867
+ If True, include gap junctions in analysis. Default is True.
868
+
869
+ Returns
870
+ -------
871
+ None
626
872
  """
873
+ if not config:
874
+ raise Exception("config not defined")
875
+ if not sources or not targets:
876
+ raise Exception("Sources or targets not defined")
877
+
878
+ sources_list = sources.split(",") if sources else []
879
+ targets_list = targets.split(",") if targets else []
880
+ if sids:
881
+ sids_list = sids.split(",")
882
+ else:
883
+ sids_list = []
884
+ if tids:
885
+ tids_list = tids.split(",")
886
+ else:
887
+ tids_list = []
627
888
 
628
- def connection_pair_histogram(**kwargs):
889
+ def connection_pair_histogram(**kwargs: Dict) -> None:
629
890
  """
630
- Creates a histogram showing the distribution of connection counts between a specific source and target cell type.
891
+ Creates a histogram showing the distribution of connection counts between specific cell types.
631
892
 
632
- This function is designed to be used with the relation_matrix utility and will only create histograms
633
- for the specified source and target cell types, ignoring all other combinations.
893
+ This function is designed to be used with the relation_matrix utility and will only
894
+ create histograms for the specified source and target cell types.
634
895
 
635
- Parameters:
636
- -----------
896
+ Parameters
897
+ ----------
637
898
  kwargs : dict
638
- Dictionary containing the following keys:
899
+ Dictionary containing edge data and filtering information.
639
900
  - edges: DataFrame containing edge information
640
901
  - sid: Column name for source ID type in the edges DataFrame
641
902
  - tid: Column name for target ID type in the edges DataFrame
642
903
  - source_id: Value to filter edges by source ID type
643
904
  - target_id: Value to filter edges by target ID type
644
905
 
645
- Global parameters used:
646
- ---------------------
647
- source_cell : str
648
- The source cell type to plot.
649
- target_cell : str
650
- The target cell type to plot.
651
- include_gap : bool
652
- Whether to include gap junctions in the analysis. If False, gap junctions are excluded.
653
-
654
- Returns:
655
- --------
906
+ Returns
907
+ -------
656
908
  None
657
- Displays a histogram showing the distribution of connection counts.
658
909
  """
659
- edges = kwargs["edges"]
910
+ edges_data = kwargs["edges"]
660
911
  source_id_type = kwargs["sid"]
661
912
  target_id_type = kwargs["tid"]
662
913
  source_id = kwargs["source_id"]
663
914
  target_id = kwargs["target_id"]
664
915
  if source_id == source_cell and target_id == target_cell:
665
- temp = edges[
666
- (edges[source_id_type] == source_id) & (edges[target_id_type] == target_id)
916
+ temp = edges_data[
917
+ (edges_data[source_id_type] == source_id) & (edges_data[target_id_type] == target_id)
667
918
  ]
668
919
  if not include_gap:
669
920
  gap_col = temp["is_gap_junction"].fillna(False).astype(bool)
@@ -676,7 +927,7 @@ def connection_histogram(
676
927
  label = "mean {:.2f} std {:.2f} median {:.2f}".format(
677
928
  conn_mean, conn_std, conn_median
678
929
  )
679
- except: # lazy fix for std not calculated with 1 node
930
+ except (statistics.StatisticsError, ValueError): # lazy fix for std not calculated with 1 node
680
931
  conn_mean = statistics.mean(node_pairs.values)
681
932
  conn_median = statistics.median(node_pairs.values)
682
933
  label = "mean {:.2f} median {:.2f}".format(conn_mean, conn_median)
@@ -692,24 +943,15 @@ def connection_histogram(
692
943
  raise Exception("config not defined")
693
944
  if not sources or not targets:
694
945
  raise Exception("Sources or targets not defined")
695
- sources = sources.split(",")
696
- targets = targets.split(",")
697
- if sids:
698
- sids = sids.split(",")
699
- else:
700
- sids = []
701
- if tids:
702
- tids = tids.split(",")
703
- else:
704
- tids = []
946
+
705
947
  util.relation_matrix(
706
948
  config,
707
949
  nodes,
708
950
  edges,
709
- sources,
710
- targets,
711
- sids,
712
- tids,
951
+ sources_list,
952
+ targets_list,
953
+ sids_list,
954
+ tids_list,
713
955
  not no_prepend_pop,
714
956
  relation_func=connection_pair_histogram,
715
957
  synaptic_info=synaptic_info,
@@ -728,15 +970,35 @@ def connection_distance(
728
970
  Plots the 3D spatial distribution of target nodes relative to a source node
729
971
  and a histogram of distances from the source node to each target node.
730
972
 
731
- Parameters:
973
+ Parameters
732
974
  ----------
733
- config: (str) A BMTK simulation config
734
- sources: (str) network name(s) to plot
735
- targets: (str) network name(s) to plot
736
- source_cell_id : (int) ID of the source cell for calculating distances to target nodes.
737
- target_id_type : (str) A string to filter target nodes based off the target_query.
738
- ignore_z : (bool) A bool to ignore_z axis or not for when calculating distance default is False
975
+ config : str
976
+ Path to a BMTK simulation config file.
977
+ sources : str
978
+ Network name(s) to plot as sources.
979
+ targets : str
980
+ Network name(s) to plot as targets.
981
+ source_cell_id : int
982
+ ID of the source cell for calculating distances to target nodes.
983
+ target_id_type : str
984
+ String to filter target nodes based off the target_query.
985
+ ignore_z : bool, optional
986
+ If True, ignore Z axis when calculating distance. Default is False.
987
+
988
+ Returns
989
+ -------
990
+ None
739
991
 
992
+ Examples
993
+ --------
994
+ >>> connection_distance(
995
+ ... config='config.json',
996
+ ... sources='PN',
997
+ ... targets='LN',
998
+ ... source_cell_id=0,
999
+ ... target_id_type='LN',
1000
+ ... ignore_z=False
1001
+ ... )
740
1002
  """
741
1003
  if not config:
742
1004
  raise Exception("config not defined")
@@ -820,46 +1082,45 @@ def connection_distance(
820
1082
 
821
1083
 
822
1084
  def edge_histogram_matrix(
823
- config=None,
824
- sources=None,
825
- targets=None,
826
- sids=None,
827
- tids=None,
828
- no_prepend_pop=None,
829
- edge_property=None,
830
- time=None,
831
- time_compare=None,
832
- report=None,
833
- title=None,
834
- save_file=None,
835
- ):
1085
+ config: str,
1086
+ sources: Optional[str] = None,
1087
+ targets: Optional[str] = None,
1088
+ sids: Optional[str] = None,
1089
+ tids: Optional[str] = None,
1090
+ no_prepend_pop: Optional[bool] = None,
1091
+ edge_property: Optional[str] = None,
1092
+ time: Optional[int] = None,
1093
+ time_compare: Optional[int] = None,
1094
+ report: Optional[str] = None,
1095
+ title: Optional[str] = None,
1096
+ save_file: Optional[str] = None,
1097
+ ) -> None:
836
1098
  """
837
- Generates a matrix of histograms showing the distribution of edge properties between different populations.
1099
+ Generates a matrix of histograms showing the distribution of edge properties between populations.
838
1100
 
839
- This function creates a grid of histograms where each cell in the grid represents the distribution of a
840
- specific edge property (e.g., synaptic weights, delays) between a source population (row) and
841
- target population (column).
1101
+ This function creates a grid of histograms where each cell represents the distribution
1102
+ of a specific edge property between source and target populations.
842
1103
 
843
- Parameters:
844
- -----------
1104
+ Parameters
1105
+ ----------
845
1106
  config : str
846
1107
  Path to a BMTK simulation config file.
847
- sources : str
1108
+ sources : str, optional
848
1109
  Comma-separated list of source network names.
849
- targets : str
1110
+ targets : str, optional
850
1111
  Comma-separated list of target network names.
851
1112
  sids : str, optional
852
1113
  Comma-separated list of source node identifiers to filter by.
853
1114
  tids : str, optional
854
1115
  Comma-separated list of target node identifiers to filter by.
855
1116
  no_prepend_pop : bool, optional
856
- If True, population names are not prepended to node identifiers in the display.
857
- edge_property : str
858
- The edge property to analyze and display in the histograms (e.g., 'syn_weight', 'delay').
1117
+ If True, population names are not prepended to node identifiers.
1118
+ edge_property : str, optional
1119
+ The edge property to analyze (e.g., 'syn_weight', 'delay').
859
1120
  time : int, optional
860
1121
  Time point to analyze from a time series report.
861
1122
  time_compare : int, optional
862
- Second time point for comparison with 'time'.
1123
+ Second time point for comparison with time.
863
1124
  report : str, optional
864
1125
  Name of the report to analyze.
865
1126
  title : str, optional
@@ -867,10 +1128,18 @@ def edge_histogram_matrix(
867
1128
  save_file : str, optional
868
1129
  Path to save the generated plot.
869
1130
 
870
- Returns:
871
- --------
1131
+ Returns
1132
+ -------
872
1133
  None
873
- Displays a matrix of histograms.
1134
+
1135
+ Examples
1136
+ --------
1137
+ >>> edge_histogram_matrix(
1138
+ ... config='config.json',
1139
+ ... sources='PN',
1140
+ ... targets='LN',
1141
+ ... edge_property='syn_weight'
1142
+ ... )
874
1143
  """
875
1144
 
876
1145
  if not config:
@@ -933,22 +1202,41 @@ def distance_delay_plot(
933
1202
  simulation_config: str, source: str, target: str, group_by: str, sid: str, tid: str
934
1203
  ) -> None:
935
1204
  """
936
- Plots the relationship between the distance and delay of connections between nodes in a neural network simulation.
937
-
938
- This function loads the node and edge data from a simulation configuration file, filters nodes by population or group,
939
- identifies connections (edges) between source and target node populations, calculates the Euclidean distance between
940
- connected nodes, and plots the delay as a function of distance.
941
-
942
- Args:
943
- simulation_config (str): Path to the simulation config file
944
- source (str): The name of the source population in the edge data.
945
- target (str): The name of the target population in the edge data.
946
- group_by (str): Column name to group nodes by (e.g., population name).
947
- sid (str): Identifier for the source group (e.g., 'PN').
948
- tid (str): Identifier for the target group (e.g., 'PN').
949
-
950
- Returns:
951
- None: The function creates and displays a scatter plot of distance vs delay.
1205
+ Plots the relationship between the distance and delay of connections between nodes in a neural network.
1206
+
1207
+ This function loads node and edge data from a simulation configuration file, filters nodes by population,
1208
+ identifies connections (edges) between source and target node populations, calculates the Euclidean distance
1209
+ between connected nodes, and plots the delay as a function of distance.
1210
+
1211
+ Parameters
1212
+ ----------
1213
+ simulation_config : str
1214
+ Path to the simulation config file.
1215
+ source : str
1216
+ The name of the source population in the edge data.
1217
+ target : str
1218
+ The name of the target population in the edge data.
1219
+ group_by : str
1220
+ Column name to group nodes by (e.g., population name).
1221
+ sid : str
1222
+ Identifier for the source group (e.g., 'PN').
1223
+ tid : str
1224
+ Identifier for the target group (e.g., 'PN').
1225
+
1226
+ Returns
1227
+ -------
1228
+ None
1229
+
1230
+ Examples
1231
+ --------
1232
+ >>> distance_delay_plot(
1233
+ ... 'config.json',
1234
+ ... 'cortex',
1235
+ ... 'cortex',
1236
+ ... 'node_type_id',
1237
+ ... 'E',
1238
+ ... 'E'
1239
+ ... )
952
1240
  """
953
1241
  nodes, edges = util.load_nodes_edges_from_config(simulation_config)
954
1242
  nodes = nodes[target]
@@ -989,37 +1277,56 @@ def distance_delay_plot(
989
1277
  plt.show()
990
1278
 
991
1279
 
992
- def plot_synapse_location(config: str, source: str, target: str, sids: str, tids: str, syn_feature: str = 'afferent_section_id') -> tuple:
1280
+ def plot_synapse_location(
1281
+ config: str,
1282
+ source: str,
1283
+ target: str,
1284
+ sids: str,
1285
+ tids: str,
1286
+ syn_feature: str = "afferent_section_id",
1287
+ ) -> Tuple[plt.Figure, plt.Axes]:
993
1288
  """
994
1289
  Generates a connectivity matrix showing synaptic distribution across different cell sections.
995
- Note does exclude gap junctions since they dont have an afferent id stored in the h5 file!
1290
+
1291
+ Note: Excludes gap junctions since they don't have an afferent id stored in the h5 file.
996
1292
 
997
1293
  Parameters
998
1294
  ----------
999
1295
  config : str
1000
- Path to BMTK config file
1296
+ Path to BMTK config file.
1001
1297
  source : str
1002
- The source BMTK network name
1298
+ The source BMTK network name.
1003
1299
  target : str
1004
- The target BMTK network name
1300
+ The target BMTK network name.
1005
1301
  sids : str
1006
- Column name in nodes file containing source population identifiers
1302
+ Column name in nodes file containing source population identifiers.
1007
1303
  tids : str
1008
- Column name in nodes file containing target population identifiers
1009
- syn_feature : str, default 'afferent_section_id'
1010
- Synaptic feature to analyze ('afferent_section_id' or 'afferent_section_pos')
1304
+ Column name in nodes file containing target population identifiers.
1305
+ syn_feature : str, optional
1306
+ Synaptic feature to analyze. Default is 'afferent_section_id'.
1307
+ Options: 'afferent_section_id' or 'afferent_section_pos'.
1011
1308
 
1012
1309
  Returns
1013
1310
  -------
1014
1311
  tuple
1015
- (matplotlib.figure.Figure, matplotlib.axes.Axes) containing the plot
1312
+ (matplotlib.figure.Figure, matplotlib.axes.Axes) containing the plot.
1016
1313
 
1017
1314
  Raises
1018
1315
  ------
1019
1316
  ValueError
1020
- If required parameters are missing or invalid
1317
+ If required parameters are missing or invalid.
1021
1318
  RuntimeError
1022
- If template loading or cell instantiation fails
1319
+ If template loading or cell instantiation fails.
1320
+
1321
+ Examples
1322
+ --------
1323
+ >>> fig, ax = plot_synapse_location(
1324
+ ... config='config.json',
1325
+ ... source='LGN',
1326
+ ... target='cortex',
1327
+ ... sids='node_type_id',
1328
+ ... tids='node_type_id'
1329
+ ... )
1023
1330
  """
1024
1331
  # Validate inputs
1025
1332
  if not all([config, source, target, sids, tids]):
@@ -1161,11 +1468,47 @@ def plot_synapse_location(config: str, source: str, target: str, sids: str, tids
1161
1468
 
1162
1469
 
1163
1470
  def plot_connection_info(
1164
- text, num, source_labels, target_labels, title, syn_info="0", save_file=None, return_dict=None
1165
- ):
1471
+ text: np.ndarray,
1472
+ num: np.ndarray,
1473
+ source_labels: List[str],
1474
+ target_labels: List[str],
1475
+ title: str,
1476
+ syn_info: str = "0",
1477
+ save_file: Optional[str] = None,
1478
+ return_dict: Optional[bool] = None,
1479
+ ) -> Union[Tuple, Dict, None]:
1166
1480
  """
1167
- Function to plot connection information as a heatmap, including handling missing source and target values.
1168
- If there is no source or target, set the value to 0.
1481
+ Plot connection information as a heatmap with text annotations.
1482
+
1483
+ Parameters
1484
+ ----------
1485
+ text : np.ndarray
1486
+ 2D array of text annotations for each cell.
1487
+ num : np.ndarray
1488
+ 2D array of numerical values for the heatmap colors.
1489
+ source_labels : list of str
1490
+ Labels for source populations (rows).
1491
+ target_labels : list of str
1492
+ Labels for target populations (columns).
1493
+ title : str
1494
+ Title for the plot.
1495
+ syn_info : str, optional
1496
+ Type of synaptic information being displayed. Options: '0', '1', '2', '3'.
1497
+ Default is '0'.
1498
+ save_file : str, optional
1499
+ Path to save the plot. If None, plot is not saved.
1500
+ return_dict : bool, optional
1501
+ If True, return connection information as a dictionary. Default is None.
1502
+
1503
+ Returns
1504
+ -------
1505
+ Union[Tuple, Dict, None]
1506
+ If return_dict=True, returns a dictionary of connection information.
1507
+ Otherwise, returns a tuple of (Figure, Axes), or None if just displaying.
1508
+
1509
+ Notes
1510
+ -----
1511
+ Handles missing source and target values by setting them to 0.
1169
1512
  """
1170
1513
  # Ensure text dimensions match num dimensions
1171
1514
  num_source = len(source_labels)
@@ -1320,35 +1663,45 @@ def plot_connection_info(
1320
1663
 
1321
1664
 
1322
1665
  def connector_percent_matrix(
1323
- csv_path: str = None,
1324
- exclude_strings=None,
1325
- assemb_key=None,
1666
+ csv_path: Optional[str] = None,
1667
+ exclude_strings: Optional[List[str]] = None,
1668
+ assemb_key: Optional[str] = None,
1326
1669
  title: str = "Percent connection matrix",
1327
- pop_order=None,
1670
+ pop_order: Optional[List[str]] = None,
1328
1671
  ) -> None:
1329
1672
  """
1330
- Generates and plots a connection matrix based on connection probabilities from a CSV file produced by bmtool.connector.
1673
+ Generates and plots a connection matrix based on connection probabilities from a CSV file.
1331
1674
 
1332
- This function is useful for visualizing percent connectivity while factoring in population distance and other parameters.
1333
- It processes the connection data by filtering the 'Source' and 'Target' columns in the CSV, and displays the percentage of
1334
- connected pairs for each population combination in a matrix.
1675
+ This function visualizes percent connectivity while factoring in population distance and other parameters.
1676
+ It processes connection data by filtering 'Source' and 'Target' columns in the CSV and displays the
1677
+ percentage of connected pairs for each population combination in a matrix.
1335
1678
 
1336
- Parameters:
1337
- -----------
1338
- csv_path : str
1339
- Path to the CSV file containing the connection data. The CSV should be an output from the bmtool.connector
1340
- classes, specifically generated by the `save_connection_report()` function.
1679
+ Parameters
1680
+ ----------
1681
+ csv_path : str, optional
1682
+ Path to the CSV file containing connection data. The CSV should be an output from the
1683
+ bmtool.connector classes, specifically generated by the `save_connection_report()` function.
1341
1684
  exclude_strings : list of str, optional
1342
1685
  List of strings to exclude rows where 'Source' or 'Target' contain these strings.
1343
- title : str, optional, default='Percent connection matrix'
1344
- Title for the generated plot.
1686
+ assemb_key : str, optional
1687
+ Key to identify and process assembly connections.
1688
+ title : str, optional
1689
+ Title for the generated plot. Default is 'Percent connection matrix'.
1345
1690
  pop_order : list of str, optional
1346
- List of population labels to specify the order for the x- and y-ticks in the plot.
1691
+ List of population labels to specify the order for x- and y-ticks in the plot.
1347
1692
 
1348
- Returns:
1349
- --------
1693
+ Returns
1694
+ -------
1350
1695
  None
1351
- Displays a heatmap plot of the connection matrix, showing the percentage of connected pairs between populations.
1696
+ Displays a heatmap plot of the connection matrix.
1697
+
1698
+ Examples
1699
+ --------
1700
+ >>> connector_percent_matrix(
1701
+ ... csv_path='connections.csv',
1702
+ ... exclude_strings=['Gap'],
1703
+ ... title='Network Connectivity'
1704
+ ... )
1352
1705
  """
1353
1706
  # Read the CSV data
1354
1707
  df = pd.read_csv(csv_path)
@@ -1496,17 +1849,44 @@ def connector_percent_matrix(
1496
1849
  plt.show()
1497
1850
 
1498
1851
 
1499
- def plot_3d_positions(config=None, sources=None, sid=None, title=None, save_file=None, subset=None):
1852
+ def plot_3d_positions(
1853
+ config: Optional[str] = None,
1854
+ sources: Optional[str] = None,
1855
+ sid: Optional[str] = None,
1856
+ title: Optional[str] = None,
1857
+ save_file: Optional[str] = None,
1858
+ subset: Optional[int] = None,
1859
+ ) -> None:
1500
1860
  """
1501
1861
  Plots a 3D graph of all cells with x, y, z location.
1502
1862
 
1503
- Parameters:
1504
- - config: A BMTK simulation config
1505
- - sources: Which network(s) to plot
1506
- - sid: How to name cell groups
1507
- - title: Plot title
1508
- - save_file: If plot should be saved
1509
- - subset: Take every Nth row. This will make plotting large network graphs easier to see.
1863
+ Parameters
1864
+ ----------
1865
+ config : str, optional
1866
+ Path to a BMTK simulation config file.
1867
+ sources : str, optional
1868
+ Which network(s) to plot. If None or 'all', plots all networks.
1869
+ sid : str, optional
1870
+ Column name to group cell types (node grouping criteria).
1871
+ title : str, optional
1872
+ Plot title. Default is '3D positions'.
1873
+ save_file : str, optional
1874
+ Path to save the plot. If None, plot is not saved.
1875
+ subset : int, optional
1876
+ Take every Nth row. This makes plotting large networks easier to visualize.
1877
+
1878
+ Returns
1879
+ -------
1880
+ None
1881
+
1882
+ Examples
1883
+ --------
1884
+ >>> plot_3d_positions(
1885
+ ... config='config.json',
1886
+ ... sources='cortex',
1887
+ ... sid='node_type_id',
1888
+ ... title='3D Neuron Positions'
1889
+ ... )
1510
1890
  """
1511
1891
 
1512
1892
  if not config:
@@ -1610,16 +1990,53 @@ def plot_3d_positions(config=None, sources=None, sid=None, title=None, save_file
1610
1990
 
1611
1991
 
1612
1992
  def plot_3d_cell_rotation(
1613
- config=None,
1614
- sources=None,
1615
- sids=None,
1616
- title=None,
1617
- save_file=None,
1618
- quiver_length=None,
1619
- arrow_length_ratio=None,
1620
- group=None,
1621
- subset=None,
1622
- ):
1993
+ config: Optional[str] = None,
1994
+ sources: Optional[List[str]] = None,
1995
+ sids: Optional[str] = None,
1996
+ title: Optional[str] = None,
1997
+ save_file: Optional[str] = None,
1998
+ quiver_length: Optional[float] = None,
1999
+ arrow_length_ratio: Optional[float] = None,
2000
+ group: Optional[str] = None,
2001
+ subset: Optional[int] = None,
2002
+ ) -> None:
2003
+ """
2004
+ Plot 3D visualization of cell rotations with quiver arrows showing rotation orientations.
2005
+
2006
+ Parameters
2007
+ ----------
2008
+ config : str, optional
2009
+ Path to a BMTK simulation config file.
2010
+ sources : list of str, optional
2011
+ Network names to plot. If None or contains 'all', plots all networks.
2012
+ sids : str, optional
2013
+ Comma-separated column names to group cell types.
2014
+ title : str, optional
2015
+ Plot title. Default is 'Cell rotations'.
2016
+ save_file : str, optional
2017
+ Path to save the plot. If None, plot is not saved.
2018
+ quiver_length : float, optional
2019
+ Length of the quiver arrows. If None, use matplotlib default.
2020
+ arrow_length_ratio : float, optional
2021
+ Ratio of arrow head size to quiver length.
2022
+ group : str, optional
2023
+ Comma-separated group names to include. If None, include all groups.
2024
+ subset : int, optional
2025
+ Take every Nth row. Useful for visualizing large networks.
2026
+
2027
+ Returns
2028
+ -------
2029
+ None
2030
+
2031
+ Examples
2032
+ --------
2033
+ >>> plot_3d_cell_rotation(
2034
+ ... config='config.json',
2035
+ ... sources=['cortex'],
2036
+ ... sids='node_type_id',
2037
+ ... title='Cell Rotation Vectors'
2038
+ ... )
2039
+ """
1623
2040
  from scipy.spatial.transform import Rotation as R
1624
2041
 
1625
2042
  if not config: