In which I use MetaPost to generate publication quality pulse sequence diagrams...
Pulse sequences are the series of radio-frequency pulses required to generate an MR image. If you are an MR Physicist you will see these a lot and probably wondered how can I generate nice pulse sequences for my thesis, papers etc. Well handily using MetaPost and these files you can! First install Tex Live*:
sudo USE="doc dvi2tty dvipdfm extra games graphics music png pstricks science truetype X" emerge -av texlive
Then install MetaPost:
sudo emerge -av metapost
Then ensure you have all the necessary files from CTAN which aren't installed alongside metapost†:
mkdir ~/texmf
mkdir ~/texmf/metapost
cd ~/texmf/metapost
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/README
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/TEX.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/boxes.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/format.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/graph.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/marith.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/mfplain.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/mpost.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/plain.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/rboxes.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/sarith.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/string.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/texnum.mp
wget http://mirrors.ctan.org/graphics/metapost/base/texmf/metapost/base/troffnum.mp
Do this in /usr/share/texmf to allow all users to access the files. Finally, download the pulse sequence files from http://www.celos.net/comp/pulses/ to the directory you intend to run MetaPost from.
Now write your pulse sequence into a metapost file. Below is an example of a generic FLASH sequence - basically treat each part of your sequence as a line and follow the documentation in the pulse.mp file:
%FLASH sequence
beginfig(1);
input pulses.mp;
initf;
startline(rf,"RF");
xline(2);
xpulse(1,1,"");
xline(6);
startline(g0,"Gx");
xline(1);
xsquare(2,0.5);
xsquare(1,-0.5);
xline(5);
startline(g1,"Gy");
xline(3);
xtable(1,0.8,5, -1);
xline(5);
startline(g2,"Gz");
xline(3);
xsquare(2,-0.5);
xsquare(3,0.5);
xline(1);
endfig;
end;
The section below if added after the image but before endfig; will add a white background instead of a transparent one.
% save image to temp variable
picture pic;
pic := currentpicture;
% clear image currentpicture := nullpicture;
% fill a bounding pox of pic with color
fill bbox pic withcolor white;
% re-draw pic ontop
draw pic;
If you have ImageMagick installed you can easily convert the image to a png or similar for use in Windows or uploading to your blog:
convert -density 300 flash.1 flash.png
You should end up with a nice pulse sequence diagram:
*Gentoo installation shown
†Gentoo doesn't pull in these files and I found the solution here: http://tiaozhanshu.com/doc/funtoo/metapost
Tom Out!
P.S. Now a Major Github repository! https://github.com/tawilkinson/pulses
References
[1] Haase, A., et al. (1986) FLASH Imaging. Rapid NMR Imaging Using Low Flip-Angle Pulses. Journal of Magnetic Resonance, 67, pp 258-66.