Skip to content

Commit

Permalink
Merge pull request #106 from CAVEconnectome/skel-rehydrate
Browse files Browse the repository at this point in the history
add `from_dict` Skeleton class function to rehydrate a skeleton
  • Loading branch information
ceesem authored Nov 18, 2024
2 parents 2495db7 + 25eaca1 commit 68fd566
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions meshparty/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,29 @@ def export_to_swc(
avoid_root=avoid_root,
)

@classmethod
def from_dict(cls, sk: dict):
"""Generate a skeleton from a dictionary. Expected format follows the caveclient `client.skeleton.get_skeleton` method defaults.
Parameters
----------
sk : dict
Dictionary with keys for vertices, edges, root, and optionally radius and compartment.
"""
vprop = dict()
if 'radius' in sk:
vprop['radius'] = np.array(sk['radius'])
if 'compartment' in sk:
vprop['compartment'] = np.array(sk['compartment'])

return cls(
vertices=np.array(sk['vertices']),
edges=np.array(sk['edges']),
root=sk.get('root'),
radius=np.array(sk.get('radius')),
vertex_properties = vprop,
)


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

0 comments on commit 68fd566

Please sign in to comment.