11
11
# code adapted from MAtlab code by Eric Schrauben: https://github.com/schrau24/XCAT-ERIC
12
12
# This code generates a 4D IVIM phantom as nifti file
13
13
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 ):
15
15
np .random .seed (42 )
16
16
if motion :
17
17
states = range (1 ,21 )
@@ -26,7 +26,7 @@ def phantom(bvalue, noise, TR=3000, TE=40, motion=False, rician=False, interleav
26
26
XCAT = XCAT [- 1 :0 :- 2 ,- 1 :0 :- 2 ,10 :160 :4 ]
27
27
28
28
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 )
30
30
if state == 1 :
31
31
Dim_out = Dim
32
32
fim_out = fim
@@ -187,7 +187,7 @@ def contrast_curve_calc():
187
187
return D , f , Ds
188
188
189
189
190
- 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 ):
191
191
###########################################################################################
192
192
# This script converts XCAT tissue values to MR contrast based on the SSFP signal equation.
193
193
# Christopher W. Roy 2018-12-04 # fetal.xcmr@gmail.com
@@ -363,7 +363,6 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
363
363
else :
364
364
T1 = Tissue [iTissue , 2 ]
365
365
T2 = Tissue [iTissue , 3 ]
366
-
367
366
if ivim_cont and not np .isnan ([D [iTissue ], f [iTissue ], Ds [iTissue ]]).any ():
368
367
# note we are assuming blood fraction has the same T1 as tissue fraction here for simplicity. Can be changed in future.
369
368
Dtemp = D [iTissue ]
@@ -374,8 +373,11 @@ def XCAT_to_MR_DCE(XCAT, TR, TE, bvalue, D, f, Ds, b0=3, ivim_cont = True):
374
373
ftemp = np .random .rand (1 )* 0.5
375
374
Dstemp = 5e-3 + np .random .rand (1 )* 1e-1
376
375
S0 = ivim (bvalue ,Dtemp ,ftemp ,Dstemp )
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 )
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
379
381
Dim = Dim + (XCAT == iTissue ) * Dtemp
380
382
fim = fim + (XCAT == iTissue ) * ftemp
381
383
Dpim = Dpim + (XCAT == iTissue ) * Dstemp
@@ -415,6 +417,7 @@ def parse_bvalues_file(file_path):
415
417
parser .add_argument ("-n" , "--noise" , type = float , default = 0.0005 , help = "Noise" )
416
418
parser .add_argument ("-m" , "--motion" , action = "store_true" , help = "Motion flag" )
417
419
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!
418
421
args = parser .parse_args ()
419
422
420
423
if args .bvalues_file and args .bvalue :
@@ -432,10 +435,11 @@ def parse_bvalues_file(file_path):
432
435
noise = args .noise
433
436
motion = args .motion
434
437
interleaved = args .interleaved
438
+ T1T2 = args .T1T2
435
439
download_data ()
436
440
for key , bvalue in bvalues .items ():
437
441
bvalue = np .array (bvalue )
438
- 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 )
439
443
# sig = np.flip(sig,axis=0)
440
444
# sig = np.flip(sig,axis=1)
441
445
res = np .eye (4 )
0 commit comments