Brain atlases ship with dozens of regions. Often you only need a subset—motor cortex for a movement study, or frontal regions for an executive function analysis. ggsegpy provides utilities to filter, rename, and reorganize atlas regions without touching the underlying data files.
from ggsegpy import atlas_region_renamerenamed = atlas_region_rename(dk(), "superior", "sup.")renamed = atlas_region_rename(renamed, "inferior", "inf.")# Check the changesprint([r for r in atlas_regions(renamed) if"sup."in r or"inf."in r])
['BANKS OF SUPERIOR TEMPORAL SULCUS', 'CAUDAL ANTERIOR CINGULATE', 'CAUDAL MIDDLE FRONTAL', 'CORPUS CALLOSUM', 'CUNEUS']
Contextual regions
atlas_region_contextual() removes regions from the data but keeps them visible as grey context:
from ggsegpy import atlas_region_contextual# Remove temporal regions from data, keep them visibleno_temporal = atlas_region_contextual(dk(), "temporal")print(f"Data regions: {len(atlas_regions(no_temporal))}")ggplot() + geom_brain(atlas=no_temporal)
Data regions: 30
Temporal regions appear grey rather than disappearing entirely.
from ggsegpy import atlas_view_reorderreordered = atlas_view_reorder(dk(), ["medial", "lateral"])ggplot() + geom_brain(atlas=reordered)
Removing small geometries
Clean up tiny fragments that sometimes appear in atlas data:
from ggsegpy import atlas_view_remove_small# Remove geometries smaller than median areaareas = dk().data.ggseg.geometry.areacleaned = atlas_view_remove_small(dk(), min_area=areas.median())
Chaining operations
All functions return a new atlas, so chain them with intermediate variables: