-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_pooled_datasets.py
53 lines (40 loc) · 1.4 KB
/
make_pooled_datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import wget
import zipfile
from pathlib import Path
import os
import sys
import json
import shutil
def make_pooled_dataset(configFilename=None, outputFolder=None):
# First argument: Path to JSON config file
# Second argument: Path to base saved directory
if configFilename is None or outputFolder is None:
# Parse function input
args = sys.argv[1:]
configFilename = args[0]
outputFolder = args[1]
# Load config file for datasets
with open(configFilename) as json_file:
data = json.load(json_file)
# Download all datasets to one folder
for submitter in data.keys():
print(data[submitter]['OSF_link'])
wget.download(data[submitter]['OSF_link'])
for filename in os.listdir(str(Path(os.getcwd()))):
if filename.endswith(".zip"):
with zipfile.ZipFile(filename,"r") as zip_ref:
zip_ref.extractall(outputFolder)
os.remove(filename)
else:
continue
print('\n')
# Pool nifti files into one directory
rootdir = Path(os.getcwd())
file_list = [f for f in rootdir.resolve().glob('**/*.nii*') if f.is_file()]
newDir = outputFolder + '_pooled'
os.mkdir(newDir)
for file in file_list:
shutil.copyfile(file, rootdir / newDir / file.name)
if __name__ == "__main__":
make_pooled_dataset()