Note
Go to the end to download the full example code.
Loading and Querying the Destrieux Atlas’ Left Hemisphere Sulci#
Uploading the Destrieux regions into NeuroLang and executing a simple query selecting the left-hemisphere sulci.
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 (deterministic) Datalog engine.
nl = NeurolangDL()
Load the Destrieux example from nilearn as a fact list
atlas_destrieux = datasets.fetch_atlas_destrieux_2009()
if 'lut' in atlas_destrieux:
# nilearn >= 0.11 provides a look-up table with label indices and names
lut = atlas_destrieux['lut']
atlas_labels = dict(zip(lut['index'], lut['name'].astype(str)))
else:
atlas_labels = {
label: str(name)
for label, name in atlas_destrieux['labels']
}
atlas_labels.pop(0, None) # background
nl.add_atlas_set('destrieux_atlas', atlas_labels, nib.load(atlas_destrieux['maps']))
[fetch_atlas_destrieux_2009] Added README.md to /home/runner/nilearn_data
[fetch_atlas_destrieux_2009] Dataset created in /home/runner/nilearn_data/destrieux_2009
[fetch_atlas_destrieux_2009] Downloading data from https://www.nitrc.org/frs/download.php/11942/destrieux2009.tgz ...
[fetch_atlas_destrieux_2009] ...done. (0 seconds, 0 min)
[fetch_atlas_destrieux_2009] Extracting data from /home/runner/nilearn_data/destrieux_2009/2a2e5a5707983d509d9319c692c867ab/destrieux2009.tgz...
[fetch_atlas_destrieux_2009] .. done.
destrieux_atlas: typing.AbstractSet[typing.Tuple[str, neurolang.regions.ExplicitVBR]] = ('L G_and_S_frontomargin', Region(VBR= affine:[[ 2. 0. 0. -76.]
[ 0. 2. 0. -109.]
[ 0. 0. 2. -64.]
[ 0. 0. 0. 1.]], voxels:[[19 81 26]
[19 82 27]
[19 82 28]
...
[34 85 24]
[34 85 25]
[34 86 23]])) ...
Add utility function
@nl.add_symbol
def startswith(prefix: str, s: str) -> bool:
return s.startswith(prefix)
Query all regions of the left hemisphere whose Destrieux name starts with
L S, that is, the left-hemisphere sulci
Visualise the first four results in a 2×2 grid, which also gives the gallery an informative thumbnail.

31 left-hemisphere sulci found
Total running time of the script: (0 minutes 5.689 seconds)