From 2b4c7e04e4a6e520b3befe90bfade8cbf9cde73c Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 19 Oct 2023 15:32:32 +0200 Subject: [PATCH 1/4] - add citation reminder to cli - increase sleep time to ensure docker is started in time --- brats_toolkit/cli.py | 20 +++++++++++++++++--- brats_toolkit/preprocessor.py | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/brats_toolkit/cli.py b/brats_toolkit/cli.py index 325e8ab..ad7687d 100644 --- a/brats_toolkit/cli.py +++ b/brats_toolkit/cli.py @@ -10,6 +10,7 @@ import subprocess import pprint import argparse +from rich.console import Console from . import segmentor, fusionator, preprocessor @@ -41,7 +42,20 @@ def list_docker_cpu(): if seg.config[id]["runtime"] == "runc": print(id) +def citation_reminder(func): + def wrapper(): + console = Console() + console.rule("[bold red]Friendly citation reminder[/bold red]") + console.print("If you use this software in your research, please [bold cyan]cite[/bold cyan] BraTS Toolkit and the original authors of the algorithms who make this repository and tool possible.", justify="center") + console.print("Details can be found at https://github.com/neuronflow/BraTS-Toolkit#citation", justify="center") + console.print("Thank you!", justify="center") + console.rule() + console.line() + func() + return wrapper + +@citation_reminder def fusion(): parser = argparse.ArgumentParser( description="Runs the Docker orchestra to fuse segmentations. All inputs have to have equal shape and label values" @@ -83,7 +97,7 @@ def fusion(): except Exception as e: print("ERROR DETAIL: ", e) - +@citation_reminder def segmentation(): parser = argparse.ArgumentParser( description="Runs the Docker orchestra to segment and fuse segmentations based on the" @@ -179,7 +193,7 @@ def segmentation(): except Exception as e: print("ERROR DETAIL: ", e) - +@citation_reminder def batchpreprocess(): parser = argparse.ArgumentParser( description="Runs the preprocessing for MRI scans on a folder of images." @@ -243,7 +257,7 @@ def batchpreprocess(): except Exception as e: print("ERROR DETAIL: ", e) - +@citation_reminder def singlepreprocess(): parser = argparse.ArgumentParser( description="Runs the preprocessing for MRI scans on a single set of images." diff --git a/brats_toolkit/preprocessor.py b/brats_toolkit/preprocessor.py index faca7db..f31808e 100644 --- a/brats_toolkit/preprocessor.py +++ b/brats_toolkit/preprocessor.py @@ -45,7 +45,7 @@ def message(data): @self.sio.on("status") def on_status(data): - print("status reveived: ", data) + print("status reeived: ", data) if data["message"] == "client ID json generation finished!": self._inspect_input() elif data["message"] == "input inspection finished!": @@ -161,7 +161,7 @@ def batch_preprocess( # setup connection # TODO do this in a more elegant way and somehow check whether docker is up and running before connect - self.sio.sleep(5) # wait 5 secs for docker to start + self.sio.sleep(8) # wait 5 secs for docker to start self._connect_client() self.sio.wait() From 462f67cf250e168db4b8675dd4a0076b1812ecf1 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 19 Oct 2023 15:34:26 +0200 Subject: [PATCH 2/4] - fix typo --- brats_toolkit/preprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brats_toolkit/preprocessor.py b/brats_toolkit/preprocessor.py index f31808e..d2222ec 100644 --- a/brats_toolkit/preprocessor.py +++ b/brats_toolkit/preprocessor.py @@ -85,7 +85,7 @@ def outdated(data): @self.sio.on("ipstatus") def on_ipstatus(data): - print("image processing status reveived:") + print("image processing status received:") print(data["examid"], ": ", data["ipstatus"]) def single_preprocess( From 1b4d26e3a20e50ea5b0e5d5c47f519fa4a44a72c Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 19 Oct 2023 15:39:14 +0200 Subject: [PATCH 3/4] - fix another typo --- brats_toolkit/preprocessor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brats_toolkit/preprocessor.py b/brats_toolkit/preprocessor.py index d2222ec..dca5f26 100644 --- a/brats_toolkit/preprocessor.py +++ b/brats_toolkit/preprocessor.py @@ -45,7 +45,7 @@ def message(data): @self.sio.on("status") def on_status(data): - print("status reeived: ", data) + print("status received: ", data) if data["message"] == "client ID json generation finished!": self._inspect_input() elif data["message"] == "input inspection finished!": @@ -161,7 +161,7 @@ def batch_preprocess( # setup connection # TODO do this in a more elegant way and somehow check whether docker is up and running before connect - self.sio.sleep(8) # wait 5 secs for docker to start + self.sio.sleep(8) # wait 8 secs for docker to start self._connect_client() self.sio.wait() From e7462c2156b316e82e1ada157141531e890361a9 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Fri, 20 Oct 2023 13:31:12 +0200 Subject: [PATCH 4/4] - moved citation reminder decorator to separate file - added rich to dependencies - added reminder to all calls, no only from cli --- brats_toolkit/cli.py | 18 +----------------- brats_toolkit/fusionator.py | 3 +++ brats_toolkit/preprocessor.py | 3 +++ brats_toolkit/segmentor.py | 2 ++ brats_toolkit/util/citation_reminder.py | 14 ++++++++++++++ pyproject.toml | 3 ++- 6 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 brats_toolkit/util/citation_reminder.py diff --git a/brats_toolkit/cli.py b/brats_toolkit/cli.py index ad7687d..63da773 100644 --- a/brats_toolkit/cli.py +++ b/brats_toolkit/cli.py @@ -10,7 +10,7 @@ import subprocess import pprint import argparse -from rich.console import Console + from . import segmentor, fusionator, preprocessor @@ -42,20 +42,7 @@ def list_docker_cpu(): if seg.config[id]["runtime"] == "runc": print(id) -def citation_reminder(func): - - def wrapper(): - console = Console() - console.rule("[bold red]Friendly citation reminder[/bold red]") - console.print("If you use this software in your research, please [bold cyan]cite[/bold cyan] BraTS Toolkit and the original authors of the algorithms who make this repository and tool possible.", justify="center") - console.print("Details can be found at https://github.com/neuronflow/BraTS-Toolkit#citation", justify="center") - console.print("Thank you!", justify="center") - console.rule() - console.line() - func() - return wrapper -@citation_reminder def fusion(): parser = argparse.ArgumentParser( description="Runs the Docker orchestra to fuse segmentations. All inputs have to have equal shape and label values" @@ -97,7 +84,6 @@ def fusion(): except Exception as e: print("ERROR DETAIL: ", e) -@citation_reminder def segmentation(): parser = argparse.ArgumentParser( description="Runs the Docker orchestra to segment and fuse segmentations based on the" @@ -193,7 +179,6 @@ def segmentation(): except Exception as e: print("ERROR DETAIL: ", e) -@citation_reminder def batchpreprocess(): parser = argparse.ArgumentParser( description="Runs the preprocessing for MRI scans on a folder of images." @@ -257,7 +242,6 @@ def batchpreprocess(): except Exception as e: print("ERROR DETAIL: ", e) -@citation_reminder def singlepreprocess(): parser = argparse.ArgumentParser( description="Runs the preprocessing for MRI scans on a single set of images." diff --git a/brats_toolkit/fusionator.py b/brats_toolkit/fusionator.py index 28c55ea..4376c3f 100644 --- a/brats_toolkit/fusionator.py +++ b/brats_toolkit/fusionator.py @@ -13,9 +13,12 @@ import os.path as op from .util import own_itk as oitk from .util import filemanager as fm +from .util.citation_reminder import citation_reminder class Fusionator(object): + + @citation_reminder def __init__(self, verbose=True): self.verbose = verbose diff --git a/brats_toolkit/preprocessor.py b/brats_toolkit/preprocessor.py index dca5f26..4a9100f 100644 --- a/brats_toolkit/preprocessor.py +++ b/brats_toolkit/preprocessor.py @@ -5,10 +5,13 @@ from pathlib import Path from brats_toolkit.util.prep_utils import tempFiler +from brats_toolkit.util.citation_reminder import citation_reminder import sys class Preprocessor(object): + + @citation_reminder def __init__(self, noDocker=False): # settings self.clientVersion = "0.0.1" diff --git a/brats_toolkit/segmentor.py b/brats_toolkit/segmentor.py index 379002d..5a5ecb7 100644 --- a/brats_toolkit/segmentor.py +++ b/brats_toolkit/segmentor.py @@ -24,6 +24,7 @@ from . import fusionator from .util import filemanager as fm from .util import own_itk as oitk +from .util.citation_reminder import citation_reminder class Segmentor(object): @@ -31,6 +32,7 @@ class Segmentor(object): Now does it all! """ + @citation_reminder def __init__( self, config=None, diff --git a/brats_toolkit/util/citation_reminder.py b/brats_toolkit/util/citation_reminder.py new file mode 100644 index 0000000..6735a47 --- /dev/null +++ b/brats_toolkit/util/citation_reminder.py @@ -0,0 +1,14 @@ +from rich.console import Console + +def citation_reminder(func): + + def wrapper(*args, **kwargs): + console = Console() + console.rule("[bold red]Friendly citation reminder[/bold red]") + console.print("If you use this software in your research, please [bold cyan]cite[/bold cyan] BraTS Toolkit and the original authors of the algorithms who make this repository and tool possible.", justify="center") + console.print("Details can be found at https://github.com/neuronflow/BraTS-Toolkit#citation", justify="center") + console.print("Thank you!", justify="center") + console.rule() + console.line() + func(*args, **kwargs) + return wrapper \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 0a441da..d2860be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,8 @@ dependencies = [ 'numpy==1.22.0', 'python-engineio==3.14.2', 'python-socketio==4.6.1', - 'requests==2.24.0' + 'requests==2.24.0', + 'rich==13.6.0' ] [project.optional-dependencies]