Use Koma in Notebooks

You can use KomaMRI with popular programming environments such as Pluto and Jupyter notebooks. The following sections show how to set up these notebooks and test KomaMRI with them.

Pluto

First, install the Pluto module in your Julia environment. Remember to press the ] button to open the Package Manager Session:

julia>

@(1.9) pkg> add Pluto

Afterward, return to the Julia Session by pressing the backspace button, and then execute the Pluto.run() function:

julia> using Pluto

julia> Pluto.run()

This should automatically open the Pluto dashboard in your default web browser:

Next, create a new notebook by clicking on + Create a new notebook:

Write and run the following code, which is identical to the Free Induction Decay example. Pluto automatically installs the required modules if they are not present on your system. Additionally, note that we do not directly use KomaMRI since we won't be utilizing the KomaUI function. Instead, we rely on the KomaMRICore and KomaMRIPlots dependencies. To display plots in Pluto, ensure that you import the PlutoPlotly package, as KomaMRIPlots requires its backend to display figures in Pluto:

One of the most outstanding features of Pluto is its ability to ensure reproducibility by storing the information necessary to recreate the package environment in the notebook file. When others open your notebook with Pluto, it automatically ensures they use the exact same package environment, guaranteeing seamless functionality on their computers.

Jupyter

Ensure you have Jupyter installed on your computer. Follow this tutorial for installation using Anaconda.

Next, install the IJulia module in your Julia environment. Remember to press the ] key to open the Package Manager Session:

julia>

(@v1.9) pkg> add IJulia

For this example, make sure to install KomaMRICore and KomaMRIPlots (we do not use KomaMRI directly since we won't be utilizing the KomaUI() function):

(@v1.9) pkg> add KomaMRICore

(@v1.9) pkg> add KomaMRIPlots

Next, open Jupyter, navigate to a working folder, and create a new notebook by clicking on New, then Julia 1.9.3."

A new, empty notebook will appear:

Proceed to write and execute the provided example:

View code
# Import modules
using KomaMRICore, KomaMRIPlots

# Define sequence
ampRF = 2e-6                        # 2 uT RF amplitude
durRF = ฯ€ / 2 / (2ฯ€ * ฮณ * ampRF)    # required duration for a 90 deg RF pulse
exc = RF(ampRF, durRF)

nADC = 8192         # number of acquisition samples
durADC = 250e-3     # duration of the acquisition
delay =  1e-3       # small delay
acq = ADC(nADC, durADC, delay)

seq = Sequence()  # empty sequence
seq += exc        # adding RF-only block
seq += acq        # adding ADC-only block

# Plot the sequence
plot_seq(seq; slider=false, height=300)

This should be sufficient, and now you can start working with KomaMRI using Jupyter notebooks.

If you encounter the issue of WebIO not being detected:

Refer to this IJulia documentation and this troubleshooting guide for details. Essentially, you need to install a WebIO extension depending on your Jupyter installation.