supereeg.Brain

class supereeg.Brain(data=None, locs=None, sessions=None, sample_rate=None, meta=None, date_created=None, label=None, kurtosis=None, kurtosis_threshold=10, minimum_voxel_size=3, maximum_voxel_size=20, filter='kurtosis')[source]

Brain data object for the supereeg package

A brain data object contains a single iEEG subject. To create one, at minimum you need data (samples x electrodes), location coordinates in MNI space and the sample rate of the data. Additionally, you can include a session id. If included, all analyses will be performed within session and then aggregated across sessions. You can also include a meta dict, which can contain any other information that might be useful (subject id, recording params, etc).

Parameters:
data : numpy.ndarray or pandas.DataFrame, supereeg.Model, supereeg.Nifti, or Nifti1Image

Samples x electrodes array containing the iEEG data.

If data is a model, returns correlation matrix.

If data is a nifti image (either supereeg.Nifti or Nifti1Image), returns nifti values as samples by electrodes array.

locs : numpy.ndarray or pandas.DataFrame

Electrode by MNI coordinate (x,y,z) array containing electrode locations

session : str, int or numpy.ndarray

Samples x 1 array containing session identifiers for each time sample. If str or int, the value will be copied for each time sample.

sample_rates : float, int or list

Sample rate (Hz) of the data. If different over multiple sessions, this is a list.

meta : dict

Optional dict containing whatever you want.

date created : str

Time created (optional)

label : list

List delineating if location was reconstructed or observed. This is computed in reconstruction.

Returns:
bo : supereeg.Brain

Instance of Brain data object.

Attributes:
data : pandas.DataFrame

Samples x electrodes dataframe containing the EEG data.

locs : pandas.DataFrame

Electrode by MNI coordinate (x,y,z) df containing electrode locations.

sessions : pandas.Series

Samples x 1 array containing session identifiers. If a single value is passed, a single session will be created.

sample_rates : list

Sample rate of the data. If different over multiple sessions, this is a list.

meta : dict

Optional dict containing whatever you want.

n_elecs : int

Number of electrodes

dur : float

Amount of data in seconds for each session

n_sessions : int

Number of sessions

label : list

Label for each session

kurtosis : int

Kurtosis threshold

filter : ‘kurtosis’ or None

If ‘kurtosis’, electrodes that exceed the kurtosis threshold will be removed. If None, no thresholding is applied.

minimum_voxel_size : positive scalar or 3D numpy array

Used to construct Nifti objects; default: 3 (mm)

maximum_voxel_size : positive scalar or 3D numpy array

Used to construct Nifti objects; default: 20 (mm)

Methods

apply_filter([inplace]) Return a filtered copy
get_data() Gets data from brain object
get_locs() Gets locations from brain object
get_slice([sample_inds, loc_inds, inplace]) Indexes brain object data
get_zscore_data() Gets zscored data from brain object
info() Print info about the brain object
next() Return next sample from Brain object (wrapper for self.__next__)
plot_data([filepath, time_min, time_max, ...]) Normalizes and plots data from brain object
plot_locs([pdfpath]) Plots electrode locations from brain object
resample([resample_rate]) Resamples data
save(fname[, compression]) Save method for the brain object
to_nii([filepath, template, vox_size, ...]) Save brain object as a nifti file.
update_filter_inds  
update_info  
apply_filter(inplace=True)[source]

Return a filtered copy

get_data()[source]

Gets data from brain object

get_locs()[source]

Gets locations from brain object

get_slice(sample_inds=None, loc_inds=None, inplace=False)[source]

Indexes brain object data

Parameters:
sample_inds : int or list

Times you wish to index

loc_inds : int or list

Locations you with to index

inplace : bool

If True, indexes in place.

get_zscore_data()[source]

Gets zscored data from brain object

info()[source]

Print info about the brain object

Prints the number of electrodes, recording time, number of recording sessions, date created, and any optional meta data.

next()[source]

Return next sample from Brain object (wrapper for self.__next__)

plot_data(filepath=None, time_min=None, time_max=None, title=None, electrode=None)[source]

Normalizes and plots data from brain object

Parameters:
filepath : str

A name for the file. If the file extension (.png) is not specified, it will be appended.

time_min : int

Minimum value for desired time window

time_max : int

Maximum value for desired time window

title : str

Title for plot

electrode : int

Location in MNI coordinate (x,y,z) by electrode df containing electrode locations

plot_locs(pdfpath=None)[source]

Plots electrode locations from brain object

Colors:
  • Observed : Blue
  • Removed : Cyan
  • Reconstructed : Red
Parameters:
pdfpath : str

A name for the file. If the file extension (.pdf) is not specified, it will be appended.

resample(resample_rate=None)[source]

Resamples data

Parameters:
resample_rate : int or float

Desired sample rate

save(fname, compression='blosc')[source]

Save method for the brain object

The data will be saved as a ‘bo’ file, which is a dictionary containing the elements of a brain object saved in the hd5 format using deepdish.

Parameters:
fname : str

A name for the file. If the file extension (.bo) is not specified, it will be appended.

compression : str

The kind of compression to use. See the deepdish documentation for options: http://deepdish.readthedocs.io/en/latest/api_io.html#deepdish.io.save

to_nii(filepath=None, template='gray', vox_size=None, sample_rate=None)[source]

Save brain object as a nifti file.

Parameters:
filepath : str

Path to save the nifti file

template : str, Nifti1Image, or None

Template is a nifti file with the desired resolution to save the brain object activity

If template is None (default) :
  • Uses gray matter masked brain downsampled to brain object voxel size (max 20 mm)
If template is str :
  • Checks if nifti file path and uses specified nifti
  • If not a filepath, checks if ‘std’ or ‘gray’
    • ‘std’: Uses standard brain downsampled to brain object voxel size
    • ‘gray’: Uses gray matter masked brain downsampled to brain object voxel size
If template is Nifti1Image :
  • Uses specified Nifti image
Returns:
nifti : supereeg.Nifti

A supereeg nifti object