From b25be2903608c95a192e69a081bd3a8d3dbfc3a3 Mon Sep 17 00:00:00 2001 From: Tal Yarkoni Date: Sat, 6 Oct 2018 16:33:44 -0500 Subject: [PATCH] revert accidental changes to tutorial --- examples/pybids tutorial.ipynb | 166 +++++++-------------------------- 1 file changed, 32 insertions(+), 134 deletions(-) diff --git a/examples/pybids tutorial.ipynb b/examples/pybids tutorial.ipynb index 81a9b8890..8b1629363 100644 --- a/examples/pybids tutorial.ipynb +++ b/examples/pybids tutorial.ipynb @@ -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": {}, @@ -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\u001b[0m in \u001b[0;36m\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" ] }, { @@ -138,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-08-01T20:05:23.926278Z", @@ -146,51 +91,21 @@ }, "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]" ] }, { @@ -202,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-08-01T20:05:23.933121Z", @@ -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" } @@ -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": {}, @@ -257,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-08-01T20:05:23.945162Z", @@ -268,23 +162,27 @@ { "data": { "text/plain": [ - "[{'A', 'B', 'C'}]" + "[,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ]" ] }, - "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" ] }, { @@ -1705,7 +1603,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.6" }, "toc": { "nav_menu": {},