Skip to content

Commit

Permalink
feat: routine that counts fragments in goog pred (#277)
Browse files Browse the repository at this point in the history
Co-authored-by: anna-grim <[email protected]>
  • Loading branch information
anna-grim and anna-grim authored Oct 31, 2024
1 parent b116176 commit 922075a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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
24 changes: 24 additions & 0 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 @@ -537,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 922075a

Please sign in to comment.