Skip to content

Commit

Permalink
revert accidental changes to tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
tyarkoni committed Oct 6, 2018
1 parent b418631 commit b25be29
Showing 1 changed file with 32 additions and 134 deletions.
166 changes: 32 additions & 134 deletions examples/pybids tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,18 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/tal/miniconda3/envs/base/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
"Failed to import duecredit due to No module named 'duecredit'\n",
"/home/ltirrell/anaconda3/envs/pybids/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n",
" return f(*args, **kwds)\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"import bids.layout\n",
"from bids import BIDSLayout\n",
"import bids.tests\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"ld = os.path.dirname(bids.layout.__file__)\n",
"path = os.path.join(ld, 'config', 'bids.json')\n",
"config = json.load(open(path))\n",
"# config"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -63,69 +48,29 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-01T20:05:23.739377Z",
"start_time": "2018-08-01T20:05:23.630505Z"
}
},
"outputs": [],
"source": [
"# Initialise a BIDSLayout of an example dataset\n",
"layout = BIDSLayout(os.path.join(bids.tests.get_test_data_path(), 'ds005'), validate=False)\n",
"# layout"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'bids_validator'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-7-1e72ffd0fcab>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mbids_validator\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mBIDSValidator\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mlayout\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidator\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBIDSValidator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindex_associated\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mlayout\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# files = [layout._validate_file(f) for f in layout.files.keys()]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# all(files)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'bids_validator'"
]
}
],
"source": [
"from bids_validator_common import BIDSValidator\n",
"layout.validator = BIDSValidator(index_associated=True)\n",
"layout.validate = True\n",
"# files = [layout._validate_file(f) for f in layout.files.keys()]\n",
"# all(files)\n",
"for f in layout.files.keys():\n",
" print(f, layout._validate_file(f))\n",
"# layout.validator.is_bids('test.nii.gz')\n",
"# layout.validate"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
"BIDS Layout: .../pybids/bids/tests/data/7t_trt | Subjects: 10 | Sessions: 20 | Runs: 20"
]
},
"execution_count": 16,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"layout.validator.is_bids('run-1_echo-5_FLASH.json')"
"# Initialise a BIDSLayout of an example dataset\n",
"layout = bids.layout.BIDSLayout(os.path.join(bids.tests.get_test_data_path(), '7t_trt'))\n",
"layout"
]
},
{
Expand All @@ -138,59 +83,29 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-01T20:05:23.926278Z",
"start_time": "2018-08-01T20:05:23.741189Z"
},
"scrolled": true
},
"outputs": [],
"source": [
"# The file objects returned are tuples of key-value pairs\n",
"layout.get()[10]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/Users/tal/Dropbox/Code/grabbit/grabbit/__init__.py'"
"File(filename='/home/ltirrell/projects/pybids/bids/tests/data/7t_trt/sub-01/ses-1/fmap/sub-01_ses-1_run-2_phasediff.json', subject='01', session='1', run='2', type='phasediff', modality='fmap')"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import grabbit\n",
"grabbit.__file__"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'sub-01/func/sub-01_task-motor_run-1_bold.nii.gz'"
]
},
"execution_count": 22,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"layout.build_path(dict(subject='01', run=1, task='motor', type='bold'), strict=True)"
"# The file objects returned are tuples of key-value pairs\n",
"layout.get()[10]"
]
},
{
Expand All @@ -202,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-01T20:05:23.933121Z",
Expand All @@ -214,10 +129,10 @@
{
"data": {
"text/plain": [
"[File(filename='/Users/tal/Dropbox/Code/pybids/bids/tests/data/7t_trt/sub-01/ses-1/anat/sub-01_ses-1_T1w.nii.gz', subject='01', session='1', type='T1w', modality='anat')]"
"[File(filename='/home/ltirrell/projects/pybids/bids/tests/data/7t_trt/sub-01/ses-1/anat/sub-01_ses-1_T1w.nii.gz', subject='01', session='1', type='T1w', modality='anat')]"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -227,27 +142,6 @@
"layout.get(type='T1w', subject='01')"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'type': 'test',\n",
" 'bval': '/Users/tal/Dropbox/Code/pybids/bids/tests/data/7t_trt/test.bval'}"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"layout.get(extensions=\"bval\", return_type='obj')[0].entities"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -257,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-08-01T20:05:23.945162Z",
Expand All @@ -268,23 +162,27 @@
{
"data": {
"text/plain": [
"[{'A', 'B', 'C'}]"
"[<grabbit.core.File at 0x7fd8ddc81a58>,\n",
" <grabbit.core.File at 0x7fd8ddc92748>,\n",
" <grabbit.core.File at 0x7fd8ddc232e8>,\n",
" <grabbit.core.File at 0x7fd8ddc29f98>,\n",
" <grabbit.core.File at 0x7fd8ddc38b00>,\n",
" <grabbit.core.File at 0x7fd8ddc4b668>,\n",
" <grabbit.core.File at 0x7fd8ddc5a2e8>,\n",
" <grabbit.core.File at 0x7fd8ddbe1d68>,\n",
" <grabbit.core.File at 0x7fd8ddbf2b38>,\n",
" <grabbit.core.File at 0x7fd8ddc04780>]"
]
},
"execution_count": 46,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Ask get() to return the matching file objects\n",
"# layout.get(type='T1w', return_type='obj')\n",
"# You can convert an obj to a tuple by using the .as_named_tuple() method\n",
"sets = [{'A', 'B', 'C'}, {'B', 'D', 'E'}, {'B', 'E', 'F'}]\n",
"def proc(x, y):\n",
" return sets[x] & sets[y]\n",
"\n",
"list(map(proc, list(range(len(sets))), [0]))"
"layout.get(type='T1w', return_type='obj')\n",
"# You can convert an obj to a tuple by using the .as_named_tuple() method"
]
},
{
Expand Down Expand Up @@ -1705,7 +1603,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.6"
},
"toc": {
"nav_menu": {},
Expand Down

0 comments on commit b25be29

Please sign in to comment.