Skip to content

Commit

Permalink
feat: routine that counts fragments in goog pred
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-grim committed Oct 31, 2024
1 parent eac48eb commit 039b7f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/deep_neurographs/utils/swc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def load_from_cloud_zipped_file(self, zip_file, path):
"""
content = util.read_zip(zip_file, path).splitlines()
if len(content) > self.min_size:
if len(content) > self.min_size - 10:
result = self.parse(content)
result["swc_id"] = util.get_swc_id(path)
return result
Expand Down
29 changes: 25 additions & 4 deletions src/deep_neurographs/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import json
import math
import networkx as nx
import os
import shutil
from io import BytesIO
Expand All @@ -21,6 +22,7 @@
import psutil
from google.cloud import storage

from deep_neurographs.utils import graph_util as gutil, swc_util

# --- os utils ---
def mkdir(path, delete=False):
Expand Down Expand Up @@ -477,10 +479,7 @@ def sample_once(my_container):
sample
"""
if type(my_container) is list:
return sample(my_container, 1)[0]
else:
return sample(list(my_container), 1)[0]
return sample(my_container, 1)[0]


# --- dictionary utils ---
Expand Down Expand Up @@ -540,6 +539,28 @@ def find_best(my_dict, maximize=True):


# --- miscellaneous ---
def count_fragments(fragments_pointer, min_size=0):
"""
Counts the number of fragments in a given predicted segmentation.
Parameters
----------
swc_pointer : dict, list, str
Object that points to swcs to be read, see class documentation for
details.
min_size : float, optional
"""
# Extract fragments
graph_loader = gutil.GraphLoader(min_size=min_size, progress_bar=True)
graph = graph_loader.run(fragments_pointer)

# Report results
print("# Connected Components:", nx.number_connected_components(graph))
print("# Nodes:", graph.number_of_nodes())
print("# Edges:", graph.number_of_edges())


def time_writer(t, unit="seconds"):
"""
Converts a runtime "t" to a larger unit of time if applicable.
Expand Down

0 comments on commit 039b7f7

Please sign in to comment.