@@ -139,7 +139,7 @@ def find_parcel_centroids(*, lhannot, rhannot, version='fsaverage',
139139 defined in `lhannot` and `rhannot`
140140 hemiid : (N,) numpy.ndarray
141141 Array denoting hemisphere designation of coordinates in `centroids`,
142- where `hemiid=0` denotes the right and `hemiid=1` the left hemisphere
142+ where `hemiid=0` denotes the left and `hemiid=1` the right hemisphere
143143 """
144144
145145 if drop is None :
@@ -363,7 +363,8 @@ def _get_fsaverage_coords(version='fsaverage', surface='sphere'):
363363
364364
365365def spin_data (data , * , lhannot , rhannot , version = 'fsaverage' , n_rotate = 1000 ,
366- drop = None , seed = None , verbose = False , return_cost = False ):
366+ spins = None , drop = None , seed = None , verbose = False ,
367+ return_cost = False ):
367368 """
368369 Projects parcellated `data` to surface, rotates, and re-parcellates
369370
@@ -429,8 +430,18 @@ def spin_data(data, *, lhannot, rhannot, version='fsaverage', n_rotate=1000,
429430 ' FSAVERAGE: {} vertices'
430431 .format (len (vertices ), len (coords )))
431432
432- spins , cost = gen_spinsamples (coords , hemiid , n_rotate = n_rotate ,
433- seed = seed , verbose = verbose )
433+ if spins is None :
434+ spins , cost = gen_spinsamples (coords , hemiid , n_rotate = n_rotate ,
435+ seed = seed , verbose = verbose )
436+ else :
437+ spins = np .asarray (spins , dtype = 'int32' )
438+ if spins .shape [- 1 ] != n_rotate :
439+ raise ValueError ('Provided `spins` does not match number of '
440+ 'requested rotations with `n_rotate`. Please '
441+ 'check inputs and try again.' )
442+ if return_cost :
443+ raise ValueError ('Cannot `return_cost` when `spins` are provided.' )
444+
434445 spun = np .zeros ((len (data ), n_rotate ))
435446 for n in range (n_rotate ):
436447 spun [:, n ] = vertices_to_parcels (vertices [spins [:, n ]],
@@ -444,7 +455,7 @@ def spin_data(data, *, lhannot, rhannot, version='fsaverage', n_rotate=1000,
444455
445456
446457def spin_parcels (* , lhannot , rhannot , version = 'fsaverage' , n_rotate = 1000 ,
447- drop = None , seed = None , verbose = False , return_cost = False ):
458+ drop = None , seed = None , return_cost = False , ** kwargs ):
448459 """
449460 Rotates parcels in `{lh,rh}annot` and re-assigns based on maximum overlap
450461
@@ -468,13 +479,11 @@ def spin_parcels(*, lhannot, rhannot, version='fsaverage', n_rotate=1000,
468479 will be inserted in place of the these regions in the returned data. If
469480 not specified, 'unknown' and 'corpuscallosum' are assumed to not be
470481 present. Default: None
471- seed : {int, np.random.RandomState instance, None}, optional
472- Seed for random number generation. Default: None
473- verbose : bool, optional
474- Whether to print occasional status messages. Default: False
475482 return_cost : bool, optional
476483 Whether to return cost array (specified as Euclidean distance) for each
477484 coordinate for each rotation Default: True
485+ kwargs : key-value, optional
486+ Key-value pairs passed to :func:`netneurotools.stats.gen_spinsamples`
478487
479488 Returns
480489 -------
@@ -531,8 +540,7 @@ def overlap(vals):
531540 .format (len (vertices ), len (coords )))
532541
533542 # spin and assign regions based on max overlap
534- spins , cost = gen_spinsamples (coords , hemiid , n_rotate = n_rotate ,
535- seed = seed , verbose = verbose )
543+ spins , cost = gen_spinsamples (coords , hemiid , n_rotate = n_rotate , ** kwargs )
536544 regions = np .zeros ((len (labels [mask ]), n_rotate ), dtype = 'int32' )
537545 for n in range (n_rotate ):
538546 regions [:, n ] = labeled_comprehension (vertices [spins [:, n ]], vertices ,
0 commit comments