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.

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

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 the first four results in a 2×2 grid, which also gives the gallery an informative thumbnail.

print(f"{len(result)} left-hemisphere sulci found")
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
for ax in axes.ravel():
    ax.set_axis_off()
for ax, result_row in zip(axes.ravel(), list(result)[:4]):
    region = result_row[0]
    plotting.plot_roi(region.spatial_image(), axes=ax)
plt.tight_layout()
plot load destrieux left hemisphere gyri
31 left-hemisphere sulci found

Total running time of the script: (0 minutes 5.689 seconds)

Gallery generated by Sphinx-Gallery