Print

Print


Dear Charlotte,

I've previously written a little script to do this which I'm including below.
The displacements are always relative to the first timepoint (assuming the
reference_no of 0 was used in eddy_correct) but apart from that it is
pretty general.

If you run it you just need to give it the name of the .ecclog file (it also
assumes the original data has the same - without the .ecclog extension).
It will then produce ec_disp.png, ec_rot.png and ec_trans.png images
and the associated .txt files with the numbers in them.

Let me know if you have any trouble running it.
You should just need to copy the text below into a file (make sure you keep 
it as pure text and don't use Word or anything like that to make the file) 
called ec_plot.sh and then do : 
  chmod 755 ec_plot.sh
If you put it in $FSLDIR/bin/ then it will be available wherever you are, but
if you put it somewhere else then you'll need to specify the path before
the "ec_plot.sh" name when you run it  (e.g.   ~/scripts/ec_plot.sh myfile.ecclog  
if you put the file in ~/scripts/ )

All the best,
	Mark



#!/bin/sh

if [ $# -lt 1 ] ; then 
  echo "Usage: `basename $0` <eddy current ecclog file>"
  exit 1;
fi

logfile=$1;
basenm=`basename $logfile .ecclog`;

nums=`grep -n 'Final' $logfile | sed 's/:.*//'`; 

touch grot_ts.txt
touch grot.mat

firsttime=yes;
m=1;
for n in $nums ; do 
    echo "Timepoint $m"
    n1=`echo $n + 1 | bc` ; 
    n2=`echo $n + 5 | bc` ;
    sed -n  "$n1,${n2}p" $logfile > grot.mat ; 
    if [ $firsttime = yes ] ; then firsttime=no; cp grot.mat grot.refmat ; cp grot.mat grot.oldmat ; fi
    absval=`$FSLDIR/bin/rmsdiff grot.mat grot.refmat $basenm`;
    relval=`$FSLDIR/bin/rmsdiff grot.mat grot.oldmat $basenm`;
    cp grot.mat grot.oldmat
    echo $absval $relval >> ec_disp.txt ;
    $FSLDIR/bin/avscale --allparams grot.mat $basenm | grep 'Rotation Angles' | sed 's/.* = //' >> ec_rot.txt ;
    $FSLDIR/bin/avscale --allparams grot.mat $basenm | grep 'Translations' | sed 's/.* = //' >> ec_trans.txt ;
    m=`echo $m + 1 | bc`;
done

echo "absolute" > grot_labels.txt
echo "relative" >> grot_labels.txt

$FSLDIR/bin/fsl_tsplot -i ec_disp.txt -t 'Eddy Current estimated mean displacement (mm)' -l grot_labels.txt -o ec_disp.png

echo "x" > grot_labels.txt
echo "y" >> grot_labels.txt
echo "z" >> grot_labels.txt

$FSLDIR/bin/fsl_tsplot -i ec_rot.txt -t 'Eddy Current estimated rotations (radians)' -l grot_labels.txt -o ec_rot.png
$FSLDIR/bin/fsl_tsplot -i ec_trans.txt -t 'Eddy Current estimated translations (mm)' -l grot_labels.txt -o ec_trans.png

# clean up temp files
/bin/rm grot_labels.txt grot.oldmat grot.refmat grot.mat