Note
Go to the end to download the full example code
Loading and Querying the Destrieux et al. Atlas’ Left Hemisphere¶
Uploading the Destrieux regions NeuroLang and executing a simple query.
import warnings
warnings.filterwarnings("ignore")
from matplotlib import pyplot as plt
import nibabel as nib
from nilearn import datasets, plotting
from neurolang.frontend import NeurolangDL
Initialise the NeuroLang probabilistic engine.
nl = NeurolangDL()
Load the Destrieux example from nilearn as a fact list
atlas_destrieux = datasets.fetch_atlas_destrieux_2009()
atlas_labels = {
label: str(name.decode('utf8'))
for label, name in atlas_destrieux['labels']
}
nl.add_atlas_set('destrieux_atlas', atlas_labels, nib.load(atlas_destrieux['maps']))
Dataset created in /home/circleci/nilearn_data/destrieux_2009
Downloading data from https://www.nitrc.org/frs/download.php/11942/destrieux2009.tgz ...
...done. (0 seconds, 0 min)
Extracting data from /home/circleci/nilearn_data/destrieux_2009/2a2e5a5707983d509d9319c692c867ab/destrieux2009.tgz..... done.
destrieux_atlas: typing.AbstractSet[typing.Tuple[str, neurolang.regions.ExplicitVBR]] = ('Background', Region(VBR= affine:[[ 2. 0. 0. -76.]
[ 0. 2. 0. -109.]
[ 0. 0. 2. -64.]
[ 0. 0. 0. 1.]], voxels:[[ 0 0 0]
[ 0 0 1]
[ 0 0 2]
...
[75 92 73]
[75 92 74]
[75 92 75]])) ...
Add utility function
@nl.add_symbol
def startswith(prefix: str, s: str) -> bool:
return s.startswith(prefix)
Query all left hemisphere regions superior to the temporal superior sulucs and anterior to the central sulcus
with nl.scope as e:
e.on_left_hemisphere[e.x] = (
e.destrieux_atlas(e.l, e.x) & e.startswith('L S', e.l)
)
result = nl.query((e.r,), e.on_left_hemisphere(e.r))
Visualise results
subplots = plt.subplots(
nrows=len(result), ncols=1,
figsize=(10, 5 * len(result))
)[1]
for (r, subplot) in zip(result, subplots):
region = r[0]
plotting.plot_roi(region.spatial_image(), axes=subplot)
Total running time of the script: (0 minutes 53.340 seconds)