Skip to content

Commit

Permalink
Merge pull request #47 from CBICA/spiros-dev
Browse files Browse the repository at this point in the history
Fixing issues with parallelization
  • Loading branch information
spirosmaggioros authored Oct 30, 2024
2 parents 520dc2a + a9b23e0 commit 875de6b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 46 deletions.
35 changes: 0 additions & 35 deletions .gitattributes

This file was deleted.

7 changes: 6 additions & 1 deletion NiChart_DLMUSE/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ def main() -> None:
print(args)
print()

if len(os.listdir(out_dir)) != 0:
print(f"Emptying output folder: {out_dir}...")
os.system(f"rm -r {out_dir}/*")

if args.clear_cache:
os.system("DLICV -i ./dummy -o ./dummy --clear_cache")
os.system("DLMUSE -i ./dummy -o ./dummy --clear_cache")

# Run pipeline
no_threads = args.cores # for now
no_threads = int(args.cores) # for now
subfolders = split_data(in_data, no_threads)

threads = []
Expand All @@ -163,6 +167,7 @@ def main() -> None:

merge_output_data(out_dir)
remove_subfolders(in_data)
remove_subfolders(out_dir)


if __name__ == "__main__":
Expand Down
17 changes: 13 additions & 4 deletions NiChart_DLMUSE/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ def dir_size(in_dir: str) -> int:

def split_data(in_dir: str, N: int) -> list:
"""
Splits the input data directory into subfolders of size N
Splits the input data directory into subfolders of size.
N should be > 0 and the number of files in each subfolder should be > 0 as well.
"""
assert N > 0
data_size = dir_size(in_dir)
no_files_in_folders = data_size / N if (data_size % N == 0) else (data_size / N) + 1
no_files_in_folders = (
data_size // N if (data_size % N == 0) else (data_size // N) + 1
)
assert no_files_in_folders > 0
subfolders = []

Expand All @@ -177,10 +180,18 @@ def split_data(in_dir: str, N: int) -> list:


def remove_subfolders(in_dir: str) -> None:
"""
Removes all the split_* subolders from the input folder
"""
os.system(f"rm -r {in_dir}/split_*")


def merge_output_data(in_dir: str) -> None:
"""
Takes all the results from the temp_working_fir and moves them into
the results/ subfolder in the output folder
"""

os.system(f"mkdir {in_dir}/results")
os.system(f"mkdir {in_dir}/results/s1_reorient_lps")
os.system(f"mkdir {in_dir}/results/s2_dlicv")
Expand Down Expand Up @@ -212,5 +223,3 @@ def merge_output_data(in_dir: str) -> None:
f"mv {in_dir}/{dir}/temp_working_dir/s6_combined/* {in_dir}/results/s6_combined/"
)
os.system(f"mv {in_dir}/{dir}/*.nii.gz {in_dir}/results/")

os.system(f"rm -r {in_dir}/split_*")
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
torch>=2.2.1
DLICV>=1.0.1
DLMUSE>=1.0.1
DLICV
DLMUSE
nibabel>=5.2
huggingface_hub
argparse
scipy
pathlib
pathlib
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from pathlib import Path

import setuptools
from setuptools import find_packages, setup

this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()

with open('requirements.txt') as f:
with open("requirements.txt") as f:
required = f.read().splitlines()


Expand Down Expand Up @@ -42,6 +41,6 @@
"nnunet",
],
package_data={
'NiChart_DLMUSE': ['**/*.csv', '**/*.json'],
"NiChart_DLMUSE": ["**/*.csv", "**/*.json"],
},
)

0 comments on commit 875de6b

Please sign in to comment.