Skip to content

Commit c6cd826

Browse files
committed
fleshed out review section and added save hooks
1 parent bce319f commit c6cd826

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

config/config.yaml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ targets:
112112
# from the sections above.
113113
cortex: |
114114
# Extract the subject object and the hsmisphere name.
115+
sid = target['Subject ID']
115116
sub = target['subject']
116117
h = target['Hemisphere'].lower()
117118
# Load retinotopic mapping data from the label directory, where these data
118119
# are stored on the NSD repository.
119-
label_path = nsd_path.subpath('freesurfer', sub, 'label')
120+
label_path = nsd_path.subpath('freesurfer', sid, 'label')
120121
props = {
121122
k: ny.load(label_path.subpath(f'{h}.{filename}'))
122123
for (k,filename) in nsd_prf_files.items()}
@@ -290,42 +291,59 @@ review: |
290291
#im = watershed_contours(annotations.values(), max_depth=1)
291292
#axes.imshow(im, cmap='hsv', vmin=0, vmax=1.5*np.max(im))
292293
import numpy as np
293-
from matplotlib.pyplot import Polygon
294294
# V1:
295295
v1uvm = annotations['V1 UVM (ventral)']
296296
v1lvm = annotations['V1 LVM (dorsal)']
297297
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)])
305299
# V2:
306300
v2uvm = annotations['V2 UVM (ventral)']
307301
v2lvm = annotations['V2 LVM (dorsal)']
308302
v2pev = annotations['V2 Ventral Periphery']
309303
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)])
318306
# V3:
319307
v3uvm = annotations['V3 UVM (ventral)']
320308
v3lvm = annotations['V3 LVM (dorsal)']
321309
v3pev = annotations['V3 Ventral Periphery']
322310
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)
330347
axes.axis('equal')
331348
axes.axis('off')
349+

0 commit comments

Comments
 (0)