From af83bda903d0e83433d75e445b9a63d3b8512eb1 Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion Date: Fri, 4 Aug 2023 16:34:39 +0200 Subject: [PATCH 1/8] added diffusion values and solved scaling --- phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 130 ++++++++++++-------------- 1 file changed, 61 insertions(+), 69 deletions(-) diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index 0640113..e679d62 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -82,86 +82,86 @@ def contrast_curve_calc(): tissue_included = np.array([1, 2, 3, 4, 5, 6, 7, 8, 13, 17, 18, 20, 22, 23, 24, 25, 26, 30, 36, 37, 40, 41, 42, 43, 50, 73]) D = np.zeros(74) - D[1] = 2e-3 # 1 Myocardium LV - D[2] = 2e-3 # 2 myocardium RV + D[1] = 2.4e-3 # 1 Myocardium LV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + D[2] = 2.4e-3 # 2 myocardium RV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 D[3] = 2e-3 # 3 myocardium la D[4] = 1.5e-3 # 4 myocardium ra D[5] = 3e-3 # 5 Blood LV D[6] = 3e-3 # 6 Blood RV D[7] = 3e-3 # 7 Blood la D[8] = 3e-3 # 8 Blood ra - D[13] = 1.2e-3 # 13 liver - D[17] = 1e-3 # 17 esophagus - D[18] = 1e-3 # 18 esophagus cont - D[20] = 1e-3 # 20 stomach wall + D[13] = 1.5e-3 # 13 liver: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + D[17] = 1.67e-3 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421 + D[18] = 1.67e-3 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421 + D[20] = 1.5e-3 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586 D[22] = 1.3e-3 # 22 Pancreas (from literature) - D[23] = 2e-3 # 23 right kydney cortex - D[24] = 1e-3 # 23 right kydney medulla - D[25] = 2e-3 # 23 left kydney cortex - D[26] = 1e-3 # 23 left kydney medulla - D[30] = 0.8e-3 # 30 spleen + D[23] = 2.12e-3 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519 + D[24] = 2.09e-3 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519 + D[25] = 2.12e-3 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519 + D[26] = 2.09e-3 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519 + D[30] = 1.3e-3 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495 D[36] = 3e-3 # 36 artery - D[37] = 3e-3 # 37 vein - D[40] = 3e-3 # 40 asc lower intestine - D[41] = 3e-3 # 41 trans lower intestine - D[42] = 3e-3 # 42 desc lower intestine - D[43] = 3e-3 # 43 small intestine + D[37] = 3e-3 # 37 vein + D[40] = 1.31e-3 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + D[41] = 1.31e-3 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + D[42] = 1.31e-3 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + D[43] = 1.31e-3 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 D[50] = 3e-3 # 50 pericardium D[73] = 1.8e-3 # 73 Pancreatic tumor (advanced state, from literature) f = np.zeros(74) - f[1] = 0.7 # 1 Myocardium LV - f[2] = 0.7 # 2 myocardium RV - f[3] = 0.7 # 3 myocardium la - f[4] = 0.7 # 4 myocardium ra + f[1] = 0.15 # 1 Myocardium LV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + f[2] = 0.15 # 2 myocardium RV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + f[3] = 0.07 # 3 myocardium la + f[4] = 0.07 # 4 myocardium ra f[5] = 1.00 # 5 Blood LV f[6] = 1.00 # 6 Blood RV f[7] = 1.00 # 7 Blood la f[8] = 1.00 # 8 Blood ra - f[13] = 0.25 # 13 liver - f[17] = 0.1 # 17 esophagus - f[18] = 0.1 # 18 esophagus cont - f[20] = 0.3 # 20 stomach wall + f[13] = 0.11 # 13 liver : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + f[17] = 0.32 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421 + f[18] = 0.32 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421 + f[20] = 0.3 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586 f[22] = 0.15 # 22 Pancreas (from literature) - f[23] = 0.3 # 23 right kydney cortex - f[24] = 0.2 # 23 right kydney medulla - f[25] = 0.3 # 23 left kydney cortex - f[26] = 0.2 # 23 left kydney medulla - f[30] = 0.4 # 30 spleen - f[36] = 1.0 # 36 artery - f[37] = 1.0 # 37 vein - f[40] = 0.19 # 40 asc lower intestine - f[41] = 0.19 # 41 trans lower intestine - f[42] = 0.19 # 42 desc lower intestine - f[43] = 0.19 # 43 small intestine + f[23] = 0.097 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519 + f[24] = 0.158 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519 + f[25] = 0.097 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519 + f[26] = 0.158 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519 + f[30] = 0.2 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495 + f[36] = 1.0 # 36 artery + f[37] = 1.0 # 37 vein + f[40] = 0.69 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + f[41] = 0.69 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + f[42] = 0.69 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + f[43] = 0.69 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 f[50] = 0.07 # 50 pericardium f[73] = 0.37 # 73 Pancreatic tumor (advanced state, from literature) Ds = np.zeros(74) - Ds[1] = 0.07 # 1 Myocardium LV - Ds[2] = 0.07 # 2 myocardium RV + Ds[1] = 0.08 # 1 Myocardium LV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + Ds[2] = 0.08 # 2 myocardium RV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 Ds[3] = 0.07 # 3 myocardium la Ds[4] = 0.07 # 4 myocardium ra Ds[5] = 0.1 # 5 Blood LV Ds[6] = 0.1 # 6 Blood RV Ds[7] = 0.1 # 7 Blood la Ds[8] = 0.1 # 8 Blood ra - Ds[13] = 0.05 # 13 liver - Ds[17] = 0.05 # 17 esophagus - Ds[18] = 0.05 # 18 esophagus cont - Ds[20] = 0.07 # 20 stomach wall + Ds[13] = 0.1 # 13 liver: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 + Ds[17] = 0.03 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421 + Ds[18] = 0.03 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421 + Ds[20] = 0.012 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586 Ds[22] = 0.01 # 22 Pancreas (from literature) - Ds[23] = 0.02 # 23 right kydney cortex - Ds[24] = 0.07 # 23 right kydney medulla - Ds[25] = 0.02 # 23 left kydney cortex - Ds[26] = 0.07 # 23 left kydney medulla - Ds[30] = 0.08 # 30 spleen - Ds[36] = 0.1 # 36 artery - Ds[37] = 0.1 # 37 vein - Ds[40] = 0.09 # 40 asc lower intestine - Ds[41] = 0.09 # 41 trans lower intestine - Ds[42] = 0.09 # 42 desc lower intestine - Ds[43] = 0.09 # 43 small intestine + Ds[23] = 0.02 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519 + Ds[24] = 0.019 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519 + Ds[25] = 0.02 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519 + Ds[26] = 0.019 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519 + Ds[30] = 0.03 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495 + Ds[36] = 0.1 # 36 artery + Ds[37] = 0.1 # 37 vein + Ds[40] = 0.029 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + Ds[41] = 0.029 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + Ds[42] = 0.029 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 + Ds[43] = 0.029 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926 Ds[50] = 0.01 # 50 pericardium Ds[73] = 0.01 # 73 Pancreatic tumor (advanced state, from literature) # Return values @@ -169,7 +169,7 @@ def contrast_curve_calc(): return tissue_included, D, f, Ds -def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_cont = True, Contrast = 'SE', FA=90): +def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_cont = True): ########################################################################################### # This script converts XCAT tissue values to MR contrast based on the SSFP signal equation. # Christopher W. Roy 2018-12-04 # fetal.xcmr@gmail.com @@ -355,19 +355,8 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_c #S0 = np.zeros(len(bvalue)) S0 = ivim(bvalue,Dtemp,ftemp,Dstemp) if T1 > 0 or T2 > 0: - if Contrast == 'GRE': - if iTissue not in [31, 32, 33]: - MR = MR + (XCAT == iTissue) * np.sin(np.deg2rad(FA)) * (1 - np.exp(-TR / T1)) / ( - 1 - (np.cos(np.deg2rad(FA)) * np.exp(-TR / T1))) - elif Contrast == 'bSSFP': - MR = MR + (XCAT == iTissue) * np.sin(np.deg2rad(FA)) * (1 - np.exp(-TR / T1)) * np.exp(-TE / T2) / ( - 1 - (np.exp(-TR / T1) - np.exp(-TR / T2)) * np.cos(np.deg2rad(FA)) - np.exp( - -TR / T1) * np.exp(-TR / T2)) - elif Contrast == 'SE': - MR = MR + np.tile(np.expand_dims(XCAT == iTissue,3),len(S0)) * S0 * (1 - 2 * np.exp(-(TR - TE / 2) / T1) + np.exp(-TR / T1)) * np.exp( - -TE / T2) - else: - raise ValueError('Unknown MR contrast. Use only GRE, bSSFP, or SE.') + MR = MR + np.tile(np.expand_dims(XCAT == iTissue,3),len(S0)) * S0 * (1 - 2 * np.exp(-(TR - TE / 2) / T1) + np.exp(-TR / T1)) * np.exp( + -TE / T2) Dim = Dim + (XCAT == iTissue) * Dtemp fim = fim + (XCAT == iTissue) * ftemp Dpim = Dpim + (XCAT == iTissue) * Dstemp @@ -396,18 +385,21 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_c output_file = 'output_xcat.nii.gz' # Replace with your desired output file name nib.save(nifti_img, output_file) - nifti_img = nib.Nifti1Image(Dim*1000000, affine=res) # Replace affine if necessary + nifti_img = nib.Nifti1Image(Dim, affine=res) # Replace affine if necessary # Save the NIfTI image to a file + nifti_img.header.set_data_dtype(np.float64) output_file = 'D.nii.gz' # Replace with your desired output file name nib.save(nifti_img, output_file) - nifti_img = nib.Nifti1Image(fim*1000, affine=res) # Replace affine if necessary + nifti_img = nib.Nifti1Image(fim, affine=res) # Replace affine if necessary # Save the NIfTI image to a file + nifti_img.header.set_data_dtype(np.float64) output_file = 'f.nii.gz' # Replace with your desired output file name nib.save(nifti_img, output_file) - nifti_img = nib.Nifti1Image(Dpim*1000, affine=res) # Replace affine if necessary + nifti_img = nib.Nifti1Image(Dpim, affine=res) # Replace affine if necessary # Save the NIfTI image to a file + nifti_img.header.set_data_dtype(np.float64) output_file = 'Dp.nii.gz' # Replace with your desired output file name nib.save(nifti_img, output_file) From e8b701c1c139a3550363fb99c862ac35931b3036 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 13 Aug 2023 21:43:17 -0700 Subject: [PATCH 2/8] Save generic signals from phantom --- phantoms/MR_XCAT_qMRI/generic.json | 762 ++++++++++++++++++++++++++ phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 185 ++++--- 2 files changed, 862 insertions(+), 85 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..7c333a2 --- /dev/null +++ b/phantoms/MR_XCAT_qMRI/generic.json @@ -0,0 +1,762 @@ +{ + "Myocardium LV": [ + 0.34898972165246894, + 0.34101242160675377, + 0.33372388000357645, + 0.3157531968317352, + 0.29503902295477363, + 0.27245023265312257, + 0.2616621088496361, + 0.25051537211502606, + 0.24042271152257536, + 0.23133001978160686, + 0.21438219286085167, + 0.18383197033343293, + 0.15779985945030905, + 0.14636217685921896, + 0.1166721702026485, + 0.09296904234139387, + 0.07394265755210767, + 0.059025760672105874 + ], + "myocardium RV": [ + 0.24871440181457757, + 0.23850273859717308, + 0.2289854730926882, + 0.20553028049431227, + 0.17847064388251438, + 0.15045806808694825, + 0.1386132346782817, + 0.12799911577203738, + 0.12115095902886129, + 0.11579837255566115, + 0.1057518702068629, + 0.08923571059677567, + 0.0756671006151337, + 0.06917423867545223, + 0.05414092369945907, + 0.042174353529610964, + 0.03274954770001436, + 0.026347028035115835 + ], + "myocardium ra": [ + 0.3701390037402836, + 0.3547247709293157, + 0.3394925431169981, + 0.30069918467966056, + 0.2577155756678938, + 0.21090209975050445, + 0.1914128797539193, + 0.17398154802469337, + 0.16026561646669835, + 0.14790483732455373, + 0.1305605363581906, + 0.09931988390848359, + 0.0773813076939424, + 0.06588794841433523, + 0.045979424789180434, + 0.03091359543634595, + 0.020548426579726765, + 0.015096269577284159 + ], + "Blood RV": [ + 0.17106052259021262, + 0.16582622007452907, + 0.16116521698120964, + 0.14853026266452848, + 0.1341440000046226, + 0.11761327736086784, + 0.10933699812277997, + 0.10031820633426025, + 0.09402859334526843, + 0.08878983893330852, + 0.08082878548914076, + 0.06778894704035736, + 0.05694827001928639, + 0.052403420068841536, + 0.04064137959584879, + 0.031595174516801355, + 0.02427306659541205, + 0.01902386285584882 + ], + "Blood RA": [ + 0.3703033790249206, + 0.3624481744017803, + 0.3537229701388481, + 0.3324304780725038, + 0.3068915045382316, + 0.27759417769336603, + 0.26229092749774474, + 0.24342725768253756, + 0.22603353118287925, + 0.2093964895071889, + 0.1825360717560458, + 0.13905342116878752, + 0.10702825903428566, + 0.09349875931020393, + 0.06421267843457956, + 0.044299349146106684, + 0.030137648764653652, + 0.021367056761294086 + ], + "body": [ + 0.14414367264868502, + 0.14254894780713223, + 0.14102540267025154, + 0.1370403554281524, + 0.13173976192125425, + 0.12412754062068529, + 0.11878700552316925, + 0.1108794216038723, + 0.10349327937708143, + 0.09749692818840278, + 0.08770085826619782, + 0.07216968456293092, + 0.059788843023755624, + 0.05451750242241992, + 0.04134033157630361, + 0.03152188276855943, + 0.024103278910228742, + 0.018524270879296933 + ], + "muscle": [ + 0.08757654862963136, + 0.08674376658664566, + 0.08592431541219317, + 0.08367162334782906, + 0.08031780816706909, + 0.0749637372493411, + 0.07079915000229199, + 0.06455999141899182, + 0.05905532471383719, + 0.0548959565550597, + 0.04860349639131267, + 0.03932000301546678, + 0.03208152623443189, + 0.029026091770908587, + 0.021533697670863577, + 0.01605968077519118, + 0.012051220980819647, + 0.009084206239931093 + ], + "Liver": [ + 0.20764655512452465, + 0.20304949087263294, + 0.19873658197571142, + 0.18749611799191773, + 0.17294976332773093, + 0.15348299728246548, + 0.14103427572470822, + 0.12532086576571294, + 0.11319360281160694, + 0.10502357821785527, + 0.09370776233349902, + 0.07818280689953981, + 0.06627775222273016, + 0.06110905360001995, + 0.048149055243257986, + 0.03806368532736532, + 0.0301369527504607, + 0.023926557581638072 + ], + "gall bladder": [ + 0.3493065062338589, + 0.3459177539619973, + 0.34276915788221696, + 0.3337678007265264, + 0.3215903768765205, + 0.3034713245206977, + 0.2901003731591599, + 0.27041065154076466, + 0.2518535625623309, + 0.23718380430075703, + 0.21415548733603126, + 0.17988018244500617, + 0.152663540856617, + 0.14095311990006207, + 0.11159082021963462, + 0.08865130135013015, + 0.07067950411814532, + 0.05633393333300527 + ], + "Right Lung": [ + 0.236116775520707, + 0.22538994140048546, + 0.21551356079114853, + 0.19130642137783227, + 0.16318964400163308, + 0.13373791047781014, + 0.12057801765369926, + 0.10846514769614894, + 0.10012707385992056, + 0.0933013884843937, + 0.08198291880498976, + 0.06429219788563631, + 0.05105953096891295, + 0.04546795505732233, + 0.03254767944227243, + 0.023343257204698934, + 0.01678606467014956, + 0.011985887933976194 + ], + "Left Lung": [ + 0.20219391502392353, + 0.20040984981695986, + 0.19892392275478604, + 0.1946251116428798, + 0.18907206303859317, + 0.1813340408431629, + 0.17590470732639651, + 0.16711631881198497, + 0.15808052265257577, + 0.14991157487786352, + 0.13539578206984829, + 0.1115826071391817, + 0.0923095260770106, + 0.08413488635205534, + 0.06369105361738163, + 0.048345743625243555, + 0.03695177490437736, + 0.02817803210968259 + ], + "esophagus": [ + 0.47740725510389664, + 0.45186638152227837, + 0.42906610068950823, + 0.373434961610736, + 0.30904967177952714, + 0.24549075375787766, + 0.21919760942267802, + 0.20120252323013257, + 0.19169524950691072, + 0.18350266542958235, + 0.16939018358081834, + 0.14387934544940623, + 0.12242796471590835, + 0.1125765018341218, + 0.08921064710814529, + 0.07013945983259418, + 0.05561724938912094, + 0.043673488730017945 + ], + "esophagus cont": [ + 0.4908291180811218, + 0.46298734193501884, + 0.4374848768124934, + 0.3755350259486313, + 0.30463285765481646, + 0.23400161289627847, + 0.20639701702872446, + 0.18721208467465203, + 0.17821957313101736, + 0.17051252450699383, + 0.1569723995669235, + 0.13322796993239644, + 0.11332436530964766, + 0.10482303156426699, + 0.08227121223269757, + 0.06492523304246411, + 0.05146934457285453, + 0.040450870910328965 + ], + "st wall": [ + 0.33972021704324323, + 0.33489876248808564, + 0.33038248564421774, + 0.31906525251468615, + 0.3054141853409019, + 0.2897553845246325, + 0.2810769065800649, + 0.26993739744640444, + 0.25875683592454635, + 0.2485725127824088, + 0.2294395631569634, + 0.19583539379628107, + 0.16764978387583143, + 0.15492748991609295, + 0.1227939834035703, + 0.09733645234521748, + 0.07728891023255187, + 0.06150417977627565 + ], + "Stomach Contents": [ + 0.3560052458252937, + 0.34991932799935316, + 0.3442698147707965, + 0.33026613719975484, + 0.3138434229862651, + 0.2954337099533313, + 0.28586841644655775, + 0.27474877939545594, + 0.2639776559525697, + 0.2539406790158555, + 0.23516487991333426, + 0.20205843786551828, + 0.17343044394190357, + 0.16087844370376087, + 0.1280621082111017, + 0.10214870316387105, + 0.08142871589721011, + 0.06489432919982008 + ], + "pancreas": [ + 0.2607580651974088, + 0.2531536308045649, + 0.24615174878114493, + 0.22828267116587056, + 0.205900714057674, + 0.17852671042230908, + 0.16251880757882584, + 0.1438039751026593, + 0.1296673723203523, + 0.12011326790844216, + 0.1061091282874786, + 0.08660070631748401, + 0.07174793040577473, + 0.06567359724996769, + 0.05031462539333168, + 0.039295240786263154, + 0.03062429306559929, + 0.024178754021125005 + ], + "Right kydney cortex": [ + 0.15963378893525246, + 0.15592535517239714, + 0.1522883109307759, + 0.14251397810220603, + 0.12822860726828772, + 0.10613880483731515, + 0.09017267577969265, + 0.0691730985592467, + 0.05492991869454863, + 0.04741904302925983, + 0.0403312549498806, + 0.03441167051556376, + 0.030004037533558382, + 0.028041654197369835, + 0.023106211605735148, + 0.019011480952706616, + 0.01568809284650648, + 0.012630445712653463 + ], + "right kidney medulla": [ + 0.15514794064191945, + 0.15102045477128537, + 0.14721225560692977, + 0.13708213010310177, + 0.12250106550381955, + 0.10082481997884392, + 0.0850354695412841, + 0.06525039603181984, + 0.05181170360998079, + 0.0448607984097072, + 0.03822526926722316, + 0.032308544754609855, + 0.0284035899717906, + 0.026673892094159924, + 0.021826118315602647, + 0.01775931247595257, + 0.014652816278214149, + 0.012271687324018633 + ], + "Left kidney cortex": [ + 0.2865960334102167, + 0.28242548008727403, + 0.2785142782913214, + 0.2675190992319904, + 0.2511810180936404, + 0.22492314700928592, + 0.2049783841959968, + 0.1770199874720396, + 0.15563485234406482, + 0.14155065337617062, + 0.12381948002483145, + 0.10108602009586574, + 0.08374660801978874, + 0.07655153259807843, + 0.05862245953110069, + 0.04524933833052055, + 0.03504402897787108, + 0.02716270228355165 + ], + "left kidney medulla": [ + 0.28071870508429503, + 0.27599110495416473, + 0.27155175898873424, + 0.25918220719680113, + 0.24102248086659805, + 0.2109532051148196, + 0.18859868765879692, + 0.15756940099201452, + 0.13456136544473948, + 0.12098350651499033, + 0.10498552477016143, + 0.08630730523641636, + 0.07233096061238732, + 0.06637479404760226, + 0.05151396116027796, + 0.04057384910601671, + 0.031746556264228475, + 0.025204453108978238 + ], + "adrenal": [ + 0.2826787411763678, + 0.27831009499717363, + 0.27371092759824794, + 0.2616251836866002, + 0.24393644939867817, + 0.21629881654153307, + 0.19581377499127034, + 0.1684868929153769, + 0.14880648072939534, + 0.13553935371698403, + 0.12078755186863444, + 0.10202768317513937, + 0.08757197318285687, + 0.08138351107427882, + 0.0653235654424977, + 0.05275031976863747, + 0.042296493872499896, + 0.03404718958125153 + ], + "Right Renal Pelvis": [ + 0.23845594027974554, + 0.2340885887968851, + 0.22926470734550777, + 0.21482880140243105, + 0.1955512896933524, + 0.16390194580931639, + 0.13862838327930652, + 0.10649279269443837, + 0.08477918144411398, + 0.07305769210877683, + 0.061746891755696455, + 0.05285223648019959, + 0.04586067619718521, + 0.04320687858631259, + 0.03586299157223977, + 0.028432215124915988, + 0.02445436566942347, + 0.019589305268583098 + ], + "Left Renal Pelvis": [ + 0.29934044796894144, + 0.2932737029677877, + 0.2877041185108748, + 0.2710250881677717, + 0.24704347642316418, + 0.20760360029872693, + 0.17839331549285958, + 0.1386621352319866, + 0.11059454180813225, + 0.09591295440295877, + 0.0817685975642877, + 0.0689974169990692, + 0.05938551000712084, + 0.05607454196727335, + 0.04512593596146897, + 0.03683226767862082, + 0.030579950438570393, + 0.02459556163525453 + ], + "spleen": [ + 0.20825262009604234, + 0.20694704899515484, + 0.20570704831467276, + 0.20212507147961328, + 0.19725229821243304, + 0.18943033146299096, + 0.18320327013640075, + 0.17286781864880957, + 0.161615547575178, + 0.1519351681953833, + 0.13520336489841728, + 0.10829727499724853, + 0.08736434649782453, + 0.07855737095755005, + 0.05742828771554922, + 0.04218246865860132, + 0.03112872853303898, + 0.023187841448832597 + ], + "Ribs": [ + 0.12711214146958372, + 0.1263954809552108, + 0.12547014589784425, + 0.12313829653088443, + 0.11956027858802483, + 0.11364687278836964, + 0.10874717793211831, + 0.10083697123473874, + 0.09358077826879158, + 0.08780976681970634, + 0.07835502891221134, + 0.06389393071053609, + 0.05264876901757898, + 0.04774045258997308, + 0.0359310306495789, + 0.027251312152600817, + 0.020714406533062647, + 0.01584052715598586 + ], + "Cortical Bone": [ + 0.009390143914629926, + 0.009099037389799763, + 0.009131460655393383, + 0.008829782724048505, + 0.0086502135563019, + 0.008069828102584907, + 0.0077680784167890315, + 0.007362268945100939, + 0.006882829387916501, + 0.0064934829532998836, + 0.005767801738684848, + 0.004527350372436516, + 0.003640243481224372, + 0.00326492376438238, + 0.002394125257379272, + 0.0016714100072533812, + 0.001144843332685241, + 0.0008363716380179653 + ], + "Spine": [ + 0.2074391650883512, + 0.20328222351873226, + 0.19951658296745667, + 0.18914993182867465, + 0.17566591689404631, + 0.15682505195441462, + 0.1443479284647448, + 0.1282986094467979, + 0.11600083158034812, + 0.10782315444682807, + 0.0965419564646553, + 0.08124431936743932, + 0.0692448576593437, + 0.0640193336812393, + 0.050755357448090184, + 0.04038920737820779, + 0.03219893194857284, + 0.02568467031437344 + ], + "spinal cord": [ + 0.14968537510540572, + 0.1474358467818982, + 0.14543252611208127, + 0.13981765341703914, + 0.13326668726926896, + 0.12551994254278298, + 0.12140964495107077, + 0.11552529390883204, + 0.11011187420590139, + 0.10394423012644549, + 0.0953245538857873, + 0.08063551244549981, + 0.06881988499396485, + 0.06310984404863128, + 0.04937163704574576, + 0.0388701590854159, + 0.030823101963032198, + 0.024307723947324944 + ], + "Bone Marrow": [ + 0.1137767818468923, + 0.11195565594192901, + 0.11033817558021898, + 0.10568139675213667, + 0.09961356724480598, + 0.09086071944436365, + 0.0847879583667797, + 0.07655126457311016, + 0.06991046724282958, + 0.06532765614212656, + 0.05861911694149705, + 0.04906131170426399, + 0.04148286776774864, + 0.03824025893353378, + 0.0299947005479393, + 0.023609033117558905, + 0.018584930597666086, + 0.014711209272766139 + ], + "Artery": [ + 0.22834647271477249, + 0.2231054294831425, + 0.21794961382660857, + 0.20498977519163897, + 0.18779391580254307, + 0.16530130471095614, + 0.1509167178895211, + 0.13288398883831373, + 0.11976722105657064, + 0.11101252429871204, + 0.0995679871896937, + 0.08393896738444352, + 0.07175624264460921, + 0.06642824374222756, + 0.052990525840176876, + 0.04234313675826943, + 0.034022916847795445, + 0.027353983241822123 + ], + "Vein": [ + 0.22441397394228915, + 0.22020896097441717, + 0.21606131782971294, + 0.20510030062414625, + 0.19105799752479158, + 0.17138968491456982, + 0.15833251939086881, + 0.14149440031896057, + 0.12814970483654534, + 0.11897468240522634, + 0.1061607717044737, + 0.08845332107116888, + 0.07465524015934527, + 0.06868361221643562, + 0.05376343264190993, + 0.04226849670653001, + 0.03331360392108922, + 0.026481578251132707 + ], + "asc lower intestine": [ + 0.2954735243830286, + 0.2906352588520771, + 0.2858040728009893, + 0.2732876505097306, + 0.2555854419555954, + 0.22985581576200326, + 0.21128491346672293, + 0.18608064851180967, + 0.16601289258896418, + 0.15240173839644594, + 0.13400187334016833, + 0.10885324742349821, + 0.08975247478641343, + 0.08153230006289827, + 0.06139854293776205, + 0.0462805910211582, + 0.03508261675195721, + 0.026645564361144645 + ], + "trans lower intestine": [ + 0.3059958856171849, + 0.3033478430012246, + 0.3008747097693397, + 0.2942893933085906, + 0.28545501121207245, + 0.27254118906081826, + 0.2630912499309692, + 0.24845192418952888, + 0.2336370590673267, + 0.22075908874945738, + 0.19894704011158446, + 0.16374014235149112, + 0.13561828103732013, + 0.12345897516597096, + 0.09371111774296453, + 0.07128210798283909, + 0.05448244944592977, + 0.04181129466668589 + ], + "desc lower intestine": [ + 0.3321131178872771, + 0.32853831493658764, + 0.3252040860498945, + 0.31695161828277213, + 0.306518435347314, + 0.2936208786613117, + 0.28524779476766704, + 0.27302246070959224, + 0.2602918045459527, + 0.24869005810018593, + 0.22787949028471127, + 0.19169263092766683, + 0.16182307271559665, + 0.14876986039111117, + 0.11598635759976698, + 0.09055906420523004, + 0.07088668437054298, + 0.055538701011291276 + ], + "small intestine": [ + 0.30074425040279856, + 0.2944845452430382, + 0.28863340515273506, + 0.2735820814981339, + 0.25453852747846045, + 0.23015611850652534, + 0.21519383720966714, + 0.19637918935500634, + 0.18132358975376156, + 0.1703002154782028, + 0.15368595652005698, + 0.12867080211654158, + 0.10855563167521692, + 0.09984876120702285, + 0.07772999966315815, + 0.060759749320596794, + 0.04756646220287644, + 0.037368264773960574 + ], + "pericardium": [ + 0.32000494407805, + 0.3088654009375722, + 0.29904980558089767, + 0.2740850878913364, + 0.24558604488847646, + 0.21536926331505973, + 0.2020222261297372, + 0.18936420984433425, + 0.18029653079469718, + 0.17201776672049646, + 0.15729878584721638, + 0.13196136697968544, + 0.11127864773724477, + 0.10224194180476164, + 0.07944915803798566, + 0.06221573834819889, + 0.04875921452691328, + 0.03834181090739235 + ], + "Cartilage": [ + 0.22023434588419283, + 0.21765363810860222, + 0.2153102069694426, + 0.20879630843180802, + 0.20028436277779857, + 0.1878493204264525, + 0.17913244131902714, + 0.16695355326774897, + 0.1559418751278614, + 0.14735487693691215, + 0.1332856707364372, + 0.11150392562163026, + 0.09371166585155002, + 0.08608967361722157, + 0.06670031907274253, + 0.051882051080158885, + 0.0404627776446415, + 0.03166323498206638 + ], + "Fat": [ + 0.04347759306594482, + 0.04331055503018695, + 0.043157782586126285, + 0.04267618521144028, + 0.041840304286041824, + 0.04042891293620974, + 0.039170850881867544, + 0.0369091385939268, + 0.034446175085675435, + 0.03229938324890682, + 0.028545694575280674, + 0.022604383587180022, + 0.017992511581896263, + 0.016066679631941184, + 0.01138662757473584, + 0.008100170353602424, + 0.005759608016476787, + 0.004089478201726281 + ] +} \ No newline at end of file diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index e679d62..5db7386 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -1,6 +1,7 @@ import numpy as np from scipy.io import loadmat import nibabel as nib +import json ########## # code written by Oliver J Gurney-Champion @@ -21,8 +22,8 @@ def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleav XCAT = mat_data['IMG'] XCAT = XCAT[0:-1:2,0:-1:2,10:160:4] - tissue_included, D, f, Ds = contrast_curve_calc() - S, Dim, fim, Dpim = XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds) + D, f, Ds = contrast_curve_calc() + S, Dim, fim, Dpim, legend = XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds) if state == 1: Dim_out = Dim fim_out = fim @@ -72,16 +73,15 @@ def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleav state2 = state2+1 else: S=np.squeeze(totsig) - return S, XCAT, Dim_out, fim_out, Dpim_out + return S, XCAT, Dim_out, fim_out, Dpim_out, legend def ivim(bvalues,D,f,Ds): return (1-f) * np.exp(-D * bvalues) + f * np.exp(-Ds * bvalues) def contrast_curve_calc(): - tissue_included = np.array([1, 2, 3, 4, 5, 6, 7, 8, 13, 17, 18, 20, 22, 23, 24, 25, 26, 30, 36, 37, 40, 41, 42, 43, 50, 73]) - D = np.zeros(74) + D = np.full(74, np.nan) D[1] = 2.4e-3 # 1 Myocardium LV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 D[2] = 2.4e-3 # 2 myocardium RV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 D[3] = 2e-3 # 3 myocardium la @@ -109,7 +109,7 @@ def contrast_curve_calc(): D[50] = 3e-3 # 50 pericardium D[73] = 1.8e-3 # 73 Pancreatic tumor (advanced state, from literature) - f = np.zeros(74) + f = np.full(74, np.nan) f[1] = 0.15 # 1 Myocardium LV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 f[2] = 0.15 # 2 myocardium RV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 f[3] = 0.07 # 3 myocardium la @@ -137,7 +137,7 @@ def contrast_curve_calc(): f[50] = 0.07 # 50 pericardium f[73] = 0.37 # 73 Pancreatic tumor (advanced state, from literature) - Ds = np.zeros(74) + Ds = np.full(74, np.nan) Ds[1] = 0.08 # 1 Myocardium LV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 Ds[2] = 0.08 # 2 myocardium RV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901 Ds[3] = 0.07 # 3 myocardium la @@ -166,10 +166,10 @@ def contrast_curve_calc(): Ds[73] = 0.01 # 73 Pancreatic tumor (advanced state, from literature) # Return values - return tissue_included, D, f, Ds + return D, f, Ds -def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_cont = True): +def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): ########################################################################################### # This script converts XCAT tissue values to MR contrast based on the SSFP signal equation. # Christopher W. Roy 2018-12-04 # fetal.xcmr@gmail.com @@ -180,78 +180,81 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_c # Stanisz GJ, Odrobina EE, Pun J, Escaravage M, Graham SJ, Bronskill MJ, Henkelman RM. T1, T2 relaxation and magnetization transfer in tissue at 3T. Magnetic resonance in medicine. 2005;54:507�12. # Portnoy S, Osmond M, Zhu MY, Seed M, Sled JG, Macgowan CK. Relaxation properties of human umbilical cord blood at 1.5 Tesla. Magnetic Resonance in Medicine. 2016;00:1�13. # https://www.itis.ethz.ch/virtual-population/tissue-properties/XCATbase/relaxation-times/ #Tissue legend: - # 1 Myocardium LV - # 2 myocardium RV # - # 3 myocardium la - # 4 myocardium ra # 5 Blood LV - #6 Blood RV - #7 Blood LA - #8 Blood RA - #9 body - #10 muscle - #11 Brain - #12 Sinus - #13 Liver - #14 gall bladder - #15 Right Lung - #16 Left Lung - #17 esophagus - #18 esophagus cont - #19 laryngopharynx - #20 st wall - #21 Stomach Contents - #22 pancreas - #23 Right kydney cortex - #24 right kidney medulla - #25 Left kidney cortex - #26 left kidney medulla - #27 adrenal - #28 Right Renal Pelvis - #29 Left Renal Pelvis - #30 spleen - #31 Ribs - #32 Cortical Bone - #33 Spine - #34 spinal cord - #35 Bone Marrow - #36 Artery - #37 Vein - #38 bladder - #39 prostate - #40 asc lower intestine - #41 trans lower intestine - #42 desc lower intestine - #43 small intestine - #44 rectum - #45 seminal vescile - #46 vas deference - #47 testicles - #48 epididymus - #49 ejac duct - #50 pericardium - #51 Cartilage - #52 Intestine Cavity - #53 ureter - #54 urethra - #55 Lymph - #56 lymph abnormal - #57 trach bronch - #58 Airway - #59 uterus - #60 vagina - #61 right ovary - #62 left ovary - #63 FAllopian tubes - #64 Parathyroid - #65 Thyroid - #66 Thymus - #67 salivary - #68 Pituitary - #69 Eye - #70 eye lens - #71 lesion - #72 Fat - # 73 Pancreas tumor ############################################################################## + legend = { + 1: 'Myocardium LV', + 2: 'myocardium RV', # + 3: 'myocardium la', + 4: 'myocardium ra', # 5 Blood LV + 6: 'Blood RV', + 7: 'Blood LA', + 8: 'Blood RA', + 9: 'body', + 10: 'muscle', + 11: 'Brain', + 12: 'Sinus', + 13: 'Liver', + 14: 'gall bladder', + 15: 'Right Lung', + 16: 'Left Lung', + 17: 'esophagus', + 18: 'esophagus cont', + 19: 'laryngopharynx', + 20: 'st wall', + 21: 'Stomach Contents', + 22: 'pancreas', + 23: 'Right kydney cortex', + 24: 'right kidney medulla', + 25: 'Left kidney cortex', + 26: 'left kidney medulla', + 27: 'adrenal', + 28: 'Right Renal Pelvis', + 29: 'Left Renal Pelvis', + 30: 'spleen', + 31: 'Ribs', + 32: 'Cortical Bone', + 33: 'Spine', + 34: 'spinal cord', + 35: 'Bone Marrow', + 36: 'Artery', + 37: 'Vein', + 38: 'bladder', + 39: 'prostate', + 40: 'asc lower intestine', + 41: 'trans lower intestine', + 42: 'desc lower intestine', + 43: 'small intestine', + 44: 'rectum', + 45: 'seminal vescile', + 46: 'vas deference', + 47: 'testicles', + 48: 'epididymus', + 49: 'ejac duct', + 50: 'pericardium', + 51: 'Cartilage', + 52: 'Intestine Cavity', + 53: 'ureter', + 54: 'urethra', + 55: 'Lymph', + 56: 'lymph abnormal', + 57: 'trach bronch', + 58: 'Airway', + 59: 'uterus', + 60: 'vagina', + 61: 'right ovary', + 62: 'left ovary', + 63: 'FAllopian tubes', + 64: 'Parathyroid', + 65: 'Thyroid', + 66: 'Thymus', + 67: 'salivary', + 68: 'Pituitary', + 69: 'Eye', + 70: 'eye lens', + 71: 'lesion', + 72: 'Fat', + 73: 'Pancreas tumor', + } + ############################################################################### np.random.seed(42) Tissue = np.zeros((74, 4)) Tissue[1] = [1030, 40, 1471, 47] @@ -343,7 +346,7 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_c T1 = Tissue[iTissue, 2] T2 = Tissue[iTissue, 3] - if ivim_cont and iTissue in tissue_included: + if ivim_cont and not np.isnan([D[iTissue], f[iTissue], Ds[iTissue]]).any(): # note we are assuming blood fraction has the same T1 as tissue fraction here for simplicity. Can be changed in future. Dtemp=D[iTissue] ftemp=f[iTissue] @@ -360,20 +363,32 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, tissue_included, D, f, Ds, b0=3, ivim_c Dim = Dim + (XCAT == iTissue) * Dtemp fim = fim + (XCAT == iTissue) * ftemp Dpim = Dpim + (XCAT == iTissue) * Dstemp - return MR, Dim, fim, Dpim + return MR, Dim, fim, Dpim, legend if __name__ == '__main__': bvalue = np.array([0., 1, 2, 5, 10, 20, 30, 50, 75, 100, 150, 250, 350, 400, 550, 700, 850, 1000]) noise = 0.005 motion = False - sig, XCAT, Dim,fim,Dpim = phantom(bvalue, noise,motion=motion,interleaved=False) - sig = sig * 50000 + sig, XCAT, Dim, fim, Dpim, legend = phantom(bvalue, noise,motion=motion,interleaved=False) sig = np.flip(sig,axis=0) sig = np.flip(sig,axis=1) res=np.eye(4) res[2]=2 + + generic_data = {} + for level, name in legend.items(): + voxels = sig[XCAT == level] + if len(voxels) < 1: + continue + signals = np.mean(voxels, axis=0).tolist() + generic_data[name] = signals + with open('generic.json', 'w') as f: + json.dump(generic_data, f, indent=4) + + nifti_img = nib.Nifti1Image(sig, affine=res) # Replace affine if necessary # Save the NIfTI image to a file + nifti_img.header.set_data_dtype(np.float64) if motion: output_file = 'output_resp_int.nii.gz' # Replace with your desired output file name else: From 782ad01b13b0a8b8ade2ca85bd147e31bbc8d042 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 13 Aug 2023 21:54:52 -0700 Subject: [PATCH 3/8] Add values to saved file --- phantoms/MR_XCAT_qMRI/generic.json | 762 ------------------ phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 10 +- tests/IVIMmodels/unit_tests/generic.json | 952 +++++++++++++++++++++++ 3 files changed, 960 insertions(+), 764 deletions(-) delete mode 100644 phantoms/MR_XCAT_qMRI/generic.json create mode 100644 tests/IVIMmodels/unit_tests/generic.json diff --git a/phantoms/MR_XCAT_qMRI/generic.json b/phantoms/MR_XCAT_qMRI/generic.json deleted file mode 100644 index 7c333a2..0000000 --- a/phantoms/MR_XCAT_qMRI/generic.json +++ /dev/null @@ -1,762 +0,0 @@ -{ - "Myocardium LV": [ - 0.34898972165246894, - 0.34101242160675377, - 0.33372388000357645, - 0.3157531968317352, - 0.29503902295477363, - 0.27245023265312257, - 0.2616621088496361, - 0.25051537211502606, - 0.24042271152257536, - 0.23133001978160686, - 0.21438219286085167, - 0.18383197033343293, - 0.15779985945030905, - 0.14636217685921896, - 0.1166721702026485, - 0.09296904234139387, - 0.07394265755210767, - 0.059025760672105874 - ], - "myocardium RV": [ - 0.24871440181457757, - 0.23850273859717308, - 0.2289854730926882, - 0.20553028049431227, - 0.17847064388251438, - 0.15045806808694825, - 0.1386132346782817, - 0.12799911577203738, - 0.12115095902886129, - 0.11579837255566115, - 0.1057518702068629, - 0.08923571059677567, - 0.0756671006151337, - 0.06917423867545223, - 0.05414092369945907, - 0.042174353529610964, - 0.03274954770001436, - 0.026347028035115835 - ], - "myocardium ra": [ - 0.3701390037402836, - 0.3547247709293157, - 0.3394925431169981, - 0.30069918467966056, - 0.2577155756678938, - 0.21090209975050445, - 0.1914128797539193, - 0.17398154802469337, - 0.16026561646669835, - 0.14790483732455373, - 0.1305605363581906, - 0.09931988390848359, - 0.0773813076939424, - 0.06588794841433523, - 0.045979424789180434, - 0.03091359543634595, - 0.020548426579726765, - 0.015096269577284159 - ], - "Blood RV": [ - 0.17106052259021262, - 0.16582622007452907, - 0.16116521698120964, - 0.14853026266452848, - 0.1341440000046226, - 0.11761327736086784, - 0.10933699812277997, - 0.10031820633426025, - 0.09402859334526843, - 0.08878983893330852, - 0.08082878548914076, - 0.06778894704035736, - 0.05694827001928639, - 0.052403420068841536, - 0.04064137959584879, - 0.031595174516801355, - 0.02427306659541205, - 0.01902386285584882 - ], - "Blood RA": [ - 0.3703033790249206, - 0.3624481744017803, - 0.3537229701388481, - 0.3324304780725038, - 0.3068915045382316, - 0.27759417769336603, - 0.26229092749774474, - 0.24342725768253756, - 0.22603353118287925, - 0.2093964895071889, - 0.1825360717560458, - 0.13905342116878752, - 0.10702825903428566, - 0.09349875931020393, - 0.06421267843457956, - 0.044299349146106684, - 0.030137648764653652, - 0.021367056761294086 - ], - "body": [ - 0.14414367264868502, - 0.14254894780713223, - 0.14102540267025154, - 0.1370403554281524, - 0.13173976192125425, - 0.12412754062068529, - 0.11878700552316925, - 0.1108794216038723, - 0.10349327937708143, - 0.09749692818840278, - 0.08770085826619782, - 0.07216968456293092, - 0.059788843023755624, - 0.05451750242241992, - 0.04134033157630361, - 0.03152188276855943, - 0.024103278910228742, - 0.018524270879296933 - ], - "muscle": [ - 0.08757654862963136, - 0.08674376658664566, - 0.08592431541219317, - 0.08367162334782906, - 0.08031780816706909, - 0.0749637372493411, - 0.07079915000229199, - 0.06455999141899182, - 0.05905532471383719, - 0.0548959565550597, - 0.04860349639131267, - 0.03932000301546678, - 0.03208152623443189, - 0.029026091770908587, - 0.021533697670863577, - 0.01605968077519118, - 0.012051220980819647, - 0.009084206239931093 - ], - "Liver": [ - 0.20764655512452465, - 0.20304949087263294, - 0.19873658197571142, - 0.18749611799191773, - 0.17294976332773093, - 0.15348299728246548, - 0.14103427572470822, - 0.12532086576571294, - 0.11319360281160694, - 0.10502357821785527, - 0.09370776233349902, - 0.07818280689953981, - 0.06627775222273016, - 0.06110905360001995, - 0.048149055243257986, - 0.03806368532736532, - 0.0301369527504607, - 0.023926557581638072 - ], - "gall bladder": [ - 0.3493065062338589, - 0.3459177539619973, - 0.34276915788221696, - 0.3337678007265264, - 0.3215903768765205, - 0.3034713245206977, - 0.2901003731591599, - 0.27041065154076466, - 0.2518535625623309, - 0.23718380430075703, - 0.21415548733603126, - 0.17988018244500617, - 0.152663540856617, - 0.14095311990006207, - 0.11159082021963462, - 0.08865130135013015, - 0.07067950411814532, - 0.05633393333300527 - ], - "Right Lung": [ - 0.236116775520707, - 0.22538994140048546, - 0.21551356079114853, - 0.19130642137783227, - 0.16318964400163308, - 0.13373791047781014, - 0.12057801765369926, - 0.10846514769614894, - 0.10012707385992056, - 0.0933013884843937, - 0.08198291880498976, - 0.06429219788563631, - 0.05105953096891295, - 0.04546795505732233, - 0.03254767944227243, - 0.023343257204698934, - 0.01678606467014956, - 0.011985887933976194 - ], - "Left Lung": [ - 0.20219391502392353, - 0.20040984981695986, - 0.19892392275478604, - 0.1946251116428798, - 0.18907206303859317, - 0.1813340408431629, - 0.17590470732639651, - 0.16711631881198497, - 0.15808052265257577, - 0.14991157487786352, - 0.13539578206984829, - 0.1115826071391817, - 0.0923095260770106, - 0.08413488635205534, - 0.06369105361738163, - 0.048345743625243555, - 0.03695177490437736, - 0.02817803210968259 - ], - "esophagus": [ - 0.47740725510389664, - 0.45186638152227837, - 0.42906610068950823, - 0.373434961610736, - 0.30904967177952714, - 0.24549075375787766, - 0.21919760942267802, - 0.20120252323013257, - 0.19169524950691072, - 0.18350266542958235, - 0.16939018358081834, - 0.14387934544940623, - 0.12242796471590835, - 0.1125765018341218, - 0.08921064710814529, - 0.07013945983259418, - 0.05561724938912094, - 0.043673488730017945 - ], - "esophagus cont": [ - 0.4908291180811218, - 0.46298734193501884, - 0.4374848768124934, - 0.3755350259486313, - 0.30463285765481646, - 0.23400161289627847, - 0.20639701702872446, - 0.18721208467465203, - 0.17821957313101736, - 0.17051252450699383, - 0.1569723995669235, - 0.13322796993239644, - 0.11332436530964766, - 0.10482303156426699, - 0.08227121223269757, - 0.06492523304246411, - 0.05146934457285453, - 0.040450870910328965 - ], - "st wall": [ - 0.33972021704324323, - 0.33489876248808564, - 0.33038248564421774, - 0.31906525251468615, - 0.3054141853409019, - 0.2897553845246325, - 0.2810769065800649, - 0.26993739744640444, - 0.25875683592454635, - 0.2485725127824088, - 0.2294395631569634, - 0.19583539379628107, - 0.16764978387583143, - 0.15492748991609295, - 0.1227939834035703, - 0.09733645234521748, - 0.07728891023255187, - 0.06150417977627565 - ], - "Stomach Contents": [ - 0.3560052458252937, - 0.34991932799935316, - 0.3442698147707965, - 0.33026613719975484, - 0.3138434229862651, - 0.2954337099533313, - 0.28586841644655775, - 0.27474877939545594, - 0.2639776559525697, - 0.2539406790158555, - 0.23516487991333426, - 0.20205843786551828, - 0.17343044394190357, - 0.16087844370376087, - 0.1280621082111017, - 0.10214870316387105, - 0.08142871589721011, - 0.06489432919982008 - ], - "pancreas": [ - 0.2607580651974088, - 0.2531536308045649, - 0.24615174878114493, - 0.22828267116587056, - 0.205900714057674, - 0.17852671042230908, - 0.16251880757882584, - 0.1438039751026593, - 0.1296673723203523, - 0.12011326790844216, - 0.1061091282874786, - 0.08660070631748401, - 0.07174793040577473, - 0.06567359724996769, - 0.05031462539333168, - 0.039295240786263154, - 0.03062429306559929, - 0.024178754021125005 - ], - "Right kydney cortex": [ - 0.15963378893525246, - 0.15592535517239714, - 0.1522883109307759, - 0.14251397810220603, - 0.12822860726828772, - 0.10613880483731515, - 0.09017267577969265, - 0.0691730985592467, - 0.05492991869454863, - 0.04741904302925983, - 0.0403312549498806, - 0.03441167051556376, - 0.030004037533558382, - 0.028041654197369835, - 0.023106211605735148, - 0.019011480952706616, - 0.01568809284650648, - 0.012630445712653463 - ], - "right kidney medulla": [ - 0.15514794064191945, - 0.15102045477128537, - 0.14721225560692977, - 0.13708213010310177, - 0.12250106550381955, - 0.10082481997884392, - 0.0850354695412841, - 0.06525039603181984, - 0.05181170360998079, - 0.0448607984097072, - 0.03822526926722316, - 0.032308544754609855, - 0.0284035899717906, - 0.026673892094159924, - 0.021826118315602647, - 0.01775931247595257, - 0.014652816278214149, - 0.012271687324018633 - ], - "Left kidney cortex": [ - 0.2865960334102167, - 0.28242548008727403, - 0.2785142782913214, - 0.2675190992319904, - 0.2511810180936404, - 0.22492314700928592, - 0.2049783841959968, - 0.1770199874720396, - 0.15563485234406482, - 0.14155065337617062, - 0.12381948002483145, - 0.10108602009586574, - 0.08374660801978874, - 0.07655153259807843, - 0.05862245953110069, - 0.04524933833052055, - 0.03504402897787108, - 0.02716270228355165 - ], - "left kidney medulla": [ - 0.28071870508429503, - 0.27599110495416473, - 0.27155175898873424, - 0.25918220719680113, - 0.24102248086659805, - 0.2109532051148196, - 0.18859868765879692, - 0.15756940099201452, - 0.13456136544473948, - 0.12098350651499033, - 0.10498552477016143, - 0.08630730523641636, - 0.07233096061238732, - 0.06637479404760226, - 0.05151396116027796, - 0.04057384910601671, - 0.031746556264228475, - 0.025204453108978238 - ], - "adrenal": [ - 0.2826787411763678, - 0.27831009499717363, - 0.27371092759824794, - 0.2616251836866002, - 0.24393644939867817, - 0.21629881654153307, - 0.19581377499127034, - 0.1684868929153769, - 0.14880648072939534, - 0.13553935371698403, - 0.12078755186863444, - 0.10202768317513937, - 0.08757197318285687, - 0.08138351107427882, - 0.0653235654424977, - 0.05275031976863747, - 0.042296493872499896, - 0.03404718958125153 - ], - "Right Renal Pelvis": [ - 0.23845594027974554, - 0.2340885887968851, - 0.22926470734550777, - 0.21482880140243105, - 0.1955512896933524, - 0.16390194580931639, - 0.13862838327930652, - 0.10649279269443837, - 0.08477918144411398, - 0.07305769210877683, - 0.061746891755696455, - 0.05285223648019959, - 0.04586067619718521, - 0.04320687858631259, - 0.03586299157223977, - 0.028432215124915988, - 0.02445436566942347, - 0.019589305268583098 - ], - "Left Renal Pelvis": [ - 0.29934044796894144, - 0.2932737029677877, - 0.2877041185108748, - 0.2710250881677717, - 0.24704347642316418, - 0.20760360029872693, - 0.17839331549285958, - 0.1386621352319866, - 0.11059454180813225, - 0.09591295440295877, - 0.0817685975642877, - 0.0689974169990692, - 0.05938551000712084, - 0.05607454196727335, - 0.04512593596146897, - 0.03683226767862082, - 0.030579950438570393, - 0.02459556163525453 - ], - "spleen": [ - 0.20825262009604234, - 0.20694704899515484, - 0.20570704831467276, - 0.20212507147961328, - 0.19725229821243304, - 0.18943033146299096, - 0.18320327013640075, - 0.17286781864880957, - 0.161615547575178, - 0.1519351681953833, - 0.13520336489841728, - 0.10829727499724853, - 0.08736434649782453, - 0.07855737095755005, - 0.05742828771554922, - 0.04218246865860132, - 0.03112872853303898, - 0.023187841448832597 - ], - "Ribs": [ - 0.12711214146958372, - 0.1263954809552108, - 0.12547014589784425, - 0.12313829653088443, - 0.11956027858802483, - 0.11364687278836964, - 0.10874717793211831, - 0.10083697123473874, - 0.09358077826879158, - 0.08780976681970634, - 0.07835502891221134, - 0.06389393071053609, - 0.05264876901757898, - 0.04774045258997308, - 0.0359310306495789, - 0.027251312152600817, - 0.020714406533062647, - 0.01584052715598586 - ], - "Cortical Bone": [ - 0.009390143914629926, - 0.009099037389799763, - 0.009131460655393383, - 0.008829782724048505, - 0.0086502135563019, - 0.008069828102584907, - 0.0077680784167890315, - 0.007362268945100939, - 0.006882829387916501, - 0.0064934829532998836, - 0.005767801738684848, - 0.004527350372436516, - 0.003640243481224372, - 0.00326492376438238, - 0.002394125257379272, - 0.0016714100072533812, - 0.001144843332685241, - 0.0008363716380179653 - ], - "Spine": [ - 0.2074391650883512, - 0.20328222351873226, - 0.19951658296745667, - 0.18914993182867465, - 0.17566591689404631, - 0.15682505195441462, - 0.1443479284647448, - 0.1282986094467979, - 0.11600083158034812, - 0.10782315444682807, - 0.0965419564646553, - 0.08124431936743932, - 0.0692448576593437, - 0.0640193336812393, - 0.050755357448090184, - 0.04038920737820779, - 0.03219893194857284, - 0.02568467031437344 - ], - "spinal cord": [ - 0.14968537510540572, - 0.1474358467818982, - 0.14543252611208127, - 0.13981765341703914, - 0.13326668726926896, - 0.12551994254278298, - 0.12140964495107077, - 0.11552529390883204, - 0.11011187420590139, - 0.10394423012644549, - 0.0953245538857873, - 0.08063551244549981, - 0.06881988499396485, - 0.06310984404863128, - 0.04937163704574576, - 0.0388701590854159, - 0.030823101963032198, - 0.024307723947324944 - ], - "Bone Marrow": [ - 0.1137767818468923, - 0.11195565594192901, - 0.11033817558021898, - 0.10568139675213667, - 0.09961356724480598, - 0.09086071944436365, - 0.0847879583667797, - 0.07655126457311016, - 0.06991046724282958, - 0.06532765614212656, - 0.05861911694149705, - 0.04906131170426399, - 0.04148286776774864, - 0.03824025893353378, - 0.0299947005479393, - 0.023609033117558905, - 0.018584930597666086, - 0.014711209272766139 - ], - "Artery": [ - 0.22834647271477249, - 0.2231054294831425, - 0.21794961382660857, - 0.20498977519163897, - 0.18779391580254307, - 0.16530130471095614, - 0.1509167178895211, - 0.13288398883831373, - 0.11976722105657064, - 0.11101252429871204, - 0.0995679871896937, - 0.08393896738444352, - 0.07175624264460921, - 0.06642824374222756, - 0.052990525840176876, - 0.04234313675826943, - 0.034022916847795445, - 0.027353983241822123 - ], - "Vein": [ - 0.22441397394228915, - 0.22020896097441717, - 0.21606131782971294, - 0.20510030062414625, - 0.19105799752479158, - 0.17138968491456982, - 0.15833251939086881, - 0.14149440031896057, - 0.12814970483654534, - 0.11897468240522634, - 0.1061607717044737, - 0.08845332107116888, - 0.07465524015934527, - 0.06868361221643562, - 0.05376343264190993, - 0.04226849670653001, - 0.03331360392108922, - 0.026481578251132707 - ], - "asc lower intestine": [ - 0.2954735243830286, - 0.2906352588520771, - 0.2858040728009893, - 0.2732876505097306, - 0.2555854419555954, - 0.22985581576200326, - 0.21128491346672293, - 0.18608064851180967, - 0.16601289258896418, - 0.15240173839644594, - 0.13400187334016833, - 0.10885324742349821, - 0.08975247478641343, - 0.08153230006289827, - 0.06139854293776205, - 0.0462805910211582, - 0.03508261675195721, - 0.026645564361144645 - ], - "trans lower intestine": [ - 0.3059958856171849, - 0.3033478430012246, - 0.3008747097693397, - 0.2942893933085906, - 0.28545501121207245, - 0.27254118906081826, - 0.2630912499309692, - 0.24845192418952888, - 0.2336370590673267, - 0.22075908874945738, - 0.19894704011158446, - 0.16374014235149112, - 0.13561828103732013, - 0.12345897516597096, - 0.09371111774296453, - 0.07128210798283909, - 0.05448244944592977, - 0.04181129466668589 - ], - "desc lower intestine": [ - 0.3321131178872771, - 0.32853831493658764, - 0.3252040860498945, - 0.31695161828277213, - 0.306518435347314, - 0.2936208786613117, - 0.28524779476766704, - 0.27302246070959224, - 0.2602918045459527, - 0.24869005810018593, - 0.22787949028471127, - 0.19169263092766683, - 0.16182307271559665, - 0.14876986039111117, - 0.11598635759976698, - 0.09055906420523004, - 0.07088668437054298, - 0.055538701011291276 - ], - "small intestine": [ - 0.30074425040279856, - 0.2944845452430382, - 0.28863340515273506, - 0.2735820814981339, - 0.25453852747846045, - 0.23015611850652534, - 0.21519383720966714, - 0.19637918935500634, - 0.18132358975376156, - 0.1703002154782028, - 0.15368595652005698, - 0.12867080211654158, - 0.10855563167521692, - 0.09984876120702285, - 0.07772999966315815, - 0.060759749320596794, - 0.04756646220287644, - 0.037368264773960574 - ], - "pericardium": [ - 0.32000494407805, - 0.3088654009375722, - 0.29904980558089767, - 0.2740850878913364, - 0.24558604488847646, - 0.21536926331505973, - 0.2020222261297372, - 0.18936420984433425, - 0.18029653079469718, - 0.17201776672049646, - 0.15729878584721638, - 0.13196136697968544, - 0.11127864773724477, - 0.10224194180476164, - 0.07944915803798566, - 0.06221573834819889, - 0.04875921452691328, - 0.03834181090739235 - ], - "Cartilage": [ - 0.22023434588419283, - 0.21765363810860222, - 0.2153102069694426, - 0.20879630843180802, - 0.20028436277779857, - 0.1878493204264525, - 0.17913244131902714, - 0.16695355326774897, - 0.1559418751278614, - 0.14735487693691215, - 0.1332856707364372, - 0.11150392562163026, - 0.09371166585155002, - 0.08608967361722157, - 0.06670031907274253, - 0.051882051080158885, - 0.0404627776446415, - 0.03166323498206638 - ], - "Fat": [ - 0.04347759306594482, - 0.04331055503018695, - 0.043157782586126285, - 0.04267618521144028, - 0.041840304286041824, - 0.04042891293620974, - 0.039170850881867544, - 0.0369091385939268, - 0.034446175085675435, - 0.03229938324890682, - 0.028545694575280674, - 0.022604383587180022, - 0.017992511581896263, - 0.016066679631941184, - 0.01138662757473584, - 0.008100170353602424, - 0.005759608016476787, - 0.004089478201726281 - ] -} \ No newline at end of file diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index 5db7386..9756ad0 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -377,11 +377,17 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): generic_data = {} for level, name in legend.items(): - voxels = sig[XCAT == level] + selector = XCAT == level + voxels = sig[selector] if len(voxels) < 1: continue signals = np.mean(voxels, axis=0).tolist() - generic_data[name] = signals + generic_data[name] = { + 'D': np.mean(Dim[selector], axis=0), + 'f': np.mean(fim[selector], axis=0), + 'Dpim': np.mean(Dpim[selector], axis=0), + 'data': signals + } with open('generic.json', 'w') as f: json.dump(generic_data, f, indent=4) diff --git a/tests/IVIMmodels/unit_tests/generic.json b/tests/IVIMmodels/unit_tests/generic.json new file mode 100644 index 0000000..3348b69 --- /dev/null +++ b/tests/IVIMmodels/unit_tests/generic.json @@ -0,0 +1,952 @@ +{ + "Myocardium LV": { + "D": 0.0024, + "f": 0.14999999999999997, + "Dpim": 0.08, + "data": [ + 0.34898972165246894, + 0.34101242160675377, + 0.33372388000357645, + 0.3157531968317352, + 0.29503902295477363, + 0.27245023265312257, + 0.2616621088496361, + 0.25051537211502606, + 0.24042271152257536, + 0.23133001978160686, + 0.21438219286085167, + 0.18383197033343293, + 0.15779985945030905, + 0.14636217685921896, + 0.1166721702026485, + 0.09296904234139387, + 0.07394265755210767, + 0.059025760672105874 + ] + }, + "myocardium RV": { + "D": 0.0024, + "f": 0.14999999999999997, + "Dpim": 0.07999999999999999, + "data": [ + 0.24871440181457757, + 0.23850273859717308, + 0.2289854730926882, + 0.20553028049431227, + 0.17847064388251438, + 0.15045806808694825, + 0.1386132346782817, + 0.12799911577203738, + 0.12115095902886129, + 0.11579837255566115, + 0.1057518702068629, + 0.08923571059677567, + 0.0756671006151337, + 0.06917423867545223, + 0.05414092369945907, + 0.042174353529610964, + 0.03274954770001436, + 0.026347028035115835 + ] + }, + "myocardium ra": { + "D": 0.0015, + "f": 0.07000000000000002, + "Dpim": 0.07000000000000002, + "data": [ + 0.3701390037402836, + 0.3547247709293157, + 0.3394925431169981, + 0.30069918467966056, + 0.2577155756678938, + 0.21090209975050445, + 0.1914128797539193, + 0.17398154802469337, + 0.16026561646669835, + 0.14790483732455373, + 0.1305605363581906, + 0.09931988390848359, + 0.0773813076939424, + 0.06588794841433523, + 0.045979424789180434, + 0.03091359543634595, + 0.020548426579726765, + 0.015096269577284159 + ] + }, + "Blood RV": { + "D": 0.0030000000000000005, + "f": 1.0, + "Dpim": 0.1, + "data": [ + 0.17106052259021262, + 0.16582622007452907, + 0.16116521698120964, + 0.14853026266452848, + 0.1341440000046226, + 0.11761327736086784, + 0.10933699812277997, + 0.10031820633426025, + 0.09402859334526843, + 0.08878983893330852, + 0.08082878548914076, + 0.06778894704035736, + 0.05694827001928639, + 0.052403420068841536, + 0.04064137959584879, + 0.031595174516801355, + 0.02427306659541205, + 0.01902386285584882 + ] + }, + "Blood RA": { + "D": 0.0029999999999999996, + "f": 1.0, + "Dpim": 0.09999999999999998, + "data": [ + 0.3703033790249206, + 0.3624481744017803, + 0.3537229701388481, + 0.3324304780725038, + 0.3068915045382316, + 0.27759417769336603, + 0.26229092749774474, + 0.24342725768253756, + 0.22603353118287925, + 0.2093964895071889, + 0.1825360717560458, + 0.13905342116878752, + 0.10702825903428566, + 0.09349875931020393, + 0.06421267843457956, + 0.044299349146106684, + 0.030137648764653652, + 0.021367056761294086 + ] + }, + "body": { + "D": 0.0016236203565420872, + "f": 0.4753571532049581, + "Dpim": 0.07819939418114051, + "data": [ + 0.14414367264868502, + 0.14254894780713223, + 0.14102540267025154, + 0.1370403554281524, + 0.13173976192125425, + 0.12412754062068529, + 0.11878700552316925, + 0.1108794216038723, + 0.10349327937708143, + 0.09749692818840278, + 0.08770085826619782, + 0.07216968456293092, + 0.059788843023755624, + 0.05451750242241992, + 0.04134033157630361, + 0.03152188276855943, + 0.024103278910228742, + 0.018524270879296933 + ] + }, + "muscle": { + "D": 0.0022959754525911096, + "f": 0.07800932022121823, + "Dpim": 0.020599452033620267, + "data": [ + 0.08757654862963136, + 0.08674376658664566, + 0.08592431541219317, + 0.08367162334782906, + 0.08031780816706909, + 0.0749637372493411, + 0.07079915000229199, + 0.06455999141899182, + 0.05905532471383719, + 0.0548959565550597, + 0.04860349639131267, + 0.03932000301546678, + 0.03208152623443189, + 0.029026091770908587, + 0.021533697670863577, + 0.01605968077519118, + 0.012051220980819647, + 0.009084206239931093 + ] + }, + "Liver": { + "D": 0.0015, + "f": 0.11000000000000007, + "Dpim": 0.1, + "data": [ + 0.20764655512452465, + 0.20304949087263294, + 0.19873658197571142, + 0.18749611799191773, + 0.17294976332773093, + 0.15348299728246548, + 0.14103427572470822, + 0.12532086576571294, + 0.11319360281160694, + 0.10502357821785527, + 0.09370776233349902, + 0.07818280689953981, + 0.06627775222273016, + 0.06110905360001995, + 0.048149055243257986, + 0.03806368532736532, + 0.0301369527504607, + 0.023926557581638072 + ] + }, + "gall bladder": { + "D": 0.002997327922401265, + "f": 0.10616955533913808, + "Dpim": 0.023182496720710072, + "data": [ + 0.3493065062338589, + 0.3459177539619973, + 0.34276915788221696, + 0.3337678007265264, + 0.3215903768765205, + 0.3034713245206977, + 0.2901003731591599, + 0.27041065154076466, + 0.2518535625623309, + 0.23718380430075703, + 0.21415548733603126, + 0.17988018244500617, + 0.152663540856617, + 0.14095311990006207, + 0.11159082021963462, + 0.08865130135013015, + 0.07067950411814532, + 0.05633393333300527 + ] + }, + "Right Lung": { + "D": 0.0010502135295603014, + "f": 0.15212112147976886, + "Dpim": 0.057475643163223775, + "data": [ + 0.236116775520707, + 0.22538994140048546, + 0.21551356079114853, + 0.19130642137783227, + 0.16318964400163308, + 0.13373791047781014, + 0.12057801765369926, + 0.10846514769614894, + 0.10012707385992056, + 0.0933013884843937, + 0.08198291880498976, + 0.06429219788563631, + 0.05105953096891295, + 0.04546795505732233, + 0.03254767944227243, + 0.023343257204698934, + 0.01678606467014956, + 0.011985887933976194 + ] + }, + "Left Lung": { + "D": 0.001795835055926347, + "f": 0.14561457009902096, + "Dpim": 0.06618528947223794, + "data": [ + 0.20219391502392353, + 0.20040984981695986, + 0.19892392275478604, + 0.1946251116428798, + 0.18907206303859317, + 0.1813340408431629, + 0.17590470732639651, + 0.16711631881198497, + 0.15808052265257577, + 0.14991157487786352, + 0.13539578206984829, + 0.1115826071391817, + 0.0923095260770106, + 0.08413488635205534, + 0.06369105361738163, + 0.048345743625243555, + 0.03695177490437736, + 0.02817803210968259 + ] + }, + "esophagus": { + "D": 0.00167, + "f": 0.31999999999999995, + "Dpim": 0.030000000000000002, + "data": [ + 0.47740725510389664, + 0.45186638152227837, + 0.42906610068950823, + 0.373434961610736, + 0.30904967177952714, + 0.24549075375787766, + 0.21919760942267802, + 0.20120252323013257, + 0.19169524950691072, + 0.18350266542958235, + 0.16939018358081834, + 0.14387934544940623, + 0.12242796471590835, + 0.1125765018341218, + 0.08921064710814529, + 0.07013945983259418, + 0.05561724938912094, + 0.043673488730017945 + ] + }, + "esophagus cont": { + "D": 0.00167, + "f": 0.31999999999999995, + "Dpim": 0.030000000000000002, + "data": [ + 0.4908291180811218, + 0.46298734193501884, + 0.4374848768124934, + 0.3755350259486313, + 0.30463285765481646, + 0.23400161289627847, + 0.20639701702872446, + 0.18721208467465203, + 0.17821957313101736, + 0.17051252450699383, + 0.1569723995669235, + 0.13322796993239644, + 0.11332436530964766, + 0.10482303156426699, + 0.08227121223269757, + 0.06492523304246411, + 0.05146934457285453, + 0.040450870910328965 + ] + }, + "st wall": { + "D": 0.0015, + "f": 0.29999999999999993, + "Dpim": 0.012, + "data": [ + 0.33972021704324323, + 0.33489876248808564, + 0.33038248564421774, + 0.31906525251468615, + 0.3054141853409019, + 0.2897553845246325, + 0.2810769065800649, + 0.26993739744640444, + 0.25875683592454635, + 0.2485725127824088, + 0.2294395631569634, + 0.19583539379628107, + 0.16764978387583143, + 0.15492748991609295, + 0.1227939834035703, + 0.09733645234521748, + 0.07728891023255187, + 0.06150417977627565 + ] + }, + "Stomach Contents": { + "D": 0.0018682099526511075, + "f": 0.39258798069650686, + "Dpim": 0.024967378215835983, + "data": [ + 0.3560052458252937, + 0.34991932799935316, + 0.3442698147707965, + 0.33026613719975484, + 0.3138434229862651, + 0.2954337099533313, + 0.28586841644655775, + 0.27474877939545594, + 0.2639776559525697, + 0.2539406790158555, + 0.23516487991333426, + 0.20205843786551828, + 0.17343044394190357, + 0.16087844370376087, + 0.1280621082111017, + 0.10214870316387105, + 0.08142871589721011, + 0.06489432919982008 + ] + }, + "pancreas": { + "D": 0.0012999999999999997, + "f": 0.14999999999999997, + "Dpim": 0.01, + "data": [ + 0.2607580651974088, + 0.2531536308045649, + 0.24615174878114493, + 0.22828267116587056, + 0.205900714057674, + 0.17852671042230908, + 0.16251880757882584, + 0.1438039751026593, + 0.1296673723203523, + 0.12011326790844216, + 0.1061091282874786, + 0.08660070631748401, + 0.07174793040577473, + 0.06567359724996769, + 0.05031462539333168, + 0.039295240786263154, + 0.03062429306559929, + 0.024178754021125005 + ] + }, + "Right kydney cortex": { + "D": 0.00212, + "f": 0.09699999999999998, + "Dpim": 0.02, + "data": [ + 0.15963378893525246, + 0.15592535517239714, + 0.1522883109307759, + 0.14251397810220603, + 0.12822860726828772, + 0.10613880483731515, + 0.09017267577969265, + 0.0691730985592467, + 0.05492991869454863, + 0.04741904302925983, + 0.0403312549498806, + 0.03441167051556376, + 0.030004037533558382, + 0.028041654197369835, + 0.023106211605735148, + 0.019011480952706616, + 0.01568809284650648, + 0.012630445712653463 + ] + }, + "right kidney medulla": { + "D": 0.0020900000000000003, + "f": 0.158, + "Dpim": 0.018999999999999993, + "data": [ + 0.15514794064191945, + 0.15102045477128537, + 0.14721225560692977, + 0.13708213010310177, + 0.12250106550381955, + 0.10082481997884392, + 0.0850354695412841, + 0.06525039603181984, + 0.05181170360998079, + 0.0448607984097072, + 0.03822526926722316, + 0.032308544754609855, + 0.0284035899717906, + 0.026673892094159924, + 0.021826118315602647, + 0.01775931247595257, + 0.014652816278214149, + 0.012271687324018633 + ] + }, + "Left kidney cortex": { + "D": 0.00212, + "f": 0.09699999999999999, + "Dpim": 0.019999999999999997, + "data": [ + 0.2865960334102167, + 0.28242548008727403, + 0.2785142782913214, + 0.2675190992319904, + 0.2511810180936404, + 0.22492314700928592, + 0.2049783841959968, + 0.1770199874720396, + 0.15563485234406482, + 0.14155065337617062, + 0.12381948002483145, + 0.10108602009586574, + 0.08374660801978874, + 0.07655153259807843, + 0.05862245953110069, + 0.04524933833052055, + 0.03504402897787108, + 0.02716270228355165 + ] + }, + "left kidney medulla": { + "D": 0.0020900000000000003, + "f": 0.158, + "Dpim": 0.018999999999999996, + "data": [ + 0.28071870508429503, + 0.27599110495416473, + 0.27155175898873424, + 0.25918220719680113, + 0.24102248086659805, + 0.2109532051148196, + 0.18859868765879692, + 0.15756940099201452, + 0.13456136544473948, + 0.12098350651499033, + 0.10498552477016143, + 0.08630730523641636, + 0.07233096061238732, + 0.06637479404760226, + 0.05151396116027796, + 0.04057384910601671, + 0.031746556264228475, + 0.025204453108978238 + ] + }, + "adrenal": { + "D": 0.0020427033152408346, + "f": 0.29620728443102123, + "Dpim": 0.009645041271999775, + "data": [ + 0.2826787411763678, + 0.27831009499717363, + 0.27371092759824794, + 0.2616251836866002, + 0.24393644939867817, + 0.21629881654153307, + 0.19581377499127034, + 0.1684868929153769, + 0.14880648072939534, + 0.13553935371698403, + 0.12078755186863444, + 0.10202768317513937, + 0.08757197318285687, + 0.08138351107427882, + 0.0653235654424977, + 0.05275031976863747, + 0.042296493872499896, + 0.03404718958125153 + ] + }, + "Right Renal Pelvis": { + "D": 0.0023226345557043155, + "f": 0.08526206184364574, + "Dpim": 0.011505159298527953, + "data": [ + 0.23845594027974554, + 0.2340885887968851, + 0.22926470734550777, + 0.21482880140243105, + 0.1955512896933524, + 0.16390194580931639, + 0.13862838327930652, + 0.10649279269443837, + 0.08477918144411398, + 0.07305769210877683, + 0.061746891755696455, + 0.05285223648019959, + 0.04586067619718521, + 0.04320687858631259, + 0.03586299157223977, + 0.028432215124915988, + 0.02445436566942347, + 0.019589305268583098 + ] + }, + "Left Renal Pelvis": { + "D": 0.0033466566117599994, + "f": 0.4828160165372796, + "Dpim": 0.08583973481164611, + "data": [ + 0.29934044796894144, + 0.2932737029677877, + 0.2877041185108748, + 0.2710250881677717, + 0.24704347642316418, + 0.20760360029872693, + 0.17839331549285958, + 0.1386621352319866, + 0.11059454180813225, + 0.09591295440295877, + 0.0817685975642877, + 0.0689974169990692, + 0.05938551000712084, + 0.05607454196727335, + 0.04512593596146897, + 0.03683226767862082, + 0.030579950438570393, + 0.02459556163525453 + ] + }, + "spleen": { + "D": 0.0012999999999999997, + "f": 0.19999999999999998, + "Dpim": 0.03000000000000001, + "data": [ + 0.20825262009604234, + 0.20694704899515484, + 0.20570704831467276, + 0.20212507147961328, + 0.19725229821243304, + 0.18943033146299096, + 0.18320327013640075, + 0.17286781864880957, + 0.161615547575178, + 0.1519351681953833, + 0.13520336489841728, + 0.10829727499724853, + 0.08736434649782453, + 0.07855737095755005, + 0.05742828771554922, + 0.04218246865860132, + 0.03112872853303898, + 0.023187841448832597 + ] + }, + "Ribs": { + "D": 0.0014138413075201123, + "f": 0.048836057003191935, + "Dpim": 0.07342330265121569, + "data": [ + 0.12711214146958372, + 0.1263954809552108, + 0.12547014589784425, + 0.12313829653088443, + 0.11956027858802483, + 0.11364687278836964, + 0.10874717793211831, + 0.10083697123473874, + 0.09358077826879158, + 0.08780976681970634, + 0.07835502891221134, + 0.06389393071053609, + 0.05264876901757898, + 0.04774045258997308, + 0.0359310306495789, + 0.027251312152600817, + 0.020714406533062647, + 0.01584052715598586 + ] + }, + "Cortical Bone": { + "D": 0.0018204574812188043, + "f": 0.06101911742238941, + "Dpim": 0.05451769101112701, + "data": [ + 0.009390143914629926, + 0.009099037389799763, + 0.009131460655393383, + 0.008829782724048505, + 0.0086502135563019, + 0.008069828102584907, + 0.0077680784167890315, + 0.007362268945100939, + 0.006882829387916501, + 0.0064934829532998836, + 0.005767801738684848, + 0.004527350372436516, + 0.003640243481224372, + 0.00326492376438238, + 0.002394125257379272, + 0.0016714100072533812, + 0.001144843332685241, + 0.0008363716380179653 + ] + }, + "Spine": { + "D": 0.0006031655633456552, + "f": 0.45466020103939103, + "Dpim": 0.030877998160001693, + "data": [ + 0.2074391650883512, + 0.20328222351873226, + 0.19951658296745667, + 0.18914993182867465, + 0.17566591689404631, + 0.15682505195441462, + 0.1443479284647448, + 0.1282986094467979, + 0.11600083158034812, + 0.10782315444682807, + 0.0965419564646553, + 0.08124431936743932, + 0.0692448576593437, + 0.0640193336812393, + 0.050755357448090184, + 0.04038920737820779, + 0.03219893194857284, + 0.02568467031437344 + ] + }, + "spinal cord": { + "D": 0.0024875668530619454, + "f": 0.1558555380447055, + "Dpim": 0.05700680211778108, + "data": [ + 0.14968537510540572, + 0.1474358467818982, + 0.14543252611208127, + 0.13981765341703914, + 0.13326668726926896, + 0.12551994254278298, + 0.12140964495107077, + 0.11552529390883204, + 0.11011187420590139, + 0.10394423012644549, + 0.0953245538857873, + 0.08063551244549981, + 0.06881988499396485, + 0.06310984404863128, + 0.04937163704574576, + 0.0388701590854159, + 0.030823101963032198, + 0.024307723947324944 + ] + }, + "Bone Marrow": { + "D": 0.002140130838029838, + "f": 0.09242722776276355, + "Dpim": 0.10195846277645583, + "data": [ + 0.1137767818468923, + 0.11195565594192901, + 0.11033817558021898, + 0.10568139675213667, + 0.09961356724480598, + 0.09086071944436365, + 0.0847879583667797, + 0.07655126457311016, + 0.06991046724282958, + 0.06532765614212656, + 0.05861911694149705, + 0.04906131170426399, + 0.04148286776774864, + 0.03824025893353378, + 0.0299947005479393, + 0.023609033117558905, + 0.018584930597666086, + 0.014711209272766139 + ] + }, + "Artery": { + "D": 0.0029999999999999988, + "f": 1.0, + "Dpim": 0.09999999999999998, + "data": [ + 0.22834647271477249, + 0.2231054294831425, + 0.21794961382660857, + 0.20498977519163897, + 0.18779391580254307, + 0.16530130471095614, + 0.1509167178895211, + 0.13288398883831373, + 0.11976722105657064, + 0.11101252429871204, + 0.0995679871896937, + 0.08393896738444352, + 0.07175624264460921, + 0.06642824374222756, + 0.052990525840176876, + 0.04234313675826943, + 0.034022916847795445, + 0.027353983241822123 + ] + }, + "Vein": { + "D": 0.002999999999999999, + "f": 1.0, + "Dpim": 0.09999999999999999, + "data": [ + 0.22441397394228915, + 0.22020896097441717, + 0.21606131782971294, + 0.20510030062414625, + 0.19105799752479158, + 0.17138968491456982, + 0.15833251939086881, + 0.14149440031896057, + 0.12814970483654534, + 0.11897468240522634, + 0.1061607717044737, + 0.08845332107116888, + 0.07465524015934527, + 0.06868361221643562, + 0.05376343264190993, + 0.04226849670653001, + 0.03331360392108922, + 0.026481578251132707 + ] + }, + "asc lower intestine": { + "D": 0.00131, + "f": 0.6899999999999998, + "Dpim": 0.028999999999999998, + "data": [ + 0.2954735243830286, + 0.2906352588520771, + 0.2858040728009893, + 0.2732876505097306, + 0.2555854419555954, + 0.22985581576200326, + 0.21128491346672293, + 0.18608064851180967, + 0.16601289258896418, + 0.15240173839644594, + 0.13400187334016833, + 0.10885324742349821, + 0.08975247478641343, + 0.08153230006289827, + 0.06139854293776205, + 0.0462805910211582, + 0.03508261675195721, + 0.026645564361144645 + ] + }, + "trans lower intestine": { + "D": 0.0013099999999999997, + "f": 0.6899999999999997, + "Dpim": 0.029000000000000012, + "data": [ + 0.3059958856171849, + 0.3033478430012246, + 0.3008747097693397, + 0.2942893933085906, + 0.28545501121207245, + 0.27254118906081826, + 0.2630912499309692, + 0.24845192418952888, + 0.2336370590673267, + 0.22075908874945738, + 0.19894704011158446, + 0.16374014235149112, + 0.13561828103732013, + 0.12345897516597096, + 0.09371111774296453, + 0.07128210798283909, + 0.05448244944592977, + 0.04181129466668589 + ] + }, + "desc lower intestine": { + "D": 0.00131, + "f": 0.6899999999999997, + "Dpim": 0.029000000000000015, + "data": [ + 0.3321131178872771, + 0.32853831493658764, + 0.3252040860498945, + 0.31695161828277213, + 0.306518435347314, + 0.2936208786613117, + 0.28524779476766704, + 0.27302246070959224, + 0.2602918045459527, + 0.24869005810018593, + 0.22787949028471127, + 0.19169263092766683, + 0.16182307271559665, + 0.14876986039111117, + 0.11598635759976698, + 0.09055906420523004, + 0.07088668437054298, + 0.055538701011291276 + ] + }, + "small intestine": { + "D": 0.00131, + "f": 0.6899999999999998, + "Dpim": 0.02900000000000001, + "data": [ + 0.30074425040279856, + 0.2944845452430382, + 0.28863340515273506, + 0.2735820814981339, + 0.25453852747846045, + 0.23015611850652534, + 0.21519383720966714, + 0.19637918935500634, + 0.18132358975376156, + 0.1703002154782028, + 0.15368595652005698, + 0.12867080211654158, + 0.10855563167521692, + 0.09984876120702285, + 0.07772999966315815, + 0.060759749320596794, + 0.04756646220287644, + 0.037368264773960574 + ] + }, + "pericardium": { + "D": 0.0030000000000000005, + "f": 0.07000000000000002, + "Dpim": 0.009999999999999998, + "data": [ + 0.32000494407805, + 0.3088654009375722, + 0.29904980558089767, + 0.2740850878913364, + 0.24558604488847646, + 0.21536926331505973, + 0.2020222261297372, + 0.18936420984433425, + 0.18029653079469718, + 0.17201776672049646, + 0.15729878584721638, + 0.13196136697968544, + 0.11127864773724477, + 0.10224194180476164, + 0.07944915803798566, + 0.06221573834819889, + 0.04875921452691328, + 0.03834181090739235 + ] + }, + "Cartilage": { + "D": 0.0026870215041229625, + "f": 0.38563517334297287, + "Dpim": 0.012404465173409039, + "data": [ + 0.22023434588419283, + 0.21765363810860222, + 0.2153102069694426, + 0.20879630843180802, + 0.20028436277779857, + 0.1878493204264525, + 0.17913244131902714, + 0.16695355326774897, + 0.1559418751278614, + 0.14735487693691215, + 0.1332856707364372, + 0.11150392562163026, + 0.09371166585155002, + 0.08608967361722157, + 0.06670031907274253, + 0.051882051080158885, + 0.0404627776446415, + 0.03166323498206638 + ] + }, + "Fat": { + "D": 0.0015908888071378827, + "f": 0.4858910413604801, + "Dpim": 0.10124472949421114, + "data": [ + 0.04347759306594482, + 0.04331055503018695, + 0.043157782586126285, + 0.04267618521144028, + 0.041840304286041824, + 0.04042891293620974, + 0.039170850881867544, + 0.0369091385939268, + 0.034446175085675435, + 0.03229938324890682, + 0.028545694575280674, + 0.022604383587180022, + 0.017992511581896263, + 0.016066679631941184, + 0.01138662757473584, + 0.008100170353602424, + 0.005759608016476787, + 0.004089478201726281 + ] + } +} \ No newline at end of file From 4053698f42eb08caa4c5b74e5794d080edc4ee9a Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 13 Aug 2023 22:06:17 -0700 Subject: [PATCH 4/8] Also add bvalues to the file --- phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 3 +++ tests/IVIMmodels/unit_tests/generic.json | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index 9756ad0..83de437 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -388,6 +388,9 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): 'Dpim': np.mean(Dpim[selector], axis=0), 'data': signals } + generic_data['config'] = { + 'bvalues': bvalue.tolist() + } with open('generic.json', 'w') as f: json.dump(generic_data, f, indent=4) diff --git a/tests/IVIMmodels/unit_tests/generic.json b/tests/IVIMmodels/unit_tests/generic.json index 3348b69..d77a718 100644 --- a/tests/IVIMmodels/unit_tests/generic.json +++ b/tests/IVIMmodels/unit_tests/generic.json @@ -948,5 +948,27 @@ 0.005759608016476787, 0.004089478201726281 ] + }, + "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 From f1bc6a3963a650d319204f411be9d8bcfc284093 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 13 Aug 2023 22:12:20 -0700 Subject: [PATCH 5/8] Rename Dpim to Dp in file --- phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 2 +- tests/IVIMmodels/unit_tests/generic.json | 76 ++++++++++++------------ 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index 83de437..b241768 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -385,7 +385,7 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): generic_data[name] = { 'D': np.mean(Dim[selector], axis=0), 'f': np.mean(fim[selector], axis=0), - 'Dpim': np.mean(Dpim[selector], axis=0), + 'Dp': np.mean(Dpim[selector], axis=0), 'data': signals } generic_data['config'] = { diff --git a/tests/IVIMmodels/unit_tests/generic.json b/tests/IVIMmodels/unit_tests/generic.json index d77a718..fb753b1 100644 --- a/tests/IVIMmodels/unit_tests/generic.json +++ b/tests/IVIMmodels/unit_tests/generic.json @@ -2,7 +2,7 @@ "Myocardium LV": { "D": 0.0024, "f": 0.14999999999999997, - "Dpim": 0.08, + "Dp": 0.08, "data": [ 0.34898972165246894, 0.34101242160675377, @@ -27,7 +27,7 @@ "myocardium RV": { "D": 0.0024, "f": 0.14999999999999997, - "Dpim": 0.07999999999999999, + "Dp": 0.07999999999999999, "data": [ 0.24871440181457757, 0.23850273859717308, @@ -52,7 +52,7 @@ "myocardium ra": { "D": 0.0015, "f": 0.07000000000000002, - "Dpim": 0.07000000000000002, + "Dp": 0.07000000000000002, "data": [ 0.3701390037402836, 0.3547247709293157, @@ -77,7 +77,7 @@ "Blood RV": { "D": 0.0030000000000000005, "f": 1.0, - "Dpim": 0.1, + "Dp": 0.1, "data": [ 0.17106052259021262, 0.16582622007452907, @@ -102,7 +102,7 @@ "Blood RA": { "D": 0.0029999999999999996, "f": 1.0, - "Dpim": 0.09999999999999998, + "Dp": 0.09999999999999998, "data": [ 0.3703033790249206, 0.3624481744017803, @@ -127,7 +127,7 @@ "body": { "D": 0.0016236203565420872, "f": 0.4753571532049581, - "Dpim": 0.07819939418114051, + "Dp": 0.07819939418114051, "data": [ 0.14414367264868502, 0.14254894780713223, @@ -152,7 +152,7 @@ "muscle": { "D": 0.0022959754525911096, "f": 0.07800932022121823, - "Dpim": 0.020599452033620267, + "Dp": 0.020599452033620267, "data": [ 0.08757654862963136, 0.08674376658664566, @@ -177,7 +177,7 @@ "Liver": { "D": 0.0015, "f": 0.11000000000000007, - "Dpim": 0.1, + "Dp": 0.1, "data": [ 0.20764655512452465, 0.20304949087263294, @@ -202,7 +202,7 @@ "gall bladder": { "D": 0.002997327922401265, "f": 0.10616955533913808, - "Dpim": 0.023182496720710072, + "Dp": 0.023182496720710072, "data": [ 0.3493065062338589, 0.3459177539619973, @@ -227,7 +227,7 @@ "Right Lung": { "D": 0.0010502135295603014, "f": 0.15212112147976886, - "Dpim": 0.057475643163223775, + "Dp": 0.057475643163223775, "data": [ 0.236116775520707, 0.22538994140048546, @@ -252,7 +252,7 @@ "Left Lung": { "D": 0.001795835055926347, "f": 0.14561457009902096, - "Dpim": 0.06618528947223794, + "Dp": 0.06618528947223794, "data": [ 0.20219391502392353, 0.20040984981695986, @@ -277,7 +277,7 @@ "esophagus": { "D": 0.00167, "f": 0.31999999999999995, - "Dpim": 0.030000000000000002, + "Dp": 0.030000000000000002, "data": [ 0.47740725510389664, 0.45186638152227837, @@ -302,7 +302,7 @@ "esophagus cont": { "D": 0.00167, "f": 0.31999999999999995, - "Dpim": 0.030000000000000002, + "Dp": 0.030000000000000002, "data": [ 0.4908291180811218, 0.46298734193501884, @@ -327,7 +327,7 @@ "st wall": { "D": 0.0015, "f": 0.29999999999999993, - "Dpim": 0.012, + "Dp": 0.012, "data": [ 0.33972021704324323, 0.33489876248808564, @@ -352,7 +352,7 @@ "Stomach Contents": { "D": 0.0018682099526511075, "f": 0.39258798069650686, - "Dpim": 0.024967378215835983, + "Dp": 0.024967378215835983, "data": [ 0.3560052458252937, 0.34991932799935316, @@ -377,7 +377,7 @@ "pancreas": { "D": 0.0012999999999999997, "f": 0.14999999999999997, - "Dpim": 0.01, + "Dp": 0.01, "data": [ 0.2607580651974088, 0.2531536308045649, @@ -402,7 +402,7 @@ "Right kydney cortex": { "D": 0.00212, "f": 0.09699999999999998, - "Dpim": 0.02, + "Dp": 0.02, "data": [ 0.15963378893525246, 0.15592535517239714, @@ -427,7 +427,7 @@ "right kidney medulla": { "D": 0.0020900000000000003, "f": 0.158, - "Dpim": 0.018999999999999993, + "Dp": 0.018999999999999993, "data": [ 0.15514794064191945, 0.15102045477128537, @@ -452,7 +452,7 @@ "Left kidney cortex": { "D": 0.00212, "f": 0.09699999999999999, - "Dpim": 0.019999999999999997, + "Dp": 0.019999999999999997, "data": [ 0.2865960334102167, 0.28242548008727403, @@ -477,7 +477,7 @@ "left kidney medulla": { "D": 0.0020900000000000003, "f": 0.158, - "Dpim": 0.018999999999999996, + "Dp": 0.018999999999999996, "data": [ 0.28071870508429503, 0.27599110495416473, @@ -502,7 +502,7 @@ "adrenal": { "D": 0.0020427033152408346, "f": 0.29620728443102123, - "Dpim": 0.009645041271999775, + "Dp": 0.009645041271999775, "data": [ 0.2826787411763678, 0.27831009499717363, @@ -527,7 +527,7 @@ "Right Renal Pelvis": { "D": 0.0023226345557043155, "f": 0.08526206184364574, - "Dpim": 0.011505159298527953, + "Dp": 0.011505159298527953, "data": [ 0.23845594027974554, 0.2340885887968851, @@ -552,7 +552,7 @@ "Left Renal Pelvis": { "D": 0.0033466566117599994, "f": 0.4828160165372796, - "Dpim": 0.08583973481164611, + "Dp": 0.08583973481164611, "data": [ 0.29934044796894144, 0.2932737029677877, @@ -577,7 +577,7 @@ "spleen": { "D": 0.0012999999999999997, "f": 0.19999999999999998, - "Dpim": 0.03000000000000001, + "Dp": 0.03000000000000001, "data": [ 0.20825262009604234, 0.20694704899515484, @@ -602,7 +602,7 @@ "Ribs": { "D": 0.0014138413075201123, "f": 0.048836057003191935, - "Dpim": 0.07342330265121569, + "Dp": 0.07342330265121569, "data": [ 0.12711214146958372, 0.1263954809552108, @@ -627,7 +627,7 @@ "Cortical Bone": { "D": 0.0018204574812188043, "f": 0.06101911742238941, - "Dpim": 0.05451769101112701, + "Dp": 0.05451769101112701, "data": [ 0.009390143914629926, 0.009099037389799763, @@ -652,7 +652,7 @@ "Spine": { "D": 0.0006031655633456552, "f": 0.45466020103939103, - "Dpim": 0.030877998160001693, + "Dp": 0.030877998160001693, "data": [ 0.2074391650883512, 0.20328222351873226, @@ -677,7 +677,7 @@ "spinal cord": { "D": 0.0024875668530619454, "f": 0.1558555380447055, - "Dpim": 0.05700680211778108, + "Dp": 0.05700680211778108, "data": [ 0.14968537510540572, 0.1474358467818982, @@ -702,7 +702,7 @@ "Bone Marrow": { "D": 0.002140130838029838, "f": 0.09242722776276355, - "Dpim": 0.10195846277645583, + "Dp": 0.10195846277645583, "data": [ 0.1137767818468923, 0.11195565594192901, @@ -727,7 +727,7 @@ "Artery": { "D": 0.0029999999999999988, "f": 1.0, - "Dpim": 0.09999999999999998, + "Dp": 0.09999999999999998, "data": [ 0.22834647271477249, 0.2231054294831425, @@ -752,7 +752,7 @@ "Vein": { "D": 0.002999999999999999, "f": 1.0, - "Dpim": 0.09999999999999999, + "Dp": 0.09999999999999999, "data": [ 0.22441397394228915, 0.22020896097441717, @@ -777,7 +777,7 @@ "asc lower intestine": { "D": 0.00131, "f": 0.6899999999999998, - "Dpim": 0.028999999999999998, + "Dp": 0.028999999999999998, "data": [ 0.2954735243830286, 0.2906352588520771, @@ -802,7 +802,7 @@ "trans lower intestine": { "D": 0.0013099999999999997, "f": 0.6899999999999997, - "Dpim": 0.029000000000000012, + "Dp": 0.029000000000000012, "data": [ 0.3059958856171849, 0.3033478430012246, @@ -827,7 +827,7 @@ "desc lower intestine": { "D": 0.00131, "f": 0.6899999999999997, - "Dpim": 0.029000000000000015, + "Dp": 0.029000000000000015, "data": [ 0.3321131178872771, 0.32853831493658764, @@ -852,7 +852,7 @@ "small intestine": { "D": 0.00131, "f": 0.6899999999999998, - "Dpim": 0.02900000000000001, + "Dp": 0.02900000000000001, "data": [ 0.30074425040279856, 0.2944845452430382, @@ -877,7 +877,7 @@ "pericardium": { "D": 0.0030000000000000005, "f": 0.07000000000000002, - "Dpim": 0.009999999999999998, + "Dp": 0.009999999999999998, "data": [ 0.32000494407805, 0.3088654009375722, @@ -902,7 +902,7 @@ "Cartilage": { "D": 0.0026870215041229625, "f": 0.38563517334297287, - "Dpim": 0.012404465173409039, + "Dp": 0.012404465173409039, "data": [ 0.22023434588419283, 0.21765363810860222, @@ -927,7 +927,7 @@ "Fat": { "D": 0.0015908888071378827, "f": 0.4858910413604801, - "Dpim": 0.10124472949421114, + "Dp": 0.10124472949421114, "data": [ 0.04347759306594482, 0.04331055503018695, From 3505aa83ee290710275459d393b58275046e63fe Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Tue, 15 Aug 2023 22:43:17 -0700 Subject: [PATCH 6/8] Added example test with phantom data --- phantoms/MR_XCAT_qMRI/sim_ivim_sig.py | 15 +- src/original/ETP_SRI/LinearFitting.py | 2 + tests/IVIMmodels/unit_tests/generic.json | 1192 ++++++----------- .../unit_tests/test_ivim_fit_linear.py | 24 + 4 files changed, 431 insertions(+), 802 deletions(-) diff --git a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py index b241768..d12fb1c 100644 --- a/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py +++ b/phantoms/MR_XCAT_qMRI/sim_ivim_sig.py @@ -355,11 +355,9 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): Dtemp=5e-4+np.random.rand(1)*3e-3 ftemp=np.random.rand(1)*0.5 Dstemp=5e-3+np.random.rand(1)*1e-1 - #S0 = np.zeros(len(bvalue)) S0 = ivim(bvalue,Dtemp,ftemp,Dstemp) if T1 > 0 or T2 > 0: - MR = MR + np.tile(np.expand_dims(XCAT == iTissue,3),len(S0)) * S0 * (1 - 2 * np.exp(-(TR - TE / 2) / T1) + np.exp(-TR / T1)) * np.exp( - -TE / T2) + MR = MR + np.tile(np.expand_dims(XCAT == iTissue,3),len(S0)) * S0 * (1 - 2 * np.exp(-(TR - TE / 2) / T1) + np.exp(-TR / T1)) * np.exp(-TE / T2) Dim = Dim + (XCAT == iTissue) * Dtemp fim = fim + (XCAT == iTissue) * ftemp Dpim = Dpim + (XCAT == iTissue) * Dstemp @@ -367,21 +365,26 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True): if __name__ == '__main__': bvalue = np.array([0., 1, 2, 5, 10, 20, 30, 50, 75, 100, 150, 250, 350, 400, 550, 700, 850, 1000]) - noise = 0.005 + noise = 0.0 # 0.005 motion = False sig, XCAT, Dim, fim, Dpim, legend = phantom(bvalue, noise,motion=motion,interleaved=False) - sig = np.flip(sig,axis=0) - sig = np.flip(sig,axis=1) + # sig = np.flip(sig,axis=0) + # sig = np.flip(sig,axis=1) res=np.eye(4) res[2]=2 + D, f, Ds = contrast_curve_calc() + ignore = np.isnan(D) generic_data = {} for level, name in legend.items(): + if len(ignore) > level and ignore[level]: + continue selector = XCAT == level voxels = sig[selector] if len(voxels) < 1: continue signals = np.mean(voxels, axis=0).tolist() + std = np.std(XCAT[selector], axis=0).tolist() generic_data[name] = { 'D': np.mean(Dim[selector], axis=0), 'f': np.mean(fim[selector], axis=0), diff --git a/src/original/ETP_SRI/LinearFitting.py b/src/original/ETP_SRI/LinearFitting.py index a89589d..47bec09 100644 --- a/src/original/ETP_SRI/LinearFitting.py +++ b/src/original/ETP_SRI/LinearFitting.py @@ -33,6 +33,8 @@ def linear_fit(self, bvalues, signal, weighting=None, stats=False): stats : boolean If true, return the polyfit statistics """ + bvalues = np.asarray(bvalues) + signal = np.asarray(signal) assert bvalues.size == signal.size, "Signal and b-values don't have the same number of values" if stats: D, stats = poly.polyfit(np.asarray(bvalues), signal, 1, full=True, w=weighting) diff --git a/tests/IVIMmodels/unit_tests/generic.json b/tests/IVIMmodels/unit_tests/generic.json index fb753b1..775fb4f 100644 --- a/tests/IVIMmodels/unit_tests/generic.json +++ b/tests/IVIMmodels/unit_tests/generic.json @@ -4,24 +4,24 @@ "f": 0.14999999999999997, "Dp": 0.08, "data": [ - 0.34898972165246894, - 0.34101242160675377, - 0.33372388000357645, - 0.3157531968317352, - 0.29503902295477363, - 0.27245023265312257, - 0.2616621088496361, - 0.25051537211502606, - 0.24042271152257536, - 0.23133001978160686, - 0.21438219286085167, - 0.18383197033343293, - 0.15779985945030905, - 0.14636217685921896, - 0.1166721702026485, - 0.09296904234139387, - 0.07394265755210767, - 0.059025760672105874 + 0.3698908244669008, + 0.36487136825030775, + 0.3601816877155644, + 0.3478486466002188, + 0.33188165633209943, + 0.3108740764046653, + 0.29759897498742127, + 0.27987038985315854, + 0.2627524992317805, + 0.24734007654897863, + 0.2193548016454079, + 0.17255033038343984, + 0.13573289722592288, + 0.12038428048447254, + 0.08398926252510874, + 0.05859732010793529, + 0.040881963010511384, + 0.02852237775574694 ] }, "myocardium RV": { @@ -29,24 +29,24 @@ "f": 0.14999999999999997, "Dp": 0.07999999999999999, "data": [ - 0.24871440181457757, - 0.23850273859717308, - 0.2289854730926882, - 0.20553028049431227, - 0.17847064388251438, - 0.15045806808694825, - 0.1386132346782817, - 0.12799911577203738, - 0.12115095902886129, - 0.11579837255566115, - 0.1057518702068629, - 0.08923571059677567, - 0.0756671006151337, - 0.06917423867545223, - 0.05414092369945907, - 0.042174353529610964, - 0.03274954770001436, - 0.026347028035115835 + 0.3698908244669135, + 0.3648713682503109, + 0.36018168771556036, + 0.3478486466002195, + 0.331881656332094, + 0.31087407640467096, + 0.29759897498743565, + 0.27987038985315865, + 0.26275249923176824, + 0.24734007654896623, + 0.2193548016454066, + 0.17255033038343306, + 0.13573289722592569, + 0.12038428048447249, + 0.08398926252510962, + 0.05859732010793496, + 0.0408819630105121, + 0.02852237775574553 ] }, "myocardium ra": { @@ -54,24 +54,24 @@ "f": 0.07000000000000002, "Dp": 0.07000000000000002, "data": [ - 0.3701390037402836, - 0.3547247709293157, - 0.3394925431169981, - 0.30069918467966056, - 0.2577155756678938, - 0.21090209975050445, - 0.1914128797539193, - 0.17398154802469337, - 0.16026561646669835, - 0.14790483732455373, - 0.1305605363581906, - 0.09931988390848359, - 0.0773813076939424, - 0.06588794841433523, - 0.045979424789180434, - 0.03091359543634595, - 0.020548426579726765, - 0.015096269577284159 + 0.3698908244669095, + 0.36762473017304237, + 0.3654777522116429, + 0.35967416516320216, + 0.3517347611253637, + 0.3402167524104105, + 0.33203235361603, + 0.3199242182917993, + 0.30753198792446795, + 0.2961058349873959, + 0.2746890679152042, + 0.23642645877086832, + 0.2034941383430144, + 0.18879036135324104, + 0.15075216548599185, + 0.12037804915366217, + 0.09612382463181281, + 0.0767564329776845 ] }, "Blood RV": { @@ -79,24 +79,24 @@ "f": 1.0, "Dp": 0.1, "data": [ - 0.17106052259021262, - 0.16582622007452907, - 0.16116521698120964, - 0.14853026266452848, - 0.1341440000046226, - 0.11761327736086784, - 0.10933699812277997, - 0.10031820633426025, - 0.09402859334526843, - 0.08878983893330852, - 0.08082878548914076, - 0.06778894704035736, - 0.05694827001928639, - 0.052403420068841536, - 0.04064137959584879, - 0.031595174516801355, - 0.02427306659541205, - 0.01902386285584882 + 0.677817039844284, + 0.6133142202334763, + 0.5549496554807847, + 0.4111168163412042, + 0.24935495383438352, + 0.09173256106993022, + 0.03374652330362896, + 0.004567095289547731, + 0.000374890010557757, + 3.0772846000746545e-05, + 2.0734580536404697e-07, + 9.41348500007354e-12, + 4.2737155782352324e-16, + 2.8796069055314523e-18, + 8.80878434535157e-25, + 2.694627572043351e-31, + 8.242928271762084e-38, + 2.5215308860622303e-44 ] }, "Blood RA": { @@ -104,74 +104,24 @@ "f": 1.0, "Dp": 0.09999999999999998, "data": [ - 0.3703033790249206, - 0.3624481744017803, - 0.3537229701388481, - 0.3324304780725038, - 0.3068915045382316, - 0.27759417769336603, - 0.26229092749774474, - 0.24342725768253756, - 0.22603353118287925, - 0.2093964895071889, - 0.1825360717560458, - 0.13905342116878752, - 0.10702825903428566, - 0.09349875931020393, - 0.06421267843457956, - 0.044299349146106684, - 0.030137648764653652, - 0.021367056761294086 - ] - }, - "body": { - "D": 0.0016236203565420872, - "f": 0.4753571532049581, - "Dp": 0.07819939418114051, - "data": [ - 0.14414367264868502, - 0.14254894780713223, - 0.14102540267025154, - 0.1370403554281524, - 0.13173976192125425, - 0.12412754062068529, - 0.11878700552316925, - 0.1108794216038723, - 0.10349327937708143, - 0.09749692818840278, - 0.08770085826619782, - 0.07216968456293092, - 0.059788843023755624, - 0.05451750242241992, - 0.04134033157630361, - 0.03152188276855943, - 0.024103278910228742, - 0.018524270879296933 - ] - }, - "muscle": { - "D": 0.0022959754525911096, - "f": 0.07800932022121823, - "Dp": 0.020599452033620267, - "data": [ - 0.08757654862963136, - 0.08674376658664566, - 0.08592431541219317, - 0.08367162334782906, - 0.08031780816706909, - 0.0749637372493411, - 0.07079915000229199, - 0.06455999141899182, - 0.05905532471383719, - 0.0548959565550597, - 0.04860349639131267, - 0.03932000301546678, - 0.03208152623443189, - 0.029026091770908587, - 0.021533697670863577, - 0.01605968077519118, - 0.012051220980819647, - 0.009084206239931093 + 0.6778170398442714, + 0.6133142202334675, + 0.5549496554807889, + 0.41111681634121156, + 0.24935495383439152, + 0.0917325610699269, + 0.03374652330362995, + 0.004567095289547695, + 0.000374890010557738, + 3.077284600074527e-05, + 2.073458053640418e-07, + 9.413485000073341e-12, + 4.273715578235351e-16, + 2.8796069055315613e-18, + 8.808784345351876e-25, + 2.6946275720432877e-31, + 8.242928271762456e-38, + 2.5215308860622383e-44 ] }, "Liver": { @@ -179,99 +129,24 @@ "f": 0.11000000000000007, "Dp": 0.1, "data": [ - 0.20764655512452465, - 0.20304949087263294, - 0.19873658197571142, - 0.18749611799191773, - 0.17294976332773093, - 0.15348299728246548, - 0.14103427572470822, - 0.12532086576571294, - 0.11319360281160694, - 0.10502357821785527, - 0.09370776233349902, - 0.07818280689953981, - 0.06627775222273016, - 0.06110905360001995, - 0.048149055243257986, - 0.03806368532736532, - 0.0301369527504607, - 0.023926557581638072 - ] - }, - "gall bladder": { - "D": 0.002997327922401265, - "f": 0.10616955533913808, - "Dp": 0.023182496720710072, - "data": [ - 0.3493065062338589, - 0.3459177539619973, - 0.34276915788221696, - 0.3337678007265264, - 0.3215903768765205, - 0.3034713245206977, - 0.2901003731591599, - 0.27041065154076466, - 0.2518535625623309, - 0.23718380430075703, - 0.21415548733603126, - 0.17988018244500617, - 0.152663540856617, - 0.14095311990006207, - 0.11159082021963462, - 0.08865130135013015, - 0.07067950411814532, - 0.05633393333300527 - ] - }, - "Right Lung": { - "D": 0.0010502135295603014, - "f": 0.15212112147976886, - "Dp": 0.057475643163223775, - "data": [ - 0.236116775520707, - 0.22538994140048546, - 0.21551356079114853, - 0.19130642137783227, - 0.16318964400163308, - 0.13373791047781014, - 0.12057801765369926, - 0.10846514769614894, - 0.10012707385992056, - 0.0933013884843937, - 0.08198291880498976, - 0.06429219788563631, - 0.05105953096891295, - 0.04546795505732233, - 0.03254767944227243, - 0.023343257204698934, - 0.01678606467014956, - 0.011985887933976194 - ] - }, - "Left Lung": { - "D": 0.001795835055926347, - "f": 0.14561457009902096, - "Dp": 0.06618528947223794, - "data": [ - 0.20219391502392353, - 0.20040984981695986, - 0.19892392275478604, - 0.1946251116428798, - 0.18907206303859317, - 0.1813340408431629, - 0.17590470732639651, - 0.16711631881198497, - 0.15808052265257577, - 0.14991157487786352, - 0.13539578206984829, - 0.1115826071391817, - 0.0923095260770106, - 0.08413488635205534, - 0.06369105361738163, - 0.048345743625243555, - 0.03695177490437736, - 0.02817803210968259 + 0.3757523005479684, + 0.37131771575970013, + 0.3672581882699903, + 0.35699036494318187, + 0.34464615916538227, + 0.3301297360337405, + 0.32176208187624367, + 0.31053405478216256, + 0.29885928095609937, + 0.2878394484992764, + 0.267039445183081, + 0.2298429696073976, + 0.19782767726570505, + 0.1835333389989244, + 0.14655434787347027, + 0.11702602370677427, + 0.09344717794668778, + 0.074619087187783 ] }, "esophagus": { @@ -279,24 +154,24 @@ "f": 0.31999999999999995, "Dp": 0.030000000000000002, "data": [ - 0.47740725510389664, - 0.45186638152227837, - 0.42906610068950823, - 0.373434961610736, - 0.30904967177952714, - 0.24549075375787766, - 0.21919760942267802, - 0.20120252323013257, - 0.19169524950691072, - 0.18350266542958235, - 0.16939018358081834, - 0.14387934544940623, - 0.12242796471590835, - 0.1125765018341218, - 0.08921064710814529, - 0.07013945983259418, - 0.05561724938912094, - 0.043673488730017945 + 0.37575230054829883, + 0.371772301532236, + 0.3678980401769538, + 0.3568790862395448, + 0.3403564817709004, + 0.3131079389556097, + 0.2919120497288492, + 0.26187214532719366, + 0.23810507949210194, + 0.22220022021702454, + 0.20022888890602014, + 0.16836979679300723, + 0.14242149256732758, + 0.13100995458562123, + 0.1019790857742543, + 0.0793816847906151, + 0.061791614673889945, + 0.04809930222996436 ] }, "esophagus cont": { @@ -304,24 +179,24 @@ "f": 0.31999999999999995, "Dp": 0.030000000000000002, "data": [ - 0.4908291180811218, - 0.46298734193501884, - 0.4374848768124934, - 0.3755350259486313, - 0.30463285765481646, - 0.23400161289627847, - 0.20639701702872446, - 0.18721208467465203, - 0.17821957313101736, - 0.17051252450699383, - 0.1569723995669235, - 0.13322796993239644, - 0.11332436530964766, - 0.10482303156426699, - 0.08227121223269757, - 0.06492523304246411, - 0.05146934457285453, - 0.040450870910328965 + 0.37575230054829883, + 0.3717723015322362, + 0.3678980401769538, + 0.35687908623954506, + 0.3403564817709003, + 0.3131079389556097, + 0.2919120497288492, + 0.2618721453271936, + 0.2381050794921019, + 0.2222002202170244, + 0.20022888890602025, + 0.16836979679300726, + 0.14242149256732764, + 0.13100995458562126, + 0.10197908577425428, + 0.0793816847906151, + 0.061791614673889945, + 0.04809930222996436 ] }, "st wall": { @@ -329,49 +204,24 @@ "f": 0.29999999999999993, "Dp": 0.012, "data": [ - 0.33972021704324323, - 0.33489876248808564, - 0.33038248564421774, - 0.31906525251468615, - 0.3054141853409019, - 0.2897553845246325, - 0.2810769065800649, - 0.26993739744640444, - 0.25875683592454635, - 0.2485725127824088, - 0.2294395631569634, - 0.19583539379628107, - 0.16764978387583143, - 0.15492748991609295, - 0.1227939834035703, - 0.09733645234521748, - 0.07728891023255187, - 0.06150417977627565 - ] - }, - "Stomach Contents": { - "D": 0.0018682099526511075, - "f": 0.39258798069650686, - "Dp": 0.024967378215835983, - "data": [ - 0.3560052458252937, - 0.34991932799935316, - 0.3442698147707965, - 0.33026613719975484, - 0.3138434229862651, - 0.2954337099533313, - 0.28586841644655775, - 0.27474877939545594, - 0.2639776559525697, - 0.2539406790158555, - 0.23516487991333426, - 0.20205843786551828, - 0.17343044394190357, - 0.16087844370376087, - 0.1280621082111017, - 0.10214870316387105, - 0.08142871589721011, - 0.06489432919982008 + 0.3102866163421927, + 0.308850703267167, + 0.30742852281062005, + 0.30324279938328824, + 0.29652679770258855, + 0.2840054118637315, + 0.27258714466438416, + 0.2525931427163126, + 0.23193584525319452, + 0.21498327582738153, + 0.18882523674270382, + 0.15391414362945668, + 0.12988207670945812, + 0.11996830801057597, + 0.09531154828088868, + 0.0760276320678361, + 0.06069604277718098, + 0.04846458361750415 ] }, "pancreas": { @@ -379,24 +229,24 @@ "f": 0.14999999999999997, "Dp": 0.01, "data": [ - 0.2607580651974088, - 0.2531536308045649, - 0.24615174878114493, - 0.22828267116587056, - 0.205900714057674, - 0.17852671042230908, - 0.16251880757882584, - 0.1438039751026593, - 0.1296673723203523, - 0.12011326790844216, - 0.1061091282874786, - 0.08660070631748401, - 0.07174793040577473, - 0.06567359724996769, - 0.05031462539333168, - 0.039295240786263154, - 0.03062429306559929, - 0.024178754021125005 + 0.3878159090920959, + 0.38680882602511973, + 0.3858080587361275, + 0.38284307408911106, + 0.37802244337576074, + 0.3688107729524123, + 0.3601300555083038, + 0.3441815555400463, + 0.32649910095689494, + 0.31085889612740686, + 0.2842221291900841, + 0.24295154237672678, + 0.21089831699785033, + 0.19704531218917545, + 0.161496748270541, + 0.13274254954395273, + 0.10919335822875502, + 0.08984098133344945 ] }, "Right kydney cortex": { @@ -404,24 +254,24 @@ "f": 0.09699999999999998, "Dp": 0.02, "data": [ - 0.15963378893525246, - 0.15592535517239714, - 0.1522883109307759, - 0.14251397810220603, - 0.12822860726828772, - 0.10613880483731515, - 0.09017267577969265, - 0.0691730985592467, - 0.05492991869454863, - 0.04741904302925983, - 0.0403312549498806, - 0.03441167051556376, - 0.030004037533558382, - 0.028041654197369835, - 0.023106211605735148, - 0.019011480952706616, - 0.01568809284650648, - 0.012630445712653463 + 0.502238531380029, + 0.5003134205024322, + 0.49840944524175584, + 0.49282054505555206, + 0.48389415792280593, + 0.4673501208747158, + 0.45231206294460286, + 0.4258303533811013, + 0.3977223603589927, + 0.3734759448125436, + 0.33240891421840096, + 0.26727319975814046, + 0.21599346200324743, + 0.19424623003634608, + 0.1413230212209555, + 0.10282647279664835, + 0.07481680087156221, + 0.05443691156735536 ] }, "right kidney medulla": { @@ -429,24 +279,24 @@ "f": 0.158, "Dp": 0.018999999999999993, "data": [ - 0.15514794064191945, - 0.15102045477128537, - 0.14721225560692977, - 0.13708213010310177, - 0.12250106550381955, - 0.10082481997884392, - 0.0850354695412841, - 0.06525039603181984, - 0.05181170360998079, - 0.0448607984097072, - 0.03822526926722316, - 0.032308544754609855, - 0.0284035899717906, - 0.026673892094159924, - 0.021826118315602647, - 0.01775931247595257, - 0.014652816278214149, - 0.012271687324018633 + 0.5204575055519256, + 0.5179949072177208, + 0.5155633471240099, + 0.5084494257594113, + 0.49716409975955694, + 0.47652045572219714, + 0.4580966186964967, + 0.4265448318722477, + 0.3944240845589328, + 0.367873224837027, + 0.32504863827624386, + 0.26059482515468585, + 0.2109745438956513, + 0.1899858534983209, + 0.13882999475749427, + 0.10146707234520133, + 0.07416060548446553, + 0.0542028227252729 ] }, "Left kidney cortex": { @@ -454,24 +304,24 @@ "f": 0.09699999999999999, "Dp": 0.019999999999999997, "data": [ - 0.2865960334102167, - 0.28242548008727403, - 0.2785142782913214, - 0.2675190992319904, - 0.2511810180936404, - 0.22492314700928592, - 0.2049783841959968, - 0.1770199874720396, - 0.15563485234406482, - 0.14155065337617062, - 0.12381948002483145, - 0.10108602009586574, - 0.08374660801978874, - 0.07655153259807843, - 0.05862245953110069, - 0.04524933833052055, - 0.03504402897787108, - 0.02716270228355165 + 0.5022385313800325, + 0.5003134205024483, + 0.4984094452417398, + 0.49282054505555506, + 0.48389415792280577, + 0.4673501208747259, + 0.4523120629446153, + 0.42583035338110464, + 0.39772236035899716, + 0.37347594481253954, + 0.3324089142183953, + 0.2672731997581461, + 0.21599346200323916, + 0.19424623003634836, + 0.1413230212209555, + 0.10282647279665207, + 0.07481680087156818, + 0.05443691156735751 ] }, "left kidney medulla": { @@ -479,99 +329,24 @@ "f": 0.158, "Dp": 0.018999999999999996, "data": [ - 0.28071870508429503, - 0.27599110495416473, - 0.27155175898873424, - 0.25918220719680113, - 0.24102248086659805, - 0.2109532051148196, - 0.18859868765879692, - 0.15756940099201452, - 0.13456136544473948, - 0.12098350651499033, - 0.10498552477016143, - 0.08630730523641636, - 0.07233096061238732, - 0.06637479404760226, - 0.05151396116027796, - 0.04057384910601671, - 0.031746556264228475, - 0.025204453108978238 - ] - }, - "adrenal": { - "D": 0.0020427033152408346, - "f": 0.29620728443102123, - "Dp": 0.009645041271999775, - "data": [ - 0.2826787411763678, - 0.27831009499717363, - 0.27371092759824794, - 0.2616251836866002, - 0.24393644939867817, - 0.21629881654153307, - 0.19581377499127034, - 0.1684868929153769, - 0.14880648072939534, - 0.13553935371698403, - 0.12078755186863444, - 0.10202768317513937, - 0.08757197318285687, - 0.08138351107427882, - 0.0653235654424977, - 0.05275031976863747, - 0.042296493872499896, - 0.03404718958125153 - ] - }, - "Right Renal Pelvis": { - "D": 0.0023226345557043155, - "f": 0.08526206184364574, - "Dp": 0.011505159298527953, - "data": [ - 0.23845594027974554, - 0.2340885887968851, - 0.22926470734550777, - 0.21482880140243105, - 0.1955512896933524, - 0.16390194580931639, - 0.13862838327930652, - 0.10649279269443837, - 0.08477918144411398, - 0.07305769210877683, - 0.061746891755696455, - 0.05285223648019959, - 0.04586067619718521, - 0.04320687858631259, - 0.03586299157223977, - 0.028432215124915988, - 0.02445436566942347, - 0.019589305268583098 - ] - }, - "Left Renal Pelvis": { - "D": 0.0033466566117599994, - "f": 0.4828160165372796, - "Dp": 0.08583973481164611, - "data": [ - 0.29934044796894144, - 0.2932737029677877, - 0.2877041185108748, - 0.2710250881677717, - 0.24704347642316418, - 0.20760360029872693, - 0.17839331549285958, - 0.1386621352319866, - 0.11059454180813225, - 0.09591295440295877, - 0.0817685975642877, - 0.0689974169990692, - 0.05938551000712084, - 0.05607454196727335, - 0.04512593596146897, - 0.03683226767862082, - 0.030579950438570393, - 0.02459556163525453 + 0.520457505551924, + 0.5179949072177192, + 0.5155633471240161, + 0.5084494257594109, + 0.49716409975954934, + 0.4765204557221888, + 0.45809661869648965, + 0.42654483187224007, + 0.39442408455894107, + 0.36787322483702434, + 0.32504863827624636, + 0.2605948251546828, + 0.21097454389565015, + 0.18998585349832475, + 0.13882999475749283, + 0.10146707234520135, + 0.07416060548446547, + 0.054202822725272895 ] }, "spleen": { @@ -579,149 +354,24 @@ "f": 0.19999999999999998, "Dp": 0.03000000000000001, "data": [ - 0.20825262009604234, - 0.20694704899515484, - 0.20570704831467276, - 0.20212507147961328, - 0.19725229821243304, - 0.18943033146299096, - 0.18320327013640075, - 0.17286781864880957, - 0.161615547575178, - 0.1519351681953833, - 0.13520336489841728, - 0.10829727499724853, - 0.08736434649782453, - 0.07855737095755005, - 0.05742828771554922, - 0.04218246865860132, - 0.03112872853303898, - 0.023187841448832597 - ] - }, - "Ribs": { - "D": 0.0014138413075201123, - "f": 0.048836057003191935, - "Dp": 0.07342330265121569, - "data": [ - 0.12711214146958372, - 0.1263954809552108, - 0.12547014589784425, - 0.12313829653088443, - 0.11956027858802483, - 0.11364687278836964, - 0.10874717793211831, - 0.10083697123473874, - 0.09358077826879158, - 0.08780976681970634, - 0.07835502891221134, - 0.06389393071053609, - 0.05264876901757898, - 0.04774045258997308, - 0.0359310306495789, - 0.027251312152600817, - 0.020714406533062647, - 0.01584052715598586 - ] - }, - "Cortical Bone": { - "D": 0.0018204574812188043, - "f": 0.06101911742238941, - "Dp": 0.05451769101112701, - "data": [ - 0.009390143914629926, - 0.009099037389799763, - 0.009131460655393383, - 0.008829782724048505, - 0.0086502135563019, - 0.008069828102584907, - 0.0077680784167890315, - 0.007362268945100939, - 0.006882829387916501, - 0.0064934829532998836, - 0.005767801738684848, - 0.004527350372436516, - 0.003640243481224372, - 0.00326492376438238, - 0.002394125257379272, - 0.0016714100072533812, - 0.001144843332685241, - 0.0008363716380179653 - ] - }, - "Spine": { - "D": 0.0006031655633456552, - "f": 0.45466020103939103, - "Dp": 0.030877998160001693, - "data": [ - 0.2074391650883512, - 0.20328222351873226, - 0.19951658296745667, - 0.18914993182867465, - 0.17566591689404631, - 0.15682505195441462, - 0.1443479284647448, - 0.1282986094467979, - 0.11600083158034812, - 0.10782315444682807, - 0.0965419564646553, - 0.08124431936743932, - 0.0692448576593437, - 0.0640193336812393, - 0.050755357448090184, - 0.04038920737820779, - 0.03219893194857284, - 0.02568467031437344 - ] - }, - "spinal cord": { - "D": 0.0024875668530619454, - "f": 0.1558555380447055, - "Dp": 0.05700680211778108, - "data": [ - 0.14968537510540572, - 0.1474358467818982, - 0.14543252611208127, - 0.13981765341703914, - 0.13326668726926896, - 0.12551994254278298, - 0.12140964495107077, - 0.11552529390883204, - 0.11011187420590139, - 0.10394423012644549, - 0.0953245538857873, - 0.08063551244549981, - 0.06881988499396485, - 0.06310984404863128, - 0.04937163704574576, - 0.0388701590854159, - 0.030823101963032198, - 0.024307723947324944 - ] - }, - "Bone Marrow": { - "D": 0.002140130838029838, - "f": 0.09242722776276355, - "Dp": 0.10195846277645583, - "data": [ - 0.1137767818468923, - 0.11195565594192901, - 0.11033817558021898, - 0.10568139675213667, - 0.09961356724480598, - 0.09086071944436365, - 0.0847879583667797, - 0.07655126457311016, - 0.06991046724282958, - 0.06532765614212656, - 0.05861911694149705, - 0.04906131170426399, - 0.04148286776774864, - 0.03824025893353378, - 0.0299947005479393, - 0.023609033117558905, - 0.018584930597666086, - 0.014711209272766139 + 0.46319733863084295, + 0.4599780163434817, + 0.4568402369558109, + 0.44789258464928544, + 0.4344008011227288, + 0.41188915420283145, + 0.39404869199434284, + 0.3679083833930618, + 0.34589804044179345, + 0.3299974208462677, + 0.30593699052207385, + 0.2677894352776353, + 0.23510223916469444, + 0.22030483766147452, + 0.1812739937338342, + 0.149158519515709, + 0.12273279934482494, + 0.10098880098053091 ] }, "Artery": { @@ -729,24 +379,24 @@ "f": 1.0, "Dp": 0.09999999999999998, "data": [ - 0.22834647271477249, - 0.2231054294831425, - 0.21794961382660857, - 0.20498977519163897, - 0.18779391580254307, - 0.16530130471095614, - 0.1509167178895211, - 0.13288398883831373, - 0.11976722105657064, - 0.11101252429871204, - 0.0995679871896937, - 0.08393896738444352, - 0.07175624264460921, - 0.06642824374222756, - 0.052990525840176876, - 0.04234313675826943, - 0.034022916847795445, - 0.027353983241822123 + 0.6331776796961799, + 0.5729228568542781, + 0.5184020385297728, + 0.3840416757814179, + 0.2329330509688469, + 0.08569128062077878, + 0.03152406042803916, + 0.004266317646796623, + 0.0003502006781663863, + 2.8746222185377432e-05, + 1.9369052150900827e-07, + 8.793536072167788e-12, + 3.992259200403357e-16, + 2.6899630898926433e-18, + 8.228659512624137e-25, + 2.5171660395312233e-31, + 7.700069325810414e-38, + 2.355469074790287e-44 ] }, "Vein": { @@ -754,24 +404,24 @@ "f": 1.0, "Dp": 0.09999999999999999, "data": [ - 0.22441397394228915, - 0.22020896097441717, - 0.21606131782971294, - 0.20510030062414625, - 0.19105799752479158, - 0.17138968491456982, - 0.15833251939086881, - 0.14149440031896057, - 0.12814970483654534, - 0.11897468240522634, - 0.1061607717044737, - 0.08845332107116888, - 0.07465524015934527, - 0.06868361221643562, - 0.05376343264190993, - 0.04226849670653001, - 0.03331360392108922, - 0.026481578251132707 + 0.4613245702485093, + 0.41742373302027014, + 0.3777006128129767, + 0.27980749593445714, + 0.16971182510167326, + 0.06243349137859716, + 0.022967997918739217, + 0.0031083805037101773, + 0.000255151409369607, + 2.094410308699206e-05, + 1.4112025654351554e-07, + 6.406849735140351e-12, + 2.9087052797413694e-16, + 1.9598702010859244e-18, + 5.995288423945661e-25, + 1.8339726409627368e-31, + 5.610164866073346e-38, + 1.7161624509297404e-44 ] }, "asc lower intestine": { @@ -779,24 +429,24 @@ "f": 0.6899999999999998, "Dp": 0.028999999999999998, "data": [ - 0.2954735243830286, - 0.2906352588520771, - 0.2858040728009893, - 0.2732876505097306, - 0.2555854419555954, - 0.22985581576200326, - 0.21128491346672293, - 0.18608064851180967, - 0.16601289258896418, - 0.15240173839644594, - 0.13400187334016833, - 0.10885324742349821, - 0.08975247478641343, - 0.08153230006289827, - 0.06139854293776205, - 0.0462805910211582, - 0.03508261675195721, - 0.026645564361144645 + 0.3757523005483084, + 0.36818898027201435, + 0.3608376872727926, + 0.33999628188438275, + 0.30896884670253955, + 0.2586353239992207, + 0.22061539539594607, + 0.1699148909386564, + 0.13503806080287922, + 0.11644696505952283, + 0.09904910053269396, + 0.0841362910398935, + 0.07365446235858479, + 0.06897758682680868, + 0.0566701553175031, + 0.04656025024863034, + 0.03825396326956039, + 0.031429507145457856 ] }, "trans lower intestine": { @@ -804,24 +454,24 @@ "f": 0.6899999999999997, "Dp": 0.029000000000000012, "data": [ - 0.3059958856171849, - 0.3033478430012246, - 0.3008747097693397, - 0.2942893933085906, - 0.28545501121207245, - 0.27254118906081826, - 0.2630912499309692, - 0.24845192418952888, - 0.2336370590673267, - 0.22075908874945738, - 0.19894704011158446, - 0.16374014235149112, - 0.13561828103732013, - 0.12345897516597096, - 0.09371111774296453, - 0.07128210798283909, - 0.05448244944592977, - 0.04181129466668589 + 0.37575230054829073, + 0.3681889802719773, + 0.3608376872726795, + 0.33999628188438735, + 0.308968846702549, + 0.2586353239992963, + 0.2206153953958967, + 0.16991489093861786, + 0.13503806080285666, + 0.11644696505952908, + 0.09904910053271923, + 0.08413629103986729, + 0.07365446235859642, + 0.06897758682680608, + 0.05667015531750176, + 0.04656025024861578, + 0.03825396326955233, + 0.031429507145451153 ] }, "desc lower intestine": { @@ -829,24 +479,24 @@ "f": 0.6899999999999997, "Dp": 0.029000000000000015, "data": [ - 0.3321131178872771, - 0.32853831493658764, - 0.3252040860498945, - 0.31695161828277213, - 0.306518435347314, - 0.2936208786613117, - 0.28524779476766704, - 0.27302246070959224, - 0.2602918045459527, - 0.24869005810018593, - 0.22787949028471127, - 0.19169263092766683, - 0.16182307271559665, - 0.14876986039111117, - 0.11598635759976698, - 0.09055906420523004, - 0.07088668437054298, - 0.055538701011291276 + 0.3757523005482983, + 0.3681889802720274, + 0.3608376872727898, + 0.33999628188437997, + 0.3089688467025362, + 0.2586353239992219, + 0.22061539539594469, + 0.16991489093865034, + 0.13503806080287217, + 0.11644696505952613, + 0.09904910053269655, + 0.08413629103989273, + 0.0736544623585807, + 0.0689775868268096, + 0.05667015531750507, + 0.046560250248629996, + 0.038253963269558745, + 0.03142950714545999 ] }, "small intestine": { @@ -854,24 +504,24 @@ "f": 0.6899999999999998, "Dp": 0.02900000000000001, "data": [ - 0.30074425040279856, - 0.2944845452430382, - 0.28863340515273506, - 0.2735820814981339, - 0.25453852747846045, - 0.23015611850652534, - 0.21519383720966714, - 0.19637918935500634, - 0.18132358975376156, - 0.1703002154782028, - 0.15368595652005698, - 0.12867080211654158, - 0.10855563167521692, - 0.09984876120702285, - 0.07772999966315815, - 0.060759749320596794, - 0.04756646220287644, - 0.037368264773960574 + 0.37575230054809006, + 0.3681889802719645, + 0.3608376872726274, + 0.33999628188415737, + 0.3089688467025522, + 0.2586353239993716, + 0.22061539539580843, + 0.1699148909386938, + 0.13503806080282693, + 0.11644696505949513, + 0.09904910053272918, + 0.08413629103985984, + 0.0736544623585498, + 0.06897758682680517, + 0.05667015531751813, + 0.04656025024860948, + 0.03825396326954586, + 0.03142950714546874 ] }, "pericardium": { @@ -879,74 +529,24 @@ "f": 0.07000000000000002, "Dp": 0.009999999999999998, "data": [ - 0.32000494407805, - 0.3088654009375722, - 0.29904980558089767, - 0.2740850878913364, - 0.24558604488847646, - 0.21536926331505973, - 0.2020222261297372, - 0.18936420984433425, - 0.18029653079469718, - 0.17201776672049646, - 0.15729878584721638, - 0.13196136697968544, - 0.11127864773724477, - 0.10224194180476164, - 0.07944915803798566, - 0.06221573834819889, - 0.04875921452691328, - 0.03834181090739235 - ] - }, - "Cartilage": { - "D": 0.0026870215041229625, - "f": 0.38563517334297287, - "Dp": 0.012404465173409039, - "data": [ - 0.22023434588419283, - 0.21765363810860222, - 0.2153102069694426, - 0.20879630843180802, - 0.20028436277779857, - 0.1878493204264525, - 0.17913244131902714, - 0.16695355326774897, - 0.1559418751278614, - 0.14735487693691215, - 0.1332856707364372, - 0.11150392562163026, - 0.09371166585155002, - 0.08608967361722157, - 0.06670031907274253, - 0.051882051080158885, - 0.0404627776446415, - 0.03166323498206638 - ] - }, - "Fat": { - "D": 0.0015908888071378827, - "f": 0.4858910413604801, - "Dp": 0.10124472949421114, - "data": [ - 0.04347759306594482, - 0.04331055503018695, - 0.043157782586126285, - 0.04267618521144028, - 0.041840304286041824, - 0.04042891293620974, - 0.039170850881867544, - 0.0369091385939268, - 0.034446175085675435, - 0.03229938324890682, - 0.028545694575280674, - 0.022604383587180022, - 0.017992511581896263, - 0.016066679631941184, - 0.01138662757473584, - 0.008100170353602424, - 0.005759608016476787, - 0.004089478201726281 + 0.3102866163422252, + 0.3092060956952832, + 0.3081303147820436, + 0.3049311200902595, + 0.2996912485375019, + 0.2895446290355466, + 0.27982059052551705, + 0.26154541829493244, + 0.24068490427293882, + 0.22176572518020518, + 0.18884455910341968, + 0.13809207932390954, + 0.10163621916967916, + 0.08731239240795743, + 0.05550794510643099, + 0.03535663555180654, + 0.022536176571754538, + 0.014367868802101617 ] }, "config": { diff --git a/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py b/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py index bcb9251..bc57783 100644 --- a/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py +++ b/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py @@ -2,6 +2,8 @@ import numpy.testing as npt import pytest import torch +import json +import pathlib from utils.data_simulation.GenerateData import GenerateData from src.original.ETP_SRI.LinearFitting import LinearFit @@ -45,3 +47,25 @@ def test_ivim_fit(f, D, Dp, bvals): npt.assert_allclose([f, D], [f_fit, D_fit], atol=1e-5) if not np.allclose(f, 0): npt.assert_allclose(Dp, Dp_fit, rtol=1e-2, atol=1e-3) + +def test_ivim_fit_saved(request): + file = pathlib.Path(request.node.fspath) + # print('current test file:', file) + generic = file.with_name('generic.json') + # print('current config file:', generic) + fit = LinearFit() + with generic.open() as f: + data = json.load(f) + bvals = data.pop('config') + bvals = bvals['bvalues'] + for name, data in data.items(): + print(f'{name} {data}') + signal = np.asarray(data['data']) + signal /= signal[0] + if data['f'] == 1.0: + linear_fit = fit.linear_fit(bvals, np.log(signal)) + npt.assert_allclose([data['f'], data['Dp']], linear_fit, atol=1e-2) + else: + [f_fit, D_fit, Dp_fit] = fit.ivim_fit(bvals, signal) + npt.assert_allclose([data['f'], data['D']], [f_fit, D_fit], atol=1e-2) + npt.assert_allclose(data['Dp'], Dp_fit, atol=1e-1) # go easy on the perfusion as it's a linear fake From db8b49e4e5f7203a2053cbd168a2fd108f1210ff Mon Sep 17 00:00:00 2001 From: Oliver Gurney-Champion <7846269+oliverchampion@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:50:33 +0200 Subject: [PATCH 7/8] Update .gitignore update .gitignore --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index d27b6ff..cc53dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ .idea* .github* *.nii.gz +__pycache__/ + + +# Unit test / coverage reports +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml From 951fa23bd6816670f53ec15698cd490db06e708f Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sat, 26 Aug 2023 12:20:33 -0700 Subject: [PATCH 8/8] Remove pytorch import --- tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py b/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py index bc57783..0664f20 100644 --- a/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py +++ b/tests/IVIMmodels/unit_tests/test_ivim_fit_linear.py @@ -1,7 +1,6 @@ import numpy as np import numpy.testing as npt import pytest -import torch import json import pathlib