Skip to content

Commit

Permalink
Assert that radius>0.0 for SWC
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldeistler committed Nov 30, 2023
1 parent 7619dde commit c71b29b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion jaxley/modules/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ def __getattr__(self, key):
return BranchView(self.pointer, self.view)


def read_swc(fname: str, nseg: int, max_branch_len: float = 300.0):
def read_swc(
fname: str,
nseg: int,
max_branch_len: float = 300.0,
min_radius: Optional[float] = None,
):
"""Reads SWC file into a `jx.Cell`."""
parents, pathlengths, radius_fns, _ = swc_to_jaxley(
fname, max_branch_len=max_branch_len, sort=True, num_lines=None
Expand All @@ -250,6 +255,13 @@ def read_swc(fname: str, nseg: int, max_branch_len: float = 300.0):
np.asarray([radius_fns[b](range_) for b in range(len(parents))]), axis=1
)
radiuses_each = radiuses.flatten(order="C")
if min_radius is None:
assert np.all(
radiuses_each > 0.0
), "Radius 0.0 in SWC file. Set `read_swc(..., min_radius=...)`."
else:
radiuses_each[radiuses_each < min_radius] = min_radius

lengths_each = np.repeat(pathlengths, nseg) / nseg

cell.set_params("length", lengths_each)
Expand Down

0 comments on commit c71b29b

Please sign in to comment.