Skip to content

Commit 8378344

Browse files
committed
going to v0.2a6, with WHS4
1 parent f3ebbdf commit 8378344

9 files changed

+32
-60
lines changed

docs/download_maps.ipynb

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"outputs": [],
1919
"source": [
2020
"import siibra\n",
21-
"atlas = siibra.atlasesMULTILEVEL_HUMAN_ATLAS"
21+
"atlas = siibra.atlases.MULTILEVEL_HUMAN_ATLAS"
2222
]
2323
},
2424
{
@@ -89,13 +89,6 @@
8989
" if mapindex>4:\n",
9090
" break"
9191
]
92-
},
93-
{
94-
"cell_type": "code",
95-
"execution_count": null,
96-
"metadata": {},
97-
"outputs": [],
98-
"source": []
9992
}
10093
],
10194
"metadata": {
@@ -119,4 +112,4 @@
119112
},
120113
"nbformat": 4,
121114
"nbformat_minor": 4
122-
}
115+
}

examples/Different species.ipynb

+4-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "7356f741",
76
"metadata": {},
87
"outputs": [],
98
"source": [
@@ -14,7 +13,6 @@
1413
},
1514
{
1615
"cell_type": "markdown",
17-
"id": "dd04581c",
1816
"metadata": {},
1917
"source": [
2018
"# Allen mouse brain atlas"
@@ -23,7 +21,6 @@
2321
{
2422
"cell_type": "code",
2523
"execution_count": null,
26-
"id": "9e161329",
2724
"metadata": {},
2825
"outputs": [],
2926
"source": [
@@ -35,7 +32,6 @@
3532
},
3633
{
3734
"cell_type": "markdown",
38-
"id": "4dcc9ab2",
3935
"metadata": {},
4036
"source": [
4137
"# Waxholm space atlas of the sprague dawley rat brain"
@@ -44,27 +40,25 @@
4440
{
4541
"cell_type": "code",
4642
"execution_count": null,
47-
"id": "14b37103",
4843
"metadata": {},
4944
"outputs": [],
5045
"source": [
5146
"atlas = siibra.atlases['waxholm rat']\n",
5247
"waxholmtpl = atlas.get_template().fetch()\n",
53-
"parcellationmap = atlas.get_map().fetch()\n",
54-
"plotting.plot_roi(parcellationmap,bg_img=waxholmtpl,cmap=\"Set1\")"
48+
"for v in [\"v3\",\"v4\"]:\n",
49+
" parcellationmap = atlas.get_map(parcellation=v).fetch()\n",
50+
" plotting.plot_roi(parcellationmap,bg_img=waxholmtpl,cmap=\"Set2\")"
5551
]
5652
},
5753
{
5854
"cell_type": "markdown",
59-
"id": "0ba085f9",
6055
"metadata": {},
6156
"source": [
6257
"# Human brain atlas"
6358
]
6459
},
6560
{
6661
"cell_type": "markdown",
67-
"id": "302bbad1",
6862
"metadata": {},
6963
"source": [
7064
"## MNI space"
@@ -73,11 +67,10 @@
7367
{
7468
"cell_type": "code",
7569
"execution_count": null,
76-
"id": "94542ae6",
7770
"metadata": {},
7871
"outputs": [],
7972
"source": [
80-
"atlas = siibra.atlasesMULTILEVEL_HUMAN_ATLAS\n",
73+
"atlas = siibra.atlases['human']\n",
8174
"mni152tpl = atlas.get_template(\"mni152\").fetch()\n",
8275
"parcellationmap = atlas.get_map(space=\"mni152\", parcellation=\"julich 2.9\")\n",
8376
"for img in parcellationmap.fetch_iter():\n",
@@ -86,7 +79,6 @@
8679
},
8780
{
8881
"cell_type": "markdown",
89-
"id": "02c1e45a",
9082
"metadata": {},
9183
"source": [
9284
"## BigBrain space"
@@ -95,7 +87,6 @@
9587
{
9688
"cell_type": "code",
9789
"execution_count": null,
98-
"id": "522ce332",
9990
"metadata": {},
10091
"outputs": [],
10192
"source": [
@@ -108,7 +99,6 @@
10899
{
109100
"cell_type": "code",
110101
"execution_count": null,
111-
"id": "b090eab3",
112102
"metadata": {},
113103
"outputs": [],
114104
"source": []

examples/Find areas and their connections.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"metadata": {},
5757
"outputs": [],
5858
"source": [
59-
"atlas = siibra.atlasesMULTILEVEL_HUMAN_ATLAS\n",
59+
"atlas = siibra.atlases.MULTILEVEL_HUMAN_ATLAS\n",
6060
"julich_pmaps = atlas.get_map(\n",
6161
" space=\"mni152\",\n",
6262
" parcellation=\"julich 2.9\",\n",

examples/Retrieve multimodal data features.ipynb

+8-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "c1232d7c",
65
"metadata": {
76
"slideshow": {
87
"slide_type": "slide"
@@ -17,7 +16,6 @@
1716
{
1817
"cell_type": "code",
1918
"execution_count": null,
20-
"id": "ff9e6a34",
2119
"metadata": {},
2220
"outputs": [],
2321
"source": [
@@ -27,7 +25,6 @@
2725
},
2826
{
2927
"cell_type": "markdown",
30-
"id": "7fd9ae52",
3128
"metadata": {},
3229
"source": [
3330
"### 1. Setup `siibra` to connect to the EBRAINS Knowledge Graph access token\n",
@@ -47,7 +44,6 @@
4744
{
4845
"cell_type": "code",
4946
"execution_count": null,
50-
"id": "e2a81972",
5147
"metadata": {},
5248
"outputs": [],
5349
"source": [
@@ -57,7 +53,6 @@
5753
},
5854
{
5955
"cell_type": "markdown",
60-
"id": "58815182",
6156
"metadata": {},
6257
"source": [
6358
"### 2. Extract transmitter receptor densities\n",
@@ -70,11 +65,10 @@
7065
{
7166
"cell_type": "code",
7267
"execution_count": null,
73-
"id": "c10eeaf7",
7468
"metadata": {},
7569
"outputs": [],
7670
"source": [
77-
"atlas = siibra.atlasesMULTILEVEL_HUMAN_ATLAS\n",
71+
"atlas = siibra.atlases.MULTILEVEL_HUMAN_ATLAS\n",
7872
"features = siibra.get_features(\n",
7973
" atlas.get_parcellation('julich'),\n",
8074
" siibra.modalities.ReceptorDistribution)\n",
@@ -84,7 +78,6 @@
8478
},
8579
{
8680
"cell_type": "markdown",
87-
"id": "df6aab97",
8881
"metadata": {},
8982
"source": [
9083
"If we select a region, the returned list is filtered accordingly. "
@@ -93,7 +86,6 @@
9386
{
9487
"cell_type": "code",
9588
"execution_count": null,
96-
"id": "ec00e841",
9789
"metadata": {},
9890
"outputs": [],
9991
"source": [
@@ -103,7 +95,6 @@
10395
},
10496
{
10597
"cell_type": "markdown",
106-
"id": "e91d9e5e",
10798
"metadata": {},
10899
"source": [
109100
"### 3. Cell distributions\n",
@@ -114,7 +105,6 @@
114105
{
115106
"cell_type": "code",
116107
"execution_count": null,
117-
"id": "0b5eab2f",
118108
"metadata": {},
119109
"outputs": [],
120110
"source": [
@@ -132,7 +122,6 @@
132122
},
133123
{
134124
"cell_type": "markdown",
135-
"id": "824ea6db",
136125
"metadata": {
137126
"slideshow": {
138127
"slide_type": "slide"
@@ -147,7 +136,6 @@
147136
{
148137
"cell_type": "code",
149138
"execution_count": null,
150-
"id": "669cc089",
151139
"metadata": {},
152140
"outputs": [],
153141
"source": [
@@ -172,7 +160,6 @@
172160
},
173161
{
174162
"cell_type": "markdown",
175-
"id": "593d7be2",
176163
"metadata": {
177164
"slideshow": {
178165
"slide_type": "slide"
@@ -188,7 +175,6 @@
188175
{
189176
"cell_type": "code",
190177
"execution_count": null,
191-
"id": "6733fab6",
192178
"metadata": {},
193179
"outputs": [],
194180
"source": [
@@ -215,7 +201,6 @@
215201
},
216202
{
217203
"cell_type": "markdown",
218-
"id": "32082ebb",
219204
"metadata": {},
220205
"source": [
221206
"### 6. Retrieving iEEG electrodes and contact points\n",
@@ -226,7 +211,6 @@
226211
{
227212
"cell_type": "code",
228213
"execution_count": null,
229-
"id": "88c2ae6e",
230214
"metadata": {},
231215
"outputs": [],
232216
"source": [
@@ -253,7 +237,6 @@
253237
},
254238
{
255239
"cell_type": "markdown",
256-
"id": "f365cfd8",
257240
"metadata": {},
258241
"source": [
259242
"### 7. Retrieving other types of regional datasets from EBRAINS"
@@ -262,14 +245,20 @@
262245
{
263246
"cell_type": "code",
264247
"execution_count": null,
265-
"id": "ba2cbdb3",
266248
"metadata": {},
267249
"outputs": [],
268250
"source": [
269251
"region = atlas.get_region(\"fp1 right\")\n",
270252
"for f in siibra.get_features(region, \"ebrains\"):\n",
271253
" print(f\"{f.name}\\n{f.url}\\n\")"
272254
]
255+
},
256+
{
257+
"cell_type": "code",
258+
"execution_count": null,
259+
"metadata": {},
260+
"outputs": [],
261+
"source": []
273262
}
274263
],
275264
"metadata": {

examples/Walkthrough.ipynb

-7
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,6 @@
372372
"for f in features:\n",
373373
" print(f.name)"
374374
]
375-
},
376-
{
377-
"cell_type": "code",
378-
"execution_count": null,
379-
"metadata": {},
380-
"outputs": [],
381-
"source": []
382375
}
383376
],
384377
"metadata": {

siibra/volumes/volume.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from ctypes import ArgumentError
2323
import numpy as np
24-
from nibabel import Nifti1Image
24+
import nibabel
2525
from cloudvolume.exceptions import OutOfBoundsError
2626
from cloudvolume import CloudVolume
2727
import os
@@ -170,7 +170,7 @@ class LocalNiftiVolume(ImageProvider):
170170

171171
volume_type = 'nii'
172172

173-
def __init__(self, name: str, img: Nifti1Image, space: Space):
173+
def __init__(self, name: str, img: nibabel.Nifti1Image, space: Space):
174174
""" Create a new local nifti volume from a Nifti1Image object.
175175
176176
Args:
@@ -179,12 +179,19 @@ def __init__(self, name: str, img: Nifti1Image, space: Space):
179179
space (Space): the reference space associated with the Image
180180
"""
181181
self.name = name
182-
if isinstance(img, Nifti1Image):
182+
if isinstance(img, nibabel.Nifti1Image):
183183
self.image = img
184184
elif isinstance(img, str):
185-
self.image = Nifti1Image.from_filename(img)
185+
self.image = nibabel.load(img)
186186
else:
187187
raise ValueError(f"Cannot create local nifti volume from image parameter {img}")
188+
189+
if np.isnan(self.image.get_fdata()).any():
190+
logger.warn(f'Replacing NaN by 0 for {self.name}')
191+
self.image = nibabel.Nifti1Image(
192+
np.nan_to_num(self.image.get_fdata()),
193+
self.image.affine
194+
)
188195
self.space = space
189196

190197
def fetch(self, **kwargs):
@@ -249,7 +256,7 @@ def fetch(self, resolution_mm=None, voi=None, mapindex=None, clip=False):
249256
f"Mapindex of {mapindex} provided for fetching from NiftiVolume, but its shape is {shape}."
250257
)
251258
else:
252-
img = Nifti1Image(
259+
img = nibabel.Nifti1Image(
253260
dataobj=self.image.dataobj[:, :, :, mapindex], affine=self.image.affine
254261
)
255262
assert img is not None
@@ -265,7 +272,7 @@ def fetch(self, resolution_mm=None, voi=None, mapindex=None, clip=False):
265272
(x0, y0, z0), (x1, y1, z1) = bb_vox.minpoint, bb_vox.maxpoint
266273
shift = np.identity(4)
267274
shift[:3, -1] = bb_vox.minpoint
268-
img = Nifti1Image(
275+
img = nibabel.Nifti1Image(
269276
dataobj=img.dataobj[x0:x1, y0:y1, z0:z1],
270277
affine=np.dot(img.affine, shift),
271278
)
@@ -526,7 +533,7 @@ def fetch(self, resolution_mm=None, voi=None, mapindex=None, clip=False):
526533
if data.ndim == 2:
527534
data = data.reshape(list(data.shape) + [1])
528535

529-
return Nifti1Image(data, self.build_affine(resolution_mm=resolution_mm, voi=voi))
536+
return nibabel.Nifti1Image(data, self.build_affine(resolution_mm=resolution_mm, voi=voi))
530537

531538
def get_shape(self, resolution_mm=None):
532539
mip = self._resolution_to_mip(resolution_mm, voi=None)

test/features/test_connectivity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_check_switch_parc(self):
3232
class TestConnectivity(unittest.TestCase):
3333
@classmethod
3434
def setUpClass(cls):
35-
atlas = siibra.atlases["human"]
35+
atlas = siibra.atlases.MULTILEVEL_HUMAN_ATLAS
3636
parcellation = atlas.get_parcellation(
3737
siibra.parcellations.JULICH_BRAIN_CYTOARCHITECTONIC_MAPS_1_18
3838
)

0 commit comments

Comments
 (0)