File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -227,16 +227,21 @@ def test_foci():
227
227
coords = [[- 36 , 18 , - 3 ],
228
228
[- 43 , 25 , 24 ],
229
229
[- 48 , 26 , - 2 ]]
230
- brain .add_foci (coords , map_surface = "white" , color = "gold" )
230
+ brain .add_foci (coords , map_surface = "white" , color = "gold" , name = 'test1' )
231
231
232
232
subj_dir = utils ._get_subjects_dir ()
233
233
annot_path = pjoin (subj_dir , subject_id , 'label' , 'lh.aparc.a2009s.annot' )
234
234
ids , ctab , names = nib .freesurfer .read_annot (annot_path )
235
235
verts = np .arange (0 , len (ids ))
236
236
coords = np .random .permutation (verts [ids == 74 ])[:10 ]
237
237
scale_factor = 0.7
238
- brain .add_foci (coords , coords_as_verts = True ,
239
- scale_factor = scale_factor , color = "#A52A2A" )
238
+ brain .add_foci (coords , coords_as_verts = True , scale_factor = scale_factor ,
239
+ color = "#A52A2A" , name = 'test2' )
240
+ with pytest .raises (ValueError ):
241
+ brain .remove_foci (['test4' ])
242
+ brain .remove_foci ('test1' )
243
+ brain .remove_foci ()
244
+ assert len (brain .foci_dict ) == 0
240
245
brain .close ()
241
246
242
247
Original file line number Diff line number Diff line change @@ -1454,6 +1454,34 @@ def remove_data(self, hemi=None):
1454
1454
if all (len (brain .data ) == 0 for brain in self .brains ):
1455
1455
self .n_times = self ._times = None
1456
1456
1457
+ def remove_foci (self , name = None ):
1458
+ """Remove foci added with ``Brain.add_foci()``.
1459
+
1460
+ Parameters
1461
+ ----------
1462
+ name : str | list of str | None
1463
+ Names of the foci to remove (if None, remove all).
1464
+
1465
+ Notes
1466
+ -----
1467
+ Only foci added with a unique names can be removed.
1468
+ """
1469
+ if name is None :
1470
+ keys = tuple (self .foci_dict )
1471
+ else :
1472
+ if isinstance (name , str ):
1473
+ keys = (name ,)
1474
+ else :
1475
+ keys = name
1476
+ if not all (key in self .foci_dict for key in keys ):
1477
+ missing = ', ' .join (key for key in keys if key not in
1478
+ self .foci_dict )
1479
+ raise ValueError ("foci=%r: no foci named %s" % (name , missing ))
1480
+
1481
+ for key in keys :
1482
+ for points in self .foci_dict .pop (key ):
1483
+ points .remove ()
1484
+
1457
1485
def remove_labels (self , labels = None , hemi = None ):
1458
1486
"""Remove one or more previously added labels from the image.
1459
1487
You can’t perform that action at this time.
0 commit comments