Skip to content

Commit dab5ac5

Browse files
committed
TST improve test coverage
1 parent 1e88636 commit dab5ac5

20 files changed

Lines changed: 128 additions & 205 deletions

tutorials/notebooks/shortclips/00_download_shortclips.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"name": "python",
9090
"nbconvert_exporter": "python",
9191
"pygments_lexer": "ipython3",
92-
"version": "3.7.12"
92+
"version": "3.9.0"
9393
}
9494
},
9595
"nbformat": 4,

tutorials/notebooks/shortclips/00_setup_colab.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"name": "python",
115115
"nbconvert_exporter": "python",
116116
"pygments_lexer": "ipython3",
117-
"version": "3.7.12"
117+
"version": "3.9.0"
118118
}
119119
},
120120
"nbformat": 4,

tutorials/notebooks/shortclips/01_plot_explainable_variance.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"from voxelwise_tutorials.io import get_data_home\ndirectory = get_data_home(dataset=\"shortclips\")\nprint(directory)"
47+
"from voxelwise_tutorials.io import get_data_home\n\ndirectory = get_data_home(dataset=\"shortclips\")\nprint(directory)"
4848
]
4949
},
5050
{
@@ -91,7 +91,7 @@
9191
},
9292
"outputs": [],
9393
"source": [
94-
"import os\nfile_name = os.path.join(directory, 'responses', f'{subject}_responses.hdf')\nY_test = load_hdf5_array(file_name, key=\"Y_test\")\nprint(\"(n_repeats, n_samples_test, n_voxels) =\", Y_test.shape)"
94+
"import os\n\nfile_name = os.path.join(directory, 'responses', f'{subject}_responses.hdf')\nY_test = load_hdf5_array(file_name, key=\"Y_test\")\nprint(\"(n_repeats, n_samples_test, n_voxels) =\", Y_test.shape)"
9595
]
9696
},
9797
{
@@ -109,7 +109,7 @@
109109
},
110110
"outputs": [],
111111
"source": [
112-
"from voxelwise_tutorials.utils import explainable_variance\nev = explainable_variance(Y_test)\nprint(\"(n_voxels,) =\", ev.shape)"
112+
"from voxelwise_tutorials.utils import explainable_variance\n\nev = explainable_variance(Y_test)\nprint(\"(n_voxels,) =\", ev.shape)"
113113
]
114114
},
115115
{
@@ -238,7 +238,7 @@
238238
},
239239
"outputs": [],
240240
"source": [
241-
"from voxelwise_tutorials.io import load_hdf5_sparse_array\nvoxel_to_fsaverage = load_hdf5_sparse_array(mapper_file,\n key='voxel_to_fsaverage')\nev_projected = voxel_to_fsaverage @ ev\nprint(\"(n_vertices,) =\", ev_projected.shape)"
241+
"from voxelwise_tutorials.io import load_hdf5_sparse_array\n\nvoxel_to_fsaverage = load_hdf5_sparse_array(mapper_file,\n key='voxel_to_fsaverage')\nev_projected = voxel_to_fsaverage @ ev\nprint(\"(n_vertices,) =\", ev_projected.shape)"
242242
]
243243
},
244244
{
@@ -337,7 +337,7 @@
337337
"name": "python",
338338
"nbconvert_exporter": "python",
339339
"pygments_lexer": "ipython3",
340-
"version": "3.7.12"
340+
"version": "3.9.0"
341341
}
342342
},
343343
"nbformat": 4,

tutorials/notebooks/shortclips/02_plot_ridge_regression.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@
406406
"name": "python",
407407
"nbconvert_exporter": "python",
408408
"pygments_lexer": "ipython3",
409-
"version": "3.7.12"
409+
"version": "3.9.0"
410410
}
411411
},
412412
"nbformat": 4,

tutorials/notebooks/shortclips/03_plot_wordnet_model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@
653653
"name": "python",
654654
"nbconvert_exporter": "python",
655655
"pygments_lexer": "ipython3",
656-
"version": "3.7.12"
656+
"version": "3.9.0"
657657
}
658658
},
659659
"nbformat": 4,

tutorials/notebooks/shortclips/04_plot_hemodynamic_response.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"from voxelwise_tutorials.io import get_data_home\ndirectory = get_data_home(dataset=\"shortclips\")\nprint(directory)"
47+
"from voxelwise_tutorials.io import get_data_home\n\ndirectory = get_data_home(dataset=\"shortclips\")\nprint(directory)"
4848
]
4949
},
5050
{
@@ -181,7 +181,7 @@
181181
},
182182
"outputs": [],
183183
"source": [
184-
"from sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom voxelwise_tutorials.delayer import Delayer\nfrom himalaya.kernel_ridge import KernelRidgeCV\nfrom himalaya.backend import set_backend\nbackend = set_backend(\"torch_cuda\", on_error=\"warn\")\n\nX_train = X_train.astype(\"float32\")\nX_test = X_test.astype(\"float32\")\n\nalphas = np.logspace(1, 20, 20)\n\npipeline = make_pipeline(\n StandardScaler(with_mean=True, with_std=False),\n Delayer(delays=[1, 2, 3, 4]),\n KernelRidgeCV(\n alphas=alphas, cv=cv,\n solver_params=dict(n_targets_batch=500, n_alphas_batch=5,\n n_targets_batch_refit=100)),\n)"
184+
"from sklearn.pipeline import make_pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom voxelwise_tutorials.delayer import Delayer\nfrom himalaya.kernel_ridge import KernelRidgeCV\nfrom himalaya.backend import set_backend\n\nbackend = set_backend(\"torch_cuda\", on_error=\"warn\")\n\nX_train = X_train.astype(\"float32\")\nX_test = X_test.astype(\"float32\")\n\nalphas = np.logspace(1, 20, 20)\n\npipeline = make_pipeline(\n StandardScaler(with_mean=True, with_std=False),\n Delayer(delays=[1, 2, 3, 4]),\n KernelRidgeCV(\n alphas=alphas, cv=cv,\n solver_params=dict(n_targets_batch=500, n_alphas_batch=5,\n n_targets_batch_refit=100)),\n)"
185185
]
186186
},
187187
{
@@ -192,7 +192,7 @@
192192
},
193193
"outputs": [],
194194
"source": [
195-
"from sklearn import set_config\nset_config(display='diagram') # requires scikit-learn 0.23\npipeline"
195+
"from sklearn import set_config\n\nset_config(display='diagram') # requires scikit-learn 0.23\npipeline"
196196
]
197197
},
198198
{
@@ -246,7 +246,7 @@
246246
},
247247
"outputs": [],
248248
"source": [
249-
"import matplotlib.pyplot as plt\nfig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True, \n sharex=True)\ntimes = np.arange(n_trs)*TR\n\naxs[0].plot(times, y, color=\"r\")\naxs[0].set_title(\"BOLD response\")\nfor i, (ax, xx) in enumerate(zip(axs.flat[1:], x_delayed.T)):\n ax.plot(times, xx, color='k')\n ax.set_title(\"$x(t - {0:.0f})$ (feature delayed by {1} sample{2})\".format(\n i*TR, i, \"\" if i == 1 else \"s\"))\nfor ax in axs.flat:\n ax.axvline(40, color='gray')\n ax.set_yticks([])\n_ = axs[-1].set_xlabel(\"Time [s]\")\nplt.show()"
249+
"import matplotlib.pyplot as plt\n\nfig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True,\n sharex=True)\ntimes = np.arange(n_trs) * TR\n\naxs[0].plot(times, y, color=\"r\")\naxs[0].set_title(\"BOLD response\")\nfor i, (ax, xx) in enumerate(zip(axs.flat[1:], x_delayed.T)):\n ax.plot(times, xx, color='k')\n ax.set_title(\"$x(t - {0:.0f})$ (feature delayed by {1} sample{2})\".format(\n i * TR, i, \"\" if i == 1 else \"s\"))\nfor ax in axs.flat:\n ax.axvline(40, color='gray')\n ax.set_yticks([])\n_ = axs[-1].set_xlabel(\"Time [s]\")\nplt.show()"
250250
]
251251
},
252252
{
@@ -352,7 +352,7 @@
352352
"name": "python",
353353
"nbconvert_exporter": "python",
354354
"pygments_lexer": "ipython3",
355-
"version": "3.7.12"
355+
"version": "3.9.0"
356356
}
357357
},
358358
"nbformat": 4,

tutorials/notebooks/shortclips/05_plot_motion_energy_model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
"name": "python",
342342
"nbconvert_exporter": "python",
343343
"pygments_lexer": "ipython3",
344-
"version": "3.7.12"
344+
"version": "3.9.0"
345345
}
346346
},
347347
"nbformat": 4,

tutorials/notebooks/shortclips/06_plot_banded_ridge_model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@
510510
"name": "python",
511511
"nbconvert_exporter": "python",
512512
"pygments_lexer": "ipython3",
513-
"version": "3.7.12"
513+
"version": "3.9.0"
514514
}
515515
},
516516
"nbformat": 4,

tutorials/notebooks/shortclips/07_extract_motion_energy.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
},
7474
"outputs": [],
7575
"source": [
76-
"import numpy as np\nfrom moten.io import imagearray2luminance\n\nfrom voxelwise_tutorials.progress_bar import bar\nfrom voxelwise_tutorials.io import load_hdf5_array\n\n\ndef compute_luminance(run_name, size=(96, 96), batch_size=100):\n\n stimuli_file = os.path.join(directory, 'stimuli', run_name)\n\n # get the number of images in the stimuli file\n with h5py.File(stimuli_file, 'r') as f:\n n_images = f['stimuli'].shape[0]\n\n # compute the luminance on each batch\n luminance = np.zeros((n_images, *size))\n for start in bar(range(0, n_images, batch_size),\n title=f'compute_luminance({run_name})'):\n # load the batch of images\n batch = slice(start, start + batch_size)\n images = load_hdf5_array(stimuli_file, key='stimuli', slice=batch)\n\n # ``imagearray2luminance`` uses uint8 arrays\n if images.dtype != 'uint8':\n images = np.int_(np.clip(images, 0, 1) * 255).astype(np.uint8)\n\n # convert RGB images to a single luminance channel\n luminance[batch] = imagearray2luminance(images, size=size)\n\n return luminance\n\n\nluminance_train = np.concatenate(\n [compute_luminance(f\"train_{ii:02d}.hdf\") for ii in range(12)])\nluminance_test = compute_luminance(\"test.hdf\")"
76+
"import numpy as np\nfrom moten.io import imagearray2luminance\n\nfrom himalaya.progress_bar import bar\nfrom voxelwise_tutorials.io import load_hdf5_array\n\n\ndef compute_luminance(run_name, size=(96, 96), batch_size=100):\n\n stimuli_file = os.path.join(directory, 'stimuli', run_name)\n\n # get the number of images in the stimuli file\n with h5py.File(stimuli_file, 'r') as f:\n n_images = f['stimuli'].shape[0]\n\n # compute the luminance on each batch\n luminance = np.zeros((n_images, *size))\n for start in bar(range(0, n_images, batch_size),\n title=f'compute_luminance({run_name})'):\n # load the batch of images\n batch = slice(start, start + batch_size)\n images = load_hdf5_array(stimuli_file, key='stimuli', slice=batch)\n\n # ``imagearray2luminance`` uses uint8 arrays\n if images.dtype != 'uint8':\n images = np.int_(np.clip(images, 0, 1) * 255).astype(np.uint8)\n\n # convert RGB images to a single luminance channel\n luminance[batch] = imagearray2luminance(images, size=size)\n\n return luminance\n\n\nluminance_train = np.concatenate(\n [compute_luminance(f\"train_{ii:02d}.hdf\") for ii in range(12)])\nluminance_test = compute_luminance(\"test.hdf\")"
7777
]
7878
},
7979
{
@@ -136,7 +136,7 @@
136136
"name": "python",
137137
"nbconvert_exporter": "python",
138138
"pygments_lexer": "ipython3",
139-
"version": "3.7.12"
139+
"version": "3.9.0"
140140
}
141141
},
142142
"nbformat": 4,

tutorials/notebooks/shortclips/merged_for_colab.ipynb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
"outputs": [],
238238
"source": [
239239
"from voxelwise_tutorials.io import get_data_home\n",
240+
"\n",
240241
"directory = get_data_home(dataset=\"shortclips\")\n",
241242
"print(directory)"
242243
]
@@ -291,6 +292,7 @@
291292
"outputs": [],
292293
"source": [
293294
"import os\n",
295+
"\n",
294296
"file_name = os.path.join(directory, 'responses', f'{subject}_responses.hdf')\n",
295297
"Y_test = load_hdf5_array(file_name, key=\"Y_test\")\n",
296298
"print(\"(n_repeats, n_samples_test, n_voxels) =\", Y_test.shape)"
@@ -313,6 +315,7 @@
313315
"outputs": [],
314316
"source": [
315317
"from voxelwise_tutorials.utils import explainable_variance\n",
318+
"\n",
316319
"ev = explainable_variance(Y_test)\n",
317320
"print(\"(n_voxels,) =\", ev.shape)"
318321
]
@@ -534,6 +537,7 @@
534537
"outputs": [],
535538
"source": [
536539
"from voxelwise_tutorials.io import load_hdf5_sparse_array\n",
540+
"\n",
537541
"voxel_to_fsaverage = load_hdf5_sparse_array(mapper_file,\n",
538542
" key='voxel_to_fsaverage')\n",
539543
"ev_projected = voxel_to_fsaverage @ ev\n",
@@ -2402,6 +2406,7 @@
24022406
"outputs": [],
24032407
"source": [
24042408
"from voxelwise_tutorials.io import get_data_home\n",
2409+
"\n",
24052410
"directory = get_data_home(dataset=\"shortclips\")\n",
24062411
"print(directory)"
24072412
]
@@ -2588,6 +2593,7 @@
25882593
"from voxelwise_tutorials.delayer import Delayer\n",
25892594
"from himalaya.kernel_ridge import KernelRidgeCV\n",
25902595
"from himalaya.backend import set_backend\n",
2596+
"\n",
25912597
"backend = set_backend(\"torch_cuda\", on_error=\"warn\")\n",
25922598
"\n",
25932599
"X_train = X_train.astype(\"float32\")\n",
@@ -2614,6 +2620,7 @@
26142620
"outputs": [],
26152621
"source": [
26162622
"from sklearn import set_config\n",
2623+
"\n",
26172624
"set_config(display='diagram') # requires scikit-learn 0.23\n",
26182625
"pipeline"
26192626
]
@@ -2710,19 +2717,20 @@
27102717
"outputs": [],
27112718
"source": [
27122719
"import matplotlib.pyplot as plt\n",
2713-
"fig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True, \n",
2714-
" sharex=True)\n",
2715-
"times = np.arange(n_trs)*TR\n",
2720+
"\n",
2721+
"fig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True,\n",
2722+
" sharex=True)\n",
2723+
"times = np.arange(n_trs) * TR\n",
27162724
"\n",
27172725
"axs[0].plot(times, y, color=\"r\")\n",
27182726
"axs[0].set_title(\"BOLD response\")\n",
27192727
"for i, (ax, xx) in enumerate(zip(axs.flat[1:], x_delayed.T)):\n",
2720-
" ax.plot(times, xx, color='k')\n",
2721-
" ax.set_title(\"$x(t - {0:.0f})$ (feature delayed by {1} sample{2})\".format(\n",
2722-
" i*TR, i, \"\" if i == 1 else \"s\"))\n",
2728+
" ax.plot(times, xx, color='k')\n",
2729+
" ax.set_title(\"$x(t - {0:.0f})$ (feature delayed by {1} sample{2})\".format(\n",
2730+
" i * TR, i, \"\" if i == 1 else \"s\"))\n",
27232731
"for ax in axs.flat:\n",
2724-
" ax.axvline(40, color='gray')\n",
2725-
" ax.set_yticks([])\n",
2732+
" ax.axvline(40, color='gray')\n",
2733+
" ax.set_yticks([])\n",
27262734
"_ = axs[-1].set_xlabel(\"Time [s]\")\n",
27272735
"plt.show()"
27282736
]
@@ -4240,7 +4248,7 @@
42404248
"name": "python",
42414249
"nbconvert_exporter": "python",
42424250
"pygments_lexer": "ipython3",
4243-
"version": "3.7.12"
4251+
"version": "3.9.0"
42444252
},
42454253
"name": "_merged"
42464254
},

0 commit comments

Comments
 (0)