Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that radius>0.0 for SWC #177

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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