Skip to content

Commit

Permalink
Fix radius bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Nov 23, 2022
1 parent e74f3d4 commit 00017e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions navis/io/swc_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def _write_swc(x: 'core.TreeNeuron',
return node_map


def sort_swc(df: pd.DataFrame, roots, sort_children=True, inplace=False):
def _sort_swc_dfs(df: pd.DataFrame, roots, sort_children=True, inplace=False):
"""Depth-first search tree to ensure parents are always defined before children."""
children = defaultdict(list)
node_id_to_orig_idx = dict()
Expand Down Expand Up @@ -631,6 +631,10 @@ def sort_swc(df: pd.DataFrame, roots, sort_children=True, inplace=False):
return df


def _sort_swc_parent(df, inplace=False):
return df.sort_values("parent_id", inplace=inplace)


def make_swc_table(x: 'core.TreeNeuron',
labels: Union[str, dict, bool] = None,
export_connectors: bool = False,
Expand Down Expand Up @@ -671,7 +675,8 @@ def make_swc_table(x: 'core.TreeNeuron',
"""
# Work on a copy sorted in depth-first order
swc = sort_swc(x.nodes, x.root, inplace=False)
# swc = _sort_swc_dfs(x.nodes, x.root, inplace=False)
swc = _sort_swc_dfs(x.nodes, x.root, inplace=False)

# Add labels
swc['label'] = 0
Expand Down Expand Up @@ -707,7 +712,7 @@ def make_swc_table(x: 'core.TreeNeuron',

# Make sure radius has no `None` or negative
swc['radius'] = swc.radius.fillna(0)
swc['radius'][swc['radius'] < 0] = 0
swc.loc[swc["radius"] < 0, "radius"] = 0

if return_node_map is not None:
# remap IDs
Expand Down

0 comments on commit 00017e1

Please sign in to comment.