From 00017e18679019264e7e08d1460c8d7d7eaff073 Mon Sep 17 00:00:00 2001 From: Chris Barnes Date: Wed, 23 Nov 2022 17:58:41 +0000 Subject: [PATCH] Fix radius bug --- navis/io/swc_io.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/navis/io/swc_io.py b/navis/io/swc_io.py index 619cce77..1da86501 100644 --- a/navis/io/swc_io.py +++ b/navis/io/swc_io.py @@ -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() @@ -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, @@ -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 @@ -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