{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# BUAN Bundle Assignment Maps Creation\n\nThis example explains how we can use BUAN [Chandio2020]_ to create assignment\nmaps on a bundle. Divide bundle into N smaller segments.\n\n\nFirst import the necessary modules.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom dipy.data import get_two_hcp842_bundles\nfrom dipy.data import fetch_bundle_atlas_hcp842\nfrom dipy.io.streamline import load_trk\nfrom dipy.stats.analysis import assignment_map\nfrom dipy.viz import actor, window" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download and read data for this tutorial\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "atlas_file, atlas_folder = fetch_bundle_atlas_hcp842()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Read AF left and CST left bundles from already fetched atlas data to use them\nas model bundles\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "model_af_l_file, model_cst_l_file = get_two_hcp842_bundles()\n\nsft_af_l = load_trk(model_af_l_file, \"same\", bbox_valid_check=False)\nmodel_af_l = sft_af_l.streamlines" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "let's visualize Arcuate Fasiculus Left (AF_L) bundle before assignment maps\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "interactive = False\n\nscene = window.Scene()\nscene.SetBackground(1, 1, 1)\nscene.add(actor.line(model_af_l, fake_tube=True, linewidth=6))\nscene.set_camera(focal_point=(-18.17281532, -19.55606842, 6.92485857),\n position=(-360.11, -30.46, -40.44),\n view_up=(-0.03, 0.028, 0.89))\nwindow.record(scene, out_path='af_l_before_assignment_maps.png',\n size=(600, 600))\nif interactive:\n window.show(scene)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. figure:: af_l_before_assignment_maps.png\n :align: center\n\n AF_L before assignment maps\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Creating 100 bundle assignment maps on AF_L using BUAN [Chandio2020]_\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "n = 100\nindx = assignment_map(model_af_l, model_af_l, n)\nindx = np.array(indx)\n\ncolors = [np.random.rand(3) for si in range(n)]\n\ndisks_color = []\nfor i in range(len(indx)):\n disks_color.append(tuple(colors[indx[i]]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "let's visualize Arcuate Fasiculus Left (AF_L) bundle after assignment maps\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "interactive = False\n\nscene = window.Scene()\nscene.SetBackground(1, 1, 1)\nscene.add(actor.line(model_af_l, fake_tube=True, colors=disks_color,\n linewidth=6))\nscene.set_camera(focal_point=(-18.17281532, -19.55606842, 6.92485857),\n position=(-360.11, -30.46, -40.44),\n view_up=(-0.03, 0.028, 0.89))\nwindow.record(scene, out_path='af_l_after_assignment_maps.png',\n size=(600, 600))\nif interactive:\n window.show(scene)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. figure:: af_l_after_assignment_maps.png\n :align: center\n\n AF_L after assignment maps\n\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## References\n\n.. [Chandio2020] Chandio, B.Q., Risacher, S.L., Pestilli, F.,\n Bullock, D., Yeh, FC., Koudoro, S., Rokem, A., Harezlak, J., and\n Garyfallidis, E. Bundle analytics, a computational framework for\n investigating the shapes and profiles of brain pathways across\n populations. Sci Rep 10, 17149 (2020)\n\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 0 }