Skip to content

Commit 4eade80

Browse files
committed
DOC improve flow with ngrok and cortex
1 parent ed289f7 commit 4eade80

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

tutorials/movies_3T/00_setup_colab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
skip it if you run the tutorials on your machine.
99
"""
1010
# sphinx_gallery_thumbnail_path = "static/colab.png"
11-
#
1211
###############################################################################
1312
# Change runtime to use a GPU
1413
# ---------------------------

tutorials/movies_3T/01_plot_explainable_variance.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
references [1]_ [2]_ [3]_.
3838
"""
3939
# sphinx_gallery_thumbnail_number = 1
40-
41-
4240
###############################################################################
4341
# Path of the data directory
4442
# --------------------------
@@ -172,19 +170,11 @@
172170
#
173171
# The second mapper we provide maps the voxel data to a Freesurfer
174172
# average surface ("fsaverage"), that can be used in ``pycortex``.
175-
# First, let's download the "fsaverage" surface.
176-
177-
import cortex
178-
179-
surface = "fsaverage"
180-
181-
if not hasattr(cortex.db, surface):
182-
cortex.utils.download_subject(subject_id=surface)
183-
184-
###############################################################################
173+
#
185174
# If you are running the notebook on Colab, you might need to update the
186175
# pycortex filestore as following:
187176

177+
import cortex
188178
try:
189179
import google.colab # noqa
190180
in_colab = True
@@ -201,11 +191,20 @@
201191
cortex.quickflat.utils.db = cortex.database.db
202192
cortex.quickflat.composite.db = cortex.database.db
203193

194+
###############################################################################
195+
# Now, let's download the "fsaverage" surface.
196+
197+
surface = "fsaverage"
198+
199+
if not hasattr(cortex.db, surface):
200+
cortex.utils.download_subject(subject_id=surface)
201+
204202
###############################################################################
205203
# Then, we load the "fsaverage" mapper. The mapper is a matrix of shape
206204
# (n_vertices, n_voxels), which maps each voxel to some vertices in the
207205
# fsaverage surface. It is stored as a sparse CSR matrix. The mapper is applied
208206
# with a dot product ``@`` (equivalent to ``np.dot``).
207+
209208
from voxelwise_tutorials.io import load_hdf5_sparse_array
210209
voxel_to_fsaverage = load_hdf5_sparse_array(mapper_file,
211210
key='voxel_to_fsaverage')
@@ -220,14 +219,9 @@
220219
vertex = cortex.Vertex(ev_projected, surface, vmin=0, vmax=0.7, cmap='viridis')
221220

222221
###############################################################################
223-
# To start an interactive 3D viewer in the browser, use the ``webshow``
224-
# function.
225-
226-
if False:
227-
cortex.webshow(vertex, open_browser=False, port=8050)
228-
229-
###############################################################################
230-
# If you are running the notebook on Colab, you need to tunnel the pycortex
222+
# To start an interactive 3D viewer in the browser, we can use the ``webshow``
223+
# function in pycortex.
224+
# If you are running the notebook on Colab, you first need to tunnel the pycortex
231225
# application out of Colab. To do so, use the following cell to start a tunnel
232226
# with ``ngrok`` and to get an address where the pycortex viewer will be made
233227
# accessible.
@@ -246,6 +240,17 @@
246240
f"{result}\n"
247241
"and not the one proposed by pycortex ('Open viewer: ...')\n")
248242

243+
244+
###############################################################################
245+
# Now you can start an interactive 3D viewer by changing ``run_webshow`` to
246+
# ``True`` and running the following cell. If you are using Colab, remember to
247+
# use the address returned by ngrok in the cell above rather than the address
248+
# returned by this cell.
249+
250+
run_webshow = False
251+
if run_webshow:
252+
cortex.webshow(vertex, open_browser=False, port=8050)
253+
249254
###############################################################################
250255
# Alternatively, to plot a flatmap in a ``matplotlib`` figure, use the
251256
# `quickshow` function.
@@ -255,7 +260,6 @@
255260

256261
from cortex.testing_utils import has_installed
257262

258-
259263
fig = cortex.quickshow(vertex, colorbar_location='right',
260264
with_rois=has_installed("inkscape"))
261265
plt.show()

0 commit comments

Comments
 (0)