Skip to content

Commit 64db158

Browse files
automated downloading from zenodo
1 parent a9cc388 commit 64db158

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ __pycache__/
99
*.mat
1010
*.raw
1111
bvals.txt
12+
download
13+
md5sums.txt
14+
*.gz
15+
*.zip
16+
*.tmp
17+
1218
# Unit test / coverage reports
1319
.tox/
1420
.coverage

phantoms/MR_XCAT_qMRI/sim_ivim_sig.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
from scipy.io import loadmat
33
import nibabel as nib
44
import json
5+
from utilities.data_simulation.Download_data import download_data
56

67
##########
78
# code written by Oliver J Gurney-Champion
89
# code adapted from MAtlab code by Eric Schrauben: https://github.com/schrau24/XCAT-ERIC
910
# This code generates a 4D IVIM phantom as nifti file
1011

11-
def phantom(bvalue, noise, TR=8000, TE=80, motion=False, rician=False, interleaved=False):
12+
def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleaved=False):
13+
download_data()
1214
np.random.seed(42)
1315
if motion:
1416
states = range(1,21)
1517
else:
1618
states = [1]
1719
for state in states:
1820
# Load the .mat file
19-
mat_data = loadmat('XCAT_MAT_RESP/XCAT5D_RP_' + str(state) + '_CP_1.mat')
21+
mat_data = loadmat('../../download/Phantoms/XCAT_MAT_RESP/XCAT5D_RP_' + str(state) + '_CP_1.mat')
2022

2123
# Access the variables in the loaded .mat file
2224
XCAT = mat_data['IMG']

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ joblib
77
dipy
88
matplotlib
99
scienceplots
10-
cvxpy
10+
cvxpy
11+
zenodo-get
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import zipfile
2+
import os
3+
import subprocess
4+
import time
5+
6+
def download_data(force=False):
7+
# Check if the folder exists, and create it if not
8+
base_folder = os.path.abspath(os.path.dirname(__file__))
9+
base_folder = os.path.split(os.path.split(base_folder)[0])[0]
10+
if not os.path.exists(os.path.join(base_folder,'download')):
11+
os.makedirs(os.path.join(base_folder,'download'))
12+
print(f"Folder '{'download'}' created.")
13+
# Change to the specified folder
14+
os.chdir(os.path.join(base_folder,'download'))
15+
subprocess.run(["zenodo_get", 'https://zenodo.org/records/10696605'])
16+
while not os.path.exists('OSIPI_TF24_data_phantoms.zip'):
17+
time.sleep(1)
18+
# Open the zip file
19+
if force or not os.path.exists('Data'):
20+
with zipfile.ZipFile('OSIPI_TF24_data_phantoms.zip', 'r') as zip_ref:
21+
# Extract all the contents to the destination folder
22+
zip_ref.extractall('.')
23+
while not os.path.exists('Data'):
24+
time.sleep(10)
25+
while not os.path.exists('Phantoms'):
26+
time.sleep(10)
27+
while not os.path.exists('Utilities'):
28+
time.sleep(10)
29+
time.sleep(10)

0 commit comments

Comments
 (0)