Skip to content

Commit

Permalink
minor upds (#38)
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 Jan 19, 2024
1 parent f726625 commit 10943b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/deep_neurographs/intake.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def build_neurograph_from_gcs_zips(
print("Process swc files...")
total_runtime, t0 = utils.init_timers()
swc_dicts = download_gcs_zips(bucket_name, cloud_path, min_size)
t_stamp, unit_stamp = utils.time_writer(time() - total_runtime)
t, unit = utils.time_writer(time() - t0)
print(f"\nTime Stamp: {round(t_stamp, 4)} {unit_stamp}")
print(f"Module Runtime(): {round(t, 4)} {unit} \n")

# Build neurograph
Expand All @@ -155,8 +153,6 @@ def build_neurograph_from_gcs_zips(
smooth=smooth,
)
t, unit = utils.time_writer(time() - t0)
t_stamp, unit_stamp = utils.time_writer(time() - total_runtime)
print(f"Time Stamp: {round(t_stamp, 4)} {unit_stamp}")
print(f"Module Runtime(): {round(t, 4)} {unit} \n")

# Generate proposals
Expand All @@ -167,13 +163,12 @@ def build_neurograph_from_gcs_zips(
search_radius, n_proposals_per_leaf=n_proposals_per_leaf
)
t, unit = utils.time_writer(time() - t0)
time_stamp, unit_stamp = utils.time_writer(time() - total_runtime)
print("\n# proposals:", len(neurograph.mutable_edges))
print(f"Time Stamp: {round(t_stamp, 4)} {unit_stamp}")
print(f"Module Runtime(): {round(t, 4)} {unit} \n")

t, unit = utils.time_writer(time() - total_runtime)
print(f"Total Runtime: {round(t, 4)} {unit}")
print(f"Memory Consumption: {round(utils.get_memory_usage(), 4)} GBs")
return neurograph


Expand Down
26 changes: 12 additions & 14 deletions src/deep_neurographs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import math
import os
import psutil
import shutil
from copy import deepcopy
from io import BytesIO
Expand Down Expand Up @@ -508,16 +509,8 @@ def reformat_number(number):
return f"{number:,}"


def time_writer(t, unit="seconds"):
assert unit in ["seconds", "minutes", "hours"]
upd_unit = {"seconds": "minutes", "minutes": "hours"}
if t < 60 or unit == "hours":
return t, unit
else:
t /= 60
unit = upd_unit[unit]
t, unit = time_writer(t, unit=unit)
return t, unit
def get_memory_usage():
return psutil.virtual_memory().used / 1e9


def init_timers():
Expand All @@ -533,8 +526,13 @@ def progress_bar(current, total, bar_length=50, eta=None, runtime=None):
print(f"\r{bar} {n_completed} | {eta} | {runtime} ", end="", flush=True)


def xor(a, b):
if (a and b) or (not a and not b):
return False
def time_writer(t, unit="seconds"):
assert unit in ["seconds", "minutes", "hours"]
upd_unit = {"seconds": "minutes", "minutes": "hours"}
if t < 60 or unit == "hours":
return t, unit
else:
return True
t /= 60
unit = upd_unit[unit]
t, unit = time_writer(t, unit=unit)
return t, unit

0 comments on commit 10943b6

Please sign in to comment.