Skip to content

Commit

Permalink
sty: format jupyter notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Aug 16, 2024
1 parent a6a2ba8 commit 944e990
Show file tree
Hide file tree
Showing 6 changed files with 726 additions and 254 deletions.
73 changes: 51 additions & 22 deletions docs/notebooks/MRIQC Web API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"source": [
"import pandas as pd\n",
"from json import load\n",
"import urllib.request, json \n",
"import urllib.request, json\n",
"from pandas.io.json import json_normalize\n",
"import seaborn as sns\n",
"import pylab as plt\n",
"import multiprocessing as mp\n",
"import numpy as np\n",
"\n",
"%matplotlib inline"
]
},
Expand All @@ -52,23 +53,22 @@
" url_root = 'https://mriqc.nimh.nih.gov/api/v1/{modality}?{query}'\n",
" page = 1\n",
" dfs = []\n",
" \n",
"\n",
" if versions is None:\n",
" versions = ['*']\n",
"\n",
" for version in versions:\n",
" while True:\n",
" query = []\n",
" \n",
"\n",
" if software is not None:\n",
" query.append('\"provenance.software\":\"%s\"' % software)\n",
" \n",
"\n",
" if version != '*':\n",
" query.append('\"provenance.version\":\"%s\"' % version)\n",
" \n",
"\n",
" page_url = url_root.format(\n",
" modality=modality,\n",
" query='where={%s}&page=%d' % (','.join(query), page)\n",
" modality=modality, query='where={%s}&page=%d' % (','.join(query), page)\n",
" )\n",
" with urllib.request.urlopen(page_url) as url:\n",
" data = json.loads(url.read().decode())\n",
Expand All @@ -87,13 +87,13 @@
" Distribution plot of a given measure\n",
" \"\"\"\n",
" sns.distplot(data, ax=ax, label=label)\n",
" \n",
"\n",
" if xlabel is not None:\n",
" ax.set_xlabel(xlabel)\n",
" \n",
"\n",
" if min is None:\n",
" min = np.percentile(data, 0.5)\n",
" \n",
"\n",
" if max is None:\n",
" max = np.percentile(data, 99.5)\n",
" ax.set_xlim((min, max))"
Expand Down Expand Up @@ -165,7 +165,7 @@
"ax.set_title('Number of T1w records in database')\n",
"ax.legend()\n",
"\n",
"plt.savefig(\"fig03a-0.svg\", bbox_inches='tight', transparent=False, pad_inches=0)"
"plt.savefig('fig03a-0.svg', bbox_inches='tight', transparent=False, pad_inches=0)"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
"ax.plot(dates_bold_u, list(range(1, len(dates_bold_u) + 1)), label='unique')\n",
"ax.set_title('Number of BOLD records in database')\n",
"ax.legend()\n",
"plt.savefig(\"fig03a-1.svg\", bbox_inches='tight', transparent=False, pad_inches=0)"
"plt.savefig('fig03a-1.svg', bbox_inches='tight', transparent=False, pad_inches=0)"
]
},
{
Expand All @@ -221,8 +221,17 @@
}
],
"source": [
"print(','.join([l for l in df_t1w.columns \n",
" if not l.startswith('_') and not l.startswith('bids_meta') and not l.startswith('provenance')]))"
"print(\n",
" ','.join(\n",
" [\n",
" l\n",
" for l in df_t1w.columns\n",
" if not l.startswith('_')\n",
" and not l.startswith('bids_meta')\n",
" and not l.startswith('provenance')\n",
" ]\n",
" )\n",
")"
]
},
{
Expand All @@ -242,14 +251,18 @@
}
],
"source": [
"f, ax = plt.subplots(1, 5, figsize=(25,5))\n",
"f, ax = plt.subplots(1, 5, figsize=(25, 5))\n",
"plot_measure(df_t1w_unique.cjv, xlabel='Coefficient of joint variation (CJV)', ax=ax[0])\n",
"plot_measure(df_t1w_unique.cnr, xlabel='Contrast-to-noise ratio (CNR)', ax=ax[1])\n",
"plot_measure(df_t1w_unique.snr_wm, xlabel='Signal-to-noise ratio estimated on the white-matter (SNR)', ax=ax[2])\n",
"plot_measure(\n",
" df_t1w_unique.snr_wm,\n",
" xlabel='Signal-to-noise ratio estimated on the white-matter (SNR)',\n",
" ax=ax[2],\n",
")\n",
"plot_measure(df_t1w_unique.fwhm_avg, xlabel='Smoothness (FWHM)', ax=ax[3])\n",
"plot_measure(df_t1w_unique.wm2max, xlabel='WM-to-max intensity ratio (WM2MAX)', ax=ax[4])\n",
"plt.suptitle('Distributions of some IQMs extracted from T1-weighted MRI')\n",
"plt.savefig(\"fig03b-0.svg\", bbox_inches='tight', transparent=False, pad_inches=0)"
"plt.savefig('fig03b-0.svg', bbox_inches='tight', transparent=False, pad_inches=0)"
]
},
{
Expand All @@ -275,8 +288,17 @@
}
],
"source": [
"print(','.join([l for l in df_bold.columns \n",
" if not l.startswith('_') and not l.startswith('bids_meta') and not l.startswith('provenance')]))"
"print(\n",
" ','.join(\n",
" [\n",
" l\n",
" for l in df_bold.columns\n",
" if not l.startswith('_')\n",
" and not l.startswith('bids_meta')\n",
" and not l.startswith('provenance')\n",
" ]\n",
" )\n",
")"
]
},
{
Expand All @@ -296,16 +318,23 @@
}
],
"source": [
"f, ax = plt.subplots(1, 5, figsize=(25,5))\n",
"plot_measure(df_bold_unique[df_bold_unique.fd_mean < 10].fd_mean, xlabel='Framewise Displacement (mm)', max=2, ax=ax[0])\n",
"f, ax = plt.subplots(1, 5, figsize=(25, 5))\n",
"plot_measure(\n",
" df_bold_unique[df_bold_unique.fd_mean < 10].fd_mean,\n",
" xlabel='Framewise Displacement (mm)',\n",
" max=2,\n",
" ax=ax[0],\n",
")\n",
"plot_measure(df_bold_unique[df_bold_unique.dvars_nstd < 100].dvars_nstd, xlabel='DVARS', ax=ax[1])\n",
"plot_measure(df_bold_unique.gcor, xlabel='Global correlation', ax=ax[2])\n",
"plot_measure(df_bold_unique.gsr_x, label='x-axis', ax=ax[3])\n",
"plot_measure(df_bold_unique.gsr_y, xlabel='Ghost-to-signal ratio (GSR)', label='y-axis', ax=ax[3])\n",
"ax[3].legend()\n",
"plot_measure(df_bold_unique.tsnr, xlabel='Temporal SNR (tSNR)', ax=ax[4])\n",
"plt.suptitle('Distributions of some IQMs extracted from BOLD fMRI')\n",
"plt.savefig(\"fig03b-1.png\", bbox_inches='tight', transparent=False, pad_inches=0, facecolor='white')"
"plt.savefig(\n",
" 'fig03b-1.png', bbox_inches='tight', transparent=False, pad_inches=0, facecolor='white'\n",
")"
]
}
],
Expand Down
Loading

0 comments on commit 944e990

Please sign in to comment.