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:

src_rec.sen_cov.evals#

Eigenvalues.

Type:

numpy.ndarray, shape(ch_cnt,)

src_rec.sen_cov.evecs#

Eigenvectors/covariance matrix.

Type:

numpy.ndarray, shape(ch_cnt,ch_cnt)

src_rec.sen_cov.ch_names#

Channel names.

Type:

list, string

src_rec.sen_cov.run(file_path, cov_path, method=None, float_sz=64, method_params=None, finnpy_speedups_path='../FinnPy_speedups/Release/FinnPy_speedups.so', overwrite=False)#

#Determines eigenvectors/values from the sensor noise covariance

Parameters:
  • file_path (string) – The (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.

  • cov_path (string) – Path to a the covariance file. If none exists, the covariance will be saved in this location.

  • method (string) – Method to be employed, either “empirically”, “shrinkage”, or “factor_analysis” (default: shrinkage).

  • 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.

  • finnpy_speedups_path (string) – Path to the finnpy speedups library

  • overwrite (boolean) – Flag to overwrite covariance calculation.

Returns:

sen_cov – Container class.

Return type:

finnpy.src_rec.sen_cov.Sen_cov

src_rec.sen_cov.load(cov_path)#

#Determines 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._get_bio_channel_type_idx(raw_file, mask=None)#

Identifies bio channel types.

Parameters:

raw_file (mne.io.read_raw_fif) – Scanned MRI file.

Returns:

  • valid_ch_indices (numpy.ndarray, shape(ch_cnt,)) – Binary list identifying channels as valid/invalid.

  • meg_ch_indices (list, int) – Indices of magnetometer channels.

  • grad_ch_indices (list, int) – Indices of gradiometer channels.

  • ch_names (list, string) – channel names.

src_rec.sen_cov._empirically_estimate_cov(cov_data, meg_ch_indices, grad_ch_indices, valid_ch_indices)#

Calculates the sensor noise covariance

Parameters:
  • cov_data (numpy.ndarray, shape(samples, channels)) – An (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.

  • meg_ch_indices (list, int) – Indices of magnetometer channels.

  • grad_ch_indices (list, int) – Indices of gradiometer channels.

  • valid_ch_indices (numpy.ndarray, shape(ch_cnt,)) – Binary list identifying channels as valid/invalid.

Returns:

cov – Covariance

Return type:

numpy.ndarray, shape(meg_ch_cnt, meg_ch_cnt)

src_rec.sen_cov._calc_sensor_noise_cov(raw_file, method=None, method_params=None, epoch_sz_s=0.2)#

Calculates the sensor noise covariance

Parameters:
  • file_path (string) – The (empty room) file to use for sensor noise covariance calculations. Important: Evaluate a number of different files to identify a good example.

  • cov_path (string) – Path to a the covariance file. If none exists, the covariance will be saved in this location.

  • 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.

Returns:

  • cov (numpy.ndarray, shape(meg_ch_cnt, meg_ch_cnt)) – Covariance

  • ch_names (list, string) – Channel names.