Skip to content

Commit a98edff

Browse files
Validate brain inputs #214
1 parent 361d320 commit a98edff

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

naplib/localization/freesurfer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
surf_type: str = "pial",
4545
subject: str = "fsaverage",
4646
coordinate_space: str = 'FSAverage',
47-
atlas: str = '',
47+
atlas=None,
4848
subject_dir=None,
4949
):
5050
"""
@@ -61,7 +61,7 @@ def __init__(
6161
Subject to use, must be a directory within ``subject_dir``
6262
coordinate_space : str, default='FSAverage'
6363
Coordinate space of brain vertices. Must be 'FSAverage' or 'MNI152'
64-
atlas : str, default=''
64+
atlas : str, default=None
6565
Atlas for brain parcellation. Defaults to 'Destrieux' for coordinate_space='FSAverage'
6666
and 'Desikan-Killiany' for 'MNI152'. Can also be an annotation file name given by
6767
``{subject_dir}/{subject}/label/?h.{atlas}.annot``
@@ -84,6 +84,8 @@ def __init__(
8484
self.surf_type = surf_type
8585
self.subject = subject
8686
self.coordinate_space = coordinate_space
87+
if atlas not in ['Desikan-Killiany', 'Destrieux'] and not os.path.exists(self.label_file(f'{self.hemi}.{self.atlas}.annot')):
88+
raise ValueError('Bad atlas. Try "Desikan-Killiany" or "Destrieux"')
8789
self.atlas = atlas
8890

8991
if subject_dir is None:
@@ -327,6 +329,7 @@ def zones(self, labels, min_alpha=0):
327329
"""
328330
if isinstance(labels, str):
329331
labels = (labels,)
332+
labels = [l for l in labels if l in self.label2num]
330333

331334
verts = np.zeros(self.n_verts, dtype=bool)
332335
zones = np.zeros(self.n_verts, dtype=int)
@@ -804,7 +807,7 @@ def __init__(
804807
surf_type: str = "pial",
805808
subject: str = "fsaverage",
806809
coordinate_space: str = 'FSAverage',
807-
atlas: str = '',
810+
atlas=None,
808811
subject_dir=None
809812
):
810813
"""
@@ -820,7 +823,7 @@ def __init__(
820823
Subject to use, must be a directory within ``subject_dir``
821824
coordinate_space : str, default='FSAverage'
822825
Coordinate space of brain vertices. Must be 'FSAverage' or 'MNI152'
823-
atlas : str, default=''
826+
atlas : str, default=None
824827
Atlas for brain parcellation. Defaults to 'Destrieux' for coordinate_space='FSAverage'
825828
and 'Desikan-Killiany' for 'MNI152'. Can also be an annotation file name given by
826829
``{subject_dir}/{subject}/label/?h.{atlas}.annot``
@@ -974,7 +977,7 @@ def annotate_coords(
974977
If provided, specifies a boolean which is True for each electrode that is in the left hemisphere.
975978
If not given, this will be inferred from the first dimension of the coords (negative is left).
976979
distance_cutoff : float, default=10
977-
Electrodes further than this distance (in mm) from the cortical surface will be labeled as "Other"
980+
Electrodes further than this distance (in mm) from the cortical surface will be labeled as None
978981
is_surf : boolean np.ndarray
979982
Array of the same shape as the number of vertices in the surface (e.g. len(self.lh.surf[0])) indicating
980983
whether those points should be included as surface options. If an electrode is closest to a point

0 commit comments

Comments
 (0)