brainiak.searchlight package

Distributed Searchlight

Submodules

brainiak.searchlight.searchlight module

class brainiak.searchlight.searchlight.Ball(rad)

Bases: brainiak.searchlight.searchlight.Shape

Searchlight shape which is a ball inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). Any location in the cube which has a Euclidean distance of equal to or less than rad from the center point is set to True.

Parameters

rad (radius, in voxels, of the sphere inscribed in the) – searchlight cube, not counting the center voxel

class brainiak.searchlight.searchlight.Cube(rad)

Bases: brainiak.searchlight.searchlight.Shape

Searchlight shape which is a cube of size (2*rad+1,2*rad+1,2*rad+1)

Parameters

rad (radius, in voxels, of the sphere inscribed in the) – searchlight cube, not counting the center voxel

class brainiak.searchlight.searchlight.Diamond(rad)

Bases: brainiak.searchlight.searchlight.Shape

Searchlight shape which is a diamond inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). Any location in the cube which has a Manhattan distance of equal to or less than rad from the center point is set to True.

Parameters

rad (radius, in voxels, of the sphere inscribed in the) – searchlight cube, not counting the center voxel

class brainiak.searchlight.searchlight.Searchlight(sl_rad=1, max_blk_edge=10, shape=<class 'brainiak.searchlight.searchlight.Cube'>, min_active_voxels_proportion=0)

Bases: object

Distributed Searchlight

Run a user-defined function over each voxel in a multi-subject dataset.

Optionally, users can define a block function which runs over larger portions of the volume called blocks.

Parameters
  • sl_rad (radius, in voxels, of the sphere inscribed in the) – searchlight cube, not counting the center voxel

  • max_blk_edge (max edge length, in voxels, of the 3D block) –

  • shape (brainiak.searchlight.searchlight.Shape indicating the) –

  • in voxels of the searchlight region (shape) –

  • min_active_voxels_proportion (float) – If a searchlight region does not have more than this minimum proportion of active voxels in the mask, it is not processed by the searchlight function. The mask used for the test is the intersection of the global (brain) mask and the Shape mask. The seed (central) voxel of the searchlight region is taken into consideration.

broadcast(bcast_var)

Distribute data to processes

Parameters

bcast_var (shared data which is broadcast to all processes) –

distribute(subjects, mask)

Distribute data to MPI ranks

Parameters
  • subjects (list of 4D arrays containing data for one or more subjects.) –

    Each entry of the list must be present on at most one rank, and the other ranks contain a “None” at this list location.

    For example, for 3 ranks you may lay out the data in the following manner:

    Rank 0: [Subj0, None, None] Rank 1: [None, Subj1, None] Rank 2: [None, None, Subj2]

    Or alternatively, you may lay out the data in this manner:

    Rank 0: [Subj0, Subj1, Subj2] Rank 1: [None, None, None] Rank 2: [None, None, None]

  • mask (3D array with "True" entries at active vertices) –

run_block_function(block_fn, extra_block_fn_params=None, pool_size=None)

Perform a function for each block in a volume.

Parameters

block_fn

Parameters

data: list of 4D arrays containing subset of subject data,

which is padded with sl_rad voxels.

mask: 3D array containing subset of mask data

sl_rad: radius, in voxels, of the sphere inscribed in the cube

bcast_var: shared data which is broadcast to all processes

extra_params: extra parameters

extra_block_fn_params: tuple

Extra parameters to pass to the block function

pool_size: int

Maximum number of processes running the block function in parallel. If None, number of available hardware threads, considering cpusets restrictions.

run_searchlight(voxel_fn, pool_size=None)

Perform a function at each voxel which is set to True in the user-provided mask. The mask passed to the searchlight function will be further masked by the user-provided searchlight shape.

Parameters

voxel_fn

Must be serializeable using pickle.

Parameters

subj: list of 4D arrays containing subset of subject data

mask: 3D array containing subset of mask data

sl_rad: radius, in voxels, of the sphere inscribed in the cube

bcast_var: shared data which is broadcast to all processes

Returns

  • A volume which is the same size as the mask, however a number of voxels

  • equal to the searchlight radius has been removed from each border of

  • the volume. This volume contains the values returned from the

  • searchlight function at each voxel which was set to True in the mask,

  • and None elsewhere.

class brainiak.searchlight.searchlight.Shape(rad)

Bases: object

Searchlight shape which is contained in a cube sized (2*rad+1,2*rad+1,2*rad+1)

mask_

which is set to True within the boundaries of the desired shape

Type

a 3D boolean numpy array of size (2*rad+1,2*rad+1,2*rad+1)

Parameters

rad (radius, in voxels, of the sphere inscribed in the) – searchlight cube, not counting the center voxel