macro_eeg_model#

Subpackages#

Classes#

GlobalSimulation

A class responsible for orchestrating the entire simulation process.

Evaluator

A class responsible for evaluating simulated EEG data .

Functions#

get_simulate_config()

First parses command line arguments using get_parsed_args(), then

Package Contents#

macro_eeg_model.get_simulate_config()[source]#

First parses command line arguments using get_parsed_args(), then creates an instance of the src.config.model_config.ModelConfig class based on the parsed arguments.

Returns:

A tuple containing:

  • config (ModelConfig): The configuration object for the simulation.

  • model_name (str): The name of the model as specified in the command line arguments.

  • n (int): The number of simulations to run, as specified in the command line arguments.

Return type:

tuple

class macro_eeg_model.GlobalSimulation(config)[source]#

A class responsible for orchestrating the entire simulation process. It integrates the development of a stationary model, the simulation of EEG data, data processing, and data analysis.

The class uses: - src.simulation.stationary_model_developer.StationaryModelDeveloper to create a stationary model from the provided configuration. - src.simulation.simulator.Simulator to generate synthetic EEG data based on the model. - src.simulation.data_processor.DataProcessor to filter and segment the simulated data. - src.simulation.eeg_analyzer.EEGAnalyzer to calculate and plot the power spectrum of the EEG data. - src.simulation.simulation_info.SimulationInfo to save the simulation results.

__init__(config)[source]#

Initializes the GlobalSimulation class with the provided configuration.

Parameters:

config (ModelConfig) – The configuration object containing parameters for the simulation (instance of the src.config.model_config.ModelConfig class).

run(save_data=False, make_plots=False, verbose=False, simulation_name=None)[source]#

Runs the global simulation process, including model development, data simulation, processing, analysis, and optional saving/plotting.

Parameters:
  • save_data (bool, optional) – If True, saves the simulation results (default is False).

  • make_plots (bool, optional) – If True, generates and saves plots of the connectivity and power spectrum (default is False).

  • verbose (bool, optional) – If True, displays progress bars and detailed information during the simulation (default is False).

  • simulation_name (str, optional) – The name of the simulation, used for saving the results (default is None).

Returns:

A tuple containing:

  • simulation_data (numpy.ndarray): The simulated EEG data.

  • frequencies (numpy.ndarray): The array of frequencies corresponding to the power spectrum.

  • power (numpy.ndarray): The power spectrum of the simulated EEG data.

Return type:

tuple

class macro_eeg_model.Evaluator[source]#

A class responsible for evaluating simulated EEG data . It computes metrics such as coherence and power spectra across different brain regions (nodes).

frequencies#

The frequency range for evaluating the data ([0, 30] Hz).

Type:

list

simulation_data_extractor#

An instance of the src.evaluation.simulation_data_extractor.SimulationDataExtractor class used to extract and process simulated EEG data.

Type:

SimulationDataExtractor

__init__()[source]#

Initializes the Evaluator class, setting up the frequency range and loading real and simulated data.

evaluate(plot_overview=True)[source]#

Evaluates and compares the coherence and power metrics using _evaluate_metric().

Parameters:

plot_overview (bool, optional) – If True, generates overview plots for the evaluated metrics; if False, generates individual plots for (pairs of) brain regions. (default is True).

_evaluate_metric(evaluation_func, desc, plot_overview, rows, cols, save_file_name)[source]#

A helper function to evaluate a specific metric (e.g., coherence or power) across nodes or node pairs.

Parameters:
  • evaluation_func (function) – The function to evaluate the metric (_evaluate_coherence_node_pair() or _evaluate_power_node()).

  • desc (str) – The description for the tqdm progress bar.

  • plot_overview (bool) – If True, generates overview plots for the evaluated metrics; if False, generates individual plots for (pairs of) brain regions.

  • rows (int) – The number of rows in the overview plot.

  • cols (int) – The number of columns in the overview plot.

  • save_file_name (str) – The file name for saving the overview plot.

_get_nodes(pairwise=False)[source]#

Generates nodes or node pairs for evaluation.

Parameters:

pairwise (bool, optional) – If True, generates pairs of nodes (for coherence evaluation), otherwise generates individual nodes (for power evaluation) (default is False).

Returns:

A tuple containing one or two nodes, depending on the value of pairwise.

Return type:

tuple

_evaluate_peaks(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates the presence of alpha peaks (using _get_peaks()) and plots (using _plot_metric()) detrended power spectrum for a given node.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_fooof(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates the presence of peaks (using _get_fooof_peaks()) and plots (using _plot_metric()) the peaks.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_power_node(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates (using _get_simulated_power()) and plots (using _plot_metric()) the power spectrum for a given node.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_coherence_node_pair(node1, node2, fig=None, ax=None, show_legend=True)[source]#

Evaluates (using _get_simulated_coherences()) and plots (using _plot_metric()) the coherence between a pair of nodes.

Parameters:
  • node1 (str) – The name of the first brain region (node).

  • node2 (str) – The name of the second brain region (node).

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_get_fooof_peaks(node)[source]#

Computes the peaks in the power spectrum for a given node using FooofTester.

Parameters:

node (str) – The name of the brain region for which to compute the peaks.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • all_binary_peaks (dict): A dictionary of binary peaks for each simulation, keyed by simulation name.

Return type:

tuple

_get_peaks(node)[source]#

Computes the peaks in the power spectrum for a given node using PeakTester.

Parameters:

node (str) – The name of the brain region for which to compute the peaks.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • powers (dict): A dictionary of simulated power spectra, keyed by simulation name.

  • p_values (dict): A dictionary of p-values for the peak test, keyed by simulation name.

  • test_names (dict): A dictionary of test names for the peak test, keyed by simulation name.

Return type:

tuple

_get_simulated_power(node)[source]#

Retrieves the simulated power spectrum for a given node.

Parameters:

node (str) – The name of the brain region for which to retrieve the simulated power spectrum.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • powers (dict): A dictionary of simulated power spectra, keyed by simulation name.

Return type:

tuple

_get_simulated_coherences(node1, node2)[source]#

Computes the simulated coherence between a pair of nodes for each simulation using src.simulation.coherence_computer.CoherenceComputer.compute_coherence_matched() .

Parameters:
  • node1 (str) – The name of the first brain region.

  • node2 (str) – The name of the second brain region.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies for coherence.

  • coherences (dict): A dictionary of simulated coherence values, keyed by simulation name.

Return type:

tuple

_plot_metric(title, sim_frequencies, sim_data, plot_type='line', fig=None, ax=None, show_legend=True, y_label=None, xlim=None, ylim=None, file_label=None, label_addons=None)[source]#

Plots a metric (e.g., coherence or power) of data using _plot_simulated_data().

Parameters:
  • title (str) – The title of the plot.

  • sim_frequencies (numpy.ndarray) – The array of frequencies for the simulated data.

  • sim_data (dict) – The simulated data (e.g., power or coherence) to plot, keyed by simulation name.

  • plot_type (str, optional) – The type of plot to create (default is “line”). Currently, “line”, “scatter”, “mean_std” are supported.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

  • y_label (str, optional) – The label for the y-axis (default is None).

  • xlim (list, optional) – The x-axis limits for the plot (default is None).

  • ylim (list, optional) – The y-axis limits for the plot (default is None).

  • file_label (str, optional) – The file name label for saving the plot (default is None).

  • label_addons (dict, optional) – The dictionary of label addons to append to the name of the data (default is None).

static _plot_simulated_data(ax, frequencies, data, label_addons, plot_type='line')[source]#

Plots the simulated EEG data on a given axis.

Parameters:
  • ax (matplotlib.axes.Axes) – The axis object for plotting.

  • frequencies (numpy.ndarray) – The array of frequencies for the simulated data.

  • data (dict) – The simulated data (e.g., power or coherence) to plot, keyed by simulation name.

  • label_addons (dict) – The dictionary of label addons to append to the name of the data.

  • plot_type (str, optional) – The type of plot to create (default is “line”). Currently, “line”, “scatter”, “mean_std” are supported.

static _get_ax(ax, rows, cols, i)[source]#

Helper function to get the appropriate subplot axis.

Parameters:
  • ax (numpy.ndarray) – The array of axis objects for subplots.

  • rows (int) – The number of rows in the subplot grid.

  • cols (int) – The number of columns in the subplot grid.

  • i (int) – The index of the current plot.

Returns:

The appropriate axis object for the current subplot.

Return type:

matplotlib.axes.Axes