Skip to content

Instantly share code, notes, and snippets.

@florisvanvugt
Last active August 19, 2017 23:28
Show Gist options
  • Save florisvanvugt/04f00088ac4c5d8e0d417aa50c27300f to your computer and use it in GitHub Desktop.
Save florisvanvugt/04f00088ac4c5d8e0d417aa50c27300f to your computer and use it in GitHub Desktop.
Compute slice timings for multiband accelerated sequences
def multiband_slice_times_oddshots(TR,slices,multiband,incrementslice):
"""
Computes the slice timings of a multiband sequence.
I think this is mostly right but I am not an expert, so please use with caution.
And let me know if you spot errors. Thanks.
This is based on the description here:
https://wiki.humanconnectome.org/download/attachments/40534057/CMRR_MB_Slice_Order.pdf?version=3&modificationDate=1386977824455&api=v2
Arguments
TR : the TR duration (in ms)
slices : number of slices (e.g. 78)
multiband : multiband acceleration factor (e.g. 6 for 6x acceleration)
incrementslice: increment slice parameter (default for Siemens is 2, check this in your sequence parameters)
Returns
a dict where the keys are the slice numbers (starting at 0) and the values are the acquisition times (in ms)
"""
numberofshots = int(slices/multiband)
assert numberofshots*multiband == slices # number of slices must be a multiple of multiband factor
assert incrementslice==2 # if not, might still work but use at your own risk
assert numberofshots%2==1 # this function only works for an odd number of shots as far as I know
slicetimes = {}
overall_shot_n = 0
for incrsl in range(incrementslice):
# Compute how many shots we can fit in (starting from this incrementslice)
for shot in range(int(ceil((numberofshots-incrsl)/incrementslice))):
# The starting point for this shot
startshot = incrsl + shot*incrementslice
# Slices excited in this shot
shotslices = startshot + arange(multiband)*numberofshots
print(shotslices)
for s in shotslices: slicetimes[s]=(float(TR)/numberofshots)*overall_shot_n
overall_shot_n += 1
return slicetimes
@florisvanvugt
Copy link
Author

I had trouble extracting the slice timings from DICOM files acquired with a multiband accelerated fMRI sequence, so I wrote this little function that computes what the slice timings should be if I understand this correctly. Please use with caution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment