Skip to content

Instantly share code, notes, and snippets.

@arokem
Created February 3, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arokem/a62377a861ca4b02db15 to your computer and use it in GitHub Desktop.
Save arokem/a62377a861ca4b02db15 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import dipy.core.gradients as dpg\n",
"import dipy.data as dpd\n",
"import dipy.reconst.dti as dti\n",
"import nibabel as nib"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%load_ext memory_profiler"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dataset is already in place. If you want to fetch it again please first remove the folder /Users/arokem/.dipy/cenir_multib \n"
]
}
],
"source": [
"img, gtab = dpd.read_cenir_multib()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data = img.get_data()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(104, 104, 72, 652)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"S0 = np.mean(data[..., ~gtab.b0s_mask], -1)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 5015.63 MiB, increment: 3870.77 MiB\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/arokem/source/dipy/dipy/reconst/dti.py:1759: RuntimeWarning: invalid value encountered in log\n",
" def decompose_tensor(tensor, min_diffusivity=0):\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 2797.88 MiB, increment: 709.55 MiB\n",
"peak memory: 5947.23 MiB, increment: 3873.91 MiB\n",
"peak memory: 6081.25 MiB, increment: 3869.66 MiB\n",
"peak memory: 5679.02 MiB, increment: 3866.48 MiB\n"
]
}
],
"source": [
"for step in [1, 10, 100, 1000, 10000]:\n",
" tenmodel = dti.TensorModel(gtab, step=step)\n",
" tenfit = tenmodel.fit(data)\n",
" %memit pred = tenfit.predict(gtab, S0) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment