mne_rsa.searchlight#

class mne_rsa.searchlight(shape, dist=None, spatial_radius=None, temporal_radius=None, sel_series=None, samples_from=0, samples_to=-1)[source]#

Generate indices for searchlight patches.

Generates a sequence of tuples that can be used to index a data array. Depending on the spatial and temporal radius, each tuple extracts a searchlight patch along time, space or both.

This function is flexible in regards to shape of the data array. The intepretation of the dimensions is as follows:

4 or more dimensions

(n_folds, n_items, n_series, n_samples, ...)

3 dimensions

(n_items, n_series, n_samples)

2 dimensions

(n_items, n_series) when spatial_radius is not None. (n_items, n_samples) when temporal_radius is not None.

1 dimension

(n_items,)

The returned tuples will match the dimensions of the data array.

Parameters
shapetuple of int

The shape of the data array to compute the searchlight patches for, as obtained with the .shape attribute.

distndarray or sparse matrix, shape (n_series, n_series) | None

The distances between all source points or sensors in meters. This parameter needs to be specified if a spatial_radius is set.

Since the distance matrix can be huge, sparse matrices are also supported. When the distance matrix is sparse, all zero distances are treated as infinity. This allows you to skip far away points during your distance computations.

Defaults to None.

spatial_radiusfloat | list of list of int | None

This controls how spatial patches will be created. There are several ways to do this:

The first way is to specify a spatial radius in meters. In this case, the dist parameter must also be specified. This will create a searchlight where each patch contains all source points within this radius.

The second way is to specify a list of predefined patches. In this case, each element of the list should itself be a list of integer indexes along the spatial dimension of the data array. Each element of this list will become a separate patch using the data at the specified indices.

The third way is to set this to None, which will disable the making of spatial patches and only perform the searchlight over time. This can be thought of as pooling everything into a single spatial patch.

Defaults to``None``.

temporal_radiusint | None

The temporal radius of the searchlight patch in samples. Set to None to only perform the searchlight over sensors/source points. Defaults to None.

sel_seriesndarray, shape (n_selected_series,) | None

When set, searchlight patches will only be generated for the subset of time series with the given indices. Defaults to None, in which case patches for all series are generated.

samples_fromint

When set, searchlight patches will only be generated for the subset of time samples with indices equal or greater than the given value. Only used when the given data shape includes a temporal dimension. Defaults to 0.

samples_toint

When set, searchlight patches will only be generated for the subset of time samples with indices up to, but not including, the given value. Only used when the given data shape includes a temporal dimension. Defaults to -1, which means there is no upper bound.

Yields
patchtuple of (slice | ndarray)

A single searchlight patch. Each element of the tuple corresponds to a dimension of the data array and can be used to index along this dimension to extract the searchlight patch.

Attributes
shape

Get the number of generated patches along multiple dimensions.

__hash__(/)#

Return hash(self).

__iter__()[source]#

Get an iterator over the searchlight patches.

__len__()[source]#

Get total number of searchlight patches that will be generated.