Sensor covariance#
This module may be employed to calculate the sensor covariance matrix.
- src_rec.sen_cov.Sen_cov(evals, evecs, ch_names)#
Container class, populed with the following items.
- Parameters:
evals (numpy.ndarray, shape(ch_cnt,)) – Eigenvalues.
evecs (numpy.ndarray, shape(ch_cnt,ch_cnt)) – Eigenvectors/covariance matrix.
ch_names (list, string) – Channel names.
- src_rec.sen_cov.run(sensor_data, fs, signal_type, valid_channels, ch_names, ch_types, method=None, float_sz=64, epoch_sz_s=0.2, method_params=None, fast_eigendecomp_path='../FinnPy_speedups/Release/FinnPy_speedups.so')#
Compute the sensor noise covariance from given data. Of note, must not contain data of interest.
- Parameters:
sensor_data (numpy.ndarray, shape(samples, ch_cnt)) – An (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.
fs (float) – Sampling frequency
signal_type (string) – Can be either “EEG” or “MEG”, determines how the data is loaded.
valid_channels (numpy.ndarray, shape(ch_cnt,)) – Binary list identifying channels as valid/invalid.
ch_names (list, len(ch_cnt)) – Name of the EEG/MEG channels.
ch_types (list, len(ch_cnt)) – Channels may be either “mag”, “grad”, or “eeg”.
grad_channels (list, int) – Indices of gradiometer channels.
method (string) – Method to be employed, either “empirically”, “shrinkage”, or “factor_analysis” (default: shrinkage).
float_sz (int) – Floating point precision used, can be either 32, 64, 128, or 256 (recommended).
epoch_sz_s (0.2) – Size of individual epochs, scaled in s.
method_params (dict()) – Method specific parameters. Only applies to sklearn.covariance.ShrunkCovariance and sklearn.decomposition.FactorAnalysis, defaults to “shrinkage” : 0.2 - epoch size in s.
fast_eigendecomp_path (string) – Path to the finnpy speedups library
- Returns:
sen_cov – Container class.
- Return type:
finnpy.src_rec.sen_cov.Sen_cov
- Raises:
AssertionError – Number of channels is higher than the number of datapoints, as this is very unlikely, the input is rejected.
- src_rec.sen_cov.load(cov_path)#
Determine eigenvectors/values from the sensor noise covariance.
- Parameters:
cov_path (string) – Path to a the covariance file. If none exists, the covariance will be saved in this location.
- Returns:
sen_cov – Container class.
- Return type:
finnpy.src_rec.sen_cov.Sen_cov
- src_rec.sen_cov._empirically_estimate_cov(cov_data, epoch_splits, signal_type, valid_ch_indices, ch_types=None)#
Calculate the sensor noise covariance.
- Parameters:
cov_data (numpy.ndarray, shape(samples, ch_cnt)) – An (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.
epoch_splits (list) – Epoching-indices for covariance calculation.
signal_type (string) – Can be either “EEG” or “MEG”, determines how the data is loaded.
valid_ch_indices (numpy.ndarray, shape(ch_cnt,)) – Binary list identifying channels as valid/invalid.
ch_types (list, len(ch_cnt)) – Channels may be either “mag”, “grad”, or “eeg”.
- Returns:
cov – Covariance
- Return type:
numpy.ndarray, shape(meg_ch_cnt, meg_ch_cnt)
- Raises:
AssertionError – Signal type is invalid, has to be either ‘EEG’ or ‘MEG’.
- src_rec.sen_cov._calc_sensor_noise_cov(sensor_data, fs, signal_type, valid_channels, ch_types=None, method=None, epoch_sz_s=0.2, method_params=None)#
Calculate the sensor noise covariance.
- Parameters:
sensor_data (numpy.ndarray, shape(samples, ch_cnt)) – An (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.
fs (float) – Sampling frequency
signal_type (string) – Can be either “EEG” or “MEG”, determines how the data is loaded.
valid_channels (numpy.ndarray, shape(ch_cnt,)) – Binary list identifying channels as valid/invalid.
ch_types (list, len(ch_cnt)) – Channels may be either “mag”, “grad”, or “eeg”.
method (string) – Method to be employed, either “empirically”, “shrinkage”, or “factor_analysis” (default: shrinkage).
epoch_sz_s (0.2) – Size of individual epochs, scaled in s.
method_params (variable) – Passed on to sklearn’s ShrunkCovariance & FactorAnalysis.
- Returns:
cov – Covariance
- Return type:
numpy.ndarray, shape(meg_ch_cnt, meg_ch_cnt)
- Raises:
AssertionError – Inversion method is invalid, has to be ‘empirically’, ‘shrinkage’ or ‘factor_analysis’.