@@ -112,11 +112,12 @@ targets:
112
112
# from the sections above.
113
113
cortex : |
114
114
# Extract the subject object and the hsmisphere name.
115
+ sid = target['Subject ID']
115
116
sub = target['subject']
116
117
h = target['Hemisphere'].lower()
117
118
# Load retinotopic mapping data from the label directory, where these data
118
119
# are stored on the NSD repository.
119
- label_path = nsd_path.subpath('freesurfer', sub , 'label')
120
+ label_path = nsd_path.subpath('freesurfer', sid , 'label')
120
121
props = {
121
122
k: ny.load(label_path.subpath(f'{h}.{filename}'))
122
123
for (k,filename) in nsd_prf_files.items()}
@@ -290,42 +291,59 @@ review: |
290
291
#im = watershed_contours(annotations.values(), max_depth=1)
291
292
#axes.imshow(im, cmap='hsv', vmin=0, vmax=1.5*np.max(im))
292
293
import numpy as np
293
- from matplotlib.pyplot import Polygon
294
294
# V1:
295
295
v1uvm = annotations['V1 UVM (ventral)']
296
296
v1lvm = annotations['V1 LVM (dorsal)']
297
297
v1per = annotations['V1 Periphery']
298
- v1pol = Polygon(
299
- np.vstack([v1uvm, v1per, np.flipud(v1lvm)]),
300
- closed=True,
301
- color='red',
302
- alpha=0.5,
303
- fill=True)
304
- axes.add_patch(v1pol)
298
+ v1pol = np.vstack([v1uvm, v1per, np.flipud(v1lvm)])
305
299
# V2:
306
300
v2uvm = annotations['V2 UVM (ventral)']
307
301
v2lvm = annotations['V2 LVM (dorsal)']
308
302
v2pev = annotations['V2 Ventral Periphery']
309
303
v2ped = annotations['V2 Dorsal Periphery']
310
- v2pol = Polygon(
311
- np.vstack(
312
- [v2uvm, v2pev, np.flipud(v1uvm), v1lvm, v2ped, np.flipud(v2lvm)]),
313
- closed=True,
314
- color='cyan',
315
- alpha=0.5,
316
- fill=True)
317
- axes.add_patch(v2pol)
304
+ v2pol = np.vstack(
305
+ [v2uvm, v2pev, np.flipud(v1uvm), v1lvm, np.flipud(v2ped), np.flipud(v2lvm)])
318
306
# V3:
319
307
v3uvm = annotations['V3 UVM (ventral)']
320
308
v3lvm = annotations['V3 LVM (dorsal)']
321
309
v3pev = annotations['V3 Ventral Periphery']
322
310
v3ped = annotations['V3 Dorsal Periphery']
323
- v3pol = Polygon(
324
- np.vstack(
325
- [v3uvm, v3pev, np.flipud(v2uvm), v2lvm, v3ped, np.flipud(v3lvm)]),
326
- color='black',
327
- alpha=0.5,
328
- closed=True)
329
- axes.add_patch(v3pol)
311
+ v3pol = np.vstack(
312
+ [v3uvm, v3pev, np.flipud(v2uvm), v2lvm, np.flipud(v3ped), np.flipud(v3lvm)])
313
+ # Turn these into traces:
314
+ fmap = target['flatmap']
315
+ v1_trace = ny.path_trace(fmap, v1pol.T, closed=True)
316
+ v2_trace = ny.path_trace(fmap, v2pol.T, closed=True)
317
+ v3_trace = ny.path_trace(fmap, v3pol.T, closed=True)
318
+ # Convert the path traces into paths then into labels:
319
+ cortex = target['cortex']
320
+ v1_path = v1_trace.to_path(cortex)
321
+ v2_path = v2_trace.to_path(cortex)
322
+ v3_path = v3_trace.to_path(cortex)
323
+ v1 = v1_path.label > 0.5
324
+ v2 = v2_path.label > 0.5
325
+ v3 = v3_path.label > 0.5
326
+ if np.sum(v1) > np.sum(~v1):
327
+ v1 = ~v1
328
+ if np.sum(v2) > np.sum(~v2):
329
+ v2 = ~v2
330
+ if np.sum(v3) > np.sum(~v3):
331
+ v3 = ~v3
332
+ labels = np.zeros(cortex.vertex_count, dtype=int)
333
+ labels[v1] = 1
334
+ labels[v2] = 2
335
+ labels[v3] = 3
336
+ fmap_labels = labels[fmap.labels]
337
+ # If the user saves the contours, we want to save these labels.
338
+ save_hooks['v123-labels.mgz'] = lambda filename: ny.save(filename, labels)
339
+ # Plot the results:
340
+ ny.cortex_plot(
341
+ fmap,
342
+ color=fmap_labels,
343
+ cmap='rainbow',
344
+ mask=(fmap_labels > 0),
345
+ axes=axes,
346
+ alpha=0.5)
330
347
axes.axis('equal')
331
348
axes.axis('off')
349
+
0 commit comments