Skip to content

Commit be72cea

Browse files
anna-grimanna-grim
andauthored
Feat s3 img reader (#288)
* refactor: anistropy not hardcoded * refactor: anisotropy not built-in * refactor: simplified graph loader * refactor: simplified swc_util --------- Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 9801329 commit be72cea

File tree

2 files changed

+112
-239
lines changed

2 files changed

+112
-239
lines changed

src/deep_neurographs/utils/graph_util.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,10 @@ def extract_irreducibles(self, graph):
178178
irreducibles = None
179179
self.prune_branches(graph)
180180
if compute_path_length(graph) > self.min_size:
181-
# Extract irreducible nodes
181+
# Irreducible nodes
182182
leafs, branchings = get_irreducible_nodes(graph)
183-
assert len(leafs) > 0, "No leaf nodes!"
184183

185-
# Extract irreducible edges
184+
# Irreducible edges
186185
edges = dict()
187186
root = None
188187
for (i, j) in nx.dfs_edges(graph, source=util.sample_once(leafs)):
@@ -282,20 +281,20 @@ def get_irreducible_nodes(graph):
282281

283282
def set_node_attrs(graph, nodes):
284283
"""
285-
Set node attributes by extracting values from "swc_dict".
284+
Set node attributes by extracting information from "graph".
286285
287286
Parameters
288287
----------
289-
swc_dict : dict
290-
Contents of an swc file.
288+
graph : networkx.Graph
289+
Graph that contains "nodes".
291290
nodes : list
292291
List of node ids to set attributes.
293292
294293
Returns
295294
-------
296295
dict
297-
Dictionary in which keys are node ids and values are a dictionary of
298-
attributes extracted from "swc_dict".
296+
Dictionary where keys are node ids and values are a dictionary of
297+
attributes extracted from the input graph.
299298
300299
"""
301300
node_attrs = dict()
@@ -310,14 +309,17 @@ def set_edge_attrs(graph, edges):
310309
edge_attrs = dict()
311310
for edge, path in edges.items():
312311
# Extract attributes
312+
length = 0
313313
radius_list, xyz_list = list(), list()
314-
for i in path:
314+
for idx, i in enumerate(path):
315315
radius_list.append(graph.nodes[i]["radius"])
316316
xyz_list.append(graph.nodes[i]["xyz"])
317+
if idx > 0:
318+
length += compute_dist(graph, path[idx], path[idx - 1])
317319

318320
# Set attributes
319321
edge_attrs[edge] = {
320-
"length": 1000,
322+
"length": length,
321323
"radius": np.array(radius_list),
322324
"xyz": np.array(xyz_list)
323325
}

0 commit comments

Comments
 (0)