|
37 | 37 | references [1]_ [2]_ [3]_. |
38 | 38 | """ |
39 | 39 | # sphinx_gallery_thumbnail_number = 1 |
40 | | - |
41 | | - |
42 | 40 | ############################################################################### |
43 | 41 | # Path of the data directory |
44 | 42 | # -------------------------- |
|
172 | 170 | # |
173 | 171 | # The second mapper we provide maps the voxel data to a Freesurfer |
174 | 172 | # 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 | +# |
185 | 174 | # If you are running the notebook on Colab, you might need to update the |
186 | 175 | # pycortex filestore as following: |
187 | 176 |
|
| 177 | +import cortex |
188 | 178 | try: |
189 | 179 | import google.colab # noqa |
190 | 180 | in_colab = True |
|
201 | 191 | cortex.quickflat.utils.db = cortex.database.db |
202 | 192 | cortex.quickflat.composite.db = cortex.database.db |
203 | 193 |
|
| 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 | + |
204 | 202 | ############################################################################### |
205 | 203 | # Then, we load the "fsaverage" mapper. The mapper is a matrix of shape |
206 | 204 | # (n_vertices, n_voxels), which maps each voxel to some vertices in the |
207 | 205 | # fsaverage surface. It is stored as a sparse CSR matrix. The mapper is applied |
208 | 206 | # with a dot product ``@`` (equivalent to ``np.dot``). |
| 207 | + |
209 | 208 | from voxelwise_tutorials.io import load_hdf5_sparse_array |
210 | 209 | voxel_to_fsaverage = load_hdf5_sparse_array(mapper_file, |
211 | 210 | key='voxel_to_fsaverage') |
|
220 | 219 | vertex = cortex.Vertex(ev_projected, surface, vmin=0, vmax=0.7, cmap='viridis') |
221 | 220 |
|
222 | 221 | ############################################################################### |
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 |
231 | 225 | # application out of Colab. To do so, use the following cell to start a tunnel |
232 | 226 | # with ``ngrok`` and to get an address where the pycortex viewer will be made |
233 | 227 | # accessible. |
|
246 | 240 | f"{result}\n" |
247 | 241 | "and not the one proposed by pycortex ('Open viewer: ...')\n") |
248 | 242 |
|
| 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 | + |
249 | 254 | ############################################################################### |
250 | 255 | # Alternatively, to plot a flatmap in a ``matplotlib`` figure, use the |
251 | 256 | # `quickshow` function. |
|
255 | 260 |
|
256 | 261 | from cortex.testing_utils import has_installed |
257 | 262 |
|
258 | | - |
259 | 263 | fig = cortex.quickshow(vertex, colorbar_location='right', |
260 | 264 | with_rois=has_installed("inkscape")) |
261 | 265 | plt.show() |
|
0 commit comments