{ "metadata": { "name": "", "signature": "sha256:a71e596f4a5552f929c07c4697c19e353df5a3c8de01edaa87ca4b6335745118" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import osmosis" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "osmosis.__file__" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "'/home/arokem/usr/local/lib/python2.7/site-packages/osmosis/__init__.pyc'" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "import osmosis.io as oio\n", "import osmosis.model.isotropic as mdm\n", "import nibabel as nib\n", "import os\n", "%matplotlib inline" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Table of Contents" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "[1] Creating white matter masks\n", "[2] Remove the ventricles from a white matter mask\n", "[3] Aggregating file pieces from parallel computing" ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Abbreviations" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Isotropic Models" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "bi_exp_rs - two decaying exponentials fit to the relative diffusion signal (bi-exponential)\n", "single_exp_rs - one decaying exponentials fit to the relative diffusion signal (single exponential)" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Diffusion Models" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "sfm - sparse fascicle model\n", " mfODF_se - multi fODF diffusion model with a single exponential isotropic model\n", " mfODF_be - multi fODF diffusion model with a bi-exponential isotropic model\n", " sfODF_se - single fODF diffusion model with a single exponential isotropic model\n", " sfODF_be - single fODF diffusion model with a bi-exponential isotropic model\n", "dtm - diffusion tensor model" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Miscellaneous" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "wm - white matter\n", "mp - model parameters\n", "cod - coefficient of determination\n", "ad - axial diffusivity\n", "rd - radial diffusivity" ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Load the data" ] }, { "cell_type": "code", "collapsed": false, "input": [ "subject_id = \"103414\"\n", "data_path = \"/biac4/wandell/data/klchan13/hcp_data_q3/%s/T1w/Diffusion/\"%subject_id\n", "\n", "data_file = nib.load(os.path.join(data_path, \"data.nii.gz\"))\n", "data = data_file.get_data()\n", "\n", "wm_data_file = nib.load(os.path.join(data_path,\"wm_mask_no_vent.nii.gz\"))\n", "wm_data = wm_data_file.get_data()\n", "\n", "bvals = np.loadtxt(os.path.join(data_path, \"bvals\"))\n", "bvecs = np.loadtxt(os.path.join(data_path, \"bvecs\"))" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "[1] Creating white matter masks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a white matter mask using the ribbon file from freesurfer." ] }, { "cell_type": "code", "collapsed": false, "input": [ "def wm_mask(ribbon_file, data_path, file_name=False):\n", " \"\"\"\n", " Takes a ribbon file and creates a white matter mask.\n", " \"\"\"\n", " ribbon_data = ribbon_file.get_data()\n", " ribbon_affine = ribbon_file.get_affine()\n", " \n", " wm_mask_out = np.zeros(ribbon_data.shape)\n", " \n", " # These are labels that should be included in the white matter mask.\n", " labels = [2, 41, 16, 17, 28, 60, 51, 53, 12, 52, 13, 18, 54, 50, 11, 251, 252, 253, 254, 255, 10, 49, 46, 7]\n", " for label in labels:\n", " wm_mask_out[np.where(ribbon_data == label)] = 1\n", " \n", " nii = nib.Nifti1Image(wm_mask_out, ribbon_affine)\n", " if file_name:\n", " nii.to_filename(os.path.join(data_path, file_name))\n", " \n", " return wm_mask_out" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extract a white matter mask from all the brains " ] }, { "cell_type": "code", "collapsed": false, "input": [ "sid_list = [\"103414\", \"105115\", \"110411\", \"111312\", \"113619\",\n", " \"115320\", \"117122\", \"118730\", \"118932\", \"110411\"]\n", "\n", "for sid in sid_list:\n", " data_path1 = \"/biac4/wandell/data/klchan13/hcp_data_q3/%s/T1w/Diffusion/\"%sid\n", " ribbon_file = nib.load(os.path.join(data_path1, \"wm_mask.nii.gz\"))\n", " wm_mask_out = wm_mask(ribbon_file, data_path1, file_name=\"wm_mask_no_vent.nii.gz\")" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "[2] Remove the ventricles from a white matter mask" ] }, { "cell_type": "code", "collapsed": false, "input": [ "wm_mask_no_vent = oio.rm_ventricles(wm_data_file, bvals, bvecs, data, data_path)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "[3] Aggregating file pieces from parallel computing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "SSH to proclus and navigate to the file directory with all the file pieces. Open up ipython and load all the data as well as the io module then enter the following. The COD file pieces are used as an example." ] }, { "cell_type": "code", "collapsed": false, "input": [ "file_names = [\"sfm_cod_multi_se\", \"sfm_cod_multi_be\"]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "missing_files, vol_list = place_files(file_names, 2000, 65, wm_data, data, bvals)" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }