Skip to content

Commit

Permalink
refactor: report runtimes (#176)
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 Jun 27, 2024
1 parent 439553e commit 331c396
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
22 changes: 3 additions & 19 deletions src/deep_neurographs/intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ def build_neurograph(
# Extract irreducibles
n_components = len(swc_dicts)
if progress_bar:
print("(1) Extract irreducible nodes and edges")
print("# connected components:", utils.reformat_number(n_components))
print("# swcs downloaded:", utils.reformat_number(n_components))
irreducibles, n_nodes, n_edges = get_irreducibles(
swc_dicts,
bbox=img_bbox,
Expand All @@ -296,29 +295,17 @@ def build_neurograph(

# Build neurograph
if progress_bar:
print("\n(2) Combine irreducibles...")
print("\nGraph Overview...")
print("# connected components":, len(irreducibles))
print("# nodes:", utils.reformat_number(n_nodes))
print("# edges:", utils.reformat_number(n_edges))

neurograph = NeuroGraph(
img_path=img_path, node_spacing=node_spacing, swc_paths=swc_paths
)
t0, t1 = utils.init_timers()
chunk_size = int(n_components * 0.02)
cnt, i = 1, 0
n_components = len(irreducibles)
while len(irreducibles):
irreducible_set = irreducibles.pop()
neurograph.add_component(irreducible_set)
if i > cnt * chunk_size and progress_bar:
cnt, t1 = utils.report_progress(
i + 1, n_components, chunk_size, cnt, t0, t1
)
i += 1
if progress_bar:
t, unit = utils.time_writer(time() - t0)
print("\n" + f"add_irreducibles(): {round(t, 4)} {unit}")

return neurograph


Expand Down Expand Up @@ -369,9 +356,6 @@ def get_irreducibles(
progress_cnt, t1 = utils.report_progress(
i + 1, n_components, chunk_size, progress_cnt, t0, t1
)
if progress_bar:
t, unit = utils.time_writer(time() - t0)
print("\n" + f"get_irreducibles(): {round(t, 4)} {unit}")
return irreducibles, n_nodes, n_edges


Expand Down
21 changes: 18 additions & 3 deletions src/deep_neurographs/swc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def read_from_gcs_zip(zip_file, path):
with zip_file.open(path) as text_file:
return text_file.read().decode("utf-8").splitlines()
except:
print(f"Failed to from {path}")
print(f"Failed to read {path}")
return ""


Expand Down Expand Up @@ -222,7 +222,7 @@ def write_list(path, entry_list, color=None):
----------
path : str
Path that swc will be written to.
entry_list : list[list[int]]
entry_list : list[str]
List of entries that will be written to an swc file.
color : str, optional
Color of nodes. The default is None.
Expand Down Expand Up @@ -370,11 +370,26 @@ def make_entry(graph, i, parent, node_to_idx):


def set_radius(graph, i):
"""
Sets the radius of node "i".
Parameters
----------
graph : networkx.Graph
Graph containing node "i".
i : int
Node.
Returns
-------
float
Radius of node "i".
"""
try:
radius = graph[i]["radius"]
return radius
except:
return 1
return 1.0


def make_simple_entry(node, parent, xyz, radius=8):
Expand Down

0 comments on commit 331c396

Please sign in to comment.