Skip to content

Commit 68fd566

Browse files
authored
Merge pull request #106 from CAVEconnectome/skel-rehydrate
add `from_dict` Skeleton class function to rehydrate a skeleton
2 parents 2495db7 + 25eaca1 commit 68fd566

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

meshparty/skeleton.py

+23
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,29 @@ def export_to_swc(
11501150
avoid_root=avoid_root,
11511151
)
11521152

1153+
@classmethod
1154+
def from_dict(cls, sk: dict):
1155+
"""Generate a skeleton from a dictionary. Expected format follows the caveclient `client.skeleton.get_skeleton` method defaults.
1156+
1157+
Parameters
1158+
----------
1159+
sk : dict
1160+
Dictionary with keys for vertices, edges, root, and optionally radius and compartment.
1161+
"""
1162+
vprop = dict()
1163+
if 'radius' in sk:
1164+
vprop['radius'] = np.array(sk['radius'])
1165+
if 'compartment' in sk:
1166+
vprop['compartment'] = np.array(sk['compartment'])
1167+
1168+
return cls(
1169+
vertices=np.array(sk['vertices']),
1170+
edges=np.array(sk['edges']),
1171+
root=sk.get('root'),
1172+
radius=np.array(sk.get('radius')),
1173+
vertex_properties = vprop,
1174+
)
1175+
11531176

11541177
def resample(sk, spacing, kind="linear", tip_length_ratio=0.5, avoid_root=True):
11551178
"""Resample a skeleton's vertices

0 commit comments

Comments
 (0)