Skip to content

Commit 1e88636

Browse files
committed
MNT fix flake8 and add comments
1 parent e2c4215 commit 1e88636

5 files changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/run_tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ jobs:
2626
2727
- uses: actions/cache@v3
2828
with:
29-
path: ~/.voxelwise_tutorials_data/shortclips
30-
key: ${{ runner.os }}-shortclips
29+
path: ~/voxelwise_tutorials_data/shortclips
30+
key: shortclips-dataset
3131

3232
- name: Install dependencies
3333
run: |
3434
pip install -U setuptools
3535
pip install -U wheel
36+
# install pycortex from source to avoid using the cached wheel
3637
pip install git+https://github.com/gallantlab/pycortex.git
3738
pip install -e ."[github]"
3839
$CONDA/bin/conda install -c conda-forge git-annex=*=alldep*
@@ -47,7 +48,7 @@ jobs:
4748
4849
- name: Config git-annex
4950
run: |
50-
# change of path not in effect before next action
51+
# note: change of path not in effect before next action
5152
echo "${CONDA}/bin" >> $GITHUB_PATH
5253
# add back python to avoid using conda's
5354
echo $(dirname $(which python)) >> $GITHUB_PATH

tutorials/shortclips/01_plot_explainable_variance.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# Path of the data directory
4242
# --------------------------
4343
from voxelwise_tutorials.io import get_data_home
44+
4445
directory = get_data_home(dataset="shortclips")
4546
print(directory)
4647

@@ -59,6 +60,7 @@
5960
# First, we load the fMRI responses on the test set, which contains brain
6061
# responses to ten (10) repeats of the same stimulus.
6162
import os
63+
6264
file_name = os.path.join(directory, 'responses', f'{subject}_responses.hdf')
6365
Y_test = load_hdf5_array(file_name, key="Y_test")
6466
print("(n_repeats, n_samples_test, n_voxels) =", Y_test.shape)
@@ -67,6 +69,7 @@
6769
# Then, we compute the explainable variance for each voxel.
6870

6971
from voxelwise_tutorials.utils import explainable_variance
72+
7073
ev = explainable_variance(Y_test)
7174
print("(n_voxels,) =", ev.shape)
7275

@@ -190,6 +193,7 @@
190193
# with a dot product ``@`` (equivalent to ``np.dot``).
191194

192195
from voxelwise_tutorials.io import load_hdf5_sparse_array
196+
193197
voxel_to_fsaverage = load_hdf5_sparse_array(mapper_file,
194198
key='voxel_to_fsaverage')
195199
ev_projected = voxel_to_fsaverage @ ev

tutorials/shortclips/04_plot_hemodynamic_response.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# Path of the data directory
3030
# --------------------------
3131
from voxelwise_tutorials.io import get_data_home
32+
3233
directory = get_data_home(dataset="shortclips")
3334
print(directory)
3435

@@ -108,6 +109,7 @@
108109
from voxelwise_tutorials.delayer import Delayer
109110
from himalaya.kernel_ridge import KernelRidgeCV
110111
from himalaya.backend import set_backend
112+
111113
backend = set_backend("torch_cuda", on_error="warn")
112114

113115
X_train = X_train.astype("float32")
@@ -126,6 +128,7 @@
126128

127129
###############################################################################
128130
from sklearn import set_config
131+
129132
set_config(display='diagram') # requires scikit-learn 0.23
130133
pipeline
131134

@@ -182,23 +185,23 @@
182185
# function.
183186

184187
import matplotlib.pyplot as plt
185-
fig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True,
186-
sharex=True)
187-
times = np.arange(n_trs)*TR
188+
189+
fig, axs = plt.subplots(6, 1, figsize=(8, 6.5), constrained_layout=True,
190+
sharex=True)
191+
times = np.arange(n_trs) * TR
188192

189193
axs[0].plot(times, y, color="r")
190194
axs[0].set_title("BOLD response")
191195
for i, (ax, xx) in enumerate(zip(axs.flat[1:], x_delayed.T)):
192-
ax.plot(times, xx, color='k')
193-
ax.set_title("$x(t - {0:.0f})$ (feature delayed by {1} sample{2})".format(
194-
i*TR, i, "" if i == 1 else "s"))
196+
ax.plot(times, xx, color='k')
197+
ax.set_title("$x(t - {0:.0f})$ (feature delayed by {1} sample{2})".format(
198+
i * TR, i, "" if i == 1 else "s"))
195199
for ax in axs.flat:
196-
ax.axvline(40, color='gray')
197-
ax.set_yticks([])
200+
ax.axvline(40, color='gray')
201+
ax.set_yticks([])
198202
_ = axs[-1].set_xlabel("Time [s]")
199203
plt.show()
200204

201-
202205
###############################################################################
203206
# Compare with a model without delays
204207
# -----------------------------------

voxelwise_tutorials/regression_toy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def plot_2d(X, y, w, flat=True, alpha=None, show_noiseless=True):
8585
#####################
8686
# left plot: y = f(x)
8787

88-
try: # computed_zorder is only available in matplotlib >= 3.4
88+
try: # computed_zorder is only available in matplotlib >= 3.4
8989
ax = fig.add_subplot(121, projection='3d', computed_zorder=False)
9090
except AttributeError:
9191
ax = fig.add_subplot(121, projection='3d')

voxelwise_tutorials/tests/test_mappers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
subject = "S01"
2222
directory = get_data_home(dataset="shortclips")
23+
print(f"\n\n{directory}\n\n")
2324
file_name = os.path.join("mappers", f'{subject}_mappers.hdf')
2425
mapper_file = os.path.join(directory, file_name)
2526

0 commit comments

Comments
 (0)