Peak to peak amplitude manual

UML diagrams presenting the flow of the analysis for each module are available here: https://github.com/ANCPLabOldenburg/MEG-QC-code/tree/main/diagrams

meg_qc.calculation.metrics.Peaks_manual_meg_qc.PP_manual_meg_qc(ptp_manual_params: dict, channels: dict, chs_by_lobe: dict, dict_epochs_mg: dict, data: Raw, m_or_g_chosen: list, verbose_plots: bool)[source]

Main Peak to peak amplitude function. Calculates:

  • Peak to peak amplitudes (PtP) of data for each channel over all time series.

  • Channels with big PtP (noisy) and small PtP (flat) over all time series.

  • PtP of data for each channel in each epoch.

  • Epochs with big PtP (noisy) and small PtP (flat).

Parameters:

ptp_manual_paramsdict

Dictionary containing the parameters for the metric

channelsdict

Dict (mag, grad) with all channel names

chs_by_lobedict

dictionary with channels grouped first by ch type and then by lobe: chs_by_lobe[‘mag’][‘Left Occipital’] or chs_by_lobe[‘grad’][‘Left Occipital’]

dict_epochs_mgdict

Dict (mag, grad) with epochs for each channel. Should be the same for both channels. Used only to check if epochs are present.

datamne.io.Raw

Raw data

m_or_g_chosenlist

‘mag’ or ‘grad’ or both, chosen by user in config file.

verbose_plotsbool

True for showing plot in notebook.

Returns:

derivs_ptplist

List with QC_deriv objects for peak-to-peak amplitude (figures and csv files)

simple_metric_ptp_manualdict

Simple metric for peak-to-peak amplitude

pp+manual_strstr

String with notes about PtP manual for report

meg_qc.calculation.metrics.Peaks_manual_meg_qc.get_ptp_all_data(data: Raw, channels: list, sfreq: int, ptp_thresh_lvl: float, max_pair_dist_sec: float)[source]

Calculate peak-to-peak amplitude for all channels over whole data (not epoched).

Parameters:

datamne.io.Raw

Raw data

channelslist

List of channel names to be used for peak-to-peak amplitude calculation

sfreqint

Sampling frequency of data. Attention to which data is used! original or resampled.

ptp_thresh_lvlfloat

The level definig how the PtP threshold will be scaled. Higher number will result in more peaks detected. The threshold is calculated as (max - min) / ptp_thresh_lvl

max_pair_dist_secfloat

Maximum distance in seconds which is allowed for negative+positive peaks to be detected as a pair

Returns:

peak_ampl_channelsdict

Peak-to-peak amplitude values for each channel.

meg_qc.calculation.metrics.Peaks_manual_meg_qc.get_ptp_epochs(channels: list, epochs_mg: Epochs, sfreq: int, ptp_thresh_lvl: float, max_pair_dist_sec: float)[source]

Calculate peak-to-peak amplitude for every epoch and every channel (mag or grad).

Parameters:

channelslist

List of channel names to be used for peak-to-peak amplitude calculation

epochs_mgmne.Epochs

Epochs data

sfreqint

Sampling frequency of data. Attention to which data is used! original or resampled.

ptp_thresh_lvlfloat

The level definig how the PtP threshold will be scaled. Higher number will result in more peaks detected. The threshold is calculated as (max - min) / ptp_thresh_lvl

max_pair_dist_secfloat

Maximum distance in seconds which is allowed for negative+positive peaks to be detected as a pair

Returns:

pd.DataFrame

Dataframe containing the mean peak-to-peak aplitude for each epoch for each channel

meg_qc.calculation.metrics.Peaks_manual_meg_qc.make_simple_metric_ptp_manual(ptp_manual_params: dict, big_ptp_with_value_all_data: dict, small_ptp_with_value_all_data: dict, channels: dict, deriv_epoch_ptp: dict, metric_local: bool, m_or_g_chosen: list)[source]

Create a simple metric for peak-to-peak amplitude. Global: The metric is calculated for all data (not epoched) and Local: for each epoch.

Parameters:

ptp_manual_paramsdict

Dictionary containing the parameters for the metric

big_ptp_with_value_all_datadict

Dict (mag, grad) with channels with peak-to-peak amplitude higher than the threshold + the value of the peak-to-peak amplitude

small_ptp_with_value_all_datadict

Dict (mag, grad) with channels with peak-to-peak amplitude lower than the threshold + the value of the peak-to-peak amplitude

channelsdict

Dict (mag, grad) with all channel names

deriv_epoch_ptpdict

Dict (mag, grad) with peak-to-peak amplitude for each epoch for each channel

metric_localbool

If True, the local metric was calculated and will be added to the simple metric

m_or_g_chosenlist

‘mag’ or ‘grad’ or both, chosen by user in config file

Returns:

simple_metricdict

Dict (mag, grad) with the simple metric for peak-to-peak manual amplitude

meg_qc.calculation.metrics.Peaks_manual_meg_qc.neighbour_peak_amplitude(max_pair_dist_sec: float, sfreq: int, pos_peak_locs: ndarray, neg_peak_locs: ndarray, pos_peak_magnitudes: ndarray, neg_peak_magnitudes: ndarray)[source]

Find a pair: postive + negative peak and calculates the amplitude between them. If no neighbour is found withing given distance - this peak is skipped. If several neighbours are found - several pairs are created. As the result a mean peak-to-peak distance is calculated over all detected pairs for given chunck of data

Parameters:

max_pair_dist_secfloat

Maximum distance in seconds which is allowed for negative+positive peaks to be detected as a pair

sfreqint

Sampling frequency of data. Attention to which data is used! original or resampled.

pos_peak_locsnp.ndarray

Output of peak_finder function - positions of detected Positive peaks

neg_peak_locsnp.ndarray

Output of peak_finder function - positions of detected Negative peaks

pos_peak_magnitudesnp.ndarray

Output of peak_finder function - magnitudes of detected Positive peaks

neg_peak_magnitudesnp.ndarray

Output of peak_finder function - magnitudes of detected Negative peaks

Returns:

mean_amplitudefloat

Mean value over all detected peak pairs for this chunck of data.

amplitudenp.ndarray

Array of all detected peak pairs for this chunck of data.