File: phantom.sh

package info (click to toggle)
bart-cuda 0.8.00-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, sid
  • size: 7,752 kB
  • sloc: ansic: 100,267; python: 717; makefile: 576; sh: 564; cpp: 104
file content (232 lines) | stat: -rwxr-xr-x 6,109 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
# Copyright 2022. TU Graz. Institute of Biomedical Imaging.
# All rights reserved. Use of this source code is governed by
# a BSD-style license which can be found in the LICENSE file.
#
# Author:
# 2022 Nick Scholand <scholand@tugraz.at>
#
# Creation of digital reference object.

set -e

LOGFILE=/dev/stdout
KSPACE=false
SENS=1
ROT_ANGLE=0
ROT_STEPS=1
GEOM=NIST

title=$(cat <<- EOF
	Digital Reference Object
EOF
)

helpstr=$(cat <<- EOF
-S \t\t Diagnostic Sonar geometry (NIST phantom is default)
-k \t\t simulate in k-space
-a d \t\t angle of rotation
-r d \t\t number of rotation steps
-s d \t\t number of simulated coils
-t <traj> \t define custom trajectory file
-l \t\t logfile
-h \t\t help

Please adjust simulation parameters inside the script.
EOF
)

usage="Usage: $0 [-h] [-k] [-r d] [-s d] [-t <traj>] <output>"

echo "$title"
echo

while getopts "hSka:r:s:t:l:" opt; do
        case $opt in
	h)
		echo "$usage"
		echo
		echo -e "$helpstr"
		exit 0
	;;
        S)
		GEOM=SONAR
	;;
        k)
		KSPACE=true
	;;
        a)
		ROT_ANGLE=$OPTARG
	;;
        r)
		ROT_STEPS=$OPTARG
	;;
        s)
		SENS=$OPTARG
	;;
        t)
		TRAJ=$(readlink -f "$OPTARG")
	;;
	l)
		LOGFILE=$(readlink -f "$OPTARG")
        ;;
        \?)
        	echo "$usage" >&2
		exit 1
        ;;
        esac
done

shift $((OPTIND - 1))

if [ $# != 1 ] ; then

        echo "$usage" >&2
        exit 1
fi


export PATH=$TOOLBOX_PATH:$PATH

if [ ! -e $TOOLBOX_PATH/bart ] ; then
        echo "\$TOOLBOX_PATH is not set correctly!" >&2
	exit 1
fi


output=$(readlink -f "$1")


# Tests for usefull input

if [ ! -z "${TRAJ}" ] && [ "$KSPACE" = false ]; then

        echo "Trajectory only works in k-space domain. Please add [-k]!" >&2
	exit 1
fi


#WORKDIR=$(mktemp -d)
# Mac: http://unix.stackexchange.com/questions/30091/fix-or-alternative-for-mktemp-in-os-x
WORKDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
trap 'rm -rf "$WORKDIR"' EXIT
cd $WORKDIR


# start group for redirection of output to the logfile
{

case $GEOM in

NIST)
        echo "NIST Phantom Geometry"
        echo "T2 Sphere of Model 130"
        echo "Relaxation Paramters for 3 T"
        echo ""

        ## Relaxation parameters for T2 Sphere of NIST phantom at 3 T (Model 130)
        ##      Stupic, KF, Ainslie, M, Boss, MA, et al.
        ##      A standard system phantom for magnetic resonance imaging.
        ##      Magn Reson Med. 2021; 86: 1194– 1211. https://doi.org/10.1002/mrm.28779
        T1=(3 2.48 2.173 1.907 1.604 1.332 1.044 0.802 0.609 0.458 0.337 0.244 0.177 0.127 0.091)
        T2=(1 0.581 0.404 0.278 0.191 0.133 0.097 0.064 0.046 0.032 0.023 0.016 0.011 0.008 0.006)
        ;;

SONAR)
        echo "Diagnostic Sonar Phantom Geometry"
        echo "Eurospin II"
        echo "Gels: 3, 4, 7, 10, 14, and 16"
        echo ""

        ## Relaxation parameters for Diagnostic Sonar phantom
        ## Eurospin II, gel nos 3, 4, 7, 10, 14, and 16)
        ## T1 from reference measurements in
        ##      Wang, X., Roeloffs, V., Klosowski, J., Tan, Z., Voit, D., Uecker, M. and Frahm, J. (2018),
        ##      Model-based T1 mapping with sparsity constraints using single-shot inversion-recovery radial FLASH.
        ##      Magn. Reson. Med, 79: 730-740. https://doi.org/10.1002/mrm.26726
        ## T2 from
        ##      T. J. Sumpf, A. Petrovic, M. Uecker, F. Knoll and J. Frahm,
        ##      Fast T2 Mapping With Improved Accuracy Using Undersampled Spin-Echo MRI and Model-Based Reconstructions With a Generating Function
        ##      IEEE Transactions on Medical Imaging, vol. 33, no. 12, pp. 2213-2222, Dec. 2014, doi: 10.1109/TMI.2014.2333370.
        T1=(3 0.311 0.458 0.633 0.805 1.1158 1.441 3)
        T2=(1 0.046 0.081 0.101 0.132 0.138 0.166 1)
        ;;
*)
    echo -n "Unknown geometry!\n"
    exit 1
    ;;
esac


# Simulation Parameters
#       Run `bart sim --seq h` for more details
SEQ=IR-FLASH    # Sequence Type
TR=0.0034       # Repetition Time [s]
TE=0.0021       # Echo Time [s]
REP=600         # Number of repetitions
IPL=0.01        # Inversion Pulse Length [s]
ISP=0.005       # Inversion Spoiler Gradient Length [s]
PPL=0           # Preparation Pulse Length [s]
TRF=0.001       # Pulse Duration [s]
FA=6            # Flip Angle [degree]
BWTP=4          # Bandwidth-Time-Product
OFF=0           # Off-Resonance [rad/s]
SLGRAD=0        # Slice Selection Gradient Strength [T/m]
SLTHICK=0       # Thickness of Simulated Slice [m]
NSPINS=1        # Number of Simulated Spins

# Run Simulation
for i in `seq 0 $((${#T1[@]}-1))`; do

        echo -e "Tube $i\t T1: ${T1[$i]} s,\tT2[$i]: ${T2[$i]} s"

        bart sim        --ODE \
                        --seq $SEQ,TR=$TR,TE=$TE,Nrep=$REP,ipl=$IPL,isp=$ISP,ppl=$PPL,Trf=$TRF,FA=$FA,BWTP=$BWTP,off=$OFF,sl-grad=$SLGRAD,slice-thickness=$SLTHICK,Nspins=$NSPINS \
                        -1 ${T1[$i]}:${T1[$i]}:1 -2 ${T2[$i]}:${T2[$i]}:1 \
                        _simu$(printf "%02d" $i)
done


# Join individual simulations
bart join 7 $(ls _simu*.cfl | sed -e 's/\.cfl//') simu

# Join simulations in a single dimension (-> 6)
bart reshape $(bart bitmask 6 7) ${#T1[@]} 1 simu simu2


# Create Geometry
if [ -z "${TRAJ}" ]; then

        if $KSPACE; then

                # Create default trajectory
                DIM=192
                SPOKES=$((DIM-1))

                bart traj -x $DIM -y $SPOKES traj

                bart phantom --${GEOM} -b -s $SENS --rotation-steps $ROT_STEPS --rotation-angle $ROT_ANGLE  -t traj geom
        else

                bart phantom --${GEOM} -b -s $SENS --rotation-steps $ROT_STEPS --rotation-angle $ROT_ANGLE geom
        fi
else
        if $KSPACE; then

                bart phantom --${GEOM} -b -s $SENS --rotation-steps $ROT_STEPS --rotation-angle $ROT_ANGLE -k -t ${TRAJ} geom
        else

                bart phantom --${GEOM} -b -s $SENS --rotation-steps $ROT_STEPS --rotation-angle $ROT_ANGLE geom
        fi
fi

# Combine simulated signal and geometry

bart fmac -s $(bart bitmask 6) geom simu2 $output

} > $LOGFILE

[ -d $WORKDIR ] && rm -rf $WORKDIR

exit 0