-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpluto-03-low-field-boost-optimization.jl
2384 lines (2103 loc) · 74 KB
/
pluto-03-low-field-boost-optimization.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.46
#> [frontmatter]
#> image = "https://upload.wikimedia.org/wikipedia/commons/a/a0/Textformatting.svg"
#> title = "Low-Field BOOST Optimization"
#> tags = ["BOOST", "Low Field", "Optimization"]
#> date = "2024-10-03"
#> description = "Optimizing sequence to improve SNR and fat supression."
#>
#> [[frontmatter.author]]
#> name = "Carlos Castillo Passi"
#> url = "https://avatars.githubusercontent.com/u/5957134?s=400&u=fe62a2a899ced18e8b882cebde6b1eefe6a1222c&v=4"
using Markdown
using InteractiveUtils
# ╔═╡ 7deadd58-b202-4508-b4c7-686f742cb713
begin
begin
using Pkg
begin
println("OS $(Base.Sys.MACHINE)") # OS
println("Julia $VERSION") # Julia version
# Koma sub-packages
for (_, pkg) in filter(((_, pkg),) -> occursin("KomaMRI", pkg.name), Pkg.dependencies())
println("$(pkg.name) $(pkg.version)")
end
end
end
end
# ╔═╡ 0b7a405e-bbb5-11ee-05ca-4b1c8567398d
using KomaMRICore, KomaMRIPlots, PlutoPlotly # Essentials
# ╔═╡ 70dbc2bd-8b93-471d-8340-04d98a008ca6
using Suppressor, PlutoUI, ProgressLogging # Extras
# ╔═╡ a99c0c47-1b70-4362-a2f6-a7e3259606fa
md"""# Low-Field BOOST Optimization
This notebook reproduces the simulation experiments performed in our manuscript:
> **"Simultaneous iNAV-Based 3D Whole-Heart Bright-Blood and Black-Blood Imaging at 0.55T"**
>
> **Carlos Castillo-Passi**, Karl P. Kunze, Michael G. Crabb, Camila Muñoz, Anastasia Fotaki, Radhouene Neji, Pablo Irarrazaval, Claudia Prieto, and René M. Botnar
>
> (2024)
Submitted to Magnetic Resonance in Medicine (MRM).
"""
# ╔═╡ 1bb3e49b-1a19-4343-ac09-fbaf1cae4ba3
TableOfContents()
# ╔═╡ fc58640b-c44c-4c25-a4fd-5a0e17d7becd
md"# 1. Simulation setup"
# ╔═╡ dbf16676-64f2-4d9b-bf1b-8de06b048602
md"## 1.1. Loading required packages"
# ╔═╡ f49655cc-460e-4981-92ea-dfd6147308bf
md"Bloch simulations were performed using **KomaMRI.jl** to optimize the proposed whole-heart BOOST parameters."
# ╔═╡ 77153e5c-71bd-42e3-bae9-e4811ffa7a3d
md"""## 1.2. Scanner
We start by defining the hardware characteristics. The `sys.B0` will be used to calculate the off-resonance of fat."""
# ╔═╡ 9e397426-b60b-4b98-be8b-f7f128621c44
begin
sys = Scanner()
sys.B0 = 0.55
sys.Gmax = 40.0e-3
sys.Smax = 25.0
sys
end
# ╔═╡ 92194fcb-582a-49ce-aad7-20b0145d40d3
md"## 1.3. Sequence"
# ╔═╡ ae72ffc5-7f8e-4907-a99e-8ad7cb8fddab
md"""
The BOOST sequence (`BOOST`) consists of:
"""
# ╔═╡ cb659118-9f22-43c3-801d-49241dee4df6
begin
# General sequence parameters
Trf = 500e-6 # 500 [ms]
B1 = 1 / (360*γ*Trf) # B1 amplitude [uT]
Tadc = 1e-6 # 1us
# Prepulses
Tfatsat = 26.624e-3 # 26.6 [ms]
T2prep_duration = 50e-3 # 50 [ms]
# Acquisition
RR = 1.0 # 1 [s]
dummy_heart_beats = 3 # Steady-state
TR = 5.3e-3 # 5.3 [ms] RF Low SAR
TE = TR / 2 # bSSFP condition
iNAV_lines = 6 # FatSat-Acq delay: iNAV_lines * TR
iNAV_flip_angle = 3.2 # 3.2 [deg]
im_segments = 20 # Acquisitino window: im_segments * TR
# To be optimized
im_flip_angle = [110, 80] # 80 [deg]
FatSat_flip_angle = 180 # 180 [deg]
IR_inversion_time = 90e-3 # 90 [ms]
seq_params = (;
dummy_heart_beats,
iNAV_lines,
im_segments,
iNAV_flip_angle,
im_flip_angle,
T2prep_duration,
IR_inversion_time,
FatSat_flip_angle,
RR
)
seq_params
end
# ╔═╡ 42417eba-46e0-400e-a874-299533362c41
md"Below we are showing the **bright-blood contrast** (containing a T2p-IR pulse):"
# ╔═╡ 4aab8a6f-d2ba-46f0-a1bf-ddc0dcf8437f
md"and **reference contrast** (only containing a FatSat pulse), later used to obtain the black-blood contrast by subtracting the bright-blood contrast. Note that this contrast has a different flip angle."
# ╔═╡ a15d6b64-f8ee-4ee4-812c-d49cf5ea784d
md"""
## 1.4. Phantom
Each tissue was represented with 200 isochromats distributed along the $z$-axis to simulate gradient spoiling effects. The isochromats for each tissue were inside a 1D voxel of size $1.5\,\mathrm{mm}$. The values for $T_1$ and $T_2$ for blood, myocardial muscle, and fat at 0.55T were obtained from the work of Campbell-Washburn, et al. Fat spins were simulated using a chemical shift of $-3.4\,\mathrm{ppm}$, simulating regular fat with $T_1=183\,\mathrm{ms}$, and fast-recovering fat with $T_1=130\,\mathrm{ms}$.
"""
# ╔═╡ f0a81c9f-5616-4663-948f-a4084e1719af
begin
fat_ppm = -3.4e-6 # -3.4ppm fat-water frequency shift
Niso = 200 # 200 isochromats in spoiler direction
Δx_voxel = 1.5e-3 # 1.5 [mm]
fat_freq = γ*sys.B0*fat_ppm # -80 [Hz]
dx = Array(range(-Δx_voxel/2, Δx_voxel/2, Niso))
md"- Phantom parameters (show/hide code)"
end
# ╔═╡ 6b870443-7be5-4287-b957-ca5c14eda89c
begin
function FatSat(α, Δf; sample=false)
# FatSat design
# cutoff_freq = sqrt(log(2) / 2) / a where B1(t) = exp(-(π t / a)^2)
cutoff = fat_freq / π # cutoff [Hz] => ≈1/10 RF power to water
a = sqrt(log(2) / 2) / cutoff # a [s]
τ = range(-Tfatsat/2, Tfatsat/2, 64) # time [s]
gauss_pulse = exp.(-(π * τ / a) .^ 2) # B1(t) [T]
# FatSat prepulse
seq = Sequence()
seq += Grad(-8e-3, 3000e-6, 500e-6) #Spoiler1
seq += RF(gauss_pulse, Tfatsat, Δf)
α_ref = get_flip_angles(seq)[2]
seq *= (α/α_ref+0im)
if sample
seq += ADC(1, 1e-6)
end
seq += Grad(8e-3, 3000e-6, 500e-6) #Spoiler2
if sample
seq += ADC(1, 1e-6)
end
return seq
end
function T2prep(TE; sample=false)
seq = Sequence()
seq += RF(90 * B1, Trf)
seq += sample ? ADC(20, TE/2 - 1.5Trf) : Delay(TE/2 - 1.5Trf)
seq += RF(180im * B1 / 2, Trf*2)
seq += sample ? ADC(20, TE/2 - 1.5Trf) : Delay(TE/2 - 1.5Trf)
seq += RF(-90 * B1, Trf)
seq += Grad(8e-3, 6000e-6, 600e-6) #Spoiler3
if sample
seq += ADC(1, 1e-6)
end
return seq
end
function IR(IR_delay; sample=false)
# Generating HS pulse
# Based on: https://onlinelibrary.wiley.com/doi/epdf/10.1002/jmri.26021
# Params
flip_angle = 900; # Peak amplitude (deg)
Trf = 10240e-6; # Pulse duration (ms)
β = 6.7e2; # frequency modulation param (rad/s)
μ = 5; # phase modulation parameter (dimensionless)
fmax = μ * β / (2π); # 2fmax = BW
# RF pulse
t = range(-Trf/2, Trf/2, 201);
B1 = sech.(β .* t);
Δf = fmax .* tanh.(β .* t);
# Spoiler length
spoiler_time = 6000e-6
spoiler_rise_fall = 600e-6
# Prepulse
seq = Sequence()
seq += RF(B1, Trf, Δf) # FM modulated pulse
seq = (flip_angle / get_flip_angles(seq)[1] + 0.0im) * seq # RF scaling
seq += Grad(8e-3, spoiler_time, spoiler_rise_fall) #Spoiler3
if sample
seq += ADC(11, IR_delay - spoiler_time - 2spoiler_rise_fall)
else
seq += Delay(IR_delay - spoiler_time - 2spoiler_rise_fall)
end
return seq
end
function bSSFP(iNAV_lines, im_segments, iNAV_flip_angle, im_flip_angle; sample=false)
k = 0
seq = Sequence()
for i = 0 : iNAV_lines + im_segments - 1
if iNAV_lines != 0
m = (im_flip_angle - iNAV_flip_angle) / iNAV_lines
α = min( m * i + iNAV_flip_angle, im_flip_angle ) * (-1)^k
else
α = im_flip_angle * (-1)^k
end
seq += RF(α * B1, Trf)
if i < iNAV_lines && !sample
seq += Delay(TR - Trf)
else
seq += Delay(TE - Trf/2 - Tadc/2)
seq += ADC(1, Tadc)
seq += Delay(TR - TE - Tadc/2 - Trf/2)
end
k += 1
end
return seq
end
md"- Sequence building blocks: `T2prep`, `IR`, `FatSat`, `bSSFP` (show/hide code)"
end
# ╔═╡ 7890f81e-cb15-48d2-a80c-9d73f9516056
begin
function BOOST(
dummy_heart_beats,
iNAV_lines,
im_segments,
iNAV_flip_angle,
im_flip_angle,
T2prep_duration=50e-3,
IR_inversion_time=90e-3,
FatSat_flip_angle=180,
RR=1.0;
sample_recovery=zeros(Bool, dummy_heart_beats+1)
)
# Seq init
seq = Sequence()
for hb = 1 : dummy_heart_beats + 1
sample = sample_recovery[hb] # Sampling recovery curve for hb
# Generating seq blocks
t2p = T2prep(T2prep_duration; sample)
ir = IR(IR_inversion_time - iNAV_lines * TR - Trf - TE; sample)
fatsat = FatSat(FatSat_flip_angle, fat_freq; sample)
# Magnetization preparations
for contrast = 1:2
preps = Sequence()
if contrast == 1 # Bright-blood contrast
preps += t2p
preps += ir
else # Reference contrast
preps += fatsat
end
# Contrst dependant flip angle
bssfp = bSSFP(iNAV_lines, im_segments, iNAV_flip_angle,
im_flip_angle[contrast]; sample)
# Concatenating seq blocks
seq += preps
seq += bssfp
# RR interval consideration
RRdelay = RR - dur(bssfp) - dur(preps)
seq += sample ? ADC(80, RRdelay) : Delay(RRdelay)
end
end
return seq
end
md"""- `BOOST` (show/hide code)
```julia
# Seq init
seq = Sequence()
for hb = 1 : dummy_heart_beats + 1
# Generating seq blocks
t2p = T2prep(T2prep_duration)
ir = IR(IR_inversion_time)
fatsat = FatSat(FatSat_flip_angle, fat_freq)
# Magnetization preparations
for contrast = 1:2
preps = Sequence()
if contrast == 1 # Bright-blood contrast
preps += t2p
preps += ir
else # Reference contrast
preps += fatsat
end
# Contrst dependant flip angle
bssfp = bSSFP(iNAV_lines, im_segments, iNAV_flip_angle,
im_flip_angle[contrast]; sample)
# Concatenating seq blocks
seq += preps
seq += bssfp
# RR interval consideration
RRdelay = RR - dur(bssfp) - dur(preps)
seq += Delay(RRdelay)
end
end
```"""
end
# ╔═╡ f57a2b6c-eb4c-45bd-8058-4a60b038925d
begin
function cardiac_phantom(off; off_fat=fat_freq)
myocard = Phantom{Float64}(x=dx, ρ=0.6*ones(Niso), T1=701e-3*ones(Niso),
T2=58e-3*ones(Niso), Δw=2π*off*ones(Niso))
blood = Phantom{Float64}(x=dx, ρ=0.7*ones(Niso), T1=1122e-3*ones(Niso),
T2=263e-3*ones(Niso), Δw=2π*off*ones(Niso))
fat1 = Phantom{Float64}(x=dx, ρ=1.0*ones(Niso), T1=183e-3*ones(Niso),
T2=93e-3*ones(Niso), Δw=2π*(off_fat + off)*ones(Niso))
fat2 = Phantom{Float64}(x=dx, ρ=1.0*ones(Niso), T1=130e-3*ones(Niso),
T2=93e-3*ones(Niso), Δw=2π*(off_fat + off)*ones(Niso))
obj = myocard + blood + fat1 + fat2
return obj
end
md"- Cardiac phantom (show/hide code)"
end
# ╔═╡ f21e9e59-25c3-4f06-8de4-792cb305eb01
md"""# 2. Simulation
Two simulation experiments were performed to optimize the sequence parameters, (1) to optimize the imaging flip angle, and (2) to optimize the FatSat flip angle.
"""
# ╔═╡ eceb326a-cab6-465e-8e5c-e835881bd3b0
md"""
## 2.0. Magnetization dynamics
"""
# ╔═╡ d54d6807-444f-4e0e-8fd6-84457974115a
md"Here we show the magnetization dynamics of the myocardium, blood, and fat signals at 0.55T."
# ╔═╡ d05dcba7-2f42-47bf-a172-6123d0113b3f
sim_params = Dict{String,Any}(
"return_type"=>"mat",
"sim_method"=>BlochDict(save_Mz=true),
"Δt_rf"=>Trf,
"gpu"=>false,
"Nthreads"=>1
)
# ╔═╡ 37f7fd7f-5cb1-48b5-b877-b2bc23a1e7dd
begin
seq = BOOST(seq_params...; sample_recovery=ones(Bool, dummy_heart_beats+1))
obj = cardiac_phantom(0)
magnetization = @suppress simulate(obj, seq, sys; sim_params)
nothing # hide output
end
# ╔═╡ 0b6c1f72-b040-483c-969b-88bfe09b32c3
plot_seq(seq; range=[5990, 6280], slider=true)
# ╔═╡ 88eb41a5-d8c2-4f0e-b379-a8b05a341a82
plot_seq(seq; range=[6900, 7190], slider=true)
# ╔═╡ 1a62ae71-58db-49ea-ae6a-9aea66145963
begin
phantom_T1 = plot(
scatter(
x=obj.x * 1e3,
y=obj.T1 * 1e3,
mode="markers",
marker=attr(;
color=obj.T1 * 1e3,
colorscale=[
[0.0, "black"],
[183.0/maximum(obj.T1 .* 1e3), "green"],
[701.0/maximum(obj.T1 .* 1e3), "blue"],
[1122.0/maximum(obj.T1 .* 1e3), "red"],
],
cmin=0.0,
cmax=1122.0,
colorbar=attr(;ticksuffix="ms", title="T1"),
showscale=false
),
showlegend=false
)
)
relayout!(
phantom_T1,
yaxis_title="T1 [ms]",
xaxis_title="x [mm]",
xaxis_tickmode="array",
xaxis_tickvals=[-1.5/2, 0.0, 1.5/2],
yaxis_tickmode="array",
yaxis_tickvals=unique(obj.T1 * 1e3),
xaxis_range=[-1.5, 1.5],
yaxis_range=[0.0, 1200.0],
title="T1 map of 1D Phantom"
)
phantom_T2 = plot(
scatter(
x=obj.x * 1e3,
y=obj.T2 * 1e3,
mode="markers",
marker=attr(;
color=obj.T2 * 1e3,
colorscale=[
[0.0, "black"],
[58.0/maximum(obj.T2 .* 1e3), "blue"],
[93.0/maximum(obj.T2 .* 1e3), "green"],
[263.0/maximum(obj.T2 .* 1e3), "red"],
],
cmin=0.0,
cmax=263.0,
colorbar=attr(;ticksuffix="ms", title="T2"),
showscale=false
),
showlegend=false
)
)
relayout!(
phantom_T2,
yaxis_title="T2 [ms]",
xaxis_title="x [mm]",
xaxis_tickmode="array",
xaxis_tickvals=[-1.5/2, 0.0, 1.5/2],
yaxis_tickmode="array",
yaxis_tickvals=unique(obj.T2 * 1e3),
xaxis_range=[-1.5, 1.5],
yaxis_range=[0.0, 300.0],
title="T2 map of 1D Phantom"
)
[phantom_T1 phantom_T2]
end
# ╔═╡ d9715bc1-49cd-4df8-8dbf-c06de42ad550
begin
# Prep plots
labs = ["Myocardium", "Blood", "Fat"]
cols = ["blue", "red", "green"]
spin_group = [(1:Niso)', (Niso+1:2Niso)', (2Niso+1:3Niso)']
t = KomaMRICore.get_adc_sampling_times(seq)
Mxy(i) = abs.(sum(magnetization[:,spin_group[i],1,1][:,1,:],dims=2)[:]/length(spin_group[i]))
Mz(i) = real.(sum(magnetization[:,spin_group[i],2,1][:,1,:],dims=2)[:]/length(spin_group[i]))
# Plot
p0 = make_subplots(
rows=2,
cols=1,
subplot_titles=["Mxy" "Mz" "Sequence"],
shared_xaxes=true,
vertical_spacing=0.1
)
for i=eachindex(spin_group)
p1 = scatter(
x=t, y=Mxy(i),
name=labs[i],
legendgroup=labs[i],
marker_color=cols[i]
)
p2 = scatter(
x=t,
y=Mz(i),
name=labs[i],
legendgroup=labs[i],
showlegend=false,
marker_color=cols[i]
)
add_trace!(p0, p1, row=1, col=1)
add_trace!(p0, p2, row=2, col=1)
end
relayout!(p0,
yaxis_range=[0, 0.4],
xaxis_range=[RR*dummy_heart_beats, RR*dummy_heart_beats+.250]
)
p0
end
# ╔═╡ 8dd704a4-bf50-4ddc-a832-d074bd52ad01
md"Three heartbeats per contrast were considered to achieve steady-state and the fourth heartbeat for each contrast was used to measure the magnetization results in the next sections."
# ╔═╡ 39f44025-2974-4c4c-b0c2-e21399bbdb1f
md"""
## 2.1. Reference contrast SNR: Flip angle optimization
For the first simulation experiment, SNR was maximized by varying the imaging flip angle (between 20 and 180 deg). To optimize SNR independently of heart rate, multiple heart rates (between 55 and 85 bpm) were simulated and the mean and standard deviation of the obtained blood signal were calculated.
"""
# ╔═╡ 7b9ae381-d0fc-4d1d-b1ee-ad31a6445ff6
begin
FAs = 20:10:180 # flip angle [deg]
RRs = 60 ./ (55:10:85) # RR [s]
mag1 = zeros(ComplexF64, im_segments, Niso*4, length(FAs), length(RRs))
@progress for (m, RR) = enumerate(RRs), (n, α) = enumerate(FAs)
seq_params1 = merge(seq_params, (; im_flip_angle=[110, α], RR))
sim_params1 = merge(sim_params, Dict("sim_method"=>BlochDict()))
seq1 = BOOST(seq_params1...)
obj1 = cardiac_phantom(0)
magaux = @suppress simulate(obj1, seq1, sys; sim_params=sim_params1)
mag1[:, :, n, m] .= magaux[end-im_segments+1:end, :] # Last heartbeat
end
end
# ╔═╡ d0377f9a-680d-4501-90ca-9ea3ab681db4
md"""## 2.2. Reference contrast fat: FatSat flip angle optimization
For the second simulation experiment, the fat signal was minimized by varying the FatSat flip angle (between 20 and 250 deg) using six iNAV readouts (identified experimentally to result in good fat suppression). To be robust to $B_0$ inhomogeneities, multiple simulations with tissue frequency shifts (between $-1$ and $1\,\mathrm{ppm}$, twice of what was reported by Restivo et al.) were performed, and the mean and standard deviation of the obtained fat signal were calculated."""
# ╔═╡ d750cd5a-3c90-41ea-9942-5723a21da60a
begin
FFAs = 20:20:250 # flip angle [deg]
Δfs = (-1:0.2:1) .* (γ * sys.B0 * 1e-6) # off-resonance Δf [s]
mag2 = zeros(ComplexF64, im_segments, Niso*4, length(FFAs), length(Δfs))
@progress for (m, Δf) = enumerate(Δfs), (n, FatSat_flip_angle) = enumerate(FFAs)
seq_params2 = merge(seq_params, (; FatSat_flip_angle))
sim_params2 = merge(sim_params, Dict("sim_method"=>BlochDict()))
seq2 = BOOST(seq_params2...)
obj2 = cardiac_phantom(Δf)
magaux = @suppress simulate(obj2, seq2, sys; sim_params=sim_params2)
mag2[:, :, n, m] .= magaux[end-im_segments+1:end, :] # Last heartbeat
end
end
# ╔═╡ b0b53632-e6b8-47e9-8d3e-79f1e599315a
md" ## 2.3. Bright-blood SNR:"
# ╔═╡ 14cf6859-a4b9-4671-b022-659781c55144
begin
mag4 = zeros(ComplexF64, im_segments, Niso*4, length(FAs), length(RRs))
@progress for (m, RR) = enumerate(RRs), (n, α) = enumerate(FAs)
seq_params4 = merge(seq_params, (; im_flip_angle=[α, 80], RR))
sim_params4 = merge(sim_params, Dict("sim_method"=>BlochDict()))
seq4 = BOOST(seq_params4...)
obj4 = cardiac_phantom(0)
magaux = @suppress simulate(obj4, seq4, sys; sim_params=sim_params4)
mag4[:, :, n, m] .= magaux[end-2im_segments+1:end-im_segments, :] # Bright-Blood
end
end
# ╔═╡ c64d38cb-2433-4b90-abbf-1fc938f70584
md"## 2.4. Bright-Blood fat: Inversion delay"
# ╔═╡ c952ecf1-25ef-4b48-9c8f-e53ded302629
begin
TIs = (50:10:130) # Inversion delay [ms]
mag3 = zeros(ComplexF64, im_segments, Niso*4, length(TIs), length(Δfs))
@progress for (m, Δf) = enumerate(Δfs), (n, TI) = enumerate(TIs)
seq_params3 = merge(seq_params, (; IR_inversion_time=TI * 1e-3, RR))
sim_params3 = merge(sim_params, Dict("sim_method"=>BlochDict()))
seq3 = BOOST(seq_params3...)
obj3 = cardiac_phantom(Δf)
magaux = @suppress simulate(obj3, seq3, sys; sim_params=sim_params3)
mag3[:, :, n, m] .= magaux[end-2im_segments+1:end-im_segments, :] # Bright-Blood
end
end
# ╔═╡ 85834365-238b-4193-a0c0-d1859416ab6c
md" ## 2.5. Bright-blood contrast: T2prep duration"
# ╔═╡ 50b551d8-a212-4319-b25b-1f8ecdd2a491
begin
T2ps = (20:10:80) # T2prep duration [ms]
mag5bb = zeros(ComplexF64, im_segments, Niso*4, length(T2ps), length(RRs))
mag5rf = zeros(ComplexF64, im_segments, Niso*4, length(T2ps), length(RRs))
@progress for (m, RR) = enumerate(RRs), (n, T2p) = enumerate(T2ps)
seq_params5 = merge(seq_params, (; T2prep_duration=T2p * 1e-3, RR))
sim_params5 = merge(sim_params, Dict("sim_method"=>BlochDict()))
seq5 = BOOST(seq_params5...)
obj5 = cardiac_phantom(0)
magaux = @suppress simulate(obj5, seq5, sys; sim_params=sim_params5)
# Bright-Blood
mag5bb[:, :, n, m] .= magaux[end-2im_segments+1:end-im_segments, :]
# Reference contrast
mag5rf[:, :, n, m] .= magaux[end-im_segments+1:end, :]
end
end
# ╔═╡ 4b1dc8bf-feb1-42b4-94f7-1b27975d944c
md"## 2.6. Black-blood contrast: T2prep duration"
# ╔═╡ 8dc11175-ebc8-407a-ab0b-6d543f849a72
begin
# Labels
labels = ["Myocardium", "Blood", "Fat (T₁=183 ms)", "Fat (T₁=130 ms)"]
colors = ["blue", "red", "green", "purple"]
spins = [(1:Niso)', ((Niso + 1):(2Niso))', ((2Niso + 1):(3Niso))', ((3Niso + 1):(4Niso))']
mean(x, dim) = sum(x; dims=dim) / size(x, dim)
std(x, dim; mu=mean(x, dim)) = sqrt.(sum(abs.(x .- mu) .^ 2; dims=dim) / (size(x, dim) - 1))
md"Aux functions (show/hide code)"
end
# ╔═╡ f73082ff-a6d3-41f8-8796-4114fa89d2bb
begin
# Reducing tissues's signal
signal_myoc = reshape(
mean(abs.(mean(mag1[:, spins[1], :, :], 3)), 1), length(FAs), length(RRs)
)
signal_bloo = reshape(
mean(abs.(mean(mag1[:, spins[2], :, :], 3)), 1), length(FAs), length(RRs)
)
diff_bloo_myoc = abs.(signal_bloo .- signal_myoc)
# Mean
mean_myoc = mean(signal_myoc, 2)
mean_bloo = mean(signal_bloo, 2)
mean_diff = mean(diff_bloo_myoc,2)
# Std
std_myoc = std(signal_myoc, 2)
std_bloo = std(signal_bloo, 2)
std_diff = std(diff_bloo_myoc,2)
# Plotting results
# Mean
s1 = scatter(;
x=FAs,
y=mean_myoc[:],
name=labels[1],
legendgroup=labels[1],
line=attr(; color=colors[1]),
)
s2 = scatter(;
x=FAs,
y=mean_bloo[:],
name=labels[2],
legendgroup=labels[2],
line=attr(; color=colors[2]),
)
s3 = scatter(;
x=FAs,
y=mean_diff[:],
name="|Blood-Myoc|",
legendgroup="|Blood-Myoc|",
line=attr(color=colors[4])
)
# Std
s4 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_myoc .- std_myoc)[:]; reverse((mean_myoc .+ std_myoc)[:])],
name=labels[1],
legendgroup=labels[1],
showlegend=false,
fill="toself",
fillcolor="rgba(0,0,255,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none"
)
s5 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_bloo .- std_bloo)[:]; reverse((mean_bloo .+ std_bloo)[:])],
name=labels[2],
legendgroup=labels[2],
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none"
)
s6 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_diff .- std_diff)[:]; reverse((mean_diff .+ std_diff)[:])],
name="|Blood-Myoc|",legendgroup="|Blood-Myoc|",
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,255,0.2)",
line=attr(color="rgba(0,0,0,0)"),
hoverinfo="none"
)
# Plots
fig = plot([s1, s2, s3, s4, s5, s6])
relayout!(
fig;
yaxis=attr(; title="Signal [a.u.]", tickmode="array"),
xaxis=attr(;
title="Flip angle [deg]",
tickmode="array",
tickvals=[FAs[1], 80, 110, 130, FAs[end]],
constrain="domain",
),
font=attr(; family="CMU Serif", size=16, scaleanchor="x", scaleratio=1),
yaxis_range=[0, 0.3],
xaxis_range=[FAs[1], FAs[end]],
width=600,
height=400,
hovermode="x unified",
)
fig
end
# ╔═╡ 44a31057-7b34-4c80-a273-6621c0773dc7
begin
## Calculating results
signal_myoc2 = reshape(
mean(abs.(mean(mag2[:, spins[1], :, :], 3)), 1), length(FFAs), length(Δfs)
)
signal_bloo2 = reshape(
mean(abs.(mean(mag2[:, spins[2], :, :], 3)), 1), length(FFAs), length(Δfs)
)
signal_fat2 = reshape(
mean(abs.(mean(mag2[:, spins[3], :, :], 3)), 1), length(FFAs), length(Δfs)
)
signal_fat22 = reshape(
mean(abs.(mean(mag2[:, spins[4], :, :], 3)), 1), length(FFAs), length(Δfs)
)
mean_myoc2 = mean(signal_myoc2, 2)
mean_bloo2 = mean(signal_bloo2, 2)
mean_fat2 = mean(signal_fat2, 2)
mean_fat22 = mean(signal_fat22, 2)
std_myoc2 = std(signal_myoc2, 2)
std_bloo2 = std(signal_bloo2, 2)
std_fat2 = std(signal_fat2, 2)
std_fat22 = std(signal_fat22, 2)
# Plotting results
# Mean
s12 = scatter(;
x=FFAs,
y=mean_myoc2[:],
name=labels[1],
legendgroup=labels[1],
line=attr(; color=colors[1]),
)
s22 = scatter(;
x=FFAs,
y=mean_bloo2[:],
name=labels[2],
legendgroup=labels[2],
line=attr(; color=colors[2]),
)
s32 = scatter(;
x=FFAs,
y=mean_fat2[:],
name=labels[3],
legendgroup=labels[3],
line=attr(; color=colors[3]),
)
s52 = scatter(;
x=FFAs,
y=mean_fat22[:],
name=labels[4],
legendgroup=labels[4],
line=attr(; color=colors[3], dash="dash"),
)
# Std
s42 = scatter(;
x=[FFAs; reverse(FFAs)],
y=[(mean_myoc2 .- std_myoc2)[:]; reverse((mean_myoc2 .+ std_myoc2)[:])],
name=labels[1],
legendgroup=labels[1],
showlegend=false,
fill="toself",
fillcolor="rgba(0,0,255,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s62 = scatter(;
x=[FFAs; reverse(FFAs)],
y=[(mean_bloo2 .- std_bloo2)[:]; reverse((mean_bloo2 .+ std_bloo2)[:])],
name=labels[2],
legendgroup=labels[2],
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s72 = scatter(;
x=[FFAs; reverse(FFAs)],
y=[(mean_fat2 .- std_fat2)[:]; reverse((mean_fat2 .+ std_fat2)[:])],
name=labels[3],
legendgroup=labels[3],
showlegend=false,
fill="toself",
fillcolor="rgba(0,255,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s82 = scatter(;
x=[FFAs; reverse(FFAs)],
y=[(mean_fat22 .- std_fat22)[:]; reverse((mean_fat22 .+ std_fat22)[:])],
name=labels[4],
legendgroup=labels[4],
showlegend=false,
fill="toself",
fillcolor="rgba(0,255,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
# Plots
fig2 = plot([s12, s22, s32, s42, s52, s62, s72, s82])
relayout!(
fig2;
yaxis=attr(; title="Signal [a.u.]", tickmode="array"),
xaxis=attr(;
title="FatSat flip angle [deg]",
tickmode="array",
tickvals=[FFAs[1], 130, 150, 180, FFAs[end]],
constrain="domain",
),
font=attr(; family="CMU Serif", size=16, scaleanchor="x", scaleratio=1),
yaxis_range=[0, 0.4],
xaxis_range=[FFAs[1], FFAs[end]],
width=600,
height=400,
hovermode="x unified",
)
fig2
end
# ╔═╡ 6649f46e-3565-4cd6-86a5-9b03d00cc3db
begin
# Reducing tissues's signal
signal_myoc4 = reshape(
mean(abs.(mean(mag4[:, spins[1], :, :], 3)), 1), length(FAs), length(RRs)
)
signal_bloo4 = reshape(
mean(abs.(mean(mag4[:, spins[2], :, :], 3)), 1), length(FAs), length(RRs)
)
diff_bloo_myoc4 = abs.(signal_bloo4 .- signal_myoc4)
# Mean
mean_myoc4 = mean(signal_myoc4, 2)
mean_bloo4 = mean(signal_bloo4, 2)
mean_diff4 = mean(diff_bloo_myoc4,2)
# Std
std_myoc4 = std(signal_myoc4, 2)
std_bloo4 = std(signal_bloo4, 2)
std_diff4 = std(diff_bloo_myoc4,2)
# Plotting results
# Mean
s14 = scatter(;
x=FAs,
y=mean_myoc4[:],
name=labels[1],
legendgroup=labels[1],
line=attr(; color=colors[1]),
)
s24 = scatter(;
x=FAs,
y=mean_bloo4[:],
name=labels[2],
legendgroup=labels[2],
line=attr(; color=colors[2]),
)
s34 = scatter(;
x=FAs,
y=mean_diff4[:],
name="|Blood-Myoc|",
legendgroup="|Blood-Myoc|",
line=attr(color=colors[4])
)
# Std
s44 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_myoc4 .- std_myoc4)[:]; reverse((mean_myoc4 .+ std_myoc4)[:])],
name=labels[1],
legendgroup=labels[1],
showlegend=false,
fill="toself",
fillcolor="rgba(0,0,255,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none"
)
s54 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_bloo4 .- std_bloo4)[:]; reverse((mean_bloo4 .+ std_bloo4)[:])],
name=labels[2],
legendgroup=labels[2],
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none"
)
s64 = scatter(;
x=[FAs; reverse(FAs)],
y=[(mean_diff4 .- std_diff4)[:]; reverse((mean_diff4 .+ std_diff4)[:])],
name="|Blood-Myoc|",legendgroup="|Blood-Myoc|",
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,255,0.2)",
line=attr(color="rgba(0,0,0,0)"),
hoverinfo="none"
)
# Plots
fig4 = plot([s14, s24, s34, s44, s54, s64])
relayout!(
fig4;
yaxis=attr(; title="Signal [a.u.]", tickmode="array"),
xaxis=attr(;
title="Flip angle [deg]",
tickmode="array",
tickvals=[FAs[1], 110, FAs[end]],
constrain="domain",
),
font=attr(; family="CMU Serif", size=16, scaleanchor="x", scaleratio=1),
yaxis_range=[0, 0.3],
xaxis_range=[FAs[1], FAs[end]],
width=600,
height=400,
hovermode="x unified",
)
fig4
end
# ╔═╡ a8751a97-c131-407b-b211-573660452142
begin
## Calculating results
signal_myoc3 = reshape(
mean(abs.(mean(mag3[:, spins[1], :, :], 3)), 1), length(TIs), length(Δfs)
)
signal_bloo3 = reshape(
mean(abs.(mean(mag3[:, spins[2], :, :], 3)), 1), length(TIs), length(Δfs)
)
signal_fat3 = reshape(
mean(abs.(mean(mag3[:, spins[3], :, :], 3)), 1), length(TIs), length(Δfs)
)
signal_fat33 = reshape(
mean(abs.(mean(mag3[:, spins[4], :, :], 3)), 1), length(TIs), length(Δfs)
)
mean_myoc3 = mean(signal_myoc3, 2)
mean_bloo3 = mean(signal_bloo3, 2)
mean_fat3 = mean(signal_fat3, 2)
mean_fat33 = mean(signal_fat33, 2)
std_myoc3 = std(signal_myoc3, 2)
std_bloo3 = std(signal_bloo3, 2)
std_fat3 = std(signal_fat3, 2)
std_fat33 = std(signal_fat33, 2)
# Plotting results
# Mean
s13 = scatter(;
x=TIs,
y=mean_myoc3[:],
name=labels[1],
legendgroup=labels[1],
line=attr(; color=colors[1]),
)
s23 = scatter(;
x=TIs,
y=mean_bloo3[:],
name=labels[2],
legendgroup=labels[2],
line=attr(; color=colors[2]),
)
s33 = scatter(;
x=TIs,
y=mean_fat3[:],
name=labels[3],
legendgroup=labels[3],
line=attr(; color=colors[3]),
)
s53 = scatter(;
x=TIs,
y=mean_fat33[:],
name=labels[4],
legendgroup=labels[4],
line=attr(; color=colors[3], dash="dash"),
)
# Std
s43 = scatter(;
x=[TIs; reverse(TIs)],
y=[(mean_myoc3 .- std_myoc3)[:]; reverse((mean_myoc3 .+ std_myoc3)[:])],
name=labels[1],
legendgroup=labels[1],
showlegend=false,
fill="toself",
fillcolor="rgba(0,0,255,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s63 = scatter(;
x=[TIs; reverse(TIs)],
y=[(mean_bloo3 .- std_bloo3)[:]; reverse((mean_bloo3 .+ std_bloo3)[:])],
name=labels[2],
legendgroup=labels[2],
showlegend=false,
fill="toself",
fillcolor="rgba(255,0,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s73 = scatter(;
x=[TIs; reverse(TIs)],
y=[(mean_fat3 .- std_fat3)[:]; reverse((mean_fat3 .+ std_fat3)[:])],
name=labels[3],
legendgroup=labels[3],
showlegend=false,
fill="toself",
fillcolor="rgba(0,255,0,0.2)",
line=attr(; color="rgba(0,0,0,0)"),
hoverinfo="none",
)
s83 = scatter(;
x=[TIs; reverse(TIs)],