Skip to content

Commit 7a8f888

Browse files
committed
maint fig5 notebook
1 parent 174f1ed commit 7a8f888

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

examples/tutorials/2025-paper-fig5.py

+17-31
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@
4343

4444
# %%
4545
# 1: Retrieve probability map of a motor area in Julich-Brain
46-
parc = siibra.parcellations.get("julich 3.0.3")
47-
region = parc.get_region("4p right")
48-
pmap = parc.get_map("mni152", "statistical").get_volume(region)
46+
region = siibra.get_region("julich 3.0.3", "4p right")
47+
region_map = siibra.get_map("julich 3.0.3", "mni152", "statistical").get_volume(region)
4948

5049
# %%
5150
# 2: Extract BigBrain 1 micron patches with high probability in this area
52-
patches = siibra.features.get(pmap, "BigBrain1MicronPatch", lower_threshold=0.7)
51+
patches = siibra.features.get(region_map, "BigBrain1MicronPatch", lower_threshold=0.5)
5352
print(f"Found {len(patches)} patches.")
5453

5554
# %%
5655
# 3: Display highly rated samples, here further reduced to a predefined section
5756
section_num = 3556
58-
candidates = filter(lambda p: p.bigbrain_section == section_num, patches)
59-
patch = next(iter(candidates))
57+
candidates = [p for p in patches if p.bigbrain_section == section_num]
58+
patch = candidates[0]
6059
plt.figure()
6160
plt.imshow(patch.fetch().get_fdata().squeeze(), cmap="gray", vmin=0, vmax=2**16)
6261
plt.axis("off")
@@ -76,34 +75,24 @@
7675
layername: plane.intersect_mesh(layermap.fetch(region=layername, format="mesh"))
7776
for layername in layermap.regions
7877
}
79-
crop_voi = patch.section.intersection(pmap.get_boundingbox().zoom(0.35))
80-
cropped_img = patch.section.fetch(voi=crop_voi, resolution_mm=0.2)
78+
ymin, ymax = [p[1] for p in patch.section.get_boundingbox()]
79+
crop_voi = siibra.BoundingBox((17.14, ymin, 40.11), (22.82, ymax, 32.91), 'bigbrain')
80+
cropped_img = patch.section.fetch(voi=crop_voi, resolution_mm=-1)
8181
phys2pix = np.linalg.inv(cropped_img.affine)
8282

8383
# The probabilities can be assigned to the contour vertices with the
8484
# probability map.
85-
points = siibra.PointCloud(
86-
np.vstack(
87-
sum(
88-
[
89-
[s.coordinates for s in contour.crop(crop_voi)]
90-
for contour in layer_contours["cortical layer 4 right"]
91-
],
92-
[],
93-
)
94-
),
95-
space="bigbrain",
85+
points = siibra.PointCloud.union(
86+
*[c.intersection(crop_voi) for c in layer_contours["cortical layer 4 right"]]
9687
)
97-
probs = pmap.evaluate_points(
98-
points
99-
) # siibra warps points to MNI152 and reads corresponding PMAP values
88+
# siibra warps points to MNI152 and reads corresponding PMAP values
89+
probs = region_map.evaluate_points(points)
10090
img_arr = cropped_img.get_fdata().squeeze().swapaxes(0, 1)
10191
plt.imshow(img_arr, cmap="gray", origin="lower")
10292
X, Y, Z = points.transform(phys2pix).coordinates.T
103-
plt.scatter(X, Z, s=2, c=probs)
104-
for p in patch.profile:
105-
x, y, z = p.transform(phys2pix)
106-
plt.plot(x, z, "r.", ms=3)
93+
plt.scatter(X, Z, s=10, c=probs)
94+
prof_x, _, prof_z = zip(*[p.transform(phys2pix) for p in patch.profile])
95+
plt.plot(prof_x, prof_z, "r", lw=2)
10796
plt.axis("off")
10897

10998
# %%
@@ -119,11 +108,8 @@
119108
pixels = segment.transform(phys2pix, space=None).homogeneous
120109
plt.plot(pixels[:, 0], pixels[:, 2], "-", ms=4, color=layercolor)
121110

122-
# plot the profile points
123-
for p in patch.profile:
124-
x, y, z = p.transform(phys2pix, space=None)
125-
plt.plot(x, z, "r.", ms=3)
126-
111+
# plot the profile
112+
plt.plot(prof_x, prof_z, "r", lw=2)
127113
plt.axis("off")
128114

129115
# sphinx_gallery_thumbnail_number = -2

0 commit comments

Comments
 (0)