Data

Data module - main class governing your data and wrapper for all other ConnectiviPy functions.

class connectivipy.data.Data(data, fs=1.0, chan_names=[], data_info='')[source]

Class governing the communication between data array and connectivity estimators.

Args:
data : numpy.array or str
  • array with data (kXNxR, k - channels nr, N - data points,
    R - nr of trials)
  • str - path to file with appropieate format
fs = 1: int
sampling frequency
chan_names = []: list
names of channels
data_info = ‘’: string
other information about the data
select_channels(channels=None)[source]

Selecting channels to plot or further analysis.

Args:
channels : list(int)
List of channel indices. If None all channels are taken into account.
filter(b, a)[source]

Filter each channel of data using forward-backward filter filtfilt from scipy.signal.

Args:
b, a : np.array
Numerator b / denominator a polynomials of the IIR filter.
resample(fs_new)[source]

Signal resampling to new sampling frequency new_fs using resample function from scipy.signal (basing on Fourier method).

Args:
fs_new : int
new sampling frequency
fit_mvar(p=None, method='yw')[source]

Fitting MVAR coefficients.

Args:
p = None : int
estimation order, default None
method = ‘yw’ : str {‘yw’, ‘ns’, ‘vm’}
method of MVAR parameters estimation all avaiable methods you can find in fitting_algorithms
conn(method, **params)[source]

Estimate connectivity pattern.

Args:
p = None : int
estimation order, default None
method : str
method of connectivity estimation all avaiable methods you can find in conn_estim_dc
short_time_conn(method, nfft=None, no=None, **params)[source]

Short-time connectivity.

Args:
method = ‘yw’ : str {‘yw’, ‘ns’, ‘vm’}
method of estimation all avaiable methods you can find in fitting_algorithms
nfft = None : int
number of data points in window; if None, it is signal length N/5.
no = None : int
number of data points in overlap; if None, it is signal length N/10.
params
other parameters for specific estimator
significance(Nrep=100, alpha=0.05, verbose=True, **params)[source]

Statistical significance values of connectivity estimation method.

Args:
Nrep = 100 : int
number of resamples
alpha = 0.05 : float
type I error rate (significance level)
verbose = True : bool
if True it prints dot on every realization
Returns:
signi: numpy.array
matrix in shape of (k, k) with values for each pair of channels
short_time_significance(Nrep=100, alpha=0.05, nfft=None, no=None, verbose=True, **params)[source]

Statistical significance values of short-time version of connectivity estimation method.

Args:
Nrep = 100 : int
number of resamples
alpha = 0.05 : float
type I error rate (significance level)
nfft = None : int
number of data points in window; if None, it is taken from Data.short_time_conn() method.
no = None : int
number of data points in overlap; if None, it is taken from short_time_conn method.
verbose = True : bool
if True it prints dot on every realization
Returns:
signi: numpy.array
matrix in shape of (k, k) with values for each pair of channels
plot_data(trial=0, show=True)[source]

Plot data in a subplot for each channel.

Args:
trial = 0 : int
if there is multichannel data it should be a number of trial you want to plot.
show = True : boolean
show the plot or not
plot_conn(name='', ylim=None, xlim=None, signi=True, show=True)[source]

Plot connectivity estimation results.

Args:
name = ‘’ : str
title of the plot
ylim = None : list
range of y-axis values shown, e.g. [0,1] None means that default values of given estimator are taken into account
xlim = None : list [from (int), to (int)]
range of y-axis values shown, if None it is from 0 to Nyquist frequency
signi = True : boolean
if significance levels are calculated they are shown in the plot
show = True : boolean
show the plot or not
plot_short_time_conn(name='', signi=True, percmax=1.0, show=True)[source]

Plot short-time version of estimation results.

Args:
name = ‘’ : str
title of the plot
signi = True : boolean
reset irrelevant values; it works only after short time significance calculation using short_time_significance
percmax = 1. : float (0,1)
percent of maximal value which is maximum on the color map
show = True : boolean
show the plot or not
export_trans3d(mod=0, filename='conntrans3d.dat', freq_band=[])[source]

Export connectivity data to trans3D data file in order to make 3D arrow plots. Args:

mod = 0 : int
0 - Data.conn() results 1 - Data.short_time_conn() results
filename = ‘conn_trnas3d.dat’ : str
title of the plot
freq_band = [] : list
frequency range [from_value, to_value] in Hz.
fill_nans(values, borders)[source]

Fill nans where values < borders (independent of frequency).

Args:
values : numpy.array
array of shape (time, freqs, channels, channels) to fill nans
borders : numpy.array
array of shape (time, channels, channels) with limes values
Returns:
values_nans : numpy.array
array of shape (time, freq, channels, channels) with nans where values were less than appropieate value from borders
mvar_coefficients

Returns mvar coefficients if calculated

mvarcoef

Returns mvar coefficients if calculated

Data loading

Additonal function which enable other data formats loading

connectivipy.load.loaders.signalml_loader(file_name)[source]

It returns data and dictionary from SignalML files.

Args:
file_name : str
must be the same for .xml and .raw files.
Returns:
data: np.array
eeg data from raw file
xmlinfo : dict
dcitionary with keys: samplingFrequency, channelCount, firstSampleTimestamp, channelNames, calibrationCoef which means the same as in SML file
connectivipy.load.loaders.give_xml_info(path)[source]

It returns dictionary from SignalML file.

Args:
path : str
SML file eg. ‘test.xml’
Returns:
xml_data : dict
dcitionary with keys: samplingFrequency, channelCount, firstSampleTimestamp, channelNames, calibrationCoef which means the same as in SML file

Additional functions

Plot tools which are separate from Data class

connectivipy.plot_conn(values, name='', fs=1, ylim=None, xlim=None, show=True)[source]

Plot connectivity estimation results. Allows to plot your results without using Data class.

Args:
values : numpy.array
connectivity estimation values in shape (fq, k, k) where fq - frequency, k - number of channels
name = ‘’ : str
title of the plot
fs = 1 : int
sampling frequency
ylim = None : list
range of y-axis values shown, e.g. [0,1] None means that default values of given estimator are taken into account
xlim = None : list [from (int), to (int)]
range of y-axis values shown, if None it is from 0 to Nyquist frequency
show = True : boolean
show the plot or not