From 64db15898f75f665800d58b52e739e3b5cf1eb65 Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion Date: Wed, 28 Feb 2024 10:02:26 +0100 Subject: [PATCH 1/4] automated downloading from zenodo --- .gitignore | 6 +++++ phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 6 +++-- requirements.txt | 3 ++- utilities/data_simulation/Download_data.py | 29 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 utilities/data_simulation/Download_data.py diff --git a/.gitignore b/.gitignore index d3420ab..f494295 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,12 @@ __pycache__/ *.mat *.raw bvals.txt +download +md5sums.txt +*.gz +*.zip +*.tmp + # Unit test / coverage reports .tox/ .coverage diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index 85eed4a..2ac69c5 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -2,13 +2,15 @@ from scipy.io import loadmat import nibabel as nib import json +from utilities.data_simulation.Download_data import download_data ########## # code written by Oliver J Gurney-Champion # code adapted from MAtlab code by Eric Schrauben: https://github.com/schrau24/XCAT-ERIC # This code generates a 4D IVIM phantom as nifti file -def phantom(bvalue, noise, TR=8000, TE=80, motion=False, rician=False, interleaved=False): +def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleaved=False): + download_data() np.random.seed(42) if motion: states = range(1,21) @@ -16,7 +18,7 @@ def phantom(bvalue, noise, TR=8000, TE=80, motion=False, rician=False, interleav states = [1] for state in states: # Load the .mat file - mat_data = loadmat('XCAT_MAT_RESP/XCAT5D_RP_' + str(state) + '_CP_1.mat') + mat_data = loadmat('../../download/Phantoms/XCAT_MAT_RESP/XCAT5D_RP_' + str(state) + '_CP_1.mat') # Access the variables in the loaded .mat file XCAT = mat_data['IMG'] diff --git a/requirements.txt b/requirements.txt index acb0486..7f9a8e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ joblib dipy matplotlib scienceplots -cvxpy \ No newline at end of file +cvxpy +zenodo-get \ No newline at end of file diff --git a/utilities/data_simulation/Download_data.py b/utilities/data_simulation/Download_data.py new file mode 100644 index 0000000..95f1c7a --- /dev/null +++ b/utilities/data_simulation/Download_data.py @@ -0,0 +1,29 @@ +import zipfile +import os +import subprocess +import time + +def download_data(force=False): + # Check if the folder exists, and create it if not + base_folder = os.path.abspath(os.path.dirname(__file__)) + base_folder = os.path.split(os.path.split(base_folder)[0])[0] + if not os.path.exists(os.path.join(base_folder,'download')): + os.makedirs(os.path.join(base_folder,'download')) + print(f"Folder '{'download'}' created.") + # Change to the specified folder + os.chdir(os.path.join(base_folder,'download')) + subprocess.run(["zenodo_get", 'https://zenodo.org/records/10696605']) + while not os.path.exists('OSIPI_TF24_data_phantoms.zip'): + time.sleep(1) + # Open the zip file + if force or not os.path.exists('Data'): + with zipfile.ZipFile('OSIPI_TF24_data_phantoms.zip', 'r') as zip_ref: + # Extract all the contents to the destination folder + zip_ref.extractall('.') + while not os.path.exists('Data'): + time.sleep(10) + while not os.path.exists('Phantoms'): + time.sleep(10) + while not os.path.exists('Utilities'): + time.sleep(10) + time.sleep(10) \ No newline at end of file From 2a8de37a32d99173d218af0fdb1eaf80bf025dca Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion Date: Wed, 28 Feb 2024 12:33:20 +0100 Subject: [PATCH 2/4] fixed the waiting --- phantoms/MR_XCAT_qMRI/generic.json | 596 +++++++++++++++++++++ utilities/data_simulation/Download_data.py | 30 +- 2 files changed, 616 insertions(+), 10 deletions(-) create mode 100644 phantoms/MR_XCAT_qMRI/generic.json diff --git a/phantoms/MR_XCAT_qMRI/generic.json b/phantoms/MR_XCAT_qMRI/generic.json new file mode 100644 index 0000000..47fcb3e --- /dev/null +++ b/phantoms/MR_XCAT_qMRI/generic.json @@ -0,0 +1,596 @@ +{ + "Myocardium LV": { + "noise": 0.0005, + "D": 0.0024, + "f": 0.14999999999999997, + "Dp": 0.08, + "data": [ + 0.37020853964957995, + 0.36495023994839576, + 0.36040161395777776, + 0.3482649413062642, + 0.3311252519245551, + 0.31128471484956144, + 0.29753771205592827, + 0.27895404495875237, + 0.2627838930390298, + 0.24600672258762385, + 0.21960592872343127, + 0.17325350570406992, + 0.13578433027277387, + 0.12026630133722724, + 0.08269998770527108, + 0.0583466003590057, + 0.04025758982493964, + 0.028838742483508213 + ] + }, + "myocardium RV": { + "noise": 0.0005, + "D": 0.0024, + "f": 0.14999999999999997, + "Dp": 0.07999999999999999, + "data": [ + 0.36977273246921033, + 0.36537365912605413, + 0.3595159042305869, + 0.34752698949768374, + 0.33173079647378234, + 0.3110608405629893, + 0.29805095418985367, + 0.27952927870925937, + 0.2623759963395676, + 0.2465802608039568, + 0.2205672287951045, + 0.17374944003807846, + 0.13502827555889882, + 0.12066297243669499, + 0.0836121527856757, + 0.05884198664879518, + 0.041489689098644505, + 0.028319859045401394 + ] + }, + "myocardium ra": { + "noise": 0.0005, + "D": 0.0015, + "f": 0.07000000000000002, + "Dp": 0.07000000000000002, + "data": [ + 0.3702523127001939, + 0.36755530947936665, + 0.3655092171111401, + 0.3587682397967246, + 0.35132224032603726, + 0.34087328451399485, + 0.3322050929514831, + 0.31948125995637927, + 0.30728799801895257, + 0.29586365531065567, + 0.2747381860006265, + 0.23736891610574076, + 0.20330679507798272, + 0.18899390991911522, + 0.15183897083022813, + 0.11947654863593715, + 0.0961082153184848, + 0.07618502040438892 + ] + }, + "Blood RV": { + "noise": 0.0005, + "D": 0.0030000000000000005, + "f": 1.0, + "Dp": 0.1, + "data": [ + 0.677301342624779, + 0.6130133898159349, + 0.5549567775209086, + 0.41065608429951045, + 0.2485679217237561, + 0.09152471508006849, + 0.03422606076706993, + 0.004391344655692806, + -0.0004185323666306052, + 0.00020745211260014227, + 9.950041472725093e-05, + 0.00033731346702161615, + -0.0004581887966317206, + 3.932025610280517e-05, + 0.0007977517497581966, + -9.674856879304352e-05, + -0.0007204219029777662, + -0.00010866334273215243 + ] + }, + "Blood RA": { + "noise": 0.0005, + "D": 0.0029999999999999996, + "f": 1.0, + "Dp": 0.09999999999999998, + "data": [ + 0.6784642687872807, + 0.6135371749705592, + 0.5551735492299803, + 0.41181139461379773, + 0.24923005810598367, + 0.0905737104418847, + 0.03324974683655229, + 0.005422829610804135, + 0.0013661550851885077, + -0.00010124567605655351, + -0.0006196825747740377, + -0.000911449851230475, + 4.552359004633976e-06, + 0.00045058131568997706, + -0.0004429879455544712, + 0.00023402108507587148, + 0.0008873455071852579, + -0.0003493718684806242 + ] + }, + "Liver": { + "noise": 0.0005, + "D": 0.0015, + "f": 0.11000000000000007, + "Dp": 0.1, + "data": [ + 0.37644062169477893, + 0.371115117353656, + 0.36798803216272463, + 0.3563630296133899, + 0.34430083828665475, + 0.3305305220923983, + 0.32121589864643874, + 0.31021138144645133, + 0.2996519813313952, + 0.2888296713839647, + 0.26634894381522295, + 0.2295414217850189, + 0.19733765396620417, + 0.18300505660775412, + 0.14688917007993096, + 0.11692921826028478, + 0.09269938996801896, + 0.07467525539976995 + ] + }, + "esophagus": { + "noise": 0.0005, + "D": 0.00167, + "f": 0.31999999999999995, + "Dp": 0.030000000000000002, + "data": [ + 0.3753101276497989, + 0.3713469825141738, + 0.36803668924761473, + 0.3561556517999572, + 0.3410493434981523, + 0.312875733963923, + 0.2915459261606361, + 0.2619677127542891, + 0.2379894063171585, + 0.2220458838581158, + 0.20015512076970554, + 0.167462024291482, + 0.1419784752197659, + 0.12989774418311542, + 0.10234154394160747, + 0.07930446754031786, + 0.06123140413656936, + 0.04776773648205296 + ] + }, + "esophagus cont": { + "noise": 0.0005, + "D": 0.00167, + "f": 0.31999999999999995, + "Dp": 0.030000000000000002, + "data": [ + 0.3760315571859291, + 0.3725261933502136, + 0.36878021796360194, + 0.35652169522898713, + 0.3386052646291958, + 0.31298259260039146, + 0.2928970721524276, + 0.2612959247167766, + 0.2382862271311805, + 0.2221373527772841, + 0.19937350825944655, + 0.16883993353226331, + 0.1424158552974854, + 0.13071358852326218, + 0.10173994625115453, + 0.07945195698352943, + 0.06243534663610846, + 0.04800948764844827 + ] + }, + "st wall": { + "noise": 0.0005, + "D": 0.0015, + "f": 0.29999999999999993, + "Dp": 0.012, + "data": [ + 0.3105272130104086, + 0.30885201953001484, + 0.3066269481129629, + 0.30274552065133936, + 0.2970795427045135, + 0.28499419004804777, + 0.2721728976730253, + 0.2524099337210839, + 0.23227124641480215, + 0.21525891994887883, + 0.18857776603497192, + 0.15443116579283125, + 0.12956411859096137, + 0.12018541366739759, + 0.09540290797868664, + 0.07646151871825584, + 0.060893544180195436, + 0.04844739095700899 + ] + }, + "pancreas": { + "noise": 0.0005, + "D": 0.0012999999999999997, + "f": 0.14999999999999997, + "Dp": 0.01, + "data": [ + 0.38790324491892814, + 0.3876291514843242, + 0.3863839489641638, + 0.38184405158251805, + 0.37867596311248974, + 0.3689126014097869, + 0.3601658251421809, + 0.3440753290932671, + 0.3259555478039212, + 0.3108907244841228, + 0.28514614179625436, + 0.24288623561383582, + 0.21079763700687396, + 0.19761965397168216, + 0.16190527129917393, + 0.13253969244152558, + 0.109498174630867, + 0.08988893299758294 + ] + }, + "Right kydney cortex": { + "noise": 0.0005, + "D": 0.00212, + "f": 0.09699999999999998, + "Dp": 0.02, + "data": [ + 0.5030626944055995, + 0.5001783921023092, + 0.4985206880919477, + 0.492235006203061, + 0.48382939238999034, + 0.46674631174303693, + 0.45237002678781385, + 0.42517107069931875, + 0.3973789957969744, + 0.3735484160962404, + 0.33239356651908736, + 0.2673529892425856, + 0.2154960685494099, + 0.1945665171600742, + 0.14102135574910862, + 0.10311364289145247, + 0.07456438398815092, + 0.053873627732706555 + ] + }, + "right kidney medulla": { + "noise": 0.0005, + "D": 0.0020900000000000003, + "f": 0.158, + "Dp": 0.018999999999999993, + "data": [ + 0.5203928163478555, + 0.5172834129714686, + 0.5154181766280577, + 0.508955947597674, + 0.4971665082609214, + 0.4765617297025814, + 0.4573353186594755, + 0.42798670009145867, + 0.3943814733854753, + 0.3678576959819498, + 0.3252024786031681, + 0.26093704038103643, + 0.2115158499487909, + 0.18986472099830365, + 0.1390757149598466, + 0.10175501422229921, + 0.0745403006178045, + 0.052954602248849326 + ] + }, + "Left kidney cortex": { + "noise": 0.0005, + "D": 0.00212, + "f": 0.09699999999999999, + "Dp": 0.019999999999999997, + "data": [ + 0.5024240367317072, + 0.49941258148509743, + 0.49805356407147056, + 0.4933194896159733, + 0.4840457529958473, + 0.4671852397846339, + 0.4521452680285715, + 0.42623711775650924, + 0.39725715329568395, + 0.37409027153921703, + 0.33217873975195317, + 0.26745366222903283, + 0.2157809336394279, + 0.19374765229746826, + 0.14049376483280698, + 0.10331460090984186, + 0.07440145499843141, + 0.05433448953174809 + ] + }, + "left kidney medulla": { + "noise": 0.0005, + "D": 0.0020900000000000003, + "f": 0.158, + "Dp": 0.018999999999999996, + "data": [ + 0.5194415728735972, + 0.517785604911926, + 0.5160301137297539, + 0.5081161819938502, + 0.4974616266593506, + 0.47681810747989994, + 0.4598785042642553, + 0.426137868936134, + 0.3953829313238142, + 0.3677361403989122, + 0.3248430621293657, + 0.26051271974899165, + 0.21029843278003593, + 0.18956042616225802, + 0.13923061439172535, + 0.10158270890079638, + 0.07404360800306067, + 0.055028684479409715 + ] + }, + "spleen": { + "noise": 0.0005, + "D": 0.0012999999999999997, + "f": 0.19999999999999998, + "Dp": 0.03000000000000001, + "data": [ + 0.46403850509317707, + 0.4599668139828373, + 0.4565050796135784, + 0.44775979510680575, + 0.4345571535066183, + 0.4116569011496948, + 0.39401165243513436, + 0.36774444861522015, + 0.3458271948654471, + 0.3294233615718273, + 0.30667603611837396, + 0.2674562035665486, + 0.23547634319485394, + 0.2201515745336398, + 0.1820120108467682, + 0.15000995189601307, + 0.12245722367383773, + 0.10106629985396444 + ] + }, + "Artery": { + "noise": 0.0005, + "D": 0.0029999999999999988, + "f": 1.0, + "Dp": 0.09999999999999998, + "data": [ + 0.6337138315409772, + 0.5730640187126045, + 0.5183053356244033, + 0.3835360405875329, + 0.23327858900709256, + 0.08548411122886704, + 0.03274861224071262, + 0.004777343857924789, + -0.000449472156073272, + 5.179481905995705e-06, + -0.0010595279088828175, + -0.0006967437546476321, + -3.6242741924784856e-05, + 0.0005019818951829742, + 0.0002644131825217677, + 0.00033417919268772877, + -0.00015136505885203394, + -0.00014363487647375497 + ] + }, + "Vein": { + "noise": 0.0005, + "D": 0.002999999999999999, + "f": 1.0, + "Dp": 0.09999999999999999, + "data": [ + 0.4607963898556654, + 0.4179229700550046, + 0.37789838853010355, + 0.2801168902809804, + 0.16939227145540162, + 0.06189817013733823, + 0.023234302719618776, + 0.0030315754490075016, + 0.0004901589324770273, + -0.0017004095520137548, + -0.0006037240267850347, + 0.000715049096502115, + -0.0003164388537626677, + -0.0005602932388408961, + -0.0008540747545262273, + 0.0002894370905108141, + 0.00025097542893550535, + 2.7938226096782815e-05 + ] + }, + "asc lower intestine": { + "noise": 0.0005, + "D": 0.00131, + "f": 0.6899999999999998, + "Dp": 0.028999999999999998, + "data": [ + 0.3764379461802061, + 0.368753536776957, + 0.3615610786383218, + 0.33986742552616955, + 0.3095708519923003, + 0.2586587529807586, + 0.2202675756946041, + 0.16913677227038204, + 0.13574910542040988, + 0.1159470963724909, + 0.09938984553504218, + 0.08421083881621177, + 0.07348586276743577, + 0.06974475141764117, + 0.05688849653030074, + 0.046677147601082956, + 0.03797211333797915, + 0.031179088207270982 + ] + }, + "trans lower intestine": { + "noise": 0.0005, + "D": 0.0013099999999999997, + "f": 0.6899999999999997, + "Dp": 0.029000000000000012, + "data": [ + 0.3762672014807758, + 0.3690953644152044, + 0.36036066425200697, + 0.3402209372451056, + 0.30943976347916957, + 0.2582806087239774, + 0.221563761814278, + 0.17024361750676187, + 0.1351444303322786, + 0.11642031090474003, + 0.09898413619434618, + 0.08390580104934697, + 0.07318355198354304, + 0.06851135869372077, + 0.056610482182588566, + 0.04597595772902957, + 0.03748809500313571, + 0.031136313419595326 + ] + }, + "desc lower intestine": { + "noise": 0.0005, + "D": 0.00131, + "f": 0.6899999999999997, + "Dp": 0.029000000000000015, + "data": [ + 0.3757756098276694, + 0.36857761887859763, + 0.3613935668445785, + 0.33986861821581216, + 0.3089720627229969, + 0.2587837365329459, + 0.22036174514041532, + 0.1700462354681048, + 0.1351358319822808, + 0.11639985207398235, + 0.0989689791051535, + 0.08424358823493776, + 0.07376418373495487, + 0.06944468021596181, + 0.05693491716291249, + 0.04609892567812359, + 0.037988533077624606, + 0.0319452543485727 + ] + }, + "small intestine": { + "noise": 0.0005, + "D": 0.00131, + "f": 0.6899999999999998, + "Dp": 0.02900000000000001, + "data": [ + 0.37622181996172344, + 0.36752971634723575, + 0.3609756275503666, + 0.339580571563921, + 0.30930331701922376, + 0.2575795626245274, + 0.22040334629181774, + 0.16896600459793495, + 0.13421224904598236, + 0.11632605863202615, + 0.09932840804199727, + 0.08375432628809912, + 0.0731745917792257, + 0.06923528604114432, + 0.05672824015665499, + 0.04626315476209859, + 0.038085645294904394, + 0.030936380311772267 + ] + }, + "pericardium": { + "noise": 0.0005, + "D": 0.0030000000000000005, + "f": 0.07000000000000002, + "Dp": 0.009999999999999998, + "data": [ + 0.30982366077717566, + 0.30993469587781963, + 0.30835311731521187, + 0.30497942046908105, + 0.30004184659823846, + 0.28976927774389194, + 0.2806614072060961, + 0.2615737929554431, + 0.24025519075401183, + 0.22082981124561804, + 0.18885845912462965, + 0.13801361831904962, + 0.10133822215077495, + 0.08843921581585718, + 0.05554544035298114, + 0.03554648221114816, + 0.02341755730966724, + 0.014847091111830489 + ] + }, + "config": { + "bvalues": [ + 0.0, + 1.0, + 2.0, + 5.0, + 10.0, + 20.0, + 30.0, + 50.0, + 75.0, + 100.0, + 150.0, + 250.0, + 350.0, + 400.0, + 550.0, + 700.0, + 850.0, + 1000.0 + ] + } +} \ No newline at end of file diff --git a/utilities/data_simulation/Download_data.py b/utilities/data_simulation/Download_data.py index 95f1c7a..5ea9bce 100644 --- a/utilities/data_simulation/Download_data.py +++ b/utilities/data_simulation/Download_data.py @@ -3,8 +3,18 @@ import subprocess import time + +def unzip_file(zip_file_path, extracted_folder_path): + # Open the zip file + with zipfile.ZipFile(zip_file_path, 'r') as zip_ref: + # Extract each file one by one + for file_info in zip_ref.infolist(): + zip_ref.extract(file_info, extracted_folder_path) + + def download_data(force=False): # Check if the folder exists, and create it if not + curdir=os.getcwd() base_folder = os.path.abspath(os.path.dirname(__file__)) base_folder = os.path.split(os.path.split(base_folder)[0])[0] if not os.path.exists(os.path.join(base_folder,'download')): @@ -17,13 +27,13 @@ def download_data(force=False): time.sleep(1) # Open the zip file if force or not os.path.exists('Data'): - with zipfile.ZipFile('OSIPI_TF24_data_phantoms.zip', 'r') as zip_ref: - # Extract all the contents to the destination folder - zip_ref.extractall('.') - while not os.path.exists('Data'): - time.sleep(10) - while not os.path.exists('Phantoms'): - time.sleep(10) - while not os.path.exists('Utilities'): - time.sleep(10) - time.sleep(10) \ No newline at end of file + # Unzip the file + unzip_file('OSIPI_TF24_data_phantoms.zip', '.') + # Wait for the extraction to complete by checking for the existence of any file + # Wait for the extraction to complete by checking for expected subdirectories + expected_subdirectories = [os.path.join('Utilities','DRO.npy'),os.path.join('Data','abdomen.nii.gz'), os.path.join('Data','brain.nii.gz'), os.path.join('Phantoms','brain','data','ballistic_snr200.nii.gz'), os.path.join('Phantoms','brain','data','diffusive_snr200.nii.gz'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_1_CP_1.mat'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_9_CP_1.mat'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_20_CP_1.mat')] # Add the expected subdirectories + while not all( + os.path.isfile(subdir) for subdir in expected_subdirectories): + time.sleep(1) # Wait for 1 second + time.sleep(10) + os.chdir(curdir) \ No newline at end of file From bd60a8ea50bd1306e1225903086543b4a9df36d5 Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion Date: Thu, 29 Feb 2024 16:40:00 +0100 Subject: [PATCH 3/4] Fixed bugs and added brain phantom --- phantoms/brain/sim_brain_phantom.py | 4 +++- utilities/data_simulation/Download_data.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/phantoms/brain/sim_brain_phantom.py b/phantoms/brain/sim_brain_phantom.py index 25e6a89..d5ba89a 100644 --- a/phantoms/brain/sim_brain_phantom.py +++ b/phantoms/brain/sim_brain_phantom.py @@ -4,8 +4,10 @@ import numpy as np import nibabel as nib from scipy.ndimage import zoom +from utilities.data_simulation.Download_data import download_data if __name__ == "__main__": + download_data() DIFFUSIVE_REGIME = 'diffusive' BALLISTIC_REGIME = 'ballistic' @@ -22,7 +24,7 @@ # Ground truth - nii = nib.load(os.path.join(folder,'ground_truth','hrgt_icbm_2009a_nls_3t.nii.gz')) + nii = nib.load(os.path.join(os.path.split(os.path.split(folder)[0])[0],'download','Phantoms','brain','ground_truth','hrgt_icbm_2009a_nls_3t.nii.gz')) segmentation = np.squeeze(nii.get_fdata()[...,-1]) with open(os.path.join(folder,'ground_truth',regime+'_groundtruth.json'), 'r') as f: diff --git a/utilities/data_simulation/Download_data.py b/utilities/data_simulation/Download_data.py index 5ea9bce..e4d3f86 100644 --- a/utilities/data_simulation/Download_data.py +++ b/utilities/data_simulation/Download_data.py @@ -21,7 +21,7 @@ def download_data(force=False): os.makedirs(os.path.join(base_folder,'download')) print(f"Folder '{'download'}' created.") # Change to the specified folder - os.chdir(os.path.join(base_folder,'download')) + os.chdir(os.path.join(base_folder,'download')) subprocess.run(["zenodo_get", 'https://zenodo.org/records/10696605']) while not os.path.exists('OSIPI_TF24_data_phantoms.zip'): time.sleep(1) From 0801ec313b0df33318df0436a97458f391a7eab8 Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion Date: Wed, 6 Mar 2024 17:31:57 +0100 Subject: [PATCH 4/4] removed waiting and resolved conflicts --- utilities/data_simulation/Download_data.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/utilities/data_simulation/Download_data.py b/utilities/data_simulation/Download_data.py index e4d3f86..d03d8eb 100644 --- a/utilities/data_simulation/Download_data.py +++ b/utilities/data_simulation/Download_data.py @@ -22,18 +22,9 @@ def download_data(force=False): print(f"Folder '{'download'}' created.") # Change to the specified folder os.chdir(os.path.join(base_folder,'download')) - subprocess.run(["zenodo_get", 'https://zenodo.org/records/10696605']) - while not os.path.exists('OSIPI_TF24_data_phantoms.zip'): - time.sleep(1) + subprocess.check_call(["zenodo_get", 'https://zenodo.org/records/10696605']) # Open the zip file if force or not os.path.exists('Data'): # Unzip the file unzip_file('OSIPI_TF24_data_phantoms.zip', '.') - # Wait for the extraction to complete by checking for the existence of any file - # Wait for the extraction to complete by checking for expected subdirectories - expected_subdirectories = [os.path.join('Utilities','DRO.npy'),os.path.join('Data','abdomen.nii.gz'), os.path.join('Data','brain.nii.gz'), os.path.join('Phantoms','brain','data','ballistic_snr200.nii.gz'), os.path.join('Phantoms','brain','data','diffusive_snr200.nii.gz'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_1_CP_1.mat'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_9_CP_1.mat'), os.path.join('Phantoms','XCAT_MAT_RESP','XCAT5D_RP_20_CP_1.mat')] # Add the expected subdirectories - while not all( - os.path.isfile(subdir) for subdir in expected_subdirectories): - time.sleep(1) # Wait for 1 second - time.sleep(10) os.chdir(curdir) \ No newline at end of file