From d820473d9e6619584f7d4a218bac3aba765442c4 Mon Sep 17 00:00:00 2001 From: anna-grim Date: Fri, 19 Jan 2024 21:46:02 +0000 Subject: [PATCH 1/2] minor upds --- src/deep_neurographs/intake.py | 7 +------ src/deep_neurographs/utils.py | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/deep_neurographs/intake.py b/src/deep_neurographs/intake.py index 72ca892..2ca0b8c 100644 --- a/src/deep_neurographs/intake.py +++ b/src/deep_neurographs/intake.py @@ -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 @@ -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 @@ -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 diff --git a/src/deep_neurographs/utils.py b/src/deep_neurographs/utils.py index 542f668..d6c444d 100644 --- a/src/deep_neurographs/utils.py +++ b/src/deep_neurographs/utils.py @@ -12,6 +12,7 @@ import json import math import os +import psutil import shutil from copy import deepcopy from io import BytesIO @@ -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(): @@ -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 From a0a60d077759595eaf05c7b94f4dd14cf81bc397 Mon Sep 17 00:00:00 2001 From: anna-grim Date: Mon, 22 Jan 2024 21:38:22 +0000 Subject: [PATCH 2/2] minor upds --- src/deep_neurographs/intake.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/deep_neurographs/intake.py b/src/deep_neurographs/intake.py index 2ca0b8c..a6eb62a 100644 --- a/src/deep_neurographs/intake.py +++ b/src/deep_neurographs/intake.py @@ -140,7 +140,7 @@ def build_neurograph_from_gcs_zips( total_runtime, t0 = utils.init_timers() swc_dicts = download_gcs_zips(bucket_name, cloud_path, min_size) t, unit = utils.time_writer(time() - t0) - print(f"Module Runtime(): {round(t, 4)} {unit} \n") + print(f"\nModule Runtime(): {round(t, 4)} {unit} \n") # Build neurograph print("Build NeuroGraph...") @@ -163,7 +163,7 @@ def build_neurograph_from_gcs_zips( search_radius, n_proposals_per_leaf=n_proposals_per_leaf ) t, unit = utils.time_writer(time() - t0) - print("\n# proposals:", len(neurograph.mutable_edges)) + print("# proposals:", utils.reformat_number(len(neurograph.mutable_edges))) print(f"Module Runtime(): {round(t, 4)} {unit} \n") t, unit = utils.time_writer(time() - total_runtime)