Callosal bundles using AFQ API#

An example using the AFQ API to find callosal bundles using the templates from: http://hdl.handle.net/1773/34926

import os.path as op
import matplotlib.pyplot as plt
import nibabel as nib

import plotly

from AFQ.api.group import GroupAFQ
import AFQ.api.bundle_dict as abd
from AFQ.definitions.image import RoiImage
import AFQ.data.fetch as afd

Get some example data#

Retrieves Stanford HARDI dataset.

afd.organize_stanford_data(clear_previous_afq="track")
  0%|          | 0/5578 MB [00:00]
  0%|          | 2/5578 MB [00:00]
  0%|          | 6/5578 MB [00:00]
  0%|          | 11/5578 MB [00:00]
  0%|          | 15/5578 MB [00:00]
  0%|          | 22/5578 MB [00:00]
  1%|          | 28/5578 MB [00:00]
  1%|          | 37/5578 MB [00:00]
  1%|          | 46/5578 MB [00:01]
  1%|          | 59/5578 MB [00:01]
  1%|▏         | 72/5578 MB [00:01]
  2%|▏         | 90/5578 MB [00:01]
  2%|▏         | 110/5578 MB [00:01]
  2%|▏         | 136/5578 MB [00:01]
  3%|▎         | 157/5578 MB [00:01]
  3%|▎         | 183/5578 MB [00:01]
  4%|▎         | 205/5578 MB [00:01]
  4%|▍         | 230/5578 MB [00:02]
  5%|▍         | 253/5578 MB [00:02]
  5%|▍         | 278/5578 MB [00:02]
  5%|▌         | 301/5578 MB [00:02]
  6%|▌         | 326/5578 MB [00:02]
  6%|▌         | 348/5578 MB [00:02]
  7%|▋         | 374/5578 MB [00:02]
  7%|▋         | 396/5578 MB [00:02]
  8%|▊         | 421/5578 MB [00:03]
  8%|▊         | 444/5578 MB [00:03]
  8%|▊         | 469/5578 MB [00:03]
  9%|▉         | 491/5578 MB [00:03]
  9%|▉         | 516/5578 MB [00:03]
 10%|▉         | 539/5578 MB [00:03]
 10%|█         | 564/5578 MB [00:03]
 11%|█         | 587/5578 MB [00:03]
 11%|█         | 612/5578 MB [00:03]
 11%|█▏        | 635/5578 MB [00:04]
 12%|█▏        | 660/5578 MB [00:04]
 12%|█▏        | 682/5578 MB [00:04]
 13%|█▎        | 707/5578 MB [00:04]
 13%|█▎        | 729/5578 MB [00:04]
 14%|█▎        | 755/5578 MB [00:04]
 14%|█▍        | 777/5578 MB [00:04]
 14%|█▍        | 803/5578 MB [00:04]
 15%|█▍        | 825/5578 MB [00:04]
 15%|█▌        | 850/5578 MB [00:05]
 16%|█▌        | 873/5578 MB [00:05]
 16%|█▌        | 898/5578 MB [00:05]
 16%|█▋        | 920/5578 MB [00:05]
 17%|█▋        | 946/5578 MB [00:05]
 17%|█▋        | 968/5578 MB [00:05]
 18%|█▊        | 993/5578 MB [00:05]
 18%|█▊        | 1016/5578 MB [00:05]
 19%|█▊        | 1041/5578 MB [00:06]
 19%|█▉        | 1063/5578 MB [00:06]
 20%|█▉        | 1089/5578 MB [00:06]
 20%|█▉        | 1111/5578 MB [00:06]
 20%|██        | 1136/5578 MB [00:06]
 21%|██        | 1159/5578 MB [00:06]
 21%|██        | 1184/5578 MB [00:06]
 22%|██▏       | 1207/5578 MB [00:06]
 22%|██▏       | 1231/5578 MB [00:06]
 22%|██▏       | 1254/5578 MB [00:07]
 23%|██▎       | 1280/5578 MB [00:07]
 23%|██▎       | 1302/5578 MB [00:07]
 24%|██▍       | 1327/5578 MB [00:07]
 24%|██▍       | 1349/5578 MB [00:07]
 25%|██▍       | 1375/5578 MB [00:07]
 25%|██▌       | 1397/5578 MB [00:07]
 26%|██▌       | 1423/5578 MB [00:07]
 26%|██▌       | 1445/5578 MB [00:08]
 26%|██▋       | 1470/5578 MB [00:08]
 27%|██▋       | 1492/5578 MB [00:08]
 27%|██▋       | 1518/5578 MB [00:08]
 28%|██▊       | 1540/5578 MB [00:08]
 28%|██▊       | 1565/5578 MB [00:08]
 28%|██▊       | 1587/5578 MB [00:08]
 29%|██▉       | 1614/5578 MB [00:08]
 29%|██▉       | 1636/5578 MB [00:08]
 30%|██▉       | 1661/5578 MB [00:09]
 30%|███       | 1684/5578 MB [00:09]
 31%|███       | 1709/5578 MB [00:09]
 31%|███       | 1731/5578 MB [00:09]
 31%|███▏      | 1756/5578 MB [00:09]
 32%|███▏      | 1778/5578 MB [00:09]
 32%|███▏      | 1804/5578 MB [00:09]
 33%|███▎      | 1826/5578 MB [00:09]
 33%|███▎      | 1852/5578 MB [00:10]
 34%|███▎      | 1874/5578 MB [00:10]
 34%|███▍      | 1899/5578 MB [00:10]
 34%|███▍      | 1922/5578 MB [00:10]
 35%|███▍      | 1948/5578 MB [00:10]
 35%|███▌      | 1970/5578 MB [00:10]
 36%|███▌      | 1995/5578 MB [00:10]
 36%|███▌      | 2017/5578 MB [00:10]
 37%|███▋      | 2043/5578 MB [00:10]
 37%|███▋      | 2065/5578 MB [00:11]
 37%|███▋      | 2090/5578 MB [00:11]
 38%|███▊      | 2112/5578 MB [00:11]
 38%|███▊      | 2138/5578 MB [00:11]
 39%|███▊      | 2160/5578 MB [00:11]
 39%|███▉      | 2186/5578 MB [00:11]
 40%|███▉      | 2208/5578 MB [00:11]
 40%|████      | 2234/5578 MB [00:11]
 40%|████      | 2256/5578 MB [00:12]
 41%|████      | 2281/5578 MB [00:12]
 41%|████▏     | 2303/5578 MB [00:12]
 42%|████▏     | 2329/5578 MB [00:12]
 42%|████▏     | 2351/5578 MB [00:12]
 43%|████▎     | 2376/5578 MB [00:12]
 43%|████▎     | 2398/5578 MB [00:12]
 43%|████▎     | 2424/5578 MB [00:12]
 44%|████▍     | 2446/5578 MB [00:12]
 44%|████▍     | 2472/5578 MB [00:13]
 45%|████▍     | 2494/5578 MB [00:13]
 45%|████▌     | 2520/5578 MB [00:13]
 46%|████▌     | 2542/5578 MB [00:13]
 46%|████▌     | 2567/5578 MB [00:13]
 46%|████▋     | 2589/5578 MB [00:13]
 47%|████▋     | 2615/5578 MB [00:13]
 47%|████▋     | 2637/5578 MB [00:13]
 48%|████▊     | 2663/5578 MB [00:14]
 48%|████▊     | 2685/5578 MB [00:14]
 49%|████▊     | 2710/5578 MB [00:14]
 49%|████▉     | 2732/5578 MB [00:14]
 49%|████▉     | 2758/5578 MB [00:14]
 50%|████▉     | 2780/5578 MB [00:14]
 50%|█████     | 2806/5578 MB [00:14]
 51%|█████     | 2828/5578 MB [00:14]
 51%|█████     | 2853/5578 MB [00:14]
 52%|█████▏    | 2875/5578 MB [00:15]
 52%|█████▏    | 2900/5578 MB [00:15]
 52%|█████▏    | 2923/5578 MB [00:15]
 53%|█████▎    | 2949/5578 MB [00:15]
 53%|█████▎    | 2971/5578 MB [00:15]
 54%|█████▎    | 2997/5578 MB [00:15]
 54%|█████▍    | 3018/5578 MB [00:15]
 55%|█████▍    | 3044/5578 MB [00:15]
 55%|█████▍    | 3067/5578 MB [00:16]
 55%|█████▌    | 3092/5578 MB [00:16]
 56%|█████▌    | 3114/5578 MB [00:16]
 56%|█████▋    | 3139/5578 MB [00:16]
 57%|█████▋    | 3162/5578 MB [00:16]
 57%|█████▋    | 3187/5578 MB [00:16]
 58%|█████▊    | 3210/5578 MB [00:16]
 58%|█████▊    | 3235/5578 MB [00:16]
 58%|█████▊    | 3257/5578 MB [00:16]
 59%|█████▉    | 3282/5578 MB [00:17]
 59%|█████▉    | 3305/5578 MB [00:17]
 60%|█████▉    | 3331/5578 MB [00:17]
 60%|██████    | 3353/5578 MB [00:17]
 61%|██████    | 3378/5578 MB [00:17]
 61%|██████    | 3400/5578 MB [00:17]
 61%|██████▏   | 3426/5578 MB [00:17]
 62%|██████▏   | 3448/5578 MB [00:17]
 62%|██████▏   | 3473/5578 MB [00:18]
 63%|██████▎   | 3495/5578 MB [00:18]
 63%|██████▎   | 3521/5578 MB [00:18]
 64%|██████▎   | 3543/5578 MB [00:18]
 64%|██████▍   | 3565/5578 MB [00:18]
 64%|██████▍   | 3586/5578 MB [00:18]
 65%|██████▍   | 3607/5578 MB [00:18]
 65%|██████▌   | 3633/5578 MB [00:18]
 66%|██████▌   | 3654/5578 MB [00:18]
 66%|██████▌   | 3675/5578 MB [00:19]
 66%|██████▋   | 3698/5578 MB [00:19]
 67%|██████▋   | 3719/5578 MB [00:19]
 67%|██████▋   | 3744/5578 MB [00:19]
 67%|██████▋   | 3765/5578 MB [00:19]
 68%|██████▊   | 3786/5578 MB [00:19]
 68%|██████▊   | 3809/5578 MB [00:19]
 69%|██████▊   | 3830/5578 MB [00:19]
 69%|██████▉   | 3855/5578 MB [00:19]
 69%|██████▉   | 3876/5578 MB [00:19]
 70%|██████▉   | 3897/5578 MB [00:20]
 70%|███████   | 3920/5578 MB [00:20]
 71%|███████   | 3941/5578 MB [00:20]
 71%|███████   | 3966/5578 MB [00:20]
 71%|███████▏  | 3987/5578 MB [00:20]
 72%|███████▏  | 4008/5578 MB [00:20]
 72%|███████▏  | 4031/5578 MB [00:20]
 73%|███████▎  | 4052/5578 MB [00:20]
 73%|███████▎  | 4078/5578 MB [00:20]
 74%|███████▎  | 4100/5578 MB [00:21]
 74%|███████▍  | 4126/5578 MB [00:21]
 74%|███████▍  | 4148/5578 MB [00:21]
 75%|███████▍  | 4173/5578 MB [00:21]
 75%|███████▌  | 4195/5578 MB [00:21]
 76%|███████▌  | 4221/5578 MB [00:21]
 76%|███████▌  | 4243/5578 MB [00:21]
 77%|███████▋  | 4268/5578 MB [00:21]
 77%|███████▋  | 4290/5578 MB [00:22]
 77%|███████▋  | 4317/5578 MB [00:22]
 78%|███████▊  | 4339/5578 MB [00:22]
 78%|███████▊  | 4364/5578 MB [00:22]
 79%|███████▊  | 4386/5578 MB [00:22]
 79%|███████▉  | 4412/5578 MB [00:22]
 79%|███████▉  | 4434/5578 MB [00:22]
 80%|███████▉  | 4460/5578 MB [00:22]
 80%|████████  | 4482/5578 MB [00:22]
 81%|████████  | 4507/5578 MB [00:23]
 81%|████████  | 4529/5578 MB [00:23]
 82%|████████▏ | 4555/5578 MB [00:23]
 82%|████████▏ | 4577/5578 MB [00:23]
 83%|████████▎ | 4603/5578 MB [00:23]
 83%|████████▎ | 4624/5578 MB [00:23]
 83%|████████▎ | 4650/5578 MB [00:23]
 84%|████████▍ | 4672/5578 MB [00:23]
 84%|████████▍ | 4698/5578 MB [00:24]
 85%|████████▍ | 4720/5578 MB [00:24]
 85%|████████▌ | 4746/5578 MB [00:24]
 85%|████████▌ | 4768/5578 MB [00:24]
 86%|████████▌ | 4795/5578 MB [00:24]
 86%|████████▋ | 4817/5578 MB [00:24]
 87%|████████▋ | 4842/5578 MB [00:24]
 87%|████████▋ | 4864/5578 MB [00:24]
 88%|████████▊ | 4890/5578 MB [00:24]
 88%|████████▊ | 4912/5578 MB [00:25]
 89%|████████▊ | 4938/5578 MB [00:25]
 89%|████████▉ | 4960/5578 MB [00:25]
 89%|████████▉ | 4986/5578 MB [00:25]
 90%|████████▉ | 5008/5578 MB [00:25]
 90%|█████████ | 5033/5578 MB [00:25]
 91%|█████████ | 5055/5578 MB [00:25]
 91%|█████████ | 5081/5578 MB [00:25]
 91%|█████████▏| 5103/5578 MB [00:26]
 92%|█████████▏| 5128/5578 MB [00:26]
 92%|█████████▏| 5150/5578 MB [00:26]
 93%|█████████▎| 5176/5578 MB [00:26]
 93%|█████████▎| 5198/5578 MB [00:26]
 94%|█████████▎| 5223/5578 MB [00:26]
 94%|█████████▍| 5245/5578 MB [00:26]
 94%|█████████▍| 5271/5578 MB [00:26]
 95%|█████████▍| 5293/5578 MB [00:26]
 95%|█████████▌| 5319/5578 MB [00:27]
 96%|█████████▌| 5341/5578 MB [00:27]
 96%|█████████▌| 5367/5578 MB [00:27]
 97%|█████████▋| 5389/5578 MB [00:27]
 97%|█████████▋| 5414/5578 MB [00:27]
 97%|█████████▋| 5436/5578 MB [00:27]
 98%|█████████▊| 5461/5578 MB [00:27]
 98%|█████████▊| 5483/5578 MB [00:27]
 99%|█████████▉| 5510/5578 MB [00:28]
 99%|█████████▉| 5532/5578 MB [00:28]
100%|█████████▉| 5557/5578 MB [00:28]
100%|██████████| 5578/5578 MB [00:28]

  0%|          | 0/1 MB [00:00]
100%|██████████| 1/1 MB [00:00]

  0%|          | 0/1 MB [00:00]
100%|██████████| 1/1 MB [00:00]

  0%|          | 0/71 MB [00:00]
  4%|▍         | 3/71 MB [00:00]
 10%|▉         | 7/71 MB [00:00]
 17%|█▋        | 12/71 MB [00:00]
 27%|██▋       | 19/71 MB [00:00]
 38%|███▊      | 27/71 MB [00:00]
 54%|█████▎    | 38/71 MB [00:00]
 72%|███████▏  | 51/71 MB [00:01]
 93%|█████████▎| 66/71 MB [00:01]
100%|██████████| 71/71 MB [00:01]

  0%|          | 0/4 MB [00:00]
100%|██████████| 4/4 MB [00:00]

  0%|          | 0/1 MB [00:00]
100%|██████████| 1/1 MB [00:00]

Set tractography parameters (optional)#

We make this tracking_params which we will pass to the GroupAFQ object which specifies that we want 100,000 seeds randomly distributed in the ROIs of every bundle.

We only do this to make this example faster and consume less space.

tracking_params = dict(seed_mask=RoiImage(),
                       n_seeds=10000,
                       random_seeds=True,
                       rng_seed=42)

Set segmentation parameters (optional)#

We make this segmentation_params which we will pass to the GroupAFQ object which specifies that we want to clip the extracted tract profiles to only be between the two ROIs.

We do this because tract profiles become less reliable as the bundles approach the gray matter-white matter boundary. On some of the non-callosal bundles, ROIs are not in a good position to clip edges. In these cases, one can remove the first and last nodes in a tract profile.

segmentation_params = {"clip_edges": True}

Initialize a GroupAFQ object:#

We specify bundle_info as the callosal bundles only (abd.callosal_bd). If we want to segment both the callosum and the other bundles, we would pass abd.callosal_bd() + abd.default18_bd() instead. This would tell the GroupAFQ object to use bundles from both the standard and callosal templates.

myafq = GroupAFQ(
    bids_path=op.join(afd.afq_home, 'stanford_hardi'),
    preproc_pipeline='vistasoft',
    bundle_info=abd.callosal_bd(),
    tracking_params=tracking_params,
    segmentation_params=segmentation_params,
    viz_backend_spec='plotly_no_gif')

# Calling export all produces all of the outputs of processing, including
# tractography, scalar maps, tract profiles and visualizations:
myafq.export_all()
  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]

  0%|          | 0/2 MB [00:00]
100%|██████████| 2/2 MB [00:00]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T2w.nii.gz

  0%|          | 0.00/13.3M [00:00<?, ?B/s]
 28%|██▊       | 3.66M/13.3M [00:00<00:00, 36.6MB/s]
100%|██████████| 13.3M/13.3M [00:00<00:00, 67.3MB/s]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_mask.nii.gz

  0%|          | 0.00/160k [00:00<?, ?B/s]
100%|██████████| 160k/160k [00:00<00:00, 18.4MB/s]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz

  0%|          | 0.00/13.7M [00:00<?, ?B/s]
 35%|███▍      | 4.74M/13.7M [00:00<00:00, 47.4MB/s]
 85%|████████▌ | 11.7M/13.7M [00:00<00:00, 60.2MB/s]
100%|██████████| 13.7M/13.7M [00:00<00:00, 57.2MB/s]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]

0it [00:00, ?it/s]
24it [00:00, 236.43it/s]
48it [00:00, 208.49it/s]
70it [00:00, 201.30it/s]
92it [00:00, 206.31it/s]
116it [00:00, 216.01it/s]
138it [00:00, 197.33it/s]
160it [00:00, 202.46it/s]
184it [00:00, 210.74it/s]
206it [00:00, 205.28it/s]
227it [00:01, 202.80it/s]
251it [00:01, 212.36it/s]
274it [00:01, 216.73it/s]
296it [00:01, 216.55it/s]
323it [00:01, 231.88it/s]
347it [00:01, 229.01it/s]
372it [00:01, 230.69it/s]
396it [00:01, 220.19it/s]
419it [00:01, 210.60it/s]
446it [00:02, 224.25it/s]
470it [00:02, 228.35it/s]
495it [00:02, 232.67it/s]
519it [00:02, 228.82it/s]
543it [00:02, 229.14it/s]
566it [00:02, 211.58it/s]
592it [00:02, 223.23it/s]
617it [00:02, 227.41it/s]
641it [00:02, 230.92it/s]
665it [00:03, 233.37it/s]
689it [00:03, 219.11it/s]
712it [00:03, 206.79it/s]
734it [00:03, 208.43it/s]
758it [00:03, 217.02it/s]
782it [00:03, 223.05it/s]
805it [00:03, 207.07it/s]
831it [00:03, 219.28it/s]
856it [00:03, 227.66it/s]
880it [00:04, 208.00it/s]
902it [00:04, 207.33it/s]
929it [00:04, 222.36it/s]
952it [00:04, 220.54it/s]
975it [00:04, 215.14it/s]
997it [00:04, 211.10it/s]
1019it [00:04, 211.51it/s]
1041it [00:04, 202.69it/s]
1062it [00:04, 195.18it/s]
1085it [00:05, 203.07it/s]
1107it [00:05, 204.25it/s]
1128it [00:05, 205.84it/s]
1151it [00:05, 211.67it/s]
1173it [00:05, 205.97it/s]
1194it [00:05, 203.57it/s]
1220it [00:05, 218.58it/s]
1244it [00:05, 221.26it/s]
1269it [00:05, 228.77it/s]
1292it [00:05, 224.59it/s]
1315it [00:06, 220.46it/s]
1338it [00:06, 222.66it/s]
1361it [00:06, 215.65it/s]
1385it [00:06, 222.45it/s]
1409it [00:06, 225.35it/s]
1435it [00:06, 233.32it/s]
1459it [00:06, 227.77it/s]
1482it [00:06, 211.66it/s]
1504it [00:06, 209.15it/s]
1526it [00:07, 201.17it/s]
1547it [00:07, 202.55it/s]
1570it [00:07, 206.56it/s]
1591it [00:07, 206.20it/s]
1612it [00:07, 199.15it/s]
1634it [00:07, 204.91it/s]
1655it [00:07, 206.06it/s]
1678it [00:07, 212.97it/s]
1700it [00:07, 203.56it/s]
1721it [00:08, 197.46it/s]
1742it [00:08, 200.90it/s]
1765it [00:08, 208.07it/s]
1787it [00:08, 209.57it/s]
1809it [00:08, 201.09it/s]
1830it [00:08, 203.45it/s]
1851it [00:08, 200.84it/s]
1872it [00:08, 200.45it/s]
1896it [00:08, 210.16it/s]
1918it [00:08, 204.48it/s]
1939it [00:09, 204.44it/s]
1960it [00:09, 204.07it/s]
1981it [00:09, 204.23it/s]
2005it [00:09, 211.76it/s]
2028it [00:09, 215.11it/s]
2054it [00:09, 221.57it/s]
2077it [00:09, 223.16it/s]
2104it [00:09, 235.77it/s]
2131it [00:09, 244.45it/s]
2156it [00:10, 241.45it/s]
2181it [00:10, 235.34it/s]
2205it [00:10, 225.26it/s]
2228it [00:10, 217.39it/s]
2252it [00:10, 220.75it/s]
2275it [00:10, 214.25it/s]
2297it [00:10, 210.98it/s]
2320it [00:10, 214.14it/s]
2342it [00:10, 207.25it/s]
2367it [00:11, 218.10it/s]
2390it [00:11, 220.44it/s]
2413it [00:11, 213.26it/s]
2438it [00:11, 218.70it/s]
2460it [00:11, 211.79it/s]
2482it [00:11, 211.38it/s]
2505it [00:11, 215.77it/s]
2527it [00:11, 214.08it/s]
2549it [00:11, 208.91it/s]
2570it [00:11, 208.00it/s]
2594it [00:12, 216.90it/s]
2619it [00:12, 222.60it/s]
2642it [00:12, 203.48it/s]
2665it [00:12, 210.57it/s]
2687it [00:12, 212.57it/s]
2709it [00:12, 201.17it/s]
2730it [00:12, 202.33it/s]
2757it [00:12, 219.40it/s]
2780it [00:12, 217.36it/s]
2804it [00:13, 219.52it/s]
2828it [00:13, 225.09it/s]
2851it [00:13, 222.28it/s]
2874it [00:13, 220.71it/s]
2897it [00:13, 223.30it/s]
2921it [00:13, 227.07it/s]
2946it [00:13, 230.83it/s]
2970it [00:13, 226.74it/s]
2993it [00:13, 209.81it/s]
3015it [00:14, 203.02it/s]
3037it [00:14, 206.99it/s]
3061it [00:14, 215.10it/s]
3089it [00:14, 232.76it/s]
3113it [00:14, 230.76it/s]
3137it [00:14, 223.69it/s]
3160it [00:14, 204.31it/s]
3185it [00:14, 215.09it/s]
3198it [00:14, 215.07it/s]
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/AFQ/tasks/segmentation.py:61: UserWarning:

Pass ['to_space'] as keyword args. From version 2.0.0 passing these as positional arguments will result in an error.


  0%|          | 0/8 [00:00<?, ?it/s]
 12%|█▎        | 1/8 [00:00<00:01,  5.49it/s]
 25%|██▌       | 2/8 [00:00<00:01,  5.97it/s]
 38%|███▊      | 3/8 [00:00<00:00,  6.15it/s]
 50%|█████     | 4/8 [00:00<00:00,  5.94it/s]
 62%|██████▎   | 5/8 [00:00<00:00,  6.04it/s]
 75%|███████▌  | 6/8 [00:00<00:00,  6.13it/s]
 88%|████████▊ | 7/8 [00:01<00:00,  6.22it/s]
100%|██████████| 8/8 [00:01<00:00,  5.99it/s]
100%|██████████| 8/8 [00:01<00:00,  6.02it/s]

  0%|          | 0/8 [00:00<?, ?it/s]
 12%|█▎        | 1/8 [00:00<00:01,  5.35it/s]
 25%|██▌       | 2/8 [00:00<00:01,  5.42it/s]
 38%|███▊      | 3/8 [00:00<00:00,  5.58it/s]
 50%|█████     | 4/8 [00:00<00:00,  5.60it/s]
 62%|██████▎   | 5/8 [00:00<00:00,  5.60it/s]
 75%|███████▌  | 6/8 [00:01<00:00,  5.56it/s]
 88%|████████▊ | 7/8 [00:01<00:00,  5.55it/s]
100%|██████████| 8/8 [00:01<00:00,  5.53it/s]
100%|██████████| 8/8 [00:01<00:00,  5.54it/s]

Create Group Density Maps:#

pyAFQ can make density maps of streamline counts per subject/session by calling myafq.export(“density_map”). When using GroupAFQ, you can also combine these into one file by calling myafq.export_group_density().

group_density = myafq.export_group_density()
group_density = nib.load(group_density).get_fdata()
fig, ax = plt.subplots(1)
ax.matshow(
    group_density[:, :, group_density.shape[-1] // 2, 0],
    cmap='viridis')
ax.axis("off")
plot afq callosal
  0%|          | 0/1 [00:00<?, ?it/s]
100%|██████████| 1/1 [00:00<00:00, 22.06it/s]

(np.float64(-0.5), np.float64(105.5), np.float64(80.5), np.float64(-0.5))

Visualizing bundles and tract profiles:#

This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.

bundle_html = myafq.export("all_bundles_figure")
plotly.io.show(bundle_html["01"][0])

Total running time of the script: (10 minutes 57.133 seconds)

Estimated memory usage: 2857 MB

Gallery generated by Sphinx-Gallery