# Advanced angiographic simulations

Angiographic simulations can be performed by providing as input a file containing the Lagrangian trajectories of the flowing spins. The flow must be continuous during the sequence and the density of spins must be spatially homogeneous. Static spins positions must also be specified.

- The input flow file can be ASCII or HDF5 (for HDF5, quadruple the negative indicators and use the structure: Group '/flow', Dataset 'trajectories', Size 4xN). The trajectories format is:
t0 spin0_x spin0_y spin0_z
-111-> SPIN ACTIVATION
t1 spin0_x spin0_y spin0_z
t2 spin0_x spin0_y spin0_z
t3 spin0_x spin0_y spin0_z
...
tN spin0_x spin0_y spin0_z
-222-> SPIN DEACTIVATION
-999999-> SPIN CHANGE INDICATOR

t0 spin1_x spin1_y spin1_z
-111
t1 spin0_x spin0_y spin0_z
t2 spin0_x spin0_y spin0_z
t3 spin0_x spin0_y spin0_z
...
tN spin0_x spin0_y spin0_z
-222
-999999
...
- In the .xml simu file, provide the path of the flow file, e.g.:

<?xml version="1.0" encoding="utf-8"?>
<simulate name="JEMRIS">
<sequence name="angio" uri="./angio.xml"/>
<sample name="vessels" name="./Flow.dat" uri="./sample.h5"/>
<RXcoilarray uri="./uniform.xml"/>
<TXcoilarray uri="./uniform.xml"/>
<parameter ConcomitantFields="0" EvolutionPrefix="evol" EvolutionSteps="0" RandomNoise="0"/>
<model name="Bloch" type="CVODE"/>
</simulate>

- Run the .xml simu file normally with jemris or pjemris.

## Flow loop option

The same flow trajectories can be reused periodically to reduce the amount of data, e.g. for steady or periodic flow (cardiac cycle). In the .xml simu files, set e.g.:

<sample name="cardiac" name="./Flow.dat" FlowLoopDuration="850" FlowLoopNumber="1500" uri="./sample.h5"/>

"FlowLoopDuration" is the duration of the flow cycle (ms). If the sample size exceeds the total number of trajectories, the N last trajectories corresponding to "FlowLoopNumber" will be reused periodically with a time shift equal to "FlowLoopDuration" (note: the spins stays at their initial position until the beginning of their trajectory). Thus, to cover the whole sequence, the input sample size must be:
NonLoopedSpins + FlowLoopNumber*SequenceDuration/FlowLoopDuration

E.g., we can imagine a vessel initially containing 10 000 spins, which entry is seeded with 1 500 spins during one cardiac cycle of 850 ms. Then, the input flow file will contain 11 500 trajectories, and a sequence of 400 000 ms will be simulated with a sample of 10 000 + 1 500*400 000/850 = 715 882 spins.

## Image reconstruction from output signal

For basic sequences, images can be visualized with the JEMRIS_sim Matlab interface. For 3D sequences or phase contrast sequences, use the specific Recon_*.m Matlab reconstruction scripts.