From 0054a4d020a51f1573bdf220d8cfdf0eed79907f Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 29 Aug 2024 09:57:18 +0200 Subject: [PATCH 1/4] Relax constraints and bump versions --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5ca431c..3e41ac7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,11 +39,11 @@ docker = ">=7.0.0" rich = ">=13.0.0" PyYAML = ">=6.0.1" dacite = ">=1.8.0" -loguru = ">=0.6.0" +loguru = ">=0.7.0" nibabel = ">=5.0.0" [tool.poetry.dev-dependencies] -pytest = "^6.2.5" +pytest = ">=8.0.0" [tool.poetry.group.docs] optional = true From 8884e2a824d9838b8f702306c4490add33bf13d3 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 29 Aug 2024 09:57:27 +0200 Subject: [PATCH 2/4] Fix doc files --- docs/source/algorithms.rst | 16 ++++++---------- docs/source/constants.rst | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/docs/source/algorithms.rst b/docs/source/algorithms.rst index 98de183..6a72be6 100644 --- a/docs/source/algorithms.rst +++ b/docs/source/algorithms.rst @@ -5,30 +5,26 @@ The following classes provide the top performing algorithms from several BraTS c All algorithms can be used for a single subject inference (one set of MRI scans) or for a batch of multiple subjects with the respective methods inherited from the base class (BraTSAlgorithm). -Challenge Algorithms +Segmentation Algorithms -------------------------------------- -.. autoclass:: brats.AdultGliomaSegmenter +.. automodule:: brats.core.segmentation_algorithms -.. autoclass:: brats.AfricaSegmenter - - -.. autoclass:: brats.MeningiomaSegmenter - +Inpainting Algorithms +-------------------------------------- -.. autoclass:: brats.MetastasesSegmenter +.. automodule:: brats.core.inpainting_algorithms -.. autoclass:: brats.PediatricSegmenter Abstract Base Class -------------------------------------- -.. autoclass:: brats.algorithms.BraTSAlgorithm +.. automodule:: brats.core.brats_algorithm diff --git a/docs/source/constants.rst b/docs/source/constants.rst index 29e295b..9daaa5f 100644 --- a/docs/source/constants.rst +++ b/docs/source/constants.rst @@ -4,5 +4,5 @@ Constants Constants used in the package ------------------------------ -.. automodule:: brats.constants +.. automodule:: brats.utils.constants :members: \ No newline at end of file From dadc9b566bbcbbb2aeacbad9a7554ad9636c5ee0 Mon Sep 17 00:00:00 2001 From: Marcel Rosier Date: Thu, 29 Aug 2024 09:57:35 +0200 Subject: [PATCH 3/4] Add docstrings --- brats/core/brats_algorithm.py | 31 ++++++++++++++++++++++++++--- brats/core/inpainting_algorithms.py | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/brats/core/brats_algorithm.py b/brats/core/brats_algorithm.py index e117f37..ad4693c 100644 --- a/brats/core/brats_algorithm.py +++ b/brats/core/brats_algorithm.py @@ -64,7 +64,13 @@ def _standardize_batch_inputs( def _process_single_output( self, tmp_output_folder: Path | str, subject_id: str, output_file: Path ) -> None: - # TODO add docstring + """ Process the output of a single inference run and save it in the specified file. + + Args: + tmp_output_folder (Path | str): Folder with the algorithm output + subject_id (str): Subject ID of the output + output_file (Path): Path to the desired output file + """ # rename output algorithm_output = Path(tmp_output_folder) / OUTPUT_NAME_SCHEMA[ self.task @@ -81,7 +87,13 @@ def _process_batch_output( output_folder: Path, mapping: dict[str, str], ) -> None: - # TODO add docstring + """ Process the outputs of a batch inference run and save them in the specified folder. + + Args: + tmp_output_folder (Path | str): Folder with the algorithm outputs + output_folder (Path): Folder to save the outputs + mapping (dict[str, str]): Mapping from internal to external subject names + """ # move outputs and change name back to initially provided one output_folder = Path(output_folder) output_folder.mkdir(parents=True, exist_ok=True) @@ -97,7 +109,14 @@ def _infer_single( inputs: dict[str, Path | str], output_file: Path | str, log_file: Optional[Path | str] = None, - ): + ) -> None: + """ Perform a single inference run with the provided inputs and save the output in the specified file. + + Args: + inputs (dict[str, Path | str]): Input Images for the task + output_file (Path | str): File to save the output + log_file (Optional[Path | str], optional): Log file with extra information. Defaults to None. + """ with InferenceSetup(log_file=log_file) as (tmp_data_folder, tmp_output_folder): logger.info(f"Performing single inference") @@ -130,7 +149,13 @@ def _infer_batch( output_folder: Path | str, log_file: Optional[Path | str] = None, ): + """ Perform a batch inference run with the provided inputs and save the outputs in the specified folder. + Args: + data_folder (Path | str): Folder with the input data + output_folder (Path | str): Folder to save the outputs + log_file (Optional[Path | str], optional): Log file with extra information. Defaults to None. + """ with InferenceSetup(log_file=log_file) as (tmp_data_folder, tmp_output_folder): # find subjects diff --git a/brats/core/inpainting_algorithms.py b/brats/core/inpainting_algorithms.py index c55ba87..741335e 100644 --- a/brats/core/inpainting_algorithms.py +++ b/brats/core/inpainting_algorithms.py @@ -93,7 +93,7 @@ def infer_single( """Perform inpainting task on a single subject with the provided images and save the result to the output file. Args: - t1n (Path | str): Path to the T1n image + t1n (Path | str): Path to the voided T1n image mask (Path | str): Path to the mask image output_file (Path | str): Path to save the segmentation log_file (Path | str, optional): Save logs to this file From 5beffe6feba9c6e5f7cb9a0e0912864ab8d99a63 Mon Sep 17 00:00:00 2001 From: "brainless-bot[bot]" <153751247+brainless-bot[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 08:11:06 +0000 Subject: [PATCH 4/4] Autoformat with black --- brats/core/brats_algorithm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/brats/core/brats_algorithm.py b/brats/core/brats_algorithm.py index ad4693c..faa4af4 100644 --- a/brats/core/brats_algorithm.py +++ b/brats/core/brats_algorithm.py @@ -64,7 +64,7 @@ def _standardize_batch_inputs( def _process_single_output( self, tmp_output_folder: Path | str, subject_id: str, output_file: Path ) -> None: - """ Process the output of a single inference run and save it in the specified file. + """Process the output of a single inference run and save it in the specified file. Args: tmp_output_folder (Path | str): Folder with the algorithm output @@ -87,7 +87,7 @@ def _process_batch_output( output_folder: Path, mapping: dict[str, str], ) -> None: - """ Process the outputs of a batch inference run and save them in the specified folder. + """Process the outputs of a batch inference run and save them in the specified folder. Args: tmp_output_folder (Path | str): Folder with the algorithm outputs @@ -110,7 +110,7 @@ def _infer_single( output_file: Path | str, log_file: Optional[Path | str] = None, ) -> None: - """ Perform a single inference run with the provided inputs and save the output in the specified file. + """Perform a single inference run with the provided inputs and save the output in the specified file. Args: inputs (dict[str, Path | str]): Input Images for the task @@ -149,7 +149,7 @@ def _infer_batch( output_folder: Path | str, log_file: Optional[Path | str] = None, ): - """ Perform a batch inference run with the provided inputs and save the outputs in the specified folder. + """Perform a batch inference run with the provided inputs and save the outputs in the specified folder. Args: data_folder (Path | str): Folder with the input data