Skip to content

Commit e2e007c

Browse files
anna-grimanna-grim
andauthored
Feat zarr reader (#296)
* feat: zarr reader * doc: improved graph_util documentation * refactor: simplified fragments graph class --------- Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 28395d4 commit e2e007c

File tree

3 files changed

+12
-60
lines changed

3 files changed

+12
-60
lines changed

src/deep_neurographs/fragments_graph.py

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class FragmentsGraph(nx.Graph):
3030
3131
"""
3232

33-
def __init__(
34-
self, anisotropy=[1.0, 1.0, 1.0], img_bbox=None, node_spacing=1
35-
):
33+
def __init__(self, anisotropy=[1.0, 1.0, 1.0], node_spacing=1):
3634
"""
3735
Initializes an instance of NeuroGraph.
3836
@@ -41,9 +39,6 @@ def __init__(
4139
anisotropy : ArrayLike, optional
4240
Image to physical coordinates scaling factors to account for the
4341
anisotropy of the microscope. The default is [1.0, 1.0, 1.0].
44-
img_bbox : dict or None, optional
45-
Dictionary with the keys "min" and "max" which specify a bounding
46-
box in an image. The default is None.
4742
node_spacing : int, optional
4843
Physical spacing (in microns) between nodes in swcs. The default
4944
is 1.
@@ -66,15 +61,6 @@ def __init__(
6661
self.swc_ids = set()
6762
self.xyz_to_edge = dict()
6863

69-
# Bounding box (if applicable)
70-
self.bbox = img_bbox
71-
if self.bbox:
72-
self.origin = img_bbox["min"].astype(int)
73-
self.shape = (img_bbox["max"] - img_bbox["min"]).astype(int)
74-
else:
75-
self.origin = np.array([0, 0, 0], dtype=int)
76-
self.shape = None
77-
7864
def copy_graph(self, add_attrs=False):
7965
graph = nx.Graph()
8066
nodes = deepcopy(self.nodes(data=add_attrs))
@@ -87,25 +73,6 @@ def copy_graph(self, add_attrs=False):
8773
graph.add_edges_from(deepcopy(self.edges))
8874
return graph
8975

90-
def set_proxy_soma_ids(self, k):
91-
"""
92-
Sets class attribute called "self.soma_swc_ids" which stores the swc
93-
ids of the "k" largest components. These components are used as a proxy
94-
for soma locations.
95-
96-
Paramters
97-
---------
98-
k : int
99-
Number of largest components to be set as proxy soma locations.
100-
101-
Returns
102-
-------
103-
None
104-
105-
"""
106-
for i in utils.graph_util.largest_components(self, k):
107-
self.soma_ids[self.nodes[i]["swc_id"]] = i
108-
10976
def get_leafs(self):
11077
"""
11178
Gets all leaf nodes in graph.
@@ -302,7 +269,6 @@ def generate_proposals(
302269
long_range_bool=False,
303270
progress_bar=True,
304271
proposals_per_leaf=3,
305-
return_trimmed_proposals=False,
306272
trim_endpoints_bool=False,
307273
):
308274
"""
@@ -326,9 +292,6 @@ def generate_proposals(
326292
proposals_per_leaf : int, optional
327293
Maximum number of proposals generated for each leaf. The default
328294
is 3.
329-
return_trimmed_proposals, optional
330-
Indication of whether to return trimmed proposal ids. The default
331-
is False.
332295
trim_endpoints_bool : bool, optional
333296
Indication of whether to trim endpoints. The default is False.
334297
@@ -349,7 +312,7 @@ def generate_proposals(
349312
trim_endpoints_bool=trim_endpoints_bool,
350313
)
351314

352-
# Establish groundtruth
315+
# Set groundtruth
353316
if groundtruth_graph:
354317
self.gt_accepts = init_targets(self, groundtruth_graph)
355318
else:
@@ -723,8 +686,8 @@ def merge_proposal(self, proposal):
723686
if somas_check and self.check_proposal_degrees(i, j):
724687
# Dense attributes
725688
attrs = dict()
726-
self.nodes[i]["radius"] = 7.3141592
727-
self.nodes[j]["radius"] = 7.3141592
689+
self.nodes[i]["radius"] = 5.3141592
690+
self.nodes[j]["radius"] = 5.3141592
728691
for k in ["xyz", "radius"]:
729692
combine = np.vstack if k == "xyz" else np.array
730693
attrs[k] = combine([self.nodes[i][k], self.nodes[j][k]])
@@ -913,21 +876,6 @@ def oriented_edge(self, edge, i, key="xyz"):
913876
else:
914877
return np.flip(self.edges[edge][key], axis=0)
915878

916-
def is_contained(self, node_or_xyz, buffer=0):
917-
if self.bbox:
918-
voxel = self.to_voxels(node_or_xyz, self.anisotropy)
919-
return util.is_contained(self.bbox, voxel, buffer=buffer)
920-
else:
921-
return True
922-
923-
def branch_contained(self, xyz_list):
924-
if self.bbox:
925-
return all(
926-
[self.is_contained(xyz, buffer=-32) for xyz in xyz_list]
927-
)
928-
else:
929-
return True
930-
931879
def to_voxels(self, node_or_xyz, shift=np.array([0, 0, 0])):
932880
# Get xyz coordinate
933881
shift = self.origin if shift else np.zeros((3))
@@ -1017,7 +965,7 @@ def to_zipped_swc(self, zip_writer, nodes, color):
1017965
if n_entries == 0:
1018966
swc_id = self.nodes[i]["swc_id"]
1019967
x, y, z = tuple(self.nodes[i]["xyz"])
1020-
r = 6 if self.nodes[i]["radius"] == 7.3141592 else 2
968+
r = 5 if self.nodes[i]["radius"] == 5.3141592 else 2
1021969

1022970
text_buffer.write("\n" + f"1 2 {x} {y} {z} {r} -1")
1023971
node_to_idx[i] = 1
@@ -1042,7 +990,7 @@ def branch_to_zip(self, text_buffer, n_entries, i, j, parent, color):
1042990
# Make entries
1043991
for k in util.spaced_idxs(len(branch_xyz), 5):
1044992
x, y, z = tuple(branch_xyz[k])
1045-
r = 6 if branch_radius[k] == 7.3141592 else 2
993+
r = 5 if branch_radius[k] == 5.3141592 else 2
1046994

1047995
node_id = n_entries + 1
1048996
parent = n_entries if k > 1 else parent

src/deep_neurographs/generate_proposals.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
@author: Anna Grim
55
@email: anna.grim@alleninstitute.org
66
7-
Module used to generate edge proposals for a fragments graph.
7+
Overview
8+
--------
9+
Code that generate edge proposals for a fragments graph.
10+
11+
Proposal Generation Algorithm:
812
913
"""
1014

src/deep_neurographs/utils/graph_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def get_irreducibles(self, swc_dicts):
152152
# Initializations
153153
if self.verbose:
154154
pbar = tqdm(total=len(swc_dicts), desc="Extract Graphs")
155+
pbar.update(1)
155156

156157
# Main
157158
with ProcessPoolExecutor() as executor:
@@ -172,7 +173,6 @@ def get_irreducibles(self, swc_dicts):
172173
irreducibles.append(result)
173174
if self.verbose:
174175
pbar.update(1)
175-
pbar.update(1)
176176
return irreducibles
177177

178178
def extract_irreducibles(self, swc_dict):

0 commit comments

Comments
 (0)