Skip to content

Commit 89c03ff

Browse files
author
IvanARashid
committed
Merge branch 'main' into wrapper_dev
2 parents c927dbc + 44051e4 commit 89c03ff

22 files changed

+4838
-2198
lines changed

.github/workflows/documentation.yml renamed to .github/workflows/website.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build & Deploy Documentation
1+
name: Build & Deploy Website
22

33
on:
44
workflow_run:
@@ -33,25 +33,42 @@ jobs:
3333
run: |
3434
pip install -r requirements.txt
3535
36-
# Action to download artifacts from a different workflow (analysis.yml)
36+
# Action Figures artifact
3737
- name: 'Download artifact'
3838
if: ${{ github.event.workflow_run.conclusion == 'success' }}
3939
uses: ./.github/actions/download-artifact
4040
with:
4141
name: 'Figures'
42+
# Action analysis data artifact
43+
- name: 'Download analysis data'
44+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
45+
uses: ./.github/actions/download-artifact
46+
with:
47+
name: 'Data'
48+
49+
- name: 'Filter and compress results file.'
50+
run: python utilities/reduce_output_size.py test_output.csv test_output.csv.gz
4251

43-
- name: Build html
52+
- name: move data to the dashboard folder
53+
run: |
54+
mv test_output.csv.gz website/dashboard
55+
56+
- name: Build documentation
4457
run: |
4558
mkdir docs/_static
4659
mv *.pdf docs/_static/
4760
sphinx-apidoc -o docs src
4861
cd docs/
4962
make html
5063
64+
- name: move data to the website folder
65+
run: |
66+
mv "docs/_build/html" "website/documentation"
67+
5168
- name: Upload docs artifact
5269
uses: actions/upload-pages-artifact@v3
5370
with:
54-
path: 'docs/_build/html'
71+
path: 'website'
5572

5673
deploy:
5774
needs: build

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ __pycache__/
1010
*.raw
1111
bvals.txt
1212
download
13+
.Introduction_to_TF24_IVIM-MRI_CodeCollection_github_and_IVIM_Analysis_using_Python.ipynb
14+
.ipynb_checkpoints
1315
md5sums.txt
1416
*.gz
1517
*.zip
@@ -21,4 +23,6 @@ md5sums.txt
2123
.cache
2224
nosetests.xml
2325
coverage.xml
24-
*.pyc
26+
*.pyc
27+
phantoms/MR_XCAT_qMRI/*.json
28+
phantoms/MR_XCAT_qMRI/*.txt

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The ISMRM Open Science Initiative for Perfusion Imaging (OSIPI) is an initiative
66
77
This **IVIM code collection** code library is maintained by OSIPI [Taskforce 2.4](https://www.osipi.org/task-force-2-4/) (*currently not available*) and aims to collect, test and share open-source code related to intravoxel incoherent motion (IVIM) analysis of diffusion encoded MRI data to be used in research and software development. Code contributions can include any code related IVIM analysis (denoising, motion correction, model fitting, etc.), but at an initial phase, development of tests and other features of the repository will predominantly focus on fitting algorithms. A goal of the IVIM OSIPI task force is to develop a fully tested and harmonized code library, building upon the contributions obtained through this initiative. Documentation and analysis are available on the [OSIPI TF2.4](https://osipi.github.io/TF2.4_IVIM-MRI_CodeCollection/).
88

9+
We have some useful tools and further documentation on https://osipi.github.io/TF2.4_IVIM-MRI_CodeCollection/.
10+
911
## How to contribute
1012

1113
If you would like to get involve in OSIPI and work within the task force, please email the contacts listed on our website.
@@ -17,6 +19,9 @@ If you would like to contribute with code, please follow the instructions below:
1719
* [Guidelines for IVIM code contribution](doc/guidelines_for_contributions.md)
1820
* [Guidelines to creating a test file](doc/creating_test.md)
1921

22+
If you would like to use code from the repository and/or are new to Github or IVIM, please see the jupyter notebook below:
23+
* [Introduction to TF2.4_IVIM-MRI_CodeCollection github and IVIM Analysis using Python](doc/Introduction_to_TF24_IVIM-MRI_CodeCollection_github_and_IVIM_Analysis_using_Python.ipynb)
24+
2025
## Repository Organization
2126

2227
The repository is organized in four main folders along with configuration files for automated testing.
@@ -32,4 +37,4 @@ The **utils** folder contains various helpful tools.
3237
## View Testing Reports
3338
[![Unit tests](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml)
3439
[![Algorithm Analysis](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/analysis.yml)
35-
[![Build & Deploy Documentation](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/documentation.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/documentation.yml)
40+
[![Build & Deploy Website](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/website.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/website.yml)

doc/Introduction_to_TF24_IVIM-MRI_CodeCollection_github_and_IVIM_Analysis_using_Python.ipynb

Lines changed: 1107 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

phantoms/MR_XCAT_qMRI/sim_ivim_sig.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# code adapted from MAtlab code by Eric Schrauben: https://github.com/schrau24/XCAT-ERIC
1212
# This code generates a 4D IVIM phantom as nifti file
1313

14-
def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleaved=False):
14+
def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleaved=False,T1T2=True):
1515
np.random.seed(42)
1616
if motion:
1717
states = range(1,21)
@@ -23,10 +23,10 @@ def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleav
2323

2424
# Access the variables in the loaded .mat file
2525
XCAT = mat_data['IMG']
26-
XCAT = XCAT[0:-1:2,0:-1:2,10:160:4]
26+
XCAT = XCAT[-1:0:-2,-1:0:-2,10:160:4]
2727

2828
D, f, Ds = contrast_curve_calc()
29-
S, Dim, fim, Dpim, legend = XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds)
29+
S, Dim, fim, Dpim, legend = XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds,T1T2=T1T2)
3030
if state == 1:
3131
Dim_out = Dim
3232
fim_out = fim
@@ -93,24 +93,29 @@ def contrast_curve_calc():
9393
D[6] = 3e-3 # 6 Blood RV
9494
D[7] = 3e-3 # 7 Blood la
9595
D[8] = 3e-3 # 8 Blood ra
96+
D[10] = 1.37e-3 # 8 Muscle: 10.3389/fresc.2022.910068
9697
D[13] = 1.5e-3 # 13 liver: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901
98+
D[14] = 3.0e-3 # 13 Galbladder
9799
D[17] = 1.67e-3 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421
98100
D[18] = 1.67e-3 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421
99101
D[20] = 1.5e-3 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586
102+
D[21] = 3.0e-3 # 21 stomach content
100103
D[22] = 1.3e-3 # 22 Pancreas (from literature)
101104
D[23] = 2.12e-3 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519
102105
D[24] = 2.09e-3 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519
103106
D[25] = 2.12e-3 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519
104107
D[26] = 2.09e-3 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519
105108
D[30] = 1.3e-3 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495
109+
D[34] = 4.1e-4 # 34 spinal cord :doi: 10.3389/fonc.2022.961473
110+
D[35] = 0.43e-3 # 35 Bone marrow : https://pubmed.ncbi.nlm.nih.gov/30194746/
106111
D[36] = 3e-3 # 36 artery
107112
D[37] = 3e-3 # 37 vein
108113
D[40] = 1.31e-3 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
109114
D[41] = 1.31e-3 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
110115
D[42] = 1.31e-3 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
111116
D[43] = 1.31e-3 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
112117
D[50] = 3e-3 # 50 pericardium
113-
D[73] = 1.8e-3 # 73 Pancreatic tumor (advanced state, from literature)
118+
D[73] = 1.32e-3 # 73 Pancreatic tumor Klaassen et al. PMC7463316
114119

115120
f = np.full(74, np.nan)
116121
f[1] = 0.15 # 1 Myocardium LV : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901
@@ -121,24 +126,29 @@ def contrast_curve_calc():
121126
f[6] = 1.00 # 6 Blood RV
122127
f[7] = 1.00 # 7 Blood la
123128
f[8] = 1.00 # 8 Blood ra
129+
f[10] = 0.10 # 8 Muscle: 10.3389/fresc.2022.910068
124130
f[13] = 0.11 # 13 liver : Delattre et al. doi: 10.1097/RLI.0b013e31826ef901
131+
f[14] = 0 # 13 Gal
125132
f[17] = 0.32 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421
126133
f[18] = 0.32 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421
127134
f[20] = 0.3 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586
135+
f[21] = 0.0 # 20 stomach content
128136
f[22] = 0.15 # 22 Pancreas (from literature)
129137
f[23] = 0.097 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519
130138
f[24] = 0.158 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519
131139
f[25] = 0.097 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519
132140
f[26] = 0.158 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519
133141
f[30] = 0.2 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495
142+
f[34] = 0.178 # 34 spinal cord :doi: 10.3389/fonc.2022.961473
143+
f[35] = 0.145 # 35 Bone marrow : https://pubmed.ncbi.nlm.nih.gov/30194746/
134144
f[36] = 1.0 # 36 artery
135145
f[37] = 1.0 # 37 vein
136146
f[40] = 0.69 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
137147
f[41] = 0.69 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
138148
f[42] = 0.69 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
139149
f[43] = 0.69 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
140150
f[50] = 0.07 # 50 pericardium
141-
f[73] = 0.37 # 73 Pancreatic tumor (advanced state, from literature)
151+
f[73] = 0.0549 # 73 Pancreatic tumor PMC7463316
142152

143153
Ds = np.full(74, np.nan)
144154
Ds[1] = 0.08 # 1 Myocardium LV: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901
@@ -149,30 +159,35 @@ def contrast_curve_calc():
149159
Ds[6] = 0.1 # 6 Blood RV
150160
Ds[7] = 0.1 # 7 Blood la
151161
Ds[8] = 0.1 # 8 Blood ra
162+
Ds[10] = 0.0263 # 8 Muscle: 10.3389/fresc.2022.910068
152163
Ds[13] = 0.1 # 13 liver: Delattre et al. doi: 10.1097/RLI.0b013e31826ef901
164+
Ds[14] = 0.1 # 14 Gal
153165
Ds[17] = 0.03 # 17 esophagus : Huang et al. doi: 10.1259/bjr.20170421
154166
Ds[18] = 0.03 # 18 esophagus cont : Huang et al. doi: 10.1259/bjr.20170421
155167
Ds[20] = 0.012 # 20 stomach wall: Li et al. doi: 10.3389/fonc.2022.821586
168+
Ds[21] = 0.0 # 20 stomach content
156169
Ds[22] = 0.01 # 22 Pancreas (from literature)
157170
Ds[23] = 0.02 # 23 right kydney cortex : van Baalen et al. Doi: jmri.25519
158171
Ds[24] = 0.019 # 23 right kydney medulla : van Baalen et al. Doi: jmri.25519
159172
Ds[25] = 0.02 # 23 left kydney cortex : van Baalen et al. Doi: jmri.25519
160173
Ds[26] = 0.019 # 23 left kydney medulla : van Baalen et al. Doi: jmri.25519
161174
Ds[30] = 0.03 # 30 spleen : Taimouri et al. Doi: 10.1118/1.4915495
175+
Ds[34] = 0.0289 # 34 spinal cord :doi: 10.3389/fonc.2022.961473
176+
Ds[35] = 0.05 # 35 Bone marrow :
162177
Ds[36] = 0.1 # 36 artery
163178
Ds[37] = 0.1 # 37 vein
164179
Ds[40] = 0.029 # 40 asc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
165180
Ds[41] = 0.029 # 41 trans lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
166181
Ds[42] = 0.029 # 42 desc lower intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
167182
Ds[43] = 0.029 # 43 small intestine : Hai-Jing et al. doi: 10.1097/RCT.0000000000000926
168183
Ds[50] = 0.01 # 50 pericardium
169-
Ds[73] = 0.01 # 73 Pancreatic tumor (advanced state, from literature)
184+
Ds[73] = 0.094 # 73 Pancreatic tumor PMC7463316/
170185
# Return values
171186

172187
return D, f, Ds
173188

174189

175-
def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
190+
def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True, T1T2=True):
176191
###########################################################################################
177192
# This script converts XCAT tissue values to MR contrast based on the SSFP signal equation.
178193
# Christopher W. Roy 2018-12-04 # fetal.xcmr@gmail.com
@@ -282,7 +297,7 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
282297
Tissue[19] = [1045.5, 37.3, 1201, 44]
283298
Tissue[20] = [981.5, 36, 1232.9, 37.20]
284299
#Tissue[20] = [981.5, 36, 1232.9, 37.20]
285-
Tissue[21] = [0, 0, 0, 0]
300+
Tissue[21] = [2500, 1250, 4000, 2000]
286301
Tissue[22] = [584, 46, 725, 43]
287302
Tissue[23] = [828, 71, 1168, 66]
288303
Tissue[24] = [1412, 85, 1545, 81]
@@ -348,7 +363,6 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
348363
else:
349364
T1 = Tissue[iTissue, 2]
350365
T2 = Tissue[iTissue, 3]
351-
352366
if ivim_cont and not np.isnan([D[iTissue], f[iTissue], Ds[iTissue]]).any():
353367
# note we are assuming blood fraction has the same T1 as tissue fraction here for simplicity. Can be changed in future.
354368
Dtemp=D[iTissue]
@@ -359,8 +373,11 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
359373
ftemp=np.random.rand(1)*0.5
360374
Dstemp=5e-3+np.random.rand(1)*1e-1
361375
S0 = ivim(bvalue,Dtemp,ftemp,Dstemp)
362-
if T1 > 0 or T2 > 0:
363-
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)
376+
if T1T2:
377+
if T1 > 0 or T2 > 0:
378+
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)
379+
else:
380+
MR = MR + np.tile(np.expand_dims(XCAT == iTissue,3),len(S0)) * S0
364381
Dim = Dim + (XCAT == iTissue) * Dtemp
365382
fim = fim + (XCAT == iTissue) * ftemp
366383
Dpim = Dpim + (XCAT == iTissue) * Dstemp
@@ -400,6 +417,7 @@ def parse_bvalues_file(file_path):
400417
parser.add_argument("-n", "--noise", type=float, default=0.0005, help="Noise")
401418
parser.add_argument("-m", "--motion", action="store_true", help="Motion flag")
402419
parser.add_argument("-i", "--interleaved", action="store_true", help="Interleaved flag")
420+
parser.add_argument("-u", "--T1T2", action="store_true", help="weight signal with T1T2") # note, set this to zero when generating test data for unit testing!
403421
args = parser.parse_args()
404422

405423
if args.bvalues_file and args.bvalue:
@@ -417,14 +435,15 @@ def parse_bvalues_file(file_path):
417435
noise = args.noise
418436
motion = args.motion
419437
interleaved = args.interleaved
438+
T1T2 = args.T1T2
420439
download_data()
421440
for key, bvalue in bvalues.items():
422441
bvalue = np.array(bvalue)
423-
sig, XCAT, Dim, fim, Dpim, legend = phantom(bvalue, noise, motion=motion, interleaved=interleaved)
442+
sig, XCAT, Dim, fim, Dpim, legend = phantom(bvalue, noise, motion=motion, interleaved=interleaved,T1T2=T1T2)
424443
# sig = np.flip(sig,axis=0)
425444
# sig = np.flip(sig,axis=1)
426445
res=np.eye(4)
427-
res[2]=2
446+
res[2,2]=2
428447

429448
voxel_selector_fraction = 0.5
430449
D, f, Ds = contrast_curve_calc()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy
1+
numpy<2
22
scipy
33
torchio
44
torch

src/original/OJ_GU/ivim_seg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,11 @@ def _Ddiff(Y, yb, b, D):
207207

208208
f = _f_from_intercept(A, S0)
209209

210+
if Y.shape[0] == 1:
211+
D = D.item()
212+
f = f.item()
213+
Dstar = Dstar.item()
214+
S0 = S0.item()
215+
210216
pars = {'D': D, 'f': f, 'Dstar': Dstar, 'S0': S0}
211217
return pars

tests/IVIMmodels/unit_tests/algorithms.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"OGC_AmsterdamUMC_biexp_segmented",
1212
"OGC_AmsterdamUMC_biexp",
1313
"PV_MUMC_biexp",
14-
"PvH_KB_NKI_IVIMfit"
14+
"PvH_KB_NKI_IVIMfit",
15+
"OJ_GU_seg"
1516
],
1617
"IAR_LU_biexp": {
1718
"tolerances": {
@@ -99,7 +100,7 @@
99100
},
100101
"ETP_SRI_LinearFitting": {
101102
"xfail_names": {
102-
"Vein": true
103+
"Blood RV": true
103104
},
104105
"options": {
105106
"thresholds": [500]

0 commit comments

Comments
 (0)