bsplot 0.0.6__tar.gz

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.
Files changed (90) hide show
  1. bsplot-0.0.6/LICENSE +193 -0
  2. bsplot-0.0.6/MANIFEST.in +20 -0
  3. bsplot-0.0.6/PKG-INFO +60 -0
  4. bsplot-0.0.6/README.md +35 -0
  5. bsplot-0.0.6/bsplot/__init__.py +24 -0
  6. bsplot-0.0.6/bsplot/anat.py +56 -0
  7. bsplot-0.0.6/bsplot/animate.py +195 -0
  8. bsplot-0.0.6/bsplot/bioicons.py +778 -0
  9. bsplot-0.0.6/bsplot/brain.py +189 -0
  10. bsplot-0.0.6/bsplot/colors.py +1936 -0
  11. bsplot-0.0.6/bsplot/data/HCP_avg-SC.txt +379 -0
  12. bsplot-0.0.6/bsplot/data/MNI152.rh.pial +0 -0
  13. bsplot-0.0.6/bsplot/data/STN_lh.nii.gz +0 -0
  14. bsplot-0.0.6/bsplot/data/STN_rh.nii.gz +0 -0
  15. bsplot-0.0.6/bsplot/data/__init__.py +23 -0
  16. bsplot-0.0.6/bsplot/data/left_electrode.ply +257270 -0
  17. bsplot-0.0.6/bsplot/data/parcellations/HCP-MMP1.L.label.gii +442 -0
  18. bsplot-0.0.6/bsplot/data/parcellations/HCP-MMP1.R.label.gii +442 -0
  19. bsplot-0.0.6/bsplot/data/parcellations/code/split_hcpmmp1.sh +4 -0
  20. bsplot-0.0.6/bsplot/data/right_electrode.ply +257270 -0
  21. bsplot-0.0.6/bsplot/data/surface.py +113 -0
  22. bsplot-0.0.6/bsplot/data/tpl-MNI152NLin2009b_atlas-hcpmmp1_desc-ordered_dseg.nii.gz +0 -0
  23. bsplot-0.0.6/bsplot/figure.py +178 -0
  24. bsplot-0.0.6/bsplot/graph/__init__.py +32 -0
  25. bsplot-0.0.6/bsplot/graph/edges.py +313 -0
  26. bsplot-0.0.6/bsplot/graph/flowchart.py +763 -0
  27. bsplot-0.0.6/bsplot/graph/layout.py +202 -0
  28. bsplot-0.0.6/bsplot/graph/network.py +975 -0
  29. bsplot-0.0.6/bsplot/graph/nodes.py +453 -0
  30. bsplot-0.0.6/bsplot/panels.py +111 -0
  31. bsplot-0.0.6/bsplot/scientific_color_maps/__init__.py +1 -0
  32. bsplot-0.0.6/bsplot/scientific_color_maps/_sync_from_zenodo_download.sh +1 -0
  33. bsplot-0.0.6/bsplot/scientific_color_maps/batlowK.txt +256 -0
  34. bsplot-0.0.6/bsplot/scientific_color_maps/batlowW.txt +256 -0
  35. bsplot-0.0.6/bsplot/scientific_color_maps/cyclic/bamO.txt +256 -0
  36. bsplot-0.0.6/bsplot/scientific_color_maps/cyclic/brocO.txt +256 -0
  37. bsplot-0.0.6/bsplot/scientific_color_maps/cyclic/corkO.txt +256 -0
  38. bsplot-0.0.6/bsplot/scientific_color_maps/cyclic/romaO.txt +256 -0
  39. bsplot-0.0.6/bsplot/scientific_color_maps/cyclic/vikO.txt +256 -0
  40. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/bam.txt +256 -0
  41. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/berlin.txt +256 -0
  42. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/broc.txt +256 -0
  43. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/cork.txt +256 -0
  44. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/lisbon.txt +256 -0
  45. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/managua.txt +256 -0
  46. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/roma.txt +256 -0
  47. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/tofino.txt +256 -0
  48. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/vanimo.txt +256 -0
  49. bsplot-0.0.6/bsplot/scientific_color_maps/diverging/vik.txt +256 -0
  50. bsplot-0.0.6/bsplot/scientific_color_maps/multisequential/bukavu.txt +256 -0
  51. bsplot-0.0.6/bsplot/scientific_color_maps/multisequential/fes.txt +256 -0
  52. bsplot-0.0.6/bsplot/scientific_color_maps/multisequential/oleron.txt +256 -0
  53. bsplot-0.0.6/bsplot/scientific_color_maps/naviaW.txt +256 -0
  54. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/acton.txt +256 -0
  55. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/bamako.txt +256 -0
  56. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/batlow.txt +256 -0
  57. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/bilbao.txt +256 -0
  58. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/buda.txt +256 -0
  59. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/davos.txt +256 -0
  60. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/devon.txt +256 -0
  61. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/glasgow.txt +256 -0
  62. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/grayC.txt +256 -0
  63. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/hawaii.txt +256 -0
  64. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/imola.txt +256 -0
  65. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/lajolla.txt +256 -0
  66. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/lapaz.txt +256 -0
  67. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/lipari.txt +256 -0
  68. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/navia.txt +256 -0
  69. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/nuuk.txt +256 -0
  70. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/oslo.txt +256 -0
  71. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/tokyo.txt +256 -0
  72. bsplot-0.0.6/bsplot/scientific_color_maps/sequential/turku.txt +256 -0
  73. bsplot-0.0.6/bsplot/streamlines.py +315 -0
  74. bsplot-0.0.6/bsplot/style.py +792 -0
  75. bsplot-0.0.6/bsplot/styles/black.mplstyle +78 -0
  76. bsplot-0.0.6/bsplot/styles/bss.mplstyle +50 -0
  77. bsplot-0.0.6/bsplot/styles/bwcomp.mplstyle +30 -0
  78. bsplot-0.0.6/bsplot/styles/nature.mplstyle +57 -0
  79. bsplot-0.0.6/bsplot/styles/transparent.mplstyle +16 -0
  80. bsplot-0.0.6/bsplot/styles/tvbo.mplstyle +57 -0
  81. bsplot-0.0.6/bsplot/surface.py +2371 -0
  82. bsplot-0.0.6/bsplot/templates.py +271 -0
  83. bsplot-0.0.6/bsplot/text.py +200 -0
  84. bsplot-0.0.6/bsplot/text2obj.py +60 -0
  85. bsplot-0.0.6/bsplot/timeseries.py +11 -0
  86. bsplot-0.0.6/bsplot/utils.py +14 -0
  87. bsplot-0.0.6/bsplot/volume.py +959 -0
  88. bsplot-0.0.6/bsplot.egg-info/SOURCES.txt +87 -0
  89. bsplot-0.0.6/pyproject.toml +50 -0
  90. bsplot-0.0.6/setup.cfg +4 -0
bsplot-0.0.6/LICENSE ADDED
@@ -0,0 +1,193 @@
1
+ Copyright © Charité Universitätsmedizin Berlin. This software is licensed under the terms of the European Union Public Licence (EUPL) version 1.2 or later.
2
+
3
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
4
+ EUPL © the European Union 2007, 2016
5
+
6
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
7
+ terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
8
+ use is covered by a right of the copyright holder of the Work).
9
+ The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
10
+ notice immediately following the copyright notice for the Work:
11
+ Licensed under the EUPL
12
+ or has expressed by any other means his willingness to license under the EUPL.
13
+
14
+ 1.Definitions
15
+ In this Licence, the following terms have the following meaning:
16
+ — ‘The Licence’:this Licence.
17
+ — ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
18
+ as Source Code and also as Executable Code as the case may be.
19
+ — ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
20
+ modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
21
+ required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
22
+ the country mentioned in Article 15.
23
+ — ‘The Work’:the Original Work or its Derivative Works.
24
+ — ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
25
+ modify.
26
+ — ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
27
+ a computer as a program.
28
+ — ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
29
+ — ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
30
+ the creation of a Derivative Work.
31
+ — ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
32
+ Licence.
33
+ — ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
34
+ transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
35
+ functionalities at the disposal of any other natural or legal person.
36
+
37
+ 2.Scope of the rights granted by the Licence
38
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
39
+ the duration of copyright vested in the Original Work:
40
+ — use the Work in any circumstance and for all usage,
41
+ — reproduce the Work,
42
+ — modify the Work, and make Derivative Works based upon the Work,
43
+ — communicate to the public, including the right to make available or display the Work or copies thereof to the public
44
+ and perform publicly, as the case may be, the Work,
45
+ — distribute the Work or copies thereof,
46
+ — lend and rent the Work or copies thereof,
47
+ — sublicense rights in the Work or copies thereof.
48
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
49
+ applicable law permits so.
50
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
51
+ by law in order to make effective the licence of the economic rights here above listed.
52
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
53
+ extent necessary to make use of the rights granted on the Work under this Licence.
54
+
55
+ 3.Communication of the Source Code
56
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
57
+ Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
58
+ each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
59
+ the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
60
+ distribute or communicate the Work.
61
+
62
+ 4.Limitations on copyright
63
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
64
+ exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
65
+ thereto.
66
+
67
+ 5.Obligations of the Licensee
68
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
69
+ obligations are the following:
70
+
71
+ Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
72
+ the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
73
+ Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
74
+ to carry prominent notices stating that the Work has been modified and the date of modification.
75
+
76
+ Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
77
+ Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
78
+ the Original Work is expressly distributed only under this version of the Licence — for example by communicating
79
+ ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
80
+ Work or Derivative Work that alter or restrict the terms of the Licence.
81
+
82
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
83
+ the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
84
+ under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
85
+ in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
86
+ his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
87
+
88
+ Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
89
+ a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
90
+ for as long as the Licensee continues to distribute or communicate the Work.
91
+
92
+ Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
93
+ of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
94
+ reproducing the content of the copyright notice.
95
+
96
+ 6.Chain of Authorship
97
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
98
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
99
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
100
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
101
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
102
+ to the Work, under the terms of this Licence.
103
+
104
+ 7.Disclaimer of Warranty
105
+ The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
106
+ and may therefore contain defects or ‘bugs’ inherent to this type of development.
107
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
108
+ concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
109
+ errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
110
+ Licence.
111
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
112
+
113
+ 8.Disclaimer of Liability
114
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
115
+ liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
116
+ Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
117
+ of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
118
+ the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
119
+
120
+ 9.Additional agreements
121
+ While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
122
+ consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
123
+ responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
124
+ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
125
+ the fact You have accepted any warranty or additional liability.
126
+
127
+ 10.Acceptance of the Licence
128
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
129
+ displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
130
+ applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
131
+ and conditions.
132
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
133
+ by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
134
+ or Communication by You of the Work or copies thereof.
135
+
136
+ 11.Information to the public
137
+ In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
138
+ by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
139
+ must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
140
+ and the way it may be accessible, concluded, stored and reproduced by the Licensee.
141
+
142
+ 12.Termination of the Licence
143
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
144
+ of the Licence.
145
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
146
+ the Licence, provided such persons remain in full compliance with the Licence.
147
+
148
+ 13.Miscellaneous
149
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
150
+ Work.
151
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
152
+ enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
153
+ and enforceable.
154
+ The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
155
+ the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
156
+ New versions of the Licence will be published with a unique version number.
157
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
158
+ advantage of the linguistic version of their choice.
159
+
160
+ 14.Jurisdiction
161
+ Without prejudice to specific agreement between parties,
162
+ — any litigation resulting from the interpretation of this License, arising between the European Union institutions,
163
+ bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
164
+ of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
165
+ — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
166
+ the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
167
+
168
+ 15.Applicable Law
169
+ Without prejudice to specific agreement between parties,
170
+ — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
171
+ resides or has his registered office,
172
+ — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
173
+ a European Union Member State.
174
+
175
+
176
+ Appendix
177
+
178
+ ‘Compatible Licences’ according to Article 5 EUPL are:
179
+ — GNU General Public License (GPL) v. 2, v. 3
180
+ — GNU Affero General Public License (AGPL) v. 3
181
+ — Open Software License (OSL) v. 2.1, v. 3.0
182
+ — Eclipse Public License (EPL) v. 1.0
183
+ — CeCILL v. 2.0, v. 2.1
184
+ — Mozilla Public Licence (MPL) v. 2
185
+ — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
186
+ — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
187
+ — European Union Public Licence (EUPL) v. 1.1, v. 1.2
188
+ — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+)
189
+
190
+ The European Commission may update this Appendix to later versions of the above licences without producing
191
+ a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
192
+ covered Source Code from exclusive appropriation.
193
+ All other changes or additions to this Appendix require the production of a new EUPL version.
@@ -0,0 +1,20 @@
1
+ include LICENSE
2
+ include README.md
3
+ include pyproject.toml
4
+
5
+ recursive-include bsplot *.py
6
+ recursive-include bsplot/styles *.mplstyle
7
+ recursive-include bsplot/data *
8
+ recursive-include bsplot/scientific_color_maps *
9
+
10
+ prune docs
11
+ prune dev
12
+ prune manuscript
13
+ prune img
14
+ prune figures
15
+ prune build
16
+ prune bsplot.egg-info
17
+ prune .github
18
+
19
+ global-exclude __pycache__
20
+ global-exclude *.py[cod]
bsplot-0.0.6/PKG-INFO ADDED
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: bsplot
3
+ Version: 0.0.6
4
+ Summary: Plotting utilities for neuroscience: styles, palettes, surfaces, glass-brain, and panel helpers.
5
+ License-Expression: EUPL-1.2
6
+ Project-URL: Repository, https://github.com/leon-k-martin/bsplot
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: matplotlib
11
+ Requires-Dist: pybtex
12
+ Requires-Dist: pyaml
13
+ Requires-Dist: scikit-image
14
+ Requires-Dist: nibabel
15
+ Requires-Dist: nilearn
16
+ Requires-Dist: templateflow
17
+ Requires-Dist: graphviz
18
+ Requires-Dist: cmap
19
+ Provides-Extra: docs
20
+ Requires-Dist: quarto; extra == "docs"
21
+ Requires-Dist: quartodoc; extra == "docs"
22
+ Requires-Dist: griffe<1.0; extra == "docs"
23
+ Requires-Dist: jupyter-cache; extra == "docs"
24
+ Dynamic: license-file
25
+
26
+ <h1>
27
+ bsplot
28
+ <img src="docs/Usage/_output/anim1.gif" alt="Sagittal volume animation" height="55" align="right">
29
+ <img src="docs/Usage/_output/anim4.gif" alt="Surface rotation animation" height="55" align="right">
30
+ </h1>
31
+
32
+ Neuroscience plotting utilities built on **matplotlib**.
33
+
34
+ ## Overview
35
+
36
+ ![](docs/overview_figure.png)
37
+
38
+ - Brain surfaces and glass-brain visualizations
39
+ - Volume slicing with anatomical overlays
40
+ - Tractography rendering
41
+ - Publication-ready styles and scientific colormaps
42
+ - Panel helpers for multi-figure layouts
43
+
44
+ ![alt text](docs/figures/brain_network_with_insets.png)
45
+
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ pip install bsplot
51
+ ```
52
+
53
+ ## Dependencies
54
+
55
+ - `matplotlib`
56
+ - `nibabel`
57
+ - `nilearn`
58
+ - `templateflow`
59
+ - `scikit-image`
60
+
bsplot-0.0.6/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <h1>
2
+ bsplot
3
+ <img src="docs/Usage/_output/anim1.gif" alt="Sagittal volume animation" height="55" align="right">
4
+ <img src="docs/Usage/_output/anim4.gif" alt="Surface rotation animation" height="55" align="right">
5
+ </h1>
6
+
7
+ Neuroscience plotting utilities built on **matplotlib**.
8
+
9
+ ## Overview
10
+
11
+ ![](docs/overview_figure.png)
12
+
13
+ - Brain surfaces and glass-brain visualizations
14
+ - Volume slicing with anatomical overlays
15
+ - Tractography rendering
16
+ - Publication-ready styles and scientific colormaps
17
+ - Panel helpers for multi-figure layouts
18
+
19
+ ![alt text](docs/figures/brain_network_with_insets.png)
20
+
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install bsplot
26
+ ```
27
+
28
+ ## Dependencies
29
+
30
+ - `matplotlib`
31
+ - `nibabel`
32
+ - `nilearn`
33
+ - `templateflow`
34
+ - `scikit-image`
35
+
@@ -0,0 +1,24 @@
1
+ # Copyright © Charité Universitätsmedizin Berlin. This software is licensed under the terms of the European Union Public Licence (EUPL) version 1.2 or later.
2
+ from os.path import abspath, dirname, join
3
+
4
+ __version__ = "0.0.6"
5
+
6
+ ROOT = abspath(dirname(__file__))
7
+ datadir = join(ROOT, "data")
8
+
9
+ from . import volume, anat, animate, brain, colors, data, figure, streamlines, style, timeseries, surface, templates, utils
10
+ from .surface import vol_to_mesh, LabeledMeshes, project_vol_to_surf, plot_surf
11
+ from .brain import glass_brain
12
+ from .volume import plot_slice, apply_brain_mask
13
+ from .colors import explore_colormaps
14
+ from .bioicons import (
15
+ BioIcons,
16
+ plot_icon,
17
+ plot_icons_grid,
18
+ IconAnnotation,
19
+ search_icons,
20
+ list_categories,
21
+ list_licenses,
22
+ )
23
+
24
+ style.use("tvbo")
@@ -0,0 +1,56 @@
1
+ # Copyright © Charité Universitätsmedizin Berlin. This software is licensed under the terms of the European Union Public Licence (EUPL) version 1.2 or later.
2
+ """Backwards compatibility module. Use bsplot.volume instead."""
3
+
4
+ import warnings
5
+ import inspect
6
+
7
+ # Only warn if imported directly by user code, not by bsplot's __init__.py
8
+ _stack = inspect.stack()
9
+ if len(_stack) >= 2:
10
+ _caller_filename = _stack[1].filename
11
+ if "bsplot/__init__.py" not in _caller_filename and "bsplot\\__init__.py" not in _caller_filename:
12
+ warnings.warn(
13
+ "bsplot.anat is deprecated, use bsplot.volume instead. "
14
+ "Also note that plot_img has been renamed to plot_slice.",
15
+ DeprecationWarning,
16
+ stacklevel=2,
17
+ )
18
+ del _stack, inspect
19
+
20
+ from bsplot.volume import (
21
+ get_center_of_mass,
22
+ get_cut_coords,
23
+ get_com_slice_index,
24
+ get_slice_index,
25
+ get_world_coords,
26
+ get_view_index,
27
+ get_plane_indices,
28
+ plot_slice,
29
+ plot_img,
30
+ translate_com,
31
+ get_com_view,
32
+ plot_img_on_bg,
33
+ plot_brain_schematics,
34
+ get_world_extent,
35
+ plot_image_extent,
36
+ apply_brain_mask,
37
+ )
38
+
39
+ __all__ = [
40
+ "get_center_of_mass",
41
+ "get_cut_coords",
42
+ "get_com_slice_index",
43
+ "get_slice_index",
44
+ "get_world_coords",
45
+ "get_view_index",
46
+ "get_plane_indices",
47
+ "plot_slice",
48
+ "plot_img",
49
+ "translate_com",
50
+ "get_com_view",
51
+ "plot_img_on_bg",
52
+ "plot_brain_schematics",
53
+ "get_world_extent",
54
+ "plot_image_extent",
55
+ "apply_brain_mask",
56
+ ]
@@ -0,0 +1,195 @@
1
+ # Copyright © Charité Universitätsmedizin Berlin. This software is licensed under the terms of the European Union Public Licence (EUPL) version 1.2 or later.
2
+ """Composable animation utilities for 4D neuroimaging data (matplotlib-only).
3
+
4
+ The core abstraction is :class:`AnimationComposer`, which manages a shared
5
+ timeline and lets you plug in per-axis animation callbacks. All higher-level
6
+ patterns (single view, multi-view, multi-image comparison) can be expressed
7
+ via this composer and a small generic helper.
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+ import nibabel as nib
12
+ import numpy as np
13
+ from matplotlib.animation import FuncAnimation
14
+
15
+
16
+ class AnimationComposer:
17
+ """Composable multi-axes animation helper (matplotlib-only).
18
+
19
+ This class lets you register per-axis update functions that are called for
20
+ every frame with the same frame index, so you can build complex, modular
21
+ animations across several axes.
22
+
23
+ Each registered callback should have the signature::
24
+
25
+ func(frame_index: int, ax: matplotlib.axes.Axes) -> list[Artist] | Artist | None
26
+
27
+ and is expected to draw on the provided axis.
28
+ """
29
+
30
+ def __init__(self, fig, axes, n_frames, interval=100, blit=False):
31
+ """Create a new AnimationComposer.
32
+
33
+ Parameters
34
+ ----------
35
+ fig : matplotlib.figure.Figure
36
+ Parent figure for the animation.
37
+ axes : Axes or sequence of Axes
38
+ One or more axes to animate.
39
+ n_frames : int
40
+ Number of frames (time points).
41
+ interval : int, default 100
42
+ Delay between frames in milliseconds.
43
+ blit : bool, default False
44
+ Whether to use blitting.
45
+ """
46
+
47
+ self.fig = fig
48
+ if hasattr(axes, "__iter__") and not isinstance(axes, (list, tuple)):
49
+ self.axes = list(axes)
50
+ elif hasattr(axes, "__iter__"):
51
+ self.axes = list(axes)
52
+ else:
53
+ self.axes = [axes]
54
+
55
+ self.n_frames = int(n_frames)
56
+ self.interval = interval
57
+ self.blit = blit
58
+ self._callbacks = [] # list of (ax, func)
59
+
60
+ def add_axis_animation(self, ax, func):
61
+ """Register an animation callback for a given axis.
62
+
63
+ Parameters
64
+ ----------
65
+ ax : matplotlib.axes.Axes
66
+ Axis that ``func`` will draw on.
67
+ func : callable
68
+ Function with signature ``func(frame_index: int, ax)`` that returns
69
+ a Matplotlib Artist or a list of Artists (optional).
70
+ """
71
+
72
+ if ax not in self.axes:
73
+ self.axes.append(ax)
74
+ self._callbacks.append((ax, func))
75
+
76
+ def _update(self, frame):
77
+ artists = []
78
+ for ax, func in self._callbacks:
79
+ res = func(frame, ax)
80
+ if res is None:
81
+ continue
82
+ if isinstance(res, (list, tuple)):
83
+ artists.extend(res)
84
+ else:
85
+ artists.append(res)
86
+ return artists
87
+
88
+ def to_animation(self):
89
+ """Create and return the underlying FuncAnimation object."""
90
+
91
+ anim = FuncAnimation(
92
+ self.fig,
93
+ self._update,
94
+ frames=self.n_frames,
95
+ interval=self.interval,
96
+ blit=self.blit,
97
+ )
98
+ return anim
99
+
100
+
101
+ def _ensure_4d(img_4d):
102
+ """Load and validate a 4D NIfTI-like image."""
103
+ if isinstance(img_4d, str):
104
+ img_4d = nib.load(img_4d)
105
+ if len(img_4d.shape) != 4:
106
+ raise ValueError(f"Expected 4D image, got shape {img_4d.shape}")
107
+ return img_4d
108
+
109
+
110
+ def _global_scale_kwargs(img_4d, threshold=0, **plot_kwargs):
111
+ """Compute global vmin/vmax across time, unless user provided scaling.
112
+
113
+ Returns a dict with optional ``vmin``/``vmax`` to forward into ``plot_img``.
114
+ """
115
+ if "vmin" in plot_kwargs or "norm" in plot_kwargs:
116
+ return {}
117
+
118
+ data_4d = img_4d.get_fdata()
119
+ if threshold > 0:
120
+ masked = np.where(np.abs(data_4d) <= threshold, np.nan, data_4d)
121
+ vmin = np.nanmin(masked)
122
+ vmax = np.nanmax(masked)
123
+ else:
124
+ nonzero = data_4d[data_4d != 0]
125
+ vmin = np.nanmin(nonzero) if nonzero.size else np.nanmin(data_4d)
126
+ vmax = np.nanmax(data_4d)
127
+
128
+ contains_negative = np.any(data_4d < 0)
129
+ if contains_negative:
130
+ vmax_abs = max(abs(vmin), abs(vmax))
131
+ vmin, vmax = -vmax_abs, vmax_abs
132
+
133
+ return {"vmin": vmin, "vmax": vmax}
134
+
135
+
136
+ def animate_axes(fig, axes, n_frames, update_fn, context=None, interval=100, blit=False):
137
+ """Convenience wrapper to build an animation over one or many axes.
138
+
139
+ This captures the common pattern used in the docs: one timeline, multiple
140
+ axes, and a single user-defined ``update_fn`` that can branch on the axis
141
+ index and/or shared ``context``.
142
+
143
+ Parameters
144
+ ----------
145
+ fig : matplotlib.figure.Figure
146
+ Parent figure for the animation.
147
+ axes : Axes or sequence of Axes
148
+ Axes to animate. Can be a single axis, a list/tuple, or any iterable
149
+ of axes as returned by ``plt.subplots``.
150
+ n_frames : int
151
+ Number of frames in the animation.
152
+ update_fn : callable
153
+ Function with signature::
154
+
155
+ update_fn(frame: int, ax, axis_idx: int, context: dict | None)
156
+
157
+ It should draw the desired state for the given ``frame`` on ``ax`` and
158
+ return a Matplotlib Artist or list of Artists (or ``None``).
159
+ context : dict or None, optional
160
+ Arbitrary, user-defined state shared across axes and frames.
161
+ interval : int, default 100
162
+ Delay between frames in milliseconds.
163
+ blit : bool, default False
164
+ Whether to use blitting.
165
+
166
+ Returns
167
+ -------
168
+ matplotlib.animation.FuncAnimation
169
+ The constructed animation object.
170
+ """
171
+
172
+ # Normalize axes into a flat list
173
+ if hasattr(axes, "__iter__") and not isinstance(axes, (list, tuple)):
174
+ axes_list = list(axes)
175
+ elif hasattr(axes, "__iter__"):
176
+ axes_list = list(axes)
177
+ else:
178
+ axes_list = [axes]
179
+
180
+ composer = AnimationComposer(fig, axes_list, n_frames=n_frames, interval=interval, blit=blit)
181
+
182
+ for axis_idx, ax in enumerate(axes_list):
183
+
184
+ def make_cb(idx_):
185
+ def _cb(frame, ax_cb):
186
+ return update_fn(frame, ax_cb, idx_, context)
187
+
188
+ return _cb
189
+
190
+ composer.add_axis_animation(ax, make_cb(axis_idx))
191
+
192
+ return composer.to_animation()
193
+
194
+
195
+