swcgeom 0.13.2__tar.gz → 0.15.0__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.

Potentially problematic release.


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

Files changed (111) hide show
  1. {swcgeom-0.13.2 → swcgeom-0.15.0}/.github/workflows/test.yml +1 -1
  2. {swcgeom-0.13.2 → swcgeom-0.15.0}/.gitignore +1 -0
  3. {swcgeom-0.13.2 → swcgeom-0.15.0}/CHANGELOG.md +62 -0
  4. swcgeom-0.15.0/LICENSE +201 -0
  5. {swcgeom-0.13.2/swcgeom.egg-info → swcgeom-0.15.0}/PKG-INFO +6 -5
  6. {swcgeom-0.13.2 → swcgeom-0.15.0}/README.md +3 -3
  7. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/ImageStack.ipynb +13 -11
  8. {swcgeom-0.13.2 → swcgeom-0.15.0}/pyproject.toml +2 -1
  9. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/_version.py +2 -2
  10. swcgeom-0.15.0/swcgeom/analysis/volume.py +152 -0
  11. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/branch_tree.py +2 -3
  12. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/population.py +6 -7
  13. swcgeom-0.15.0/swcgeom/core/swc_utils/assembler.py +26 -0
  14. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/subtree.py +2 -2
  15. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/tree.py +19 -12
  16. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/tree_utils.py +23 -5
  17. swcgeom-0.15.0/swcgeom/core/tree_utils_impl.py +55 -0
  18. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/images/folder.py +42 -17
  19. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/images/io.py +65 -36
  20. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/base.py +41 -21
  21. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/branch.py +5 -5
  22. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/geometry.py +42 -18
  23. swcgeom-0.15.0/swcgeom/transforms/image_stack.py +200 -0
  24. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/images.py +2 -2
  25. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/mst.py +5 -13
  26. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/population.py +2 -2
  27. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/tree.py +7 -13
  28. swcgeom-0.15.0/swcgeom/transforms/tree_assembler.py +173 -0
  29. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/__init__.py +1 -1
  30. swcgeom-0.15.0/swcgeom/utils/sdf.py +329 -0
  31. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/solid_geometry.py +26 -0
  32. swcgeom-0.15.0/swcgeom/utils/volumetric_object.py +504 -0
  33. {swcgeom-0.13.2 → swcgeom-0.15.0/swcgeom.egg-info}/PKG-INFO +6 -5
  34. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom.egg-info/SOURCES.txt +4 -3
  35. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom.egg-info/requires.txt +1 -0
  36. swcgeom-0.15.0/tests/analysis/test_volume.py +57 -0
  37. swcgeom-0.15.0/tests/utils/test_sdf.py +69 -0
  38. {swcgeom-0.13.2 → swcgeom-0.15.0}/tests/utils/test_solid_geometry.py +40 -2
  39. swcgeom-0.13.2/tests/utils/test_geometry_object.py → swcgeom-0.15.0/tests/utils/test_volumetric_object.py +48 -38
  40. swcgeom-0.13.2/LICENSE +0 -3
  41. swcgeom-0.13.2/swcgeom/analysis/volume.py +0 -67
  42. swcgeom-0.13.2/swcgeom/core/swc_utils/assembler.py +0 -155
  43. swcgeom-0.13.2/swcgeom/core/tree_utils_impl.py +0 -39
  44. swcgeom-0.13.2/swcgeom/transforms/image_stack.py +0 -220
  45. swcgeom-0.13.2/swcgeom/transforms/tree_assembler.py +0 -107
  46. swcgeom-0.13.2/swcgeom/utils/geometry_object.py +0 -255
  47. swcgeom-0.13.2/swcgeom/utils/sdf.py +0 -172
  48. swcgeom-0.13.2/tests/analysis/test_volume.py +0 -20
  49. {swcgeom-0.13.2 → swcgeom-0.15.0}/.github/workflows/build.yml +0 -0
  50. {swcgeom-0.13.2 → swcgeom-0.15.0}/.github/workflows/github-publish.yml +0 -0
  51. {swcgeom-0.13.2 → swcgeom-0.15.0}/.github/workflows/pypi-publish.yml +0 -0
  52. {swcgeom-0.13.2 → swcgeom-0.15.0}/.pylintrc +0 -0
  53. {swcgeom-0.13.2 → swcgeom-0.15.0}/.vscode/settings.json +0 -0
  54. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/Branch.ipynb +0 -0
  55. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/BranchTree.ipynb +0 -0
  56. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/CollectTips.ipynb +0 -0
  57. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/CutTree.ipynb +0 -0
  58. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/Features.ipynb +0 -0
  59. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/GeometryTransform.ipynb +0 -0
  60. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/MST.ipynb +0 -0
  61. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/SpectralClustering.ipynb +0 -0
  62. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/Tree.ipynb +0 -0
  63. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/data/101711-10_4p5-of-16_initial.CNG.swc +0 -0
  64. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/data/101711-11_16-of-16_initial.CNG.swc +0 -0
  65. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/data/1059283677_15257_2226-X16029-Y23953.swc +0 -0
  66. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/data/toydata.swc +0 -0
  67. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/dgl/graph.py +0 -0
  68. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/pytorch/branch.py +0 -0
  69. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/pytorch/branch_dataset.py +0 -0
  70. {swcgeom-0.13.2 → swcgeom-0.15.0}/examples/pytorch/tree_folder_dataset.py +0 -0
  71. {swcgeom-0.13.2 → swcgeom-0.15.0}/git-conventional-commits.yaml +0 -0
  72. {swcgeom-0.13.2 → swcgeom-0.15.0}/setup.cfg +0 -0
  73. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/__init__.py +0 -0
  74. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/__init__.py +0 -0
  75. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/branch_features.py +0 -0
  76. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/feature_extractor.py +0 -0
  77. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/node_features.py +0 -0
  78. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/path_features.py +0 -0
  79. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/sholl.py +0 -0
  80. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/trunk.py +0 -0
  81. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/analysis/visualization.py +0 -0
  82. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/__init__.py +0 -0
  83. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/branch.py +0 -0
  84. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/node.py +0 -0
  85. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/path.py +0 -0
  86. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/segment.py +0 -0
  87. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc.py +0 -0
  88. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/__init__.py +0 -0
  89. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/base.py +0 -0
  90. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/checker.py +0 -0
  91. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/io.py +0 -0
  92. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/core/swc_utils/normalizer.py +0 -0
  93. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/images/__init__.py +0 -0
  94. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/images/augmentation.py +0 -0
  95. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/__init__.py +0 -0
  96. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/transforms/path.py +0 -0
  97. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/debug.py +0 -0
  98. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/download.py +0 -0
  99. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/dsu.py +0 -0
  100. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/ellipse.py +0 -0
  101. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/file.py +0 -0
  102. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/neuromorpho.py +0 -0
  103. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/numpy_helper.py +0 -0
  104. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/renderer.py +0 -0
  105. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom/utils/transforms.py +0 -0
  106. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom.egg-info/dependency_links.txt +0 -0
  107. {swcgeom-0.13.2 → swcgeom-0.15.0}/swcgeom.egg-info/top_level.txt +0 -0
  108. {swcgeom-0.13.2 → swcgeom-0.15.0}/tests/__init__.py +0 -0
  109. {swcgeom-0.13.2 → swcgeom-0.15.0}/tests/utils/__init__.py +0 -0
  110. {swcgeom-0.13.2 → swcgeom-0.15.0}/tests/utils/test_dsu.py +0 -0
  111. {swcgeom-0.13.2 → swcgeom-0.15.0}/tests/utils/test_transforms.py +0 -0
@@ -7,7 +7,7 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- python-version: ["pypy3.10", "3.10", "3.11", "3.12"]
10
+ python-version: ["3.10", "3.11", "3.12"]
11
11
 
12
12
  steps:
13
13
  - uses: actions/checkout@v4
@@ -1,5 +1,6 @@
1
1
  # Auto generated
2
2
  _version.py
3
+ .DS_Store
3
4
 
4
5
  # Byte-compiled / optimized / DLL files
5
6
  __pycache__/
@@ -1,5 +1,67 @@
1
1
  # Changelog
2
2
 
3
+ ## **0.15.0**&emsp;<sub><sup>2024-01-28 ([d300b41...8c9e0ab](https://github.com/yzx9/swcgeom/compare/d300b41689ee892fe5a23dad57f92e1054c0f9e9...8c9e0ab45c447d3d8121b0cc4178be5f65d18a56?diff=split))</sup></sub>
4
+
5
+ ### Features
6
+
7
+ ##### `core`
8
+
9
+ - expose subtree id mapping ([35738a3](https://github.com/yzx9/swcgeom/commit/35738a31b2373a43ab29550335a457c51b7befce))
10
+
11
+ ##### `images`
12
+
13
+ - add dtype support ([d300b41](https://github.com/yzx9/swcgeom/commit/d300b41689ee892fe5a23dad57f92e1054c0f9e9))
14
+
15
+ ##### `transforms`
16
+
17
+ - generate image stack patch ([decd3a1](https://github.com/yzx9/swcgeom/commit/decd3a1ee63e1657aafa24ec5dfbf7439d25a551))
18
+ - add \`extra\_repr\` api ([ca19361](https://github.com/yzx9/swcgeom/commit/ca1936146783ebccc2ffe25596799580e89b3432))
19
+
20
+ ### Bug Fixes
21
+
22
+ ##### `core`
23
+
24
+ - fix classmethod typing annotations ([0123eeb](https://github.com/yzx9/swcgeom/commit/0123eeb46142c3c3a695a5cf2495588a2effe275))
25
+
26
+ ##### `transforms`
27
+
28
+ - should stack images ([8c9e0ab](https://github.com/yzx9/swcgeom/commit/8c9e0ab45c447d3d8121b0cc4178be5f65d18a56))
29
+
30
+
31
+ ### BREAKING CHANGES
32
+ - `core` remove assembler module ([414533d](https://github.com/yzx9/swcgeom/commit/414533d17238ed45972dff1909cf025a19b7fa1e))
33
+ <br>
34
+
35
+
36
+ ## **0.14.0**&emsp;<sub><sup>2023-12-26 ([b9c95f5...cc22018](https://github.com/yzx9/swcgeom/compare/b9c95f58f725490f3b624233cc0be20b31605e53...cc22018ad79af18ecd812b932812a0ff40a0fe40?diff=split))</sup></sub>
37
+
38
+ ### Features
39
+
40
+ ##### `analysis`
41
+ * add high accuracy volume calculation ([9b51b74](https://github.com/yzx9/swcgeom/commit/9b51b7401efffc1b0cfbfecbdf3eb60300e1e114))
42
+
43
+ ### Bug Fixes
44
+
45
+ ##### `analysis`
46
+ * subtract volume between frustum cone ([dae116e](https://github.com/yzx9/swcgeom/commit/dae116e45146428f5cb61c696ff1d6804e03993c))
47
+
48
+ ##### `utils`
49
+ * avoid numerical error ([a6bd4ad](https://github.com/yzx9/swcgeom/commit/a6bd4adc87e86dcaca2bcb45aee68cea51a540c0))
50
+
51
+ ### Performance Improvements
52
+
53
+ ##### `analysis`
54
+ * use bvh scene ([7a7b988](https://github.com/yzx9/swcgeom/commit/7a7b98864fd6d0378b0b696d2963353d0592b4d3))
55
+
56
+ ##### `utils`
57
+ * use \`sdflit\` instead custom impl ([a47a190](https://github.com/yzx9/swcgeom/commit/a47a19091b46a1071140a12fb20105cdf851a85a))
58
+
59
+ ### BREAKING CHANGES
60
+ * `transforms` rewrite image stack ([cc22018](https://github.com/yzx9/swcgeom/commit/cc22018ad79af18ecd812b932812a0ff40a0fe40))
61
+
62
+ <br>
63
+
64
+
3
65
  ## **0.13.2**&emsp;<sub><sup>2023-12-16 ([10f330d...291ae2a](https://github.com/yzx9/swcgeom/compare/10f330d13b49aba19c043b91c42c183e1f9ad4d4...291ae2afde6d29d234e8f1b3521d3f221350e01e?diff=split))</sup></sub>
4
66
 
5
67
  ### Performance Improvements
swcgeom-0.15.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2024] [Zexin Yuan]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swcgeom
3
- Version: 0.13.2
3
+ Version: 0.15.0
4
4
  Summary: Neuron geometry library for swc format
5
5
  Author-email: yzx9 <yuan.zx@outlook.com>
6
- License: CC4.0 BY-NC-SA
6
+ License: Apache-2.0
7
7
  Project-URL: repository, https://github.com/yzx9/swcgeom
8
8
  Keywords: neuronscience,neuron,neuroanatomy,neuron-morphology
9
9
  Requires-Python: >=3.10
@@ -15,6 +15,7 @@ Requires-Dist: numpy>=1.22.3
15
15
  Requires-Dist: pandas>=1.4.2
16
16
  Requires-Dist: pynrrd>=1.0.0
17
17
  Requires-Dist: scipy>=1.9.1
18
+ Requires-Dist: sdflit>=0.2.1
18
19
  Requires-Dist: seaborn>=0.12.0
19
20
  Requires-Dist: tifffile>=2022.8.12
20
21
  Requires-Dist: typing_extensions>=4.4.0
@@ -30,8 +31,6 @@ Requires-Dist: urllib3>=1.26.0; extra == "all"
30
31
 
31
32
  # SWCGEOM
32
33
 
33
- <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />
34
-
35
34
  [![Run tests](https://github.com/yzx9/swcgeom/actions/workflows/test.yml/badge.svg)](https://github.com/yzx9/swcgeom/actions/workflows/test.yml)
36
35
  [![Release to GitHub](https://github.com/yzx9/swcgeom/actions/workflows/github-publish.yml/badge.svg)](https://github.com/yzx9/swcgeom/releases)
37
36
  [![Release to PyPI](https://github.com/yzx9/swcgeom/actions/workflows/pypi-publish.yml/badge.svg)](https://pypi.org/project/swcgeom/)
@@ -67,4 +66,6 @@ Static analysis don't support import hook used in editable install for [PEP660](
67
66
 
68
67
  ## LICENSE
69
68
 
70
- This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
69
+ This work is licensed under a <a rel="license" href="https://www.apache.org/licenses/">Apache-2.0</a>.
70
+
71
+ Copyright (c) 2022-present, Zexin Yuan
@@ -1,7 +1,5 @@
1
1
  # SWCGEOM
2
2
 
3
- <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />
4
-
5
3
  [![Run tests](https://github.com/yzx9/swcgeom/actions/workflows/test.yml/badge.svg)](https://github.com/yzx9/swcgeom/actions/workflows/test.yml)
6
4
  [![Release to GitHub](https://github.com/yzx9/swcgeom/actions/workflows/github-publish.yml/badge.svg)](https://github.com/yzx9/swcgeom/releases)
7
5
  [![Release to PyPI](https://github.com/yzx9/swcgeom/actions/workflows/pypi-publish.yml/badge.svg)](https://pypi.org/project/swcgeom/)
@@ -37,4 +35,6 @@ Static analysis don't support import hook used in editable install for [PEP660](
37
35
 
38
36
  ## LICENSE
39
37
 
40
- This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
38
+ This work is licensed under a <a rel="license" href="https://www.apache.org/licenses/">Apache-2.0</a>.
39
+
40
+ Copyright (c) 2022-present, Zexin Yuan
@@ -22,17 +22,13 @@
22
22
  "source": [
23
23
  "\"\"\"Create image stack from morphology.\"\"\"\n",
24
24
  "\n",
25
- "import numpy as np\n",
26
- "import numpy.typing as npt\n",
27
- "\n",
28
- "import swcgeom\n",
29
25
  "from swcgeom import Tree\n",
30
26
  "from swcgeom.transforms import ToImageStack\n"
31
27
  ]
32
28
  },
33
29
  {
34
30
  "cell_type": "code",
35
- "execution_count": 35,
31
+ "execution_count": 3,
36
32
  "metadata": {},
37
33
  "outputs": [],
38
34
  "source": [
@@ -41,18 +37,24 @@
41
37
  "swc3 = \"data/1059283677_15257_2226-X16029-Y23953.swc\"\n",
42
38
  "\n",
43
39
  "# create a tree\n",
44
- "tree1 = swcgeom.Tree.from_swc(swc1)\n",
45
- "tree2 = swcgeom.Tree.from_swc(swc2)\n",
46
- "tree3 = swcgeom.Tree.from_swc(swc3, extra_cols=[\"seg_id\",\"level\",\"mode\",\"timestamp\",\"TFresindex\"])"
40
+ "tree1 = Tree.from_swc(swc1)\n",
41
+ "tree2 = Tree.from_swc(swc2)\n",
42
+ "tree3 = Tree.from_swc(swc3, extra_cols=[\"seg_id\",\"level\",\"mode\",\"timestamp\",\"TFresindex\"])"
47
43
  ]
48
44
  },
49
45
  {
50
46
  "cell_type": "code",
51
- "execution_count": 39,
47
+ "execution_count": null,
52
48
  "metadata": {},
53
49
  "outputs": [],
54
50
  "source": [
55
- "trans = ToImageStack(resolution=[1, 1, 1], z_per_iter=8)\n",
51
+ "trans = ToImageStack(resolution=[1, 1, 1])\n",
52
+ "\n",
53
+ "# load entire image stack into memory, should be avoided for large images\n",
54
+ "x = trans(tree1)\n",
55
+ "print(x.dtype, x.shape)\n",
56
+ "\n",
57
+ "# save image stack to file\n",
56
58
  "trans.transform_and_save(\"test.tif\", tree1)"
57
59
  ]
58
60
  }
@@ -73,7 +75,7 @@
73
75
  "name": "python",
74
76
  "nbconvert_exporter": "python",
75
77
  "pygments_lexer": "ipython3",
76
- "version": "3.10.7"
78
+ "version": "3.12.1"
77
79
  },
78
80
  "orig_nbformat": 4,
79
81
  "vscode": {
@@ -10,7 +10,7 @@ readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  authors = [{ name = "yzx9", email = "yuan.zx@outlook.com" }]
12
12
  keywords = ["neuronscience", "neuron", "neuroanatomy", "neuron-morphology"]
13
- license = { text = "CC4.0 BY-NC-SA" }
13
+ license = { text = "Apache-2.0" }
14
14
  dependencies = [
15
15
  "imagecodecs>=2023.3.16",
16
16
  "matplotlib>=3.5.2",
@@ -18,6 +18,7 @@ dependencies = [
18
18
  "pandas>=1.4.2",
19
19
  "pynrrd>=1.0.0",
20
20
  "scipy>=1.9.1",
21
+ "sdflit>=0.2.1",
21
22
  "seaborn>=0.12.0",
22
23
  "tifffile>=2022.8.12",
23
24
  "typing_extensions>=4.4.0",
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.13.2'
16
- __version_tuple__ = version_tuple = (0, 13, 2)
15
+ __version__ = version = '0.15.0'
16
+ __version_tuple__ = version_tuple = (0, 15, 0)
@@ -0,0 +1,152 @@
1
+ """Analysis of volume of a SWC tree."""
2
+
3
+ from typing import Dict, List, Literal
4
+
5
+ import numpy as np
6
+ from sdflit import ColoredMaterial, ObjectsScene, SDFObject, UniformSampler
7
+
8
+ from swcgeom.core import Tree
9
+ from swcgeom.utils import VolFrustumCone, VolSphere
10
+
11
+ __all__ = ["get_volume"]
12
+
13
+ ACCURACY_LEVEL = Literal["low", "middle", "high"]
14
+ ACCURACY_LEVELS: Dict[ACCURACY_LEVEL, int] = {"low": 3, "middle": 5, "high": 8}
15
+
16
+
17
+ def get_volume(
18
+ tree: Tree,
19
+ *,
20
+ method: Literal["frustum_cone"] = "frustum_cone",
21
+ accuracy: int | ACCURACY_LEVEL = "middle",
22
+ ) -> float:
23
+ """Get the volume of the tree.
24
+
25
+ Parameters
26
+ ----------
27
+ tree : Tree
28
+ Neuronal tree.
29
+ method : {"frustum_cone"}, optional
30
+ Method for volume calculation.
31
+ accuracy : int or {"low", "middle", "high"}, optional
32
+ Accuracy level for volume calculation. The higher the accuracy,
33
+ the more accurate the volume calculation, but the slower the
34
+ calculation. The accuracy level can be specified either as an
35
+ integer or as a string.
36
+
37
+ The string values correspond to the following accuracy levels:
38
+
39
+ - "low": 3
40
+ - "middle": 5
41
+ - "high": 8
42
+
43
+ Returns
44
+ -------
45
+ volume : float
46
+ Volume of the tree.
47
+
48
+ Notes
49
+ -----
50
+ The SWC format is a method for representing neurons, which includes
51
+ both the radius of individual points and their interconnectivity.
52
+ Consequently, there are multiple distinct approaches to
53
+ representation within this framework.
54
+
55
+ Currently, we support a standard approach to volume calculation.
56
+ This method involves treating each node as a sphere and
57
+ representing the connections between them as truncated cone-like
58
+ structures, or frustums, with varying radii at their top and bottom
59
+ surfaces.
60
+
61
+ We welcome additional representation methods through pull requests.
62
+ """
63
+
64
+ if isinstance(accuracy, str):
65
+ accuracy = ACCURACY_LEVELS[accuracy]
66
+
67
+ assert 0 < accuracy <= 10
68
+
69
+ match method:
70
+ case "frustum_cone":
71
+ return _get_volume_frustum_cone(tree, accuracy=accuracy)
72
+ case _:
73
+ raise ValueError(f"Unsupported method: {method}")
74
+
75
+
76
+ def _get_volume_frustum_cone(tree: Tree, *, accuracy: int) -> float:
77
+ """Get the volume of the tree using the frustum cone method.
78
+
79
+ Parameters
80
+ ----------
81
+ tree : Tree
82
+ Neuronal tree.
83
+ accuracy : int
84
+ 1 : Sphere only
85
+ 2 : Sphere and Frustum Cone
86
+ 3 : Sphere, Frustum Cone, and intersection in single-branch
87
+ 5 : Above and Sphere-Frustum Cone intersection in multi-branch
88
+ 10 : Fully calculated by Monte Carlo method
89
+ """
90
+
91
+ if accuracy == 10:
92
+ return _get_volume_frustum_cone_mc_only(tree)
93
+
94
+ volume = 0.0
95
+
96
+ def leave(n: Tree.Node, children: List[VolSphere]) -> VolSphere:
97
+ sphere = VolSphere(n.xyz(), n.r)
98
+ cones = [VolFrustumCone(n.xyz(), n.r, c.center, c.radius) for c in children]
99
+
100
+ v = sphere.get_volume()
101
+ if accuracy >= 2:
102
+ v += sum(fc.get_volume() for fc in cones)
103
+
104
+ if accuracy >= 3:
105
+ v -= sum(sphere.intersect(fc).get_volume() for fc in cones)
106
+ v -= sum(s.intersect(fc).get_volume() for s, fc in zip(children, cones))
107
+ v += sum(s.intersect(sphere).get_volume() for s in children)
108
+
109
+ if accuracy >= 5:
110
+ v -= sum(
111
+ cones[i].intersect(cones[j]).subtract(sphere).get_volume()
112
+ for i in range(len(cones))
113
+ for j in range(i + 1, len(cones))
114
+ )
115
+
116
+ nonlocal volume
117
+ volume += v
118
+ return sphere
119
+
120
+ tree.traverse(leave=leave)
121
+ return volume
122
+
123
+
124
+ def _get_volume_frustum_cone_mc_only(tree: Tree) -> float:
125
+ if tree.number_of_nodes() == 0:
126
+ return 0
127
+
128
+ material = ColoredMaterial((1, 0, 0)).into()
129
+ scene = ObjectsScene()
130
+ scene.set_background((0, 0, 0))
131
+
132
+ def leave(n: Tree.Node, children: List[VolSphere]) -> VolSphere:
133
+ sphere = VolSphere(n.xyz(), n.r)
134
+ scene.add_object(SDFObject(sphere.sdf, material).into())
135
+
136
+ for c in children:
137
+ fc = VolFrustumCone(n.xyz(), n.r, c.center, c.radius)
138
+ scene.add_object(SDFObject(fc.sdf, material).into())
139
+
140
+ return sphere
141
+
142
+ tree.traverse(leave=leave)
143
+ scene.build_bvh()
144
+
145
+ # TODO: estimate the number of samples needed
146
+ n_samples = 100_000_000
147
+
148
+ vmin, vmax = scene.bounding_box()
149
+ sampler = UniformSampler(vmin, vmax)
150
+ data = sampler.sample(scene.into(), n_samples)
151
+ volume = data.sum() / n_samples * np.subtract(vmax, vmin).prod()
152
+ return volume
@@ -5,7 +5,6 @@ from typing import Dict, List
5
5
 
6
6
  import numpy as np
7
7
  import pandas as pd
8
- from typing_extensions import Self
9
8
 
10
9
  from swcgeom.core.branch import Branch
11
10
  from swcgeom.core.swc_utils import to_sub_topology
@@ -31,7 +30,7 @@ class BranchTree(Tree):
31
30
  return self.branches[idx]
32
31
 
33
32
  @classmethod
34
- def from_tree(cls, tree: Tree) -> Self:
33
+ def from_tree(cls, tree: Tree) -> "BranchTree":
35
34
  """Generating a branch tree from tree."""
36
35
 
37
36
  branches = tree.get_branches()
@@ -56,6 +55,6 @@ class BranchTree(Tree):
56
55
  return branch_tree
57
56
 
58
57
  @classmethod
59
- def from_data_frame(cls, df: pd.DataFrame, *args, **kwargs) -> Self:
58
+ def from_data_frame(cls, df: pd.DataFrame, *args, **kwargs) -> "BranchTree":
60
59
  tree = super().from_data_frame(df, *args, **kwargs)
61
60
  return cls.from_tree(tree)
@@ -17,7 +17,6 @@ from typing import (
17
17
 
18
18
  import numpy as np
19
19
  import numpy.typing as npt
20
- from typing_extensions import Self
21
20
 
22
21
  from swcgeom.core.swc import eswc_cols
23
22
  from swcgeom.core.tree import Tree
@@ -155,7 +154,7 @@ class Population:
155
154
  return f"Neuron population in '{self.root}'"
156
155
 
157
156
  @classmethod
158
- def from_swc(cls, root: str, ext: str = ".swc", **kwargs) -> Self:
157
+ def from_swc(cls, root: str, ext: str = ".swc", **kwargs) -> "Population":
159
158
  if not os.path.exists(root):
160
159
  raise FileNotFoundError(
161
160
  f"the root does not refers to an existing directory: {root}"
@@ -171,7 +170,7 @@ class Population:
171
170
  ext: str = ".eswc",
172
171
  extra_cols: Optional[Iterable[str]] = None,
173
172
  **kwargs,
174
- ) -> Self:
173
+ ) -> "Population":
175
174
  extra_cols = list(extra_cols) if extra_cols is not None else []
176
175
  extra_cols.extend(k for k, t in eswc_cols)
177
176
  return cls.from_swc(root, ext, extra_cols=extra_cols, **kwargs)
@@ -244,7 +243,7 @@ class Populations:
244
243
  check_same: bool = False,
245
244
  labels: Optional[Iterable[str]] = None,
246
245
  **kwargs,
247
- ) -> Self:
246
+ ) -> "Populations":
248
247
  """Get population from dirs.
249
248
 
250
249
  Parameters
@@ -268,7 +267,7 @@ class Populations:
268
267
 
269
268
  fs = [inter for _ in roots]
270
269
  elif check_same:
271
- assert reduce(lambda a, b: a == b, fs), "not the same among populations"
270
+ assert [fs[0] == a for a in fs[1:]], "not the same among populations"
272
271
 
273
272
  populations = [
274
273
  Population(
@@ -276,7 +275,7 @@ class Populations:
276
275
  )
277
276
  for i, d in enumerate(roots)
278
277
  ]
279
- return cls(populations, labels=labels)
278
+ return Populations(populations, labels=labels)
280
279
 
281
280
  @classmethod
282
281
  def from_eswc(
@@ -286,7 +285,7 @@ class Populations:
286
285
  *,
287
286
  ext: str = ".eswc",
288
287
  **kwargs,
289
- ) -> Self:
288
+ ) -> "Populations":
290
289
  extra_cols = list(extra_cols) if extra_cols is not None else []
291
290
  extra_cols.extend(k for k, t in eswc_cols)
292
291
  return cls.from_swc(roots, extra_cols=extra_cols, ext=ext, **kwargs)