Notes on FIRMM

Before registering a subject, run the “start FIRMM” batch file from the scanner console start menu. If you see “CONNECTED” you should be good to go.  If you see “NOT CONNECTED”, FIRMM will not work.

If you see “NOT CONNECTED”, run “stop FIRMM” from the console. Then restart the FIRMM tablet by pressing the power button. Note that it is possible to accidentally put the tablet into desktop mode. If that happens, just restart it again. FIRMM should launch and the tablet should say “not connected” and “please start a scan”. Now, run “start FIRMM” from the start menu again. This time there should be a “CONNECTED” message in the command window. Register your subject and FIRMM should work.

If you do this while a subject is already registered, you will need to close and re-register the subject before FIRMM will work again.

Preprocessing of diffusion data

This page gives an example of how to use the FSL tools “topup” and “eddy” to preprocess diffusion data.

This is all discussed in greater detail on the FSL wiki, and I recommend you read those pages as well before performing any actual analysis of your own data.

Acquisition:

First of all, we need data acquired with at least two different phase encoding directions: for example, AP and PA, or RL and LR. At a minimum, we need at least two B0 volumes with opposite phase encoding directions. We could either run the entire diffusion acquisition twice with opposite phase encoding, or just rerun the B0 volumes with opposite phase encoding, or run two completely different acquisitions, as long as we wind up with at least two B0 volumes, each with an opposite phase encoding direction.

For our example, we have two identical acquisitions consisting of a single B0 volumes followed by 64 diffusion directions arranged on a sphere. Series 1 has RL phase encoding; series 2 has LR phase encoding.

Preparing for topup:

The first step is to convert our data to nifti format. We are using MRIConvert, and we always make sure we use the latest version. We know that later we’ll need the total readout time for our acquisition, and we can get that now from the MRIConvert “series information” screen: 0.063 s. This information is also output in a text file for each converted series. (This parameter is discussed in more depth on the “field map” section of this wiki.) Next, we need to extract the B0 images from the nifti files and combine them into a single volume:

fslroi series1 b0_rl 0 -1 0 -1 0 -1 0 1
fslroi series2 b0_lr 0 -1 0 -1 0 -1 65 1
fslmerge -a b0_rl_lr b0_rl b0_lr

Now we create an acquisition parameters file. This file has one row for each b0 volume (2 in our example), and four columns. The first three columns indicate the phase encoding directions (+RL, +PA, +HF) and column four is for the total readout time. Our file, which we will name acqparams.txt, looks like this:

1 0 0 0.063
-1 0 0 0.063

The topup FAQ (http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP/Faq) has a helpful illustration of different phase encode directions and proper values for this file.

Running topup

We’re going to use the default parameters and configuration file. We need the output parameters and the unwarped images. We are also going to output the field map, because we’re going to use it to correct some other EPI images later (see here for how we might use this file):

topup --imain=b0_rl_lr --datain=acqparams.txt --config=b02b0.cnf --out=topup_results --iout=b0_unwarped --fout=fieldmap_Hz

Decision time

We now have the topup results (go read the FSL topup page if you want to know what just happened) and a pair of corrected B0 images. There are two ways to proceed from here. One is to use “applytopup” to apply those results to the remaining data. The other is to use the FSL tool “eddy” together with the topup results to correct the data. Although considerably slower, “eddy” will probably do a better job, especially if there is subject motion present. If you decide to use “applytopup” you may want to run the tool “eddy_correct” first. You should NOT run both “applytopup” and “eddy”, however. Since we meet the requirements for “eddy” (sampling on the full sphere) we decide to use that.

Running eddy

We need a brain mask, and we’re going to get it from the undistorted b0 data:

fslmaths b0_unwarped -Tmean b0_unwarped_mean
bet b0_unwarped_mean b0_unwarped_brain -make

Then we need a single 4D nifti file with all the diffusion data. The first volume of this file should be identical to the first b0 volume fed to “topup” earlier:

fslmerge -a diffusion_data series1 series2

We need to combine the two bvec files from series1 and series2 into a single file, and we need to do the same for the bval files. We decide to do this with the linux “paste” command:

paste -d"" series1_bvecs series2_bvecs >> bvecs
paste -d"" series1_bvals series2_bvals >> bvals

We also an index file that tells eddy which line of the “acqparams.txt” file to use for each volume of data. In our example, that will be a file (we’ll call it “index.txt”) that has a single line with 65 1’s followed by 65 2’s, separated by spaces:

indx=""
for ((i=0; i<65; ++i)); do indx="$indx 1"; done
for ((i=0; i<65; ++i)); do indx="$indx 2"; done
echo $indx > index.txt

Finally, we can run eddy:

eddy --imain=diffusion_data --mask=b0_unwarped_brain_mask --acqp=acqparams.txt --index=index.txt --bvecs=bvecs --bvals=bvals --topup=topup_results --out=eddy_corrected_data

After some time (possibly hours), we will have our eddy_corrected_data file, ready to be used in dtifit or whatever diffusion processing pipeline we intend to use.

Using Calpendo’s iCal Feed

As of version 7.0.40, Calpendo supports an ics feed for bookings of resources. When used with calendar software that support .ics feeds, this allows viewing Calpendo bookings without needing to log in or even requiring a Calpendo account.

The URL for .ics feeds is available with the iCal button on the Calendar view:

Calpendo's iCal button

You can choose to export bookings for all resources or a specific resource. We recommend using one feed per resource. If you do this,  you can import each feed into  your calendar and choose which selection of resources you wish to view.

Each type of calendar software has its own way of importing .ics feeds. For Google Calendar, this is done by pressing the down arrow to the right of “Other calendars” and selecting “Add by URL”. You then paste the URL given by Calpendo’s iCal dialog.

Note that updates to Calpendo may take up to an hour to propagate to your external calendar. Also, past events will not be synced/shown.

Mock Scanner

Our mock scanner is designed to provide participants an experience similar to what they will experience in the real scanner. It has a moving table, a realistic head coil, visual and audio stimulus capabilities and a set of button boxes for participant response. There is also a TR pulse simulator so you can trigger your stimulus programs just like the scanner would. Scheduling for the simulator is available in Calpendo.

Mock ScannerMock Scanner – Red arrow indicates location of the controls for moving the table.

Operation of the simulator table is done with a simple two-switch system, one to turn on the system, the other to move the table in and out. The location of these controls is indicated by the red arrow on the picture of the mock scanner, above.Table ControlsTable Controls – Power switch is on the left, in-out switch is on the right.

The table will automatically stop moving when it has reached the limits of its travel.

Visual stimuli are provided by an LG projector connected to a KVM switch. The switch is connected to a stimulus presentation computer on port two. Port one is available for your own laptop.

Projector and Controllers

Visual Stimulus – Provided by a small projector, switchable between two different video sources.

The switch controls the source video signal (DVI) delivered to the projector as well as the computer that receives the USB signal from the Psychology Software Tools button box system.

Audio simulating magnet noise is delivered by either the mac mini or your own computer. A power amplifier drives the simulator’s built-in speaker system.

It is important that your stimulus programs respond properly to the trigger pulse sent by the scanner. To test this, you can use our pulse simulator, a small black box located next to the projector. The green light indicates a powered on condition. Press the button indicated by the red arrow to generate the pulse.

TR Pulse Simulator

TR Pulse Simulator – Red arrow indicates the button used to generate a pulse.

Getting started at LCNI

Here are the steps to get a new project going at the center once you have completed safety training and have IRB approval for your study.

1. Get Research Compliance (IRB) approval. Send your approval notice to LCNI at lcni@uoregon.edu

2. Schedule R&D for your project, email LCNI at lcni@uoregon.edu

  • R&D worksheet: This will help us help you set up your protocol on the scanner. Bring this form to your R&D session with Vince and get it filled out. This will also help you estimate the resources you need when setting up your project in calpendo below. Email Diana to set up a time.

3. Set up Calpendo

  • If you do not have a Calpendo account, request one at the site
  • Go to Calpendo and create a new project under the Project menu. If you are unsure about how to answer fields in the Project menu, email us.

4. Start running your study

  • Schedule time through Calpendo. LCNI staff is available Monday-Friday 9a-5:30p. For after hours and weekend coverage details, email us at lcni@uoregon.edu.

5. Get access to dicoms

Collecting physiological data

It is possible to collect and record peripheral pulse, respiration, and electrocardiography data during any scan. In addition, two external trigger pulses may be recorded. The external trigger may be used to record the optical trigger out. This signal is currently available for BOLD echo-planar sequences and phosphorous spectroscopy, and may be added to other sequences if needed.

To record physiological signals, follow the instructions in the scanner operator manual. For peripheral pulse, simply place the pulse monitor on the subject’s fingertip, with the light facing the pad of the finger. Three sizes of transducer are available. The unit will begin measuring automatically and the results will be displayed in the monitor on the scanner.

To record the optical trigger, run a cable from the optical-to-digital converter box through the patch panel and into the external trigger in on the scanner. Alternatively, a second external trigger in is located in the equipment room.

Recording of physiological data files is initiated from the console and can be incorporated into any protocol. The files produced are text files, and begin with some header information and (for physiological signals) an average waveform. All signals have been resampled to 400 Hz, or a 2.5 ms sampling interval. Any detected triggers are marked with a value of 5000; these need to be removed from the file for accurate timing.

A command-line tool is available for converting these files to a more straightforward format is available to LCNI users. Currently it’s been compiled for Windows but can be recompiled for other platforms as needed.

This tool is run with the following options:

pmu_logfile_decoder filename [-t] [-r]

“filename” is the name of the logfiles, without extensions. The software will look for all matching logfiles in that location. The output files will have the additional extension “.out” and will consist of pairs of numbers: time in milliseconds and signal value, separated by a tab, with line breaks between pairs. Electrocardiogram signal files will be in groups of five: time, average, and individual channels.

The option -t indicates that all signals should be aligned with the external trigger in (currently this only works for the bay trigger, not ext2 located in the equipment room). All data before the first trigger signal and after the last trigger signal (plus the interval between triggers) is discarded for all signals. The option -r indicates that the “5000” trigger marks should be discarded. Both, either, or neither option may be chosen.

Auditory stimulus options

There are four options for auditory stimulus presentation and subject communication at LCNI: room intercom, the standard Siemens headphones, a set of headphones from Nordic Neurolabs (NNL), and a set of Sensimetrics earbuds. The right option for your project depends on which coils you are using and whether you are presenting auditory stimuli or simply communicating with the participant.

If you are using the 32-channel or 64-channel head coils, the options for stimulus presentation are the Sensimetrics earbuds or feeding audio into the room intercom. You may use the earbuds for stimulus presentation and the room intercom for subject communication.

If you are using prerecorded stimuli with the Sensimetrics earbuds, the sound quality will be greatly enhanced by prefiltering your sound files. Filtering software is available here: http://www.sens.com/products/model-s14/#downloads. You will also need the custom filter files for our earbuds; contact  for more information.

When using another head coil, or no head coil, we recommend either the Siemens or NNL headphones, as they will provide better sound insulation than the earbuds for most participants. For simple communication with the participant, the Siemens headphones will suffice. If you are presenting auditory stimuli, you should use the NNL headphones.

For participant-to-operator communications, you may use either the room intercom or the Persaio MR noise cancelling audio system.

Acquiring and using field maps

EPI images can be quite distorted due to B0 inhomogeneities, which in the brain are especially pronounced near the sinuses. While signal lost to these inhomogeneities cannot be recovered, signal that has been merely displaced can be returned to its proper location in the image if a map of the B0 field has been acquired. This document discusses two methods used at the center to acquire images that can be used to create field maps, and how to use tools in FSL and SPM to create and apply field maps. This document focuses on the practicalities of how to generate and use the field maps.

Make sure you read this part

Applying distortion correction should make your images look LESS distorted, not more. If after applying distortion correction your images look worse, or about the same, you should look for a mistake somewhere in your processing.

Another really important thing: please don’t take scripts written by someone else in your lab for their project and just assume everything will work. Your acquisition parameters could very well be different from theirs. Things do change.

I already took the data, what kind of field map do I have?

If you are asking this question, the answer is that you don’t have a field map yet. You have data that you will use to calculate a field map. This article covers how to do that for two different methods. Method 1 calculates a field map based on the difference in phase between two different echos in a double echo sequence. Method 2 uses two separate acquisitions with opposite phase encoding directions to calculate a field map based on the difference in distortion between the two acquisitions. If you are an LCNI user, we use both methods. If you don’t know what kind of data you acquired, it should be clear once you look at the results: if you used the stock double-echo gradient echo field map sequence (method 1), you’ll have two series. The first will contain two magnitude images, one for each echo. The second series will contain a single phase difference image, a subtraction of the two phase images from each echo.

gre_magnitude

Gradient double echo phase difference image

If you used the se-epi with opposite phase encode method (method 2), you will also get two series. Each will contain a single magnitude volume, and one will have the opposite phase encoding direction from the other.

se_epi_ap

se_epi_pa

Effective echo spacing and total readout time

There are two parameters you will frequently need when calculating and applying field maps: the effective echo spacing and the total readout time for an EPI sequence. We use the “effective” echo spacing, rather than the actual echo spacing, in order to include the effects of parallel imaging, phase oversampling, etc. Siemens has helpfully included this information in the DICOM file with the parameter “Bandwidth Per Pixel Phase Encode”, stored in DICOM tag (0019, 1028). Multiplying this by the size of the reconstructed image in the phase direction (aka the number of reconstructed phase lines) will give you the reciprocal of the effective echo spacing:

Effective Echo Spacing (s) = 1/(BandwidthPerPixelPhaseEncode * MatrixSizePhase)

The size of the image in the phase direction is *usually* the first number in the field (0051, 100b), AcquisitionMatrixText. This is, however, not always the case, so it is better to determine the actual size (rows or columns) of your reconstructed image in the phase encode direction. You can also just read the effective echo spacing from the Series Info screen in MRIConvert if you are running the latest version.

The total readout time (FSL definition) is the time from the center of the first echo to the center of the last:

Total readout time (FSL) = (number of echoes - 1) * echo spacing

In the case of a simple EPI sequence, with no parallel imaging, no partial fourier, no phase oversampling, etc, this is straightforward enough. For the general case, it’s appropriate to consider this an “effective” readout time, calculated using the effective echo spacing and the number of reconstructed phase lines:

Total readout time (FSL) = (MatrixSizePhase - 1) * EffectiveEchoSpacing

For the majority of scans the length of a single echo is so short compared to the readout time that you can use the SPM definition of total readout time. SPM defines it to be from the beginning of the first echo to the end of the last echo. This is just the reciprocal of the Bandwidth Per Pixel Phase Encode:

Total Readout Time (SPM) = 1/(BandwidthPerPixelPhaseEncode)

Since the Bandwidth Per Pixel Phase Encode is in Hz, this will give the readout time in seconds. MRIConvert reports both definitions, and you should find them to be within 2% of each other for most sequences.

Acquiring a field map, method 1: double echo

This method calculates a field map from a double-echo gradient echo sequence. The difference in phase between the two images is proportional to the difference in echo times and the B0 inhomogeneity. The field map is calculated by taking the difference between the two phase images, and dividing that by the echo time difference.

Setting up the sequence

The Skyra conveniently comes with a field map sequence installed. The echo time difference is set to a specific value in order to minimize the effect of the fat-water chemical shift, so don’t change it unless you know what you’re doing. The field map should be in the same orientation as the EPIs you are planning to correct (eg, axial), but does not need to have exactly the same geometry, field of view, or resolution. Make sure that you save both the magnitude images (there will be two, one for each echo) and the phase difference image.

Calculating the field map

FSL has a handy utility for converting a Siemens phase difference image to a field map: fsl_prepare_fieldmap. The syntax is:

fsl_prepare_fieldmap <scanner> <phase_image> <magnitude_image> <out_image> <deltaTE (in ms)>

The magnitude image should be brain extracted, and the brain extraction should be tight. This is discussed in more detail on the FSL wiki if you want more information. You can use either echo from the fieldmap aquisition, or average them together. “deltaTE” will be 2.46 unless you changed the echo times in the fieldmap acquisition. The output image will be in rad/s, ready for use in FEAT or FUGUE.

Acquiring a field map, method 2: opposite phase encoded EPIs

This method acquires two or more echo planar images with opposite phase encode directions. More info on how it uses this information will be added later.

Setting up the sequence

If you are doing this with the multiband sequence, you probably used the SE-EPI. More details on this will be added later, but you should have two series in the end, each with opposite phase encoding. The rest of this document assumes those directions are “AP” and “PA”.

Calculating the field map

You will need to use the FSL tool “topup” to create a field map for use with FUGUE or FEAT. Detailed documentation on topup is available on the FSL wiki, but here is an abbreviated list of necessary steps that should work for most users.

IMPORTANT WARNING: Until FSL release 5.0.9, topup up did not write any orientation information into the outputted nifti header files. The consequences of this omission range from minor to disastrous. Be sure you are using the latest release of FSL, or fix the orientation information in the nifti files after the fact.

1. Use fslmerge to combine the two se-epi images into one 4D file: fslmerge -t [output] [inputAP] [inputPA].

2. Create a “datain” file. This is a text file with four columns. The first three columns indicate the phase encode direction, and the fourth is the total readout time (defined as the time from the center of the first echo to the center of the last) in seconds for the se-epi acquisition. The total readout time is given by the (number of echoes minus one) * echo spacing. See the above discussion on total readout time for how to calculate this value. Remember, this is all from the se-epi sequence, NOT the functional sequence you will be applying the fieldmap to later. When in doubt, ask your local physicist for help. The correct values for the first three columns may change depending on how the files were converted to NIFTI format. You’ll wind up with a file that looks something like this:

0 -1 0 .0351 // This is just an example!
0 1 0 .0351  // Don't just copy these values!

3. Run topup. You can use the default config file b02b0.cnf (you do not need to create this file). The command will look something like this:

topup --imain=se_epi_merged --datain=datain.txt --config=b02b0.cnf --fout=my_fieldmap --iout=se_epi_unwarped

4. The fieldmap will be in units of Hz, but you’ll need it in units of rad/s for use with fugue or feat, so multiply by 2pi:

fslmaths my_fieldmap -mul 6.28 my_fieldmap_rads

5. Finally, if you will be using this with Feat, you’ll need a single magnitude image, and a brain extracted version of that image. You can get that this way:

fslmaths se_epi_unwarped -Tmean my_fieldmap_mag

bet2 my_fieldmap_mag my_fieldmap_mag_brain

Make sure the brain extracted image has the same name as the non brain extracted image, but with _brain at the end.

Applying distortion correction: FSL

In Feat, you’ll need to specify the field map image (the one you created with units of rad/s) and the brain extracted magnitude image from the field map acquisition. Feat will look for a non brain extracted magnitude image in the same directory and having the same name, but without _brain at the end, so make sure it’s there. For fieldmaps acquired with the double echo method, it’s very important that the brain extracted image excludes all non-brain regions, as the field map will be quite noisy in those areas. For fieldmaps acquired with the se-epi method this is less vital.

Next you will need the TE from the functional epi series you are processing (not the field map!), and the unwarp direction (-y for AP phase encoding and “FSL NIFTI” output type from MRIConvert). Finally, you’ll need the effective EPI echo spacing in ms (again, from the functional EPI series, not the field map). See the above discussion for how to get the effective echo spacing from the DICOM file.

Calculating and Applying Fieldmaps with SPM

First, let’s use the SPM gui to do one fieldmap, acquired using method 1, for one subject. We’ll cover batch mode later. SPM uses the FieldMap Toolbox to calculate a voxel displacement map that is used to correct the BOLD epi images. The parameters for this can be changed in the GUI, or in a defaults file. There are a bunch of default files already, none of which are likely to be correct for you, but you can save your own. The first parameters you’ll need to change are the short and long echo times.

pm_def.SHORT_ECHO_TIME = 4.37;
pm_def.LONG_ECHO_TIME = 6.83;

These are the two echo times in the Siemens double echo stock fieldmap sequence. The values I’ve given here are probably the same ones you used, but double check by looking in the DICOM file (MRIConvert will show you these values in the “series info” screen). Hit “load phase” and select the phase difference image from your field map acquisition. When you are asked “Scale this to radians?” choose yes. Then hit “load mag” and choose one of the two magnitude images from the field map sequence. “Mask brain” can be either “yes” or “no”. Finally, choose “calculate”. A fieldmap should appear in the graphics window.

If your fieldmap was created using method 2, you will have to use FSL & topup to calculate a field map as discussed above. In that case, you will need to load a precalculated fieldmap using the obvious button. The fieldmap needs to already be in Hz, must have a filename starting with “fpm”, and must be in a NIFTI pair file format.

The lower window has information about the EPI image you wish to unwarp. This is where we need to total readout time, which is also in the defaults file like this:

pm_def.TOTAL_EPI_READOUT_TIME = 21.1 // Replace with the right value for your data!

This is the total epi readout time in ms for the BOLD series you are correcting, NOT the total readout time from the field map acquisition. See the above discussion on total readout time for how to get this from the DICOM. “EPI based fieldmap” should be “no”, and “apply jacobian modulation” should also be “no”. Polarity of the blips depends not only on your acquisition but also on how your data was converted to NIFTI, so it could be either + or – ve. The easiest thing to do is to try it both ways. Once these parameters are set, load an EPI image. After a moment, you’ll see the fieldmap, warped EPI, and unwarped EPI in the graphics window.

se_epi_pa

As I stated way up at the beginning, the unwarped EPI should look objectively “better” than the warped. If you see that a big piece of brain is now missing, it’s because the voxel displacement map is not lined up with the EPI.

spm_misaligned

You should be able to fix this using the “match VDM to EPI”. Sometimes, however, this doesn’t work, and now I’m afraid I have to get a bit long-winded.

The phase difference between the two echos depends on the local field — that’s how field mapping works. We create a fieldmap that maps out this field, in units of Hz. This includes not only susceptibility effects, but also global drifts in frequency from the nominal center value. If a frequency adjustment is not performed immediately before running the fieldmap sequence, the difference image will include this offset. You may notice that some phase difference images look a little different from the one above:

Phase difference with offset

Another phase difference with offset

There’s nothing wrong mathematically, they just aren’t “centered” at the correct “zero”. FSL, in the “fsl_prepare_fieldmaps” script, includes a final demeaning step to account for this. As far as I can tell, SPM does not (or at least does not do it the same way), and it is not able to handle large offsets from the nominal center frequency. It is easy to check this in the fieldmap toolbox gui: after loading an EPI image, switch the polarity of the phase-encode blips. Areas that are not distorted should not change. If, however, the entire brain “jumps” up and down, you have a global offset. If you have a global offset, the voxel displacement map will be wrong and will not unwarp the EPI correctly.

One way of fixing this problem is to calculate your fieldmaps in FSL and load them into SPM. Another is to demean the fieldmaps in SPM by adding the line fm.upm = fm.upm – median(fm.upm(:)); to the file pm_make_fieldmap.m. In SPM12 you’ll want to add it at line 190:

if flags.pad ~= 0
   npxs = pxs/pxs(1);
   ks = floor((flags.pad+1)*[1 1 1]./npxs);
   if ~mod(ks(1),2) ks(1) = ks(1)+1; end
   if ~mod(ks(2),2) ks(2) = ks(2)+1; end
   if ~mod(ks(3),2) ks(3) = ks(3)+1; end
   kernel = ones(ks);
   [fm.upm,fm.mask] = pm_pad(fm.upm,fm.mask,kernel);
end
fm.upm = fm.upm - median(fm.upm(:));

Note that I am still in the process of testing this and no promises are made! Once you have everything all figured out, you’ll probably be using batch mode in SPM instead of the gui. I’m assuming that’s straightforward, but if I run into trouble when I try doing it myself I’ll add that info here.

Please contact Jolinda if you are a LCNI user with more questions about any of this.