From 77a28fe08455a7f7f4a18b79da674f9416c63f44 Mon Sep 17 00:00:00 2001
From: Michiel Cottaar <MichielCottaar@protonmail.com>
Date: Thu, 25 Jul 2024 12:12:29 +0100
Subject: [PATCH] BF: Interpret zero-length ADC as SingleReadout

---
 src/build_sequences.jl    |  2 +-
 src/sequence_io/pulseq.jl | 16 ++++++++++------
 test/test_IO.jl           |  3 ++-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/build_sequences.jl b/src/build_sequences.jl
index 2d5487f..0b78486 100644
--- a/src/build_sequences.jl
+++ b/src/build_sequences.jl
@@ -23,7 +23,7 @@ Within the code block you can create one or more sequences, e.g.
 seq = Sequence(
     SincPulse(flip_angle=90, phase=0, duration=2., bandwidth=:max)
     nothing.,
-    InstantReadout
+    SingleReadout
 )
 ```
 
diff --git a/src/sequence_io/pulseq.jl b/src/sequence_io/pulseq.jl
index 6efec6f..5f84e23 100644
--- a/src/sequence_io/pulseq.jl
+++ b/src/sequence_io/pulseq.jl
@@ -6,7 +6,7 @@ import Interpolations: linear_interpolation
 import ..PulseqIO.Types: PulseqSequence, PulseqBlock, PulseqTrapezoid, PulseqGradient, PulseqRFPulse, PulseqShape, PulseqADC
 import ..PulseqIO.Extensions: parse_extension, get_extension_name, add_extension_definition!, PulseqExtension, PulseqExtensionDefinition
 import ...Containers: Sequence, BuildingBlock, BaseBuildingBlock, events, waveform, iter_blocks, start_time
-import ...Components: GenericPulse, ADC, RFPulseComponent, InstantPulse, InstantGradient, InstantGradient3D
+import ...Components: GenericPulse, ADC, RFPulseComponent, InstantPulse, InstantGradient, InstantGradient3D, SingleReadout
 import ...Scanners: Scanner
 import ...Variables: variables, make_generic
 
@@ -44,11 +44,15 @@ function BuildingBlock(pulseq::PulseqBlock; version, BlockDurationRaster, Radiof
         dwell_time = pulseq.adc.dwell * 1e-6
         push!(events, (
             pulseq.adc.delay * 1e-3,
-            ADC(
-                pulseq.adc.num,
-                dwell_time,
-                dwell_time * pulseq.adc.num / 2,
-                1.
+            (
+                iszero(dwell_time) ?
+                SingleReadout() :
+                ADC(
+                    pulseq.adc.num,
+                    dwell_time,
+                    dwell_time * pulseq.adc.num / 2,
+                    1.
+                )
             )
         ))
     end
diff --git a/test/test_IO.jl b/test/test_IO.jl
index 4fa3199..12c10ef 100644
--- a/test/test_IO.jl
+++ b/test/test_IO.jl
@@ -108,7 +108,7 @@
                 end
             end
         end
-        @testset "check that format $(format) works for some sequences with instant pulses/gradients" begin
+        @testset "check that format $(format) works for some sequences with instant pulses/gradients/readouts" begin
             for seq_orig in [
                 DWI(TE=80., bval=2., scanner=Siemens_Connectom),
                 DWI(TE=80., bval=2., scanner=Siemens_Terra, gradient=(type=:instant, )),
@@ -123,6 +123,7 @@
                 @test all(isapprox.(variables.duration.(seq_orig), variables.duration.(seq_json), atol=1e-5))
                 @test length(iter_instant_gradients(seq_json)) == length(iter_instant_gradients(seq_json))
                 @test length(iter_instant_pulses(seq_json)) == length(iter_instant_pulses(seq_json))
+                @test length(variables.readout_times(seq_orig)) == length(variables.readout_times(seq_json))
                 @test all(isapprox.(variables.readout_times(seq_orig), variables.readout_times(seq_json), atol=1e-5))
             end
         end
-- 
GitLab