swcgeom 0.17.1__py3-none-any.whl → 0.18.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of swcgeom might be problematic. Click here for more details.
- swcgeom/__init__.py +14 -0
- swcgeom/_version.py +2 -2
- swcgeom/analysis/__init__.py +15 -0
- swcgeom/analysis/feature_extractor.py +27 -3
- swcgeom/analysis/features.py +31 -4
- swcgeom/analysis/lmeasure.py +43 -7
- swcgeom/analysis/sholl.py +21 -24
- swcgeom/analysis/trunk.py +15 -0
- swcgeom/analysis/visualization.py +15 -0
- swcgeom/analysis/visualization3d.py +15 -0
- swcgeom/analysis/volume.py +15 -0
- swcgeom/core/__init__.py +15 -0
- swcgeom/core/branch.py +15 -0
- swcgeom/core/branch_tree.py +15 -0
- swcgeom/core/compartment.py +15 -0
- swcgeom/core/node.py +30 -1
- swcgeom/core/path.py +18 -7
- swcgeom/core/population.py +43 -3
- swcgeom/core/swc.py +15 -0
- swcgeom/core/swc_utils/__init__.py +15 -1
- swcgeom/core/swc_utils/assembler.py +15 -0
- swcgeom/core/swc_utils/base.py +15 -0
- swcgeom/core/swc_utils/checker.py +19 -12
- swcgeom/core/swc_utils/io.py +17 -1
- swcgeom/core/swc_utils/normalizer.py +16 -1
- swcgeom/core/swc_utils/subtree.py +15 -0
- swcgeom/core/tree.py +37 -9
- swcgeom/core/tree_utils.py +17 -7
- swcgeom/core/tree_utils_impl.py +15 -0
- swcgeom/images/__init__.py +15 -0
- swcgeom/images/augmentation.py +15 -0
- swcgeom/images/contrast.py +15 -0
- swcgeom/images/folder.py +17 -10
- swcgeom/images/io.py +18 -6
- swcgeom/transforms/__init__.py +16 -0
- swcgeom/transforms/base.py +17 -2
- swcgeom/transforms/branch.py +74 -8
- swcgeom/transforms/branch_tree.py +82 -0
- swcgeom/transforms/geometry.py +22 -7
- swcgeom/transforms/image_preprocess.py +15 -0
- swcgeom/transforms/image_stack.py +30 -4
- swcgeom/transforms/images.py +17 -10
- swcgeom/transforms/mst.py +15 -0
- swcgeom/transforms/neurolucida_asc.py +16 -1
- swcgeom/transforms/path.py +15 -0
- swcgeom/transforms/population.py +15 -0
- swcgeom/transforms/tree.py +76 -23
- swcgeom/transforms/tree_assembler.py +19 -4
- swcgeom/utils/__init__.py +15 -0
- swcgeom/utils/debug.py +15 -0
- swcgeom/utils/download.py +59 -21
- swcgeom/utils/dsu.py +15 -0
- swcgeom/utils/ellipse.py +15 -0
- swcgeom/utils/file.py +15 -0
- swcgeom/utils/neuromorpho.py +18 -7
- swcgeom/utils/numpy_helper.py +15 -0
- swcgeom/utils/plotter_2d.py +15 -0
- swcgeom/utils/plotter_3d.py +18 -1
- swcgeom/utils/renderer.py +15 -0
- swcgeom/utils/sdf.py +17 -5
- swcgeom/utils/solid_geometry.py +15 -0
- swcgeom/utils/transforms.py +16 -1
- swcgeom/utils/volumetric_object.py +15 -0
- {swcgeom-0.17.1.dist-info → swcgeom-0.18.1.dist-info}/LICENSE +1 -1
- {swcgeom-0.17.1.dist-info → swcgeom-0.18.1.dist-info}/METADATA +26 -22
- swcgeom-0.18.1.dist-info/RECORD +68 -0
- {swcgeom-0.17.1.dist-info → swcgeom-0.18.1.dist-info}/WHEEL +1 -1
- swcgeom-0.17.1.dist-info/RECORD +0 -67
- {swcgeom-0.17.1.dist-info → swcgeom-0.18.1.dist-info}/top_level.txt +0 -0
swcgeom/core/population.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Neuron population is a set of tree."""
|
|
2
17
|
|
|
3
18
|
import os
|
|
@@ -97,6 +112,19 @@ class ChainTrees:
|
|
|
97
112
|
return (self[i] for i in range(self.__len__()))
|
|
98
113
|
|
|
99
114
|
|
|
115
|
+
class NestTrees:
|
|
116
|
+
def __init__(self, trees: Trees, idx: Iterable[int], /) -> None:
|
|
117
|
+
super().__init__()
|
|
118
|
+
self.trees = trees
|
|
119
|
+
self.idx = list(idx)
|
|
120
|
+
|
|
121
|
+
def __getitem__(self, key: int, /) -> Tree:
|
|
122
|
+
return self.trees[self.idx[key]]
|
|
123
|
+
|
|
124
|
+
def __len__(self) -> int:
|
|
125
|
+
return len(self.idx)
|
|
126
|
+
|
|
127
|
+
|
|
100
128
|
class Population:
|
|
101
129
|
"""Neuron population."""
|
|
102
130
|
|
|
@@ -135,13 +163,14 @@ class Population:
|
|
|
135
163
|
|
|
136
164
|
# fmt:off
|
|
137
165
|
@overload
|
|
138
|
-
def __getitem__(self, key: slice) ->
|
|
166
|
+
def __getitem__(self, key: slice) -> Trees: ...
|
|
139
167
|
@overload
|
|
140
168
|
def __getitem__(self, key: int) -> Tree: ...
|
|
141
169
|
# fmt:on
|
|
142
|
-
def __getitem__(self, key):
|
|
170
|
+
def __getitem__(self, key: int | slice):
|
|
143
171
|
if isinstance(key, slice):
|
|
144
|
-
|
|
172
|
+
trees = NestTrees(self.trees, range(*key.indices(len(self))))
|
|
173
|
+
return cast(Trees, trees)
|
|
145
174
|
|
|
146
175
|
if isinstance(key, (int, np.integer)):
|
|
147
176
|
return cast(Tree, self.trees[int(key)])
|
|
@@ -328,3 +357,14 @@ def _get_idx(key: int, length: int) -> int:
|
|
|
328
357
|
key += length
|
|
329
358
|
|
|
330
359
|
return key
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# experimental
|
|
363
|
+
def filter_population(
|
|
364
|
+
pop: Population, predicate: Callable[[Tree], bool]
|
|
365
|
+
) -> "Population":
|
|
366
|
+
"""Filter trees in the population."""
|
|
367
|
+
|
|
368
|
+
# TODO: how to avoid load trees
|
|
369
|
+
idx = [i for i, t in enumerate(pop) if predicate(t)]
|
|
370
|
+
return Population(NestTrees(pop.trees, idx), root=pop.root)
|
swcgeom/core/swc.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""SWC format."""
|
|
2
17
|
|
|
3
18
|
import warnings
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""SWC format utils.
|
|
2
17
|
|
|
3
18
|
Notes
|
|
@@ -8,7 +23,6 @@ If you use the method here, please review the code more frequently, we
|
|
|
8
23
|
will try to flag all breaking changes but NO promises.
|
|
9
24
|
"""
|
|
10
25
|
|
|
11
|
-
|
|
12
26
|
from swcgeom.core.swc_utils.assembler import *
|
|
13
27
|
from swcgeom.core.swc_utils.base import *
|
|
14
28
|
from swcgeom.core.swc_utils.checker import *
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Assemble lines to swc.
|
|
2
17
|
|
|
3
18
|
Notes
|
swcgeom/core/swc_utils/base.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Base SWC format utils."""
|
|
2
17
|
|
|
3
18
|
from collections.abc import Callable
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Check common"""
|
|
2
17
|
|
|
3
|
-
import warnings
|
|
4
18
|
from collections import defaultdict
|
|
5
19
|
from typing import Optional
|
|
6
20
|
|
|
7
21
|
import numpy as np
|
|
8
22
|
import pandas as pd
|
|
23
|
+
from typing_extensions import deprecated
|
|
9
24
|
|
|
10
25
|
from swcgeom.core.swc_utils.base import SWCNames, Topology, get_dsu, get_names, traverse
|
|
11
26
|
from swcgeom.utils import DisjointSetUnion
|
|
@@ -81,6 +96,7 @@ def has_cyclic(topology: Topology) -> bool:
|
|
|
81
96
|
return False
|
|
82
97
|
|
|
83
98
|
|
|
99
|
+
@deprecated("Use `is_single_root` instead")
|
|
84
100
|
def check_single_root(*args, **kwargs) -> bool:
|
|
85
101
|
"""Check if the tree is single root.
|
|
86
102
|
|
|
@@ -88,14 +104,10 @@ def check_single_root(*args, **kwargs) -> bool:
|
|
|
88
104
|
Use :meth:`is_single_root` instead.
|
|
89
105
|
"""
|
|
90
106
|
|
|
91
|
-
warnings.warn(
|
|
92
|
-
"`check_single_root` has been renamed to `is_single_root` since"
|
|
93
|
-
"v0.5.0, and will be removed in next version",
|
|
94
|
-
DeprecationWarning,
|
|
95
|
-
)
|
|
96
107
|
return is_single_root(*args, **kwargs)
|
|
97
108
|
|
|
98
109
|
|
|
110
|
+
@deprecated("Use `is_bifurcate` instead")
|
|
99
111
|
def is_binary_tree(
|
|
100
112
|
df: pd.DataFrame, exclude_root: bool = True, *, names: Optional[SWCNames] = None
|
|
101
113
|
) -> bool:
|
|
@@ -105,11 +117,6 @@ def is_binary_tree(
|
|
|
105
117
|
Use :meth:`is_bifurcate` instead.
|
|
106
118
|
"""
|
|
107
119
|
|
|
108
|
-
warnings.warn(
|
|
109
|
-
"`is_binary_tree` has been replaced by to `is_bifurcate` since"
|
|
110
|
-
"v0.8.0, and will be removed in next version",
|
|
111
|
-
DeprecationWarning,
|
|
112
|
-
)
|
|
113
120
|
names = get_names(names)
|
|
114
121
|
topo = (df[names.id].to_numpy(), df[names.pid].to_numpy())
|
|
115
122
|
return is_bifurcate(topo, exclude_root=exclude_root)
|
swcgeom/core/swc_utils/io.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Read and write swc format."""
|
|
2
17
|
|
|
3
18
|
import re
|
|
@@ -172,7 +187,8 @@ def parse_swc(
|
|
|
172
187
|
RE_FLOAT, # r
|
|
173
188
|
r"(-?[0-9]+)", # pid
|
|
174
189
|
] + [
|
|
175
|
-
RE_FLOAT
|
|
190
|
+
RE_FLOAT
|
|
191
|
+
for _ in extras # assert float
|
|
176
192
|
]
|
|
177
193
|
|
|
178
194
|
re_swc_cols_str = r"\s+".join(re_swc_cols)
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""SWC format utils.
|
|
2
17
|
|
|
3
18
|
Methods ending with a underline imply an in-place transformation.
|
|
@@ -77,7 +92,7 @@ def link_roots_to_nearest_(
|
|
|
77
92
|
vs = df[[names.x, names.y, names.z]] - row[[names.x, names.y, names.z]]
|
|
78
93
|
dis = np.linalg.norm(vs.to_numpy(), axis=1)
|
|
79
94
|
subtree = dsu == dsu[i] # type: ignore
|
|
80
|
-
dis = np.where(subtree, np.
|
|
95
|
+
dis = np.where(subtree, np.inf, dis) # avoid link to same tree
|
|
81
96
|
dsu = np.where(subtree, dsu[dis.argmin()], dsu) # merge set
|
|
82
97
|
df.loc[i, names.pid] = df[names.id].iloc[dis.argmin()] # type: ignore
|
|
83
98
|
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Cut subtree.
|
|
2
17
|
|
|
3
18
|
This module provides a series of low-level topological subtree methods,
|
swcgeom/core/tree.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Neuron tree."""
|
|
2
17
|
|
|
3
18
|
import itertools
|
|
@@ -8,6 +23,7 @@ from typing import Literal, Optional, TypeVar, Union, overload
|
|
|
8
23
|
import numpy as np
|
|
9
24
|
import numpy.typing as npt
|
|
10
25
|
import pandas as pd
|
|
26
|
+
from typing_extensions import deprecated
|
|
11
27
|
|
|
12
28
|
from swcgeom.core.branch import Branch
|
|
13
29
|
from swcgeom.core.compartment import Compartment, Compartments
|
|
@@ -38,11 +54,11 @@ class Tree(DictSWC):
|
|
|
38
54
|
|
|
39
55
|
def branch(self) -> "Tree.Branch":
|
|
40
56
|
ns: list["Tree.Node"] = [self]
|
|
41
|
-
while not ns[-1].
|
|
57
|
+
while not ns[-1].is_furcation() and (p := ns[-1].parent()) is not None:
|
|
42
58
|
ns.append(p)
|
|
43
59
|
|
|
44
60
|
ns.reverse()
|
|
45
|
-
while not (ns[-1].
|
|
61
|
+
while not (ns[-1].is_furcation() or ns[-1].is_tip()):
|
|
46
62
|
ns.append(ns[-1].children()[0])
|
|
47
63
|
|
|
48
64
|
return Tree.Branch(self.attach, [n.id for n in ns])
|
|
@@ -187,16 +203,28 @@ class Tree(DictSWC):
|
|
|
187
203
|
raise ValueError(f"no soma found in: {self.source}")
|
|
188
204
|
return n
|
|
189
205
|
|
|
190
|
-
def
|
|
191
|
-
"""Get all node of
|
|
192
|
-
|
|
206
|
+
def get_furcations(self) -> list[Node]:
|
|
207
|
+
"""Get all node of furcations."""
|
|
208
|
+
furcations: list[int] = []
|
|
193
209
|
|
|
194
|
-
def
|
|
210
|
+
def collect_furcations(n: Tree.Node, children: list[None]) -> None:
|
|
195
211
|
if len(children) > 1:
|
|
196
|
-
|
|
212
|
+
furcations.append(n.id)
|
|
213
|
+
|
|
214
|
+
self.traverse(leave=collect_furcations)
|
|
215
|
+
return [self.node(i) for i in furcations]
|
|
197
216
|
|
|
198
|
-
|
|
199
|
-
|
|
217
|
+
@deprecated("Use `get_furcations` instead")
|
|
218
|
+
def get_bifurcations(self) -> list[Node]:
|
|
219
|
+
"""Get all node of furcations.
|
|
220
|
+
|
|
221
|
+
Notes
|
|
222
|
+
-----
|
|
223
|
+
Deprecated due to the wrong spelling of furcation. For now, it
|
|
224
|
+
is just an alias of `get_furcations` and raise a warning. It
|
|
225
|
+
will be change to raise an error in the future.
|
|
226
|
+
"""
|
|
227
|
+
return self.get_furcations()
|
|
200
228
|
|
|
201
229
|
def get_tips(self) -> list[Node]:
|
|
202
230
|
"""Get all node of tips."""
|
swcgeom/core/tree_utils.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""SWC util wrapper for tree."""
|
|
2
17
|
|
|
3
18
|
import warnings
|
|
@@ -5,6 +20,7 @@ from collections.abc import Callable, Iterable
|
|
|
5
20
|
from typing import Optional, TypeVar, overload
|
|
6
21
|
|
|
7
22
|
import numpy as np
|
|
23
|
+
from typing_extensions import deprecated
|
|
8
24
|
|
|
9
25
|
from swcgeom.core.swc import SWCLike
|
|
10
26
|
from swcgeom.core.swc_utils import (
|
|
@@ -95,6 +111,7 @@ def cut_tree(tree: Tree, *, enter=None, leave=None):
|
|
|
95
111
|
return to_subtree(tree, removals)
|
|
96
112
|
|
|
97
113
|
|
|
114
|
+
@deprecated("Use `to_subtree` instead")
|
|
98
115
|
def to_sub_tree(swc_like: SWCLike, sub: Topology) -> tuple[Tree, dict[int, int]]:
|
|
99
116
|
"""Create subtree from origin tree.
|
|
100
117
|
|
|
@@ -111,13 +128,6 @@ def to_sub_tree(swc_like: SWCLike, sub: Topology) -> tuple[Tree, dict[int, int]]
|
|
|
111
128
|
id_map : dict[int, int]
|
|
112
129
|
"""
|
|
113
130
|
|
|
114
|
-
warnings.warn(
|
|
115
|
-
"`to_sub_tree` will be removed in v0.6.0, it is replaced by "
|
|
116
|
-
"`to_subtree` beacuse it is easy to use, and this will be "
|
|
117
|
-
"removed in next version",
|
|
118
|
-
DeprecationWarning,
|
|
119
|
-
)
|
|
120
|
-
|
|
121
131
|
sub = propagate_removal(sub)
|
|
122
132
|
(new_id, new_pid), id_map_arr = to_sub_topology(sub)
|
|
123
133
|
|
swcgeom/core/tree_utils_impl.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""SWC util wrapper for tree, split to avoid circle imports.
|
|
2
17
|
|
|
3
18
|
Notes
|
swcgeom/images/__init__.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Image Stack Related."""
|
|
2
17
|
|
|
3
18
|
from swcgeom.images.folder import *
|
swcgeom/images/augmentation.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Play augment in image stack.
|
|
2
17
|
|
|
3
18
|
Notes
|
swcgeom/images/contrast.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""The contrast of an image.
|
|
2
17
|
|
|
3
18
|
Notes
|
swcgeom/images/folder.py
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Image stack folder."""
|
|
2
17
|
|
|
3
18
|
import math
|
|
4
19
|
import os
|
|
5
20
|
import re
|
|
6
|
-
import warnings
|
|
7
21
|
from collections.abc import Callable, Iterable
|
|
8
22
|
from dataclasses import dataclass
|
|
9
23
|
from typing import Generic, Literal, Optional, TypeVar, overload
|
|
@@ -11,7 +25,7 @@ from typing import Generic, Literal, Optional, TypeVar, overload
|
|
|
11
25
|
import numpy as np
|
|
12
26
|
import numpy.typing as npt
|
|
13
27
|
from tqdm import tqdm
|
|
14
|
-
from typing_extensions import Self
|
|
28
|
+
from typing_extensions import Self, deprecated
|
|
15
29
|
|
|
16
30
|
from swcgeom.images.io import ScalarType, read_imgs
|
|
17
31
|
from swcgeom.transforms import Identity, Transform
|
|
@@ -65,6 +79,7 @@ class ImageStackFolderBase(Generic[ScalarType, T]):
|
|
|
65
79
|
return fs
|
|
66
80
|
|
|
67
81
|
@staticmethod
|
|
82
|
+
@deprecated("Use `~swcgeom.images.io.read_imgs(fname).get_full()` instead")
|
|
68
83
|
def read_imgs(fname: str) -> npt.NDArray[np.float32]:
|
|
69
84
|
"""Read images.
|
|
70
85
|
|
|
@@ -72,14 +87,6 @@ class ImageStackFolderBase(Generic[ScalarType, T]):
|
|
|
72
87
|
Use :meth:`~swcgeom.images.io.read_imgs(fname).get_full()` instead.
|
|
73
88
|
"""
|
|
74
89
|
|
|
75
|
-
warnings.warn(
|
|
76
|
-
"`ImageStackFolderBase.read_imgs` serves as a "
|
|
77
|
-
"straightforward wrapper for `~swcgeom.images.io.read_imgs(fname).get_full()`. "
|
|
78
|
-
"However, as it is not utilized within our internal "
|
|
79
|
-
"processes, it is scheduled for removal in the "
|
|
80
|
-
"forthcoming version.",
|
|
81
|
-
DeprecationWarning,
|
|
82
|
-
)
|
|
83
90
|
return read_imgs(fname).get_full()
|
|
84
91
|
|
|
85
92
|
|
swcgeom/images/io.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Read and write image stack."""
|
|
2
17
|
|
|
3
18
|
import os
|
|
@@ -12,6 +27,7 @@ import nrrd
|
|
|
12
27
|
import numpy as np
|
|
13
28
|
import numpy.typing as npt
|
|
14
29
|
import tifffile
|
|
30
|
+
from typing_extensions import deprecated
|
|
15
31
|
from v3dpy.loaders import PBD, Raw
|
|
16
32
|
|
|
17
33
|
__all__ = ["read_imgs", "save_tiff", "read_images"]
|
|
@@ -537,7 +553,7 @@ class TeraflyImageStack(ImageStack[ScalarType]):
|
|
|
537
553
|
if (invalid := diff > 10 * v).all():
|
|
538
554
|
return None, None
|
|
539
555
|
|
|
540
|
-
diff[invalid] = np.
|
|
556
|
+
diff[invalid] = -np.inf # remove values which greater than v
|
|
541
557
|
|
|
542
558
|
# find the index of the value smaller than v and closest to v
|
|
543
559
|
idx = np.argmax(diff)
|
|
@@ -601,6 +617,7 @@ class GrayImageStack:
|
|
|
601
617
|
return self.imgs.shape[:-1]
|
|
602
618
|
|
|
603
619
|
|
|
620
|
+
@deprecated("Use `read_imgs` instead")
|
|
604
621
|
def read_images(*args, **kwargs) -> GrayImageStack:
|
|
605
622
|
"""Read images.
|
|
606
623
|
|
|
@@ -608,9 +625,4 @@ def read_images(*args, **kwargs) -> GrayImageStack:
|
|
|
608
625
|
Use :meth:`read_imgs` instead.
|
|
609
626
|
"""
|
|
610
627
|
|
|
611
|
-
warnings.warn(
|
|
612
|
-
"`read_images` has been replaced by `read_imgs` because it"
|
|
613
|
-
"provide rgb support, and this will be removed in next version",
|
|
614
|
-
DeprecationWarning,
|
|
615
|
-
)
|
|
616
628
|
return GrayImageStack(read_imgs(*args, **kwargs))
|
swcgeom/transforms/__init__.py
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""A series of transformations to compose codes."""
|
|
2
17
|
|
|
3
18
|
from swcgeom.transforms.base import *
|
|
4
19
|
from swcgeom.transforms.branch import *
|
|
20
|
+
from swcgeom.transforms.branch_tree import *
|
|
5
21
|
from swcgeom.transforms.geometry import *
|
|
6
22
|
from swcgeom.transforms.image_preprocess import *
|
|
7
23
|
from swcgeom.transforms.image_stack import *
|
swcgeom/transforms/base.py
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# Copyright 2022-2025 Zexin Yuan
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
"""Transformation in tree."""
|
|
2
17
|
|
|
3
18
|
from abc import ABC, abstractmethod
|
|
@@ -33,7 +48,7 @@ class Transform(ABC, Generic[T, K]):
|
|
|
33
48
|
repr_ = self.extra_repr()
|
|
34
49
|
return f"{classname}({repr_})"
|
|
35
50
|
|
|
36
|
-
def extra_repr(self):
|
|
51
|
+
def extra_repr(self) -> str:
|
|
37
52
|
"""Provides a human-friendly representation of the module.
|
|
38
53
|
|
|
39
54
|
This method extends the basic string representation provided by
|
|
@@ -48,7 +63,7 @@ class Transform(ABC, Generic[T, K]):
|
|
|
48
63
|
def __init__(self, my_parameter: int = 1):
|
|
49
64
|
self.my_parameter = my_parameter
|
|
50
65
|
|
|
51
|
-
def extra_repr(self):
|
|
66
|
+
def extra_repr(self) -> str:
|
|
52
67
|
return f"my_parameter={self.my_parameter}"
|
|
53
68
|
|
|
54
69
|
Notes
|