Universal plotting functions

In the html report:

  • all the plots produced by MEQ-QC are interactive, they can be scrolled through and enlarged.

  • a few plots from MNE (in ECG and EOG sections) are not interactive.

class meg_qc.plotting.universal_plots.MEG_channels(name: str, type: str, lobe: str, lobe_color: str, loc: list, time_series: list | None = None, std_overall: float | None = None, std_epoch: list | None = None, ptp_overall: float | None = None, ptp_epoch: list | None = None, psd: list | None = None, freq: list | None = None, mean_ecg: list | None = None, mean_ecg_smoothed: list | None = None, mean_eog: list | None = None, mean_eog_smoothed: list | None = None, ecg_time=None, eog_time=None, ecg_corr_coeff=None, ecg_pval=None, eog_corr_coeff=None, eog_pval=None, muscle=None, head=None, muscle_time=None, head_time=None)[source]

Channel with info for plotting: name, type, lobe area, color code, location, initial time series + other data calculated by QC metrics (assigned in each metric separately while plotting).

add_ecg_info(Avg_artif_list, artif_time_vector)[source]

Adds ECG artifact info to the channel object.

add_eog_info(Avg_artif_list, artif_time_vector)[source]

Adds EOG artifact info to the channel object.

to_df()[source]

Returns the object as a pandas DataFrame. To be later exported into a tsv file.

meg_qc.plotting.universal_plots.Plot_psd_csv(m_or_g: str, f_path: str, method: str, verbose_plots: bool)[source]

Plotting Power Spectral Density for all channels based on dtaa from tsv file.

Parameters:
  • m_or_g (str) – ‘mag’ or ‘grad’

  • f_path (str) – Path to the tsv file with PSD data.

  • method (str) – ‘welch’ or ‘multitaper’ or other method

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

class meg_qc.plotting.universal_plots.QC_derivative(content, name, content_type, description_for_user='', fig_order=0)[source]

Derivative of a QC measurement, main content of which is figure, data frame (saved later as csv) or html string.

content

The main content of the derivative.

Type:

figure, pd.DataFrame or str

name

The name of the derivative (used to save in to file system)

Type:

str

content_type

The type of the content: ‘plotly’, ‘matplotlib’, ‘csv’, ‘report’ or ‘mne_report’. Used to choose the right way to save the derivative in main function.

Type:

str

description_for_user

The description of the derivative, by default ‘Add measurement description for a user…’ Used in the report to describe the derivative.

Type:

str, optional

convert_fig_to_html()[source]

Converts figure to html string.

Returns:

html – Html string or None if content_type is not ‘plotly’ or ‘matplotlib’.

Return type:

str or None

convert_fig_to_html_add_description()[source]

Converts figure to html string and adds description.

Returns:

html – Html string: fig + description or None + description if content_type is not ‘plotly’ or ‘matplotlib’.

Return type:

str or None

get_section()[source]

Return a section of the report based on the info saved in the name. Normally not used. Use if cant figure out the derivative type.

Returns:

section – ‘RMSE’, ‘PTP_MANUAL’, ‘PTP_AUTO’, ‘PSD’, ‘EOG’, ‘ECG’, ‘MUSCLE’, ‘HEAD’.

Return type:

str

meg_qc.plotting.universal_plots.add_log_buttons(fig: Figure)[source]

Add buttons to switch scale between log and linear. For some reason only swithcing the Y scale works so far.

Parameters:

fig (go.Figure) – The figure to be modified withot buttons

Returns:

fig – The modified figure with the buttons

Return type:

go.Figure

meg_qc.plotting.universal_plots.assign_channels_properties(raw: Raw)[source]

Assign lobe area to each channel according to the lobe area dictionary + the color for plotting + channel location.

Can later try to make this function a method of the MEG_channels class. At the moment not possible because it needs to know the total number of channels to figure which meg system to use for locations. And MEG_channels class is created for each channel separately.

Parameters:

raw (mne.io.Raw) – Raw data set.

Returns:

  • channels_objs (dict) – Dictionary with channel names for each channel type: mag, grad. Each channel has assigned lobe area and color for plotting + channel location.

  • lobes_color_coding_str (str) – A string with information about the color coding of the lobes.

meg_qc.plotting.universal_plots.assign_epoched_std_ptp_to_channels(what_data, chs_by_lobe, df_std_ptp)[source]

Assign std or ptp values of each epoch as list to each channel. This is done for easier plotting when need to plot epochs per channel and also color coded by lobes.

Parameters:
  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • chs_by_lobe (dict) – dictionary with channel objects sorted by lobe.

  • df_std_ptp (pd.DataFrame) – Data Frame containing std or ptp value for each chnnel and each epoch

Returns:

chs_by_lobe – updated dictionary with channel objects sorted by lobe - with info about std or ptp of epochs.

Return type:

dict

meg_qc.plotting.universal_plots.boxplot_all_time(chs_by_lobe: dict, ch_type: str, what_data: str, verbose_plots: bool)[source]

Create representation of calculated std data as a boxplot over the whoe time series, not epoched. (box contains magnetometers or gradiomneters, not together): each dot represents 1 channel (std value over whole data of this channel). Too high/low stds are outliers.

Old version.

Parameters:
  • chs_by_lobe (dict) – dictionary with channel objects sorted by lobe.

  • ch_type (str) – ‘mag’ or ‘grad’

  • channels (list) – list of channel names

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_all_time_OLD(std_data_named: dict, ch_type: str, channels: list, what_data: str, verbose_plots: bool)[source]

Create representation of calculated std data as a boxplot (box containd magnetometers or gradiomneters, not together): each dot represents 1 channel: name: std value over whole data of this channel. Too high/low stds are outliers. OLD but still working version, currently not used. Other principal than the current one so left for reference.

Parameters:
  • std_data_named (dict) – std values for each channel

  • ch_type (str) – ‘mag’ or ‘grad’

  • channels (list) – list of channel names

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_all_time_csv(std_csv_path: str, ch_type: str, what_data: str, verbose_plots: bool)[source]

Create representation of calculated std data as a boxplot over the whoe time series, not epoched. (box contains magnetometers or gradiomneters, not together): each dot represents 1 channel (std value over whole data of this channel). Too high/low stds are outliers.

On base of the data from tsv file.

Parameters:
  • std_csv_path (str) – Path to the tsv file with std data.

  • ch_type (str) – ‘mag’ or ‘grad’

  • channels (list) – list of channel names

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epoched_xaxis_channels(chs_by_lobe: dict, df_std_ptp: DataFrame, ch_type: str, what_data: str, verbose_plots: bool)[source]

Creates representation of calculated data as multiple boxplots. Used in STD and PtP_manual measurements. Color tagged channels by lobes. One box is one channel, boxes are on x axis. Epoch are inside as dots. Y axis shows the STD/PtP value.

Parameters:
  • chs_by_lobe (dict) – Dictionary with channel objects sorted by lobe.

  • df_std_ptp (pd.DataFrame) – Data Frame containing std or ptp value for each chnnel and each epoch

  • ch_type (str) – Type of the channel: ‘mag’, ‘grad’

  • what_data (str) – Type of the data: ‘peaks’ or ‘stds’

  • x_axis_boxes (str) – What to plot as boxplot on x axis: ‘channels’ or ‘epochs’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig_deriv – derivative containing plotly figure

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epoched_xaxis_channels_csv(std_csv_path: str, ch_type: str, what_data: str, verbose_plots: bool)[source]

Creates representation of calculated data as multiple boxplots. Used in STD and PtP_manual measurements. Color tagged channels by lobes. One box is one channel, boxes are on x axis. Epoch are inside as dots. Y axis shows the STD/PtP value.

On base of the data from tsv file.

Parameters:
  • std_csv_path (str) – Path to the tsv file with std data

  • ch_type (str) – Type of the channel: ‘mag’, ‘grad’

  • what_data (str) – Type of the data: ‘peaks’ or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig_deriv – derivative containing plotly figure

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epoched_xaxis_epochs(chs_by_lobe: dict, df_std_ptp: DataFrame, ch_type: str, what_data: str, verbose_plots: bool)[source]

Represent std of epochs for each channel as box plots, where each box on x axis is 1 epoch. Dots inside the box are channels.

Process: Each box need to be plotted as a separate trace first. Each channels inside each box has to be plottted as separate trace to allow diffrenet color coding

For each box_representing_epoch:

box trace For each color coded lobe:

For each dot_representing_channel in lobe:

dot trace

Add all traces to plotly figure

Parameters:
  • chs_by_lobe (dict) – dictionary with channel objects sorted by lobe.

  • df_std_ptp (pd.DataFrame) – Data Frame containing std or ptp value for each chnnel and each epoch

  • ch_type (str) – ‘mag’ or ‘grad’

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epoched_xaxis_epochs_csv(std_csv_path: str, ch_type: str, what_data: str, verbose_plots: bool)[source]

Represent std of epochs for each channel as box plots, where each box on x axis is 1 epoch. Dots inside the box are channels. On base of the data from tsv file

Process: Each box need to be plotted as a separate trace first. Each channels inside each box has to be plottted as separate trace to allow diffrenet color coding

For each box_representing_epoch:

box trace For each color coded lobe:

For each dot_representing_channel in lobe:

dot trace

Add all traces to plotly figure

Parameters:
  • std_csv_path (str) – Path to the tsv file with std data

  • ch_type (str) – ‘mag’ or ‘grad’

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epochs(df_mg: DataFrame, ch_type: str, what_data: str, x_axis_boxes: str, verbose_plots: bool)[source]

Creates representation of calculated data as multiple boxplots. Used in STD and PtP_manual measurements.

  • If x_axis_boxes is ‘channels’, each box represents 1 epoch, each dot is std of 1 channel for this epoch

  • If x_axis_boxes is ‘epochs’, each box represents 1 channel, each dot is std of 1 epoch for this channel

Parameters:
  • df_mg (pd.DataFrame) – Data frame with std or peak-to-peak values for each channel and epoch. Columns are epochs, rows are channels.

  • ch_type (str) – Type of the channel: ‘mag’, ‘grad’

  • what_data (str) – Type of the data: ‘peaks’ or ‘stds’

  • x_axis_boxes (str) – What to plot as boxplot on x axis: ‘channels’ or ‘epochs’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig_deriv – derivative containing plotly figure

Return type:

QC_derivative

meg_qc.plotting.universal_plots.boxplot_epochs_old(df_mg: DataFrame, ch_type: str, what_data: str, verbose_plots: bool) QC_derivative[source]

Create representation of calculated data as multiple boxplots: each box represents 1 channel, each dot is std of 1 epoch in this channel Implemented with plotly: https://plotly.github.io/plotly.py-docs/generated/plotly.graph_objects.Box.html The figure will be saved as an interactive html file.

Old version, not used.

Parameters:
  • df_mg (pd.DataFrame) – data frame containing data (stds, peak-to-peak amplitudes, etc) for each epoch, each channel, mags OR grads, not together

  • ch_type (str) – title, like “Magnetometers”, or “Gradiometers”,

  • what_data (str) – ‘peaks’ for peak-to-peak amplitudes or ‘stds’

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig – plottly figure

Return type:

go.Figure

meg_qc.plotting.universal_plots.check_num_channels_correct(chs_by_lobe: dict, note: str)[source]

Print total number of channels in all lobes for 1 ch type (must be 102 mag and 204 grad in Elekta/Neuromag)

Parameters:
  • chs_by_lobe (dict) – A dictionary of channels sorted by ch type and lobe.

  • note (str) – A note to print with the total number of channels.

meg_qc.plotting.universal_plots.figure_x_axis(df, metric)[source]

‘ Get the x axis for the plot based on the metric.

Parameters:
  • df (pd.DataFrame) – Data frame with the data.

  • metric (str) – The metric for which the x axis is needed. Can be ‘PSD’, ‘ECG’, ‘EOG’, ‘Muscle’, ‘Head’.

Returns:

  • freqs (np.ndarray) – Frequencies for the PSD plot.

  • time_vec (np.ndarray) – Time vector for the ECG, EOG, Muscle, Head plots.

meg_qc.plotting.universal_plots.get_ch_color_knowing_name(ch_name: str, chs_by_lobe: dict)[source]

Get channel color from chs_by_lobe knowing its name. Currently not used in pipeline. Might be useful later.

Parameters:
  • ch_name (str) – channel name

  • chs_by_lobe (dict) – dictionary with channel objects sorted by lobe

Returns:

color – color of the channel

Return type:

str

meg_qc.plotting.universal_plots.get_tit_and_unit(m_or_g: str, psd: bool = False)[source]

Return title and unit for a given type of data (magnetometers or gradiometers) and type of plot (psd or not)

Parameters:
  • m_or_g (str) – ‘mag’ or ‘grad’

  • psd (bool, optional) – True if psd plot, False if not, by default False

Returns:

  • m_or_g_tit (str) – ‘Magnetometers’ or ‘Gradiometers’

  • unit (str) – ‘T’ or ‘T/m’ or ‘T/Hz’ or ‘T/m / Hz’

meg_qc.plotting.universal_plots.make_3d_sensors_trace(d3_locs: list, names: list, color: str, textsize: int, legend_category: str = 'channels', symbol: str = 'circle', textposition: str = 'top right')[source]

Since grads have 2 sensors located in the same spot - need to put their names together to make pretty plot labels.

Parameters:
  • d3_locs (list) – A list of 3D locations of the sensors.

  • names (list) – A list of names of the sensors.

  • color (str) – A color of the sensors.

  • textsize (int) – A size of the text.

  • ch_type (str) – A type of the channels.

  • symbol (str) – A symbol of the sensors.

  • textposition (str) – A position of the text.

Returns:

trace – A trace of the sensors.

Return type:

plotly.graph_objs._scatter3d.Scatter3d

meg_qc.plotting.universal_plots.make_head_pos_plot_csv(f_path: str, verbose_plots: bool)[source]

Plot positions and rotations of the head. On base of data from tsv file.

Parameters:
  • f_path (str) – Path to a file with data.

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

  • head_derivs (list) – List of QC_derivative objects containing figures with head positions and rotations.

  • head_pos_baselined (np.ndarray) – Head positions and rotations starting from 0 instead of the mne detected starting point. Can be used for plotting.

meg_qc.plotting.universal_plots.make_head_pos_plot_mne(raw: Raw, head_pos: ndarray, verbose_plots: bool)[source]

Currently not used if we wanna plot solely from csv. This function requires also raw as input and cant be only from csv.

TODO: but we can calculate these inputs earlier and add them to csv as well.

meg_qc.plotting.universal_plots.plot_ECG_EOG_channel(ch_data: ndarray, peaks: ndarray, ch_name: str, fs: float, verbose_plots: bool)[source]

Plot the ECG channel data and detected peaks

Parameters:
  • ch_data (list or np.ndarray) – Data of the channel

  • peaks (list or np.ndarray) – Indices of the peaks in the data

  • ch_name (str) – Name of the channel

  • fs (int) – Sampling frequency of the data

  • verbose_plots (bool) – If True, show the figure in the notebook

Returns:

fig – Plot of the channel data and detected peaks

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_ECG_EOG_channel_csv(f_path, verbose_plots: bool)[source]

Plot the ECG channel data and detected peaks

Parameters:
  • ch_data (list or np.ndarray) – Data of the channel

  • peaks (list or np.ndarray) – Indices of the peaks in the data

  • ch_name (str) – Name of the channel

  • fs (int) – Sampling frequency of the data

  • verbose_plots (bool) – If True, show the figure in the notebook

Returns:

fig – Plot of the channel data and detected peaks

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_affected_channels_csv(df, artifact_lvl: float, t: ndarray, m_or_g: str, ecg_or_eog: str, title: str, flip_data: bool = 'flip', smoothed: bool = False, verbose_plots: bool = True)[source]

Plot the mean artifact amplitude for all affected (not affected) channels in 1 plot together with the artifact_lvl. Based on the data from tsv file.

Parameters:
  • df (pd.DataFrame) – Data frame with the data.

  • artifact_lvl (float) – The threshold for the artifact amplitude.

  • t (np.ndarray) – Time vector.

  • m_or_g (str) – Either ‘mag’ or ‘grad’.

  • ecg_or_eog (str) – Either ‘ECG’ or ‘EOG’.

  • title (str) – The title of the figure.

  • flip_data (bool) – If True, the absolute value of the data will be used for the calculation of the mean artifact amplitude. Default to ‘flip’. ‘flip’ means that the data will be flipped if the peak of the artifact is negative. This is donr to get the same sign of the artifact for all channels, then to get the mean artifact amplitude over all channels and the threshold for the artifact amplitude onbase of this mean And also for the reasons of visualization: the artifact amplitude is always positive.

  • smoothed (bool) – Plot smoothed data (true) or nonrmal (false)

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig – The plotly figure with the mean artifact amplitude for all affected (not affected) channels in 1 plot together with the artifact_lvl.

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_artif_per_ch_correlated_lobes_csv(f_path: str, m_or_g: str, ecg_or_eog: str, flip_data: bool, verbose_plots: bool)[source]

This is the final function. Plot average artifact for each channel, colored by lobe, channels are split into 3 separate plots, based on their correlation with mean_rwave: equal number of channels in each group. Based on the data from tsv file.

Parameters:
  • f_path (str) – Path to the tsv file with data.

  • m_or_g (str) – Type of the channel: mag or grad

  • ecg_or_eog (str) – Type of the artifact: ECG or EOG

  • flip_data (bool) – Use True or False, doesnt matter here. It is only passed into the plotting function and influences the threshold presentation. But since treshold is not used in correlation method, this is not used.

  • verbose_plots (bool) – If True, plots are shown in the notebook.

Returns:

  • artif_per_ch (list) – List of objects of class Avg_artif

  • affected_derivs (list) – List of objects of class QC_derivative (plots)

meg_qc.plotting.universal_plots.plot_correlation_csv(f_path: str, ecg_or_eog: str, m_or_g: str, verbose_plots=False)[source]

Plot correlation coefficient and p-value between mean R wave and each channel in artif_per_ch. Based on the data from tsv file.

Parameters:
  • f_path (str) – Path to the tsv file with data.

  • ecg_or_eog (str) – Either ‘ECG’ or ‘EOG’.

  • m_or_g (str) – Either ‘mag’ or ‘grad’.

  • verbose_plots (bool) – If True, plot will be displayed in a notebook.

Returns:

corr_derivs – List with 1 QC_derivative instance: Figure with correlation coefficient and p-value between mean R wave and each channel in artif_per_ch.

Return type:

list

meg_qc.plotting.universal_plots.plot_df_of_channels_data_as_lines_by_lobe(chs_by_lobe: dict, df_data: DataFrame, x_values: list)[source]

Plots data from a data frame as lines, each lobe has own color as set in chs_by_lobe.

Currntly not used.

Parameters:
  • chs_by_lobe (dict) – Dictionary with lobes as keys and lists of channels as values.

  • df_data (pd.DataFrame) – Data frame with data to plot.

  • x_values (list) – List of x values for the plot.

Returns:

fig – Plotly figure.

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_df_of_channels_data_as_lines_by_lobe_OLD(chs_by_lobe: dict, df_data: DataFrame, x_values)[source]

Plots data from a data frame as lines, each lobe has own color as set in chs_by_lobe. Old version. Here we plot all channels of one lobe together, then all channels of next lobe - gives less visual separation of traces since they blend together.

Parameters:
  • chs_by_lobe (dict) – Dictionary with lobes as keys and lists of channels as values.

  • df_data (pd.DataFrame) – Data frame with data to plot.

  • x_values (list) – List of x values for the plot.

Returns:

fig – Plotly figure.

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_df_of_channels_data_as_lines_by_lobe_csv(f_path: str, metric: str, x_values, m_or_g, df=None)[source]

Plots data from a data frame as lines, each lobe has own color. Data is taken from previously saved tsv file.

Parameters:
  • f_path (str) – Path to the csv file with the data to plot.

  • metric (str) – The metric of the data to plot: ‘psd’, ‘ecg’, ‘eog’, ‘smoothed_ecg’, ‘smoothed_eog’.

Returns:

fig – Plotly figure.

Return type:

plotly.graph_objects.Figure

meg_qc.plotting.universal_plots.plot_muscle_annotations_mne(raw: Raw, m_or_g: str, annot_muscle: Annotations | None = None, interactive_matplot: bool = False)[source]

Currently not used since cant be added into HTML report

meg_qc.plotting.universal_plots.plot_muscle_csv(f_path, m_or_g: str, verbose_plots: bool)[source]

Plot the muscle events with the z-scores and the threshold. On base of the data from tsv file.

Parameters:
  • f_path (str) – Path to tsv file with data.

  • m_or_g (str) – The channel type used for muscle detection: ‘mag’ or ‘grad’.

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

fig_derivs – A list of QC_derivative objects with plotly figures for muscle events.

Return type:

list

meg_qc.plotting.universal_plots.plot_pie_chart_freq(amplitudes_relative: list, amplitudes_abs: list, total_amplitude: float, m_or_g: str, bands_names: list, fig_tit: str, fig_name: str, verbose_plots: bool)[source]

Plot pie chart representation of relative amplitude of each frequency band over the entire times series of mags or grads, not separated by individual channels.

Parameters:
  • freq_amplitudes_relative (list) – list of relative amplitudes of each frequency band

  • freq_amplitudes_absolute (list) – list of absolute amplitudes of each frequency band

  • total_freq_ampl (float) – total amplitude of all frequency bands. It might be diffrent from simple sum of mean_abs_values. In this case ‘unknown’ band will be added in this fucntion

  • m_or_g (str) – ‘mag’ or ‘grad’

  • bands_names (list) – list of names of frequency bands

  • fig_tit (str) – extra title to be added to the plot

  • fig_name (str) – name of the figure to be saved

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.plot_pie_chart_freq_csv(tsv_pie_path: str, m_or_g: str, noise_or_waves: str, verbose_plots: bool = False)[source]

Plot pie chart representation of relative amplitude of each frequency band over the entire times series of mags or grads, not separated by individual channels.

Parameters:
  • tsv_pie_path (str) – Path to the tsv file with pie chart data

  • m_or_g (str) – ‘mag’ or ‘grad’

  • bands_names (list) – list of names of frequency bands

  • fig_tit (str) – extra title to be added to the plot

  • fig_name (str) – name of the figure to be saved

  • verbose_plots (bool) – True for showing plot in notebook.

Returns:

QC_derivative object with plotly figure as content

Return type:

QC_derivative

meg_qc.plotting.universal_plots.plot_sensors_3d(chs_by_lobe: dict)[source]

Plots the 3D locations of the sensors in the raw file. Plot both mags and grads (if both present) in 1 figure. Can turn mags/grads visialisation on and off. Separete channels into brain areas by color coding.

Parameters:

chs_by_lobe (dict) – A dictionary of channels by ch type and lobe.

Returns:

qc_derivative – A list of QC_derivative objects containing the plotly figures with the sensor locations.

Return type:

list

meg_qc.plotting.universal_plots.plot_sensors_3d_csv(sensors_csv_path: str)[source]

Plots the 3D locations of the sensors in the raw file. Plot both mags and grads (if both present) in 1 figure. Can turn mags/grads visialisation on and off. Separete channels into brain areas by color coding.

Plot is made on base of the tsv file with sensors locations.

Parameters:

sensors_csv_path (str) – Path to the tsv file with the sensors locations.

Returns:

qc_derivative – A list of QC_derivative objects containing the plotly figures with the sensor locations.

Return type:

list

meg_qc.plotting.universal_plots.plot_sensors_3d_separated(raw: Raw, m_or_g_chosen: str)[source]

Plots the 3D locations of the sensors in the raw file. Not used any more. As it plots mag and grad sensors separately and only if both are chosen for analysis. Also it doesnt care for the lobe areas.

Parameters:
  • raw (mne.io.Raw) – The raw file to be plotted.

  • m_or_g_chosen (str) – The type of the channels to be plotted: ‘mag’ or ‘grad’.

Returns:

qc_derivative – A list of QC_derivative objects containing the plotly figures with the sensor locations.

Return type:

list

meg_qc.plotting.universal_plots.plot_time_series(raw: Raw, m_or_g: str, chs_by_lobe: dict)[source]

Plots time series of the chosen channels.

Parameters:
  • raw (mne.io.Raw) – The raw file to be plotted.

  • m_or_g_chosen (str) – The type of the channels to be plotted: ‘mag’ or ‘grad’.

  • chs_by_lobe (dict) – A dictionary with the keys as the names of the lobes and the values as the lists of the channels in the lobe.

Returns:

qc_derivative – A list of QC_derivative objects containing the plotly figure with interactive time series of each channel.

Return type:

list

meg_qc.plotting.universal_plots.plot_time_series_avg(raw: Raw, m_or_g: str)[source]

Plots time series of the chosen channels.

Parameters:
  • raw (mne.io.Raw) – The raw file to be plotted.

  • m_or_g_chosen (str) – The type of the channels to be plotted: ‘mag’ or ‘grad’.

Returns:

qc_derivative – A list of QC_derivative objects containing the plotly figure with interactive average time series.

Return type:

list

meg_qc.plotting.universal_plots.sort_channel_by_lobe(channels_objs: dict)[source]

Sorts channels by lobes.

Parameters:

channels_objs (dict) – A dictionary of channel objects.

Returns:

chs_by_lobe – A dictionary of channels sorted by ch type and lobe.

Return type:

dict

meg_qc.plotting.universal_plots.split_correlated_artifacts_into_3_groups_csv(df: DataFrame, metric: str)[source]

Collect artif_per_ch into 3 lists - for plotting: - a third of all channels that are the most correlated with mean_rwave - a third of all channels that are the least correlated with mean_rwave - a third of all channels that are in the middle of the correlation with mean_rwave

Parameters:
  • df (pd.DataFrame) – Data frame with the data.

  • metric (str) – The metric for which the x axis is needed. Can be ‘ECG’ or ‘EOG’.

Returns:

  • artif_per_ch (list) – List of objects of class Avg_artif, ranked by correlation coefficient

  • most_correlated (list) – List of objects of class Avg_artif that are the most correlated with mean_rwave

  • least_correlated (list) – List of objects of class Avg_artif that are the least correlated with mean_rwave

  • middle_correlated (list) – List of objects of class Avg_artif that are in the middle of the correlation with mean_rwave

  • corr_val_of_last_least_correlated (float) – Correlation value of the last channel in the list of the least correlated channels

  • corr_val_of_last_middle_correlated (float) – Correlation value of the last channel in the list of the middle correlated channels

  • corr_val_of_last_most_correlated (float) – Correlation value of the last channel in the list of the most correlated channels

meg_qc.plotting.universal_plots.switch_names_on_off(fig: Figure)[source]

Switches between showing channel names when hovering and always showing channel names.

Parameters:

fig (go.Figure) – The figure to be modified.

Returns:

fig – The modified figure.

Return type:

go.Figure