medusa.plots package

Submodules

medusa.plots.brain_plots module

medusa.plots.erp_plots module

Created on Friday October 01 10:09:11 2021

In this module you will find useful functions and classes to plot event-related potentials (ERPs). This module is not finished, it has numerous improvement points but can be useful for a quick plot. Enjoy!

@author: Eduardo Santamaría-Vázquez

medusa.plots.erp_plots.compute_dev_epochs(epochs, measure='C95')[source]
medusa.plots.erp_plots.plot_erp(erp_epochs, noerp_epochs, channel, window=(0, 1000), plot=True)[source]

Function designed to quickly plot an ERP with 95% confidence interval. It does offer limited functions that will be improved in the future.

TODO: a lot of things, very basic functionality

Parameters
  • erp_epochs (numpy.ndarray) – Epochs that contain ERPs (go epochs)

  • noerp_epochs (numpy.ndarray) – Epochs that do not contain ERPs (nogo epochs)

  • channel (int) – Channel index to plot

  • window (list) – List with the lower and upper window time in milliseconds

  • plot (bool) – Set to True to plot the ERP

Returns

  • erp_mean (numpy.ndarray) – ERP activity (mean of the go epochs)

  • erp_dev (numpy.ndarray) – 95% confidence interval

  • noerp_mean (numpy.ndarray) – No ERP activity (mean of the nogo epochs)

  • noerp_dev (numpy.ndarray) – 95% confidence interval

medusa.plots.erp_plots.plot_erp_from_erp_speller_runs(erp_speller_runs, channel, window=(0, 1000), plot=True)[source]

medusa.plots.generic_plots module

Created on Tue Sep 27 10:45:15 2022

@author: Víctor Martínez-Cagigal

medusa.plots.generic_plots.shaded_plot(data, error='std', times=None, axes=None)[source]

This function plots the mean and the shaded error of a time series.

Parameters
  • data (2D numpy.ndarray) – Data being plotted, with dimensions [observations x signal]

  • error (basestring) – Type of error being plotted (mean+error, mean-error), which can be: - ‘std’: standard deviation - ‘sem’: standard error mean - ‘var’: variance - ‘c95’: 95% confidence interval (assuming normality)

  • times (numpy.ndarray) – Timestamps of the time series.

  • axes (matplotlib.pyplot.axes) – If a matplotlib axes are specified, the plot is displayed inside it. Otherwise, the plot will generate a new figure.

Returns

axes

Return type

matplotlib.pyplot.axes

medusa.plots.mi_plots module

Created on Fri Dec 20 15:34:18 2019 Edited on Mon Jun 13 10:00:00 2022

@author: VICTOR @editor: Sergio Pérez-Velasco

class medusa.plots.mi_plots.MIPlots[source]

Bases: object

__init__(fir_order=1000, fir_cutoff=(5, 35), fir_btype='bandpass', fir_method='filtfilt', w_baseline_t=(- 1000, 0), w_epoch_t=(- 1000, 6000), norm='z', baseline_mode='trial', target_fs=None)[source]
extract_features(files)[source]
plot_erd_ers_freq(ch_to_plot, axs_to_plot=None, welch_seg_len_pct=50, welch_overlap_pct=75, mov_mean_hz=0)[source]
plot_erd_ers_r2_topo(ch_to_plot, ax_to_plot=None, welch_seg_len_pct=50, welch_overlap_pct=75)[source]
plot_erd_ers_time()[source]
plot_spectrogram(ch_to_plot, axs_to_plot=None, welch_seg_len_pct=50, welch_overlap_pct=75, mov_mean_hz=0)[source]
set_sizes(label_size=6, axes_size=5, line_width=1)[source]
medusa.plots.mi_plots.plot_erd_ers_freq(files, ch_to_plot, features=None, track_info=None, fs=None, lcha=None, channel_set=None, welch_seg_len_pct=50, welch_overlap_pct=75, mov_mean_hz=0, **kwargs)[source]

This function depicts the ERD/ERS events of MI BCIs over the frequency spectrum. :param files: List of paths pointing to MI files. :type files: list :param ch_to_plot: List with the labels of the channels to plot :type ch_to_plot: list

medusa.plots.mi_plots.plot_erd_ers_time(files, ch_to_plot, features=None, track_info=None, fs=None, lcha=None, channel_set=None, mov_mean_ms=1000, **kwargs)[source]

Plotting function of ERD/ERS from motor imagery runs of MEDUSA. :param files: List of paths pointing to MI files. :type files: list :param ch_to_plot: List with the labels of the channels to plot :type ch_to_plot: list

medusa.plots.mi_plots.plot_r2_topoplot(files, ch_to_plot, features=None, track_info=None, fs=None, lcha=None, channel_set=None, welch_seg_len_pct=50, welch_overlap_pct=75, background=False, **kwargs)[source]

medusa.plots.optimal_subplots module

medusa.plots.optimal_subplots.factor(n)[source]

Computes an irreducible factorization of a number.

nint

Number to factorize

Returns

List of factors

Return type

list

medusa.plots.optimal_subplots.optimal_subplot_row_col(n_items)[source]

Computes the optimal arrangement of items in rows and columns.

n_itemsint

Number of items.

Returns

Optimal number of rows and columns, respectively

Return type

int, int

medusa.plots.timeplot module

Created on Thu Aug 25 17:09:18 2022

@author: Diego Marcos-Martínez

medusa.plots.timeplot.time_plot(epoch, fs=1.0, ch_labels=None)[source]
Parameters
  • epoch (numpy array) – Signal with shape of [n_epochs,n_samples, n_channels] or [n_samples, n_channels]

  • fs (float) – Sampling rate. Value 1 as default

  • ch_labels (list of strings or None) – List containing the channel labels

medusa.plots.topographic_plots module

In this module, you will find some functions to represent connectivity graphs and topographic plots over a 2D head model. Enjoy!

@authors: Víctor Martínez-Cagigal and Diego Marcos-Martínez

medusa.plots.topographic_plots.compute_nearest_values(coor_add, coor_neigh, val_neigh, k)[source]

This function computes the mean values of the k-nearest neighbors.

Parameters
  • coor_add (XY coordinates of the virtual electrodes.) –

  • coor_neigh (XY coordinates of the real electrodes.) –

  • val_neigh (Values of the real electrodes.) –

  • k (Number of neighbors to consider.) –

medusa.plots.topographic_plots.ear_rho(ear_theta, ellipse_a, ellipse_b)[source]

This function computes the ear coordinates according to an ellipse.

medusa.plots.topographic_plots.get_cartesian_coordinates(channel_set)[source]
medusa.plots.topographic_plots.plot_connectivity(channel_set, adj_mat, head_radius=0.7266, plot_channels=True, plot_skin_in_color=True, plot_clabels=True, plot_contour_ch=False, chcontour_radius=None, interp_points=500, cmap='seismic', show=True, clim=None)[source]

This function depicts a connectivity map over the desired channel locations.

Parameters
  • channel_set (eeg_standards.EEGChannelSet) – EEG channel set according of class eeg_standards.EEGChannelSet

  • adj_mat (numpy.ndarray) – Numpy array with the connectivity values. It must be of the must have the following dimensions [n_channels, n_channels]

  • head_radius (float) – Head radius. Default is 0.7266, coinciding with FPz. The nasion and inion are located at r=1.0

  • plot_channels (bool) – Boolean that controls if the channel points should be plotted (default: True)

  • plot_skin_in_color (bool) – Boolean that controls if the skin of the head should be coloured (default: False)

  • plot_clabels (bool (Optional)) – Boolean that controls if the channel labels should be plotted (default: False)

  • plot_contour_ch (bool (Optional)) – Boolean that controls if a contour around each channel should be plotted (default: False)

  • chcontour_radius (float or None) – Radius of the channel contour if plot_contour_ch is set True. If None value, an automatic value is computed, considering the minimum distance between channels (default: None)

  • interp_points (int (Optional)) – No. interpolation points. The lower N, the lower resolution and faster computation (default: 500)

  • cmap (str) – Matplotlib colormap

  • show (bool) – Show matplotlib figure

  • clim (list or None) – Color bar limits. Index 0 contain the lower limit, whereas index 1 must contain the upper limit. if none, min and max values are used

Returns

figure – Figure with the connectivity plot

Return type

plt.figure

medusa.plots.topographic_plots.plot_head(channel_set, head_radius=0.7266, plot_channels=True, plot_skin_in_color=False, plot_clabels=False, plot_contour_ch=False, chcontour_radius=None, interp_points=500, show=True, axes=None, fig=None, linewidth=4.0, background=False)[source]

This function depicts a two-dimensional head diagram.

Parameters
  • channel_set (eeg_standards.EEGChannelSet) – EEG channel set according of class eeg_standards.EEGChannelSet

  • head_radius (float) – Head radius. Default is 0.7266, coinciding with FPz. The nasion and inion are located at r=1.0

  • plot_channels (bool) – Boolean that controls if the channel points should be plotted (default: True)

  • plot_skin_in_color (bool (Optional)) – Boolean that controls if the skin of the head should be coloured (default: False)

  • plot_clabels (bool (Optional)) – Boolean that controls if the channel labels should be plotted (default: False)

  • plot_contour_ch (bool (Optional)) – Boolean that controls if a contour around each channel should be plotted (default: False)

  • chcontour_radius (float or None) – Radius of the channel contour if plot_contour_ch is set True. If None value, an automatic value is computed, considering the minimum distance between channels (default: None)

  • interp_points (int (Optional)) – No. interpolation points. The lower N, the lower resolution and faster computation (default: 500)

  • background (bool (Optional)) – Set background

  • show (bool) – Show matplotlib figure

  • axes (matplotlib.pyplot.axes) – If a matplotlib axes are specified, the plot is displayed inside it. Otherwise, the plot will generate a new figure.

Returns

figure – Figure with the head plot

Return type

plt.figure

medusa.plots.topographic_plots.plot_topography(channel_set, values, head_radius=0.7266, plot_extra=0.29, k=3, make_contour=True, plot_channels=True, plot_skin_in_color=False, plot_clabels=False, plot_contour_ch=False, chcontour_radius=None, interp_points=500, cmap='YlGnBu_r', show=True, clim=None, axes=None, fig=None, show_colorbar=True, linewidth=4.0, background=False)[source]

This function depicts a topographic map of the scalp over the desired channel locations.

Parameters
  • channel_set (eeg_standards.EEGChannelSet) – EEG channel set according of class eeg_standards.EEGChannelSet

  • values (list or numpy.ndarray) – Numpy array with the channel values. It must be of the same size as channels.

  • head_radius (float) – Head radius. Default is 0.7266, coinciding with FPz. The nasion and inion are located at r=1.0

  • plot_extra (float) – Extra radius of the plot surface

  • k (int) – Number of nearest neighbors for interpolation

  • make_contour (bool) – Boolean that controls if the contour lines should be plotted (default: True)

  • plot_channels (bool) – Boolean that controls if the channel points should be plotted (default: True)

  • plot_skin_in_color (bool (Optional)) – Boolean that controls if the skin of the head should be coloured (default: False)

  • plot_clabels (bool (Optional)) – Boolean that controls if the channel labels should be plotted (default: False)

  • plot_contour_ch (bool (Optional)) – Boolean that controls if a contour around each channel should be plotted (default: False)

  • chcontour_radius (float or None) – Radius of the channel contour if plot_contour_ch is set True. If None value, an automatic value is computed, considering the minimum distance between channels (default: None)

  • interp_points (int (Optional)) – No. interpolation points. The lower N, the lower resolution and faster computation (default: 500)

  • cmap (str) – Matplotlib colormap

  • background (bool (Optional)) – Set background

  • show (bool) – Show matplotlib figure

  • axes (matplotlib.pyplot.axes) – If a matplotlib axes are specified, the plot is displayed inside it. Otherwise, the plot will generate a new axes.

  • clim (list or None) – Color bar limits. Index 0 contain the lower limit, whereas index 1 must contain the upper limit. if none, min and max values are used

Returns

figure – Figure with the topography plot

Return type

plt.figure

medusa.plots.topographic_plots.pol2cart(rho, phi)[source]

This function converts polar coordinates to cartesian coordinates.

Parameters
  • rho (Array of radii) –

  • phi (Array of angles) –