Celos.Net
Pulse sequences
[Updated: Mark on 15 Sep 2008]

Sequence diagrams with MetaPost

As an MRI person I fairly often find myself drawing sequence timing diagrams. I've written a set of macros for MetaPost for doing this job. It's swings and roundabouts as to whether you prefer a GUI drawing package (try inkscape) for these, but I find they're easy and fast to describe as a series of objects along a line.

If you want to try it, download pulses.mp and the set of example diagrams in seq.mp. Many TeX installations come with MetaPost (usually called mpost), so you might well have it already. The package certainly isn't complete -- I've added elements as I've needed them -- but it might be a useful starting place. You're free to use, modify or copy the files in any way you like, as long as you credit me with copyright and authorship for the bits I wrote, and understand that it comes without any kind of guarantee. You're also welcome to send me comments - you can find my email address on the contact page.

Examples

Diagram are built up by accumulating objects along each line; most objects are scaled from 1 unit size. There are several more examples in seq.mp, including at least one use of every macro, I think. The easiest way to find out what the arguments do is probably to look in pulses.mp.

Here's an example fragment showing a gradient echo:

MetaPost source:

      % Gradient echo fragment
      beginfig(2);

          initf;

          startline(rf,"RF");
          xline(1);
          xpulse(1,1,"a" infont "Symbol");
          ospan(-0.5,-1.5,4,"TE");
          ospan(-0.5,-2,2,"TE/2");
          xline(2);
          oecho(1.5);
          xacq(3);
          xline(2);

          startline(g0,"Gx");
          xline(1.5);
          oshade(0,2,-0.5);
          xsquare(2,-0.5);
          oshade(0,2,0.5);
          oguide(2,2);
          xsquare(4,0.5);
          xline(1.5);

      endfig;
    

Another example, illustrating a simple schematic multislice spin echo sequence:

MetaPost source:

      % Multislice SE volume acquisition - outline of sequence
      beginfig(6);

          initf;

          startline(rf,"RF");
          xline(1);
          ospan(0.5,-1.8,4,"TE/2");
          xpulse(1,1,"a" infont "Symbol");
          xline(3);
          ospan(0.5,-1.8,4,"TE/2");
          xpulse(1,1.6,"180");
          xline(2);
          oecho(1.5);
          xacq(3);
          xline(1);

          startline(g0,"Gx");
          xline(2.5);
          ospan(0,-0.4,2,"Tr/2");
          xsquare(2,0.5);
          xline(3);
          ospan(0,-0.4,4,"Tr");
          xsquare(4,0.5);
          xline(0.5);

          startline(g1,"Gy");
          xline(2.5);
          ospan(0,-1.2,2,"Tp");
          xtable(2,0.8,5,-1);
          xline(7.5);
          
          startline(g2,"Gz");
          xline(0.5);
          ospan(0,-1.1,2,"Ts");
          xsquare(2,0.5);
          ospan(0,-1.1,1,"Ts/2");
          xsquare(1,-0.5);
          xline(8.5);

      endfig;