Skip to content

Commit 2cd4411

Browse files
authored
Fix ADC Pulseq raster timing (#756)
1 parent 7e2730f commit 2cd4411

6 files changed

Lines changed: 20 additions & 17 deletions

File tree

KomaMRIBase/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "KomaMRIBase"
22
uuid = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
33

4-
version = "0.10.0"
4+
version = "0.10.1"
55
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
66

77
[workspace]

KomaMRIBase/src/datatypes/sequence/TimingChecks.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ function _check_adc_dwell(dwell, raster, block_id)
131131
error("Block $block_id ADC dwell ($(dwell) s) is not aligned to raster $(raster) s.")
132132
end
133133

134-
function _check_adc_timing(adc, raster, block_id)
134+
function _check_adc_timing(adc, adc_raster, rf_raster, block_id)
135135
dwell = adc.N == 1 ? adc.T : adc.T / (adc.N - 1)
136-
_check_adc_dwell(dwell, raster, block_id)
136+
_check_adc_dwell(dwell, adc_raster, block_id)
137137
adc.delay + PULSEQ_TIME_TOL >= dwell / 2 || error("Block $block_id ADC delay ($(adc.delay) s) is smaller than dwell/2 ($(dwell / 2) s).")
138-
_check_raster_multiple(adc.delay - dwell / 2, raster, block_id, "ADC delay")
138+
_check_raster_multiple(adc.delay - dwell / 2, rf_raster, block_id, "ADC delay")
139139
return nothing
140140
end
141141

@@ -169,7 +169,7 @@ function check_timing(seq::Sequence, raster::NamedTuple)
169169
_check_grad_timing(gr, raster.GradientRasterTime, i, name)
170170
end
171171
adc = seq.ADC[i]
172-
is_ADC_on(adc) && _check_adc_timing(adc, raster.AdcRasterTime, i)
172+
is_ADC_on(adc) && _check_adc_timing(adc, raster.AdcRasterTime, raster.RadiofrequencyRasterTime, i)
173173
end
174174
return nothing
175175
end

KomaMRIBase/test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,14 @@ using TestItems, TestItemRunner
941941
@addblock compact_adc += (ADC(2, 100e-9, 50e-9), Duration(10e-6))
942942
@test isnothing(check_timing(compact_adc))
943943
adc_raster_seq = Sequence(Scanner(RF_Δt=10e-6, ADC_Δt=100e-9))
944-
@addblock adc_raster_seq += (ADC(111, 4.4e-6 * 110, 151e-6), Duration(650e-6))
944+
@addblock adc_raster_seq += (ADC(111, 4.4e-6 * 110, 152.2e-6), Duration(650e-6))
945945
@test isnothing(check_timing(adc_raster_seq))
946+
adc_bad_dwell = Sequence(Scanner(ADC_Δt=100e-9))
947+
@addblock adc_bad_dwell += (ADC(2, 150e-9, 75e-9), Duration(10e-6))
948+
@test_throws ErrorException check_timing(adc_bad_dwell)
949+
adc_bad_delay = Sequence(Scanner(RF_Δt=10e-6, ADC_Δt=100e-9))
950+
@addblock adc_bad_delay += (ADC(2, 100e-9, 150e-9), Duration(10e-6))
951+
@test_throws ErrorException check_timing(adc_bad_delay)
946952
seq_bad = Sequence()
947953
@addblock seq_bad += RF(1e-6, 10.5e-6)
948954
@test_throws ErrorException check_timing(seq_bad)

KomaMRIFiles/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "KomaMRIFiles"
22
uuid = "fcf631a6-1c7e-4e88-9e64-b8888386d9dc"
33

4-
version = "0.10.1"
4+
version = "0.10.2"
55
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
66

77
[workspace]

KomaMRIFiles/src/Sequence/pulseq/WritePulseq.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ function quantize_adc!(adc, raster, block_id, warn_count)
991991
qt(value, field; step, step_name) =
992992
quantize_time_value(value, step, warn_ctx, field; step_name)
993993
dwell = adc.N == 1 ? adc.T : adc.T / (adc.N - 1)
994-
dwell = qt(dwell, :dwell_time; step=1e-9, step_name=:nanoseconds)
994+
dwell = qt(dwell, :dwell_time; step=raster.AdcRasterTime, step_name=:AdcRasterTime)
995995
adc.T = adc.N == 1 ? dwell : (adc.N - 1) * dwell
996996
pulseq_delay = adc.delay - dwell / 2
997997
if pulseq_delay < 0
@@ -1001,7 +1001,7 @@ This means the Koma delay must be >= dwell/2. Clamping it to this minimum value.
10011001
See https://pulseq.github.io/pulseq_shapes_and_times.pdf#page=10"
10021002
pulseq_delay = 0
10031003
end
1004-
pulseq_delay = qt(pulseq_delay, :pulseq_delay; step=1e-6, step_name=:microseconds)
1004+
pulseq_delay = qt(pulseq_delay, :pulseq_delay; step=raster.RadiofrequencyRasterTime, step_name=:RadiofrequencyRasterTime)
10051005
adc.delay = pulseq_delay + dwell / 2
10061006
return adc.delay + adc.T + dwell / 2
10071007
end

KomaMRIFiles/test/runtests.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,17 @@ end
261261
generated_prefix = "koma-generated-"
262262
pth = joinpath(@__DIR__, "test_files/pulseq/read_comparison/")
263263
versions = ["v1.2", "v1.3", "v1.4", "v1.5"]
264-
constraint_sys = Scanner(B1=1.0, Gmax=100.0, Smax=1e12, ADC_Δt=100e-9)
265264
mktempdir() do tmpdir
266265
for v in versions
267266
pulseq_files = filter(endswith(".seq"), readdir(pth * v)) .|> x -> splitext(x)[1]
268267
for pulseq_file in pulseq_files
269268
label = "$v/$pulseq_file"
270-
seq = @suppress read_seq("$pth$v/$pulseq_file.seq")
269+
seq = read_seq("$pth$v/$pulseq_file.seq"; verbose=false)
271270
filename = joinpath(tmpdir, "$(generated_prefix)$(v)-$(pulseq_file).seq")
272-
if occursin("JEMRIS", label) || occursin("gammaSTAR", label)
273-
@suppress write_seq(seq, filename; check_timing=false)
274-
else
275-
@suppress write_seq(seq, filename; sys=constraint_sys)
276-
end
277-
seq2 = @suppress read_seq(filename)
271+
# Legacy JEMRIS files omit AdcRasterTime but use 1 ns dwell precision.
272+
occursin("JEMRIS", label) && (seq.DEF["AdcRasterTime"] = 1e-9)
273+
write_seq(seq, filename; verbose=false)
274+
seq2 = read_seq(filename; verbose=false)
278275
@testset "$label" begin
279276
@test seq2 seq
280277
end

0 commit comments

Comments
 (0)