Analysis

The Analysis class is designed to facilitate statistical analysis and data visualization.

Parameters

Name Type Description
data list, np.ndarray, pd.DataFrame Data to be analyzed

Methods

lmer

Perform linear mixed-effects model (lmer) or linear model (lm) comparisons using R's `lme4`, `emmeans` and `nlme` packages.

Parameters

Name Type Default Description
control_group str 'HC' The control group to be used for comparisons
data_col str 'Y' The name of the data column to be analyzed
other_col list ['ID', 'Group', 'Epoch', 'Sensor'] The names of other columns to include in the analysis
data_index int -1 The index of the data column to be analyzed (-1 for entire column)
models dict None Dictionary of model formulas (keys are model names)
bic_models list None List of models to evaluate using BIC
anova_tests dict None Dictionary specifying models for ANOVA tests
specs string None Specifications for emmeans function in R

Returns

dict: A dictionary containing analysis results (keys are group comparison names, values are DataFrames)

cohend

Compute Cohen's d for all pairwise group comparisons across sensors.

Parameters

Name Type Default Description
control_group str 'HC' The control group to be used for comparisons
data_col str 'Y' The name of the data column to be analyzed
data_index int -1 The index of the data column to be analyzed (-1 for entire column)

Returns

dict: A dictionary containing Cohen's d values (keys are group comparison names, values are DataFrames)

EEG_topographic_plot

Generate a topographical plot of EEG data using the 10-20 electrode placement system.

Parameters

Name Type Default Description
radius float 0.6 Radius of the head circumference
pos float 0.0 Position of the head on the x-axis
electrode_size float 0.9 Size of the electrodes
label bool True Show the colorbar label
ax matplotlib Axes None Axes object to plot the data
fig matplotlib Figure None Figure object to plot the data
vmin float None Min value used for plotting
vmax float None Max value used for plotting

Features

Class for computing features from electrophysiological data recordings.

Constructor

__init__

Initialize the Features class with specified computation method.

Parameters
Name Type Default Description
method str 'catch22' Feature computation method ('catch22', 'power_spectrum_parameterization', 'fEI', 'DFA', or 'hctsa')
params dict None Parameters for feature computation

Methods

catch22

Compute the catch22 features from a time-series sample.

Parameters

Name Type Description
sample np.array Sample data

Returns

np.array: Array with the catch22 feature values

power_spectrum_parameterization

Power spectrum parameterization of a time-series sample using the FOOOF algorithm.

Parameters

Name Type Default Description
sample np.array Time-series sample
fs float Sampling frequency
fmin float Minimum frequency for power spectrum fit
fmax float Maximum frequency for power spectrum fit
fooof_setup dict Parameters for FOOOF algorithm
r_squared_th float 0.9 Threshold for r_squared value
freq_range list [30., 200.] Frequency range for peak search
nperseg int -1 Length of each segment for power spectrum
compute_knee bool False Whether to compute knee parameter

Returns

np.array: Array with aperiodic components, peak parameters, and mean power

fEI

Calculates fEI (on a set window size) for a signal.

Parameters

Name Type Description
signal array Amplitude envelope for all channels
sampling_frequency int Sampling frequency
window_size_sec float Window size in seconds
window_overlap float Fraction of overlap between windows (0-1)
DFA_array array Array of DFA values for thresholding
bad_idxes array Channels to ignore from computation

Returns

tuple: (fEI_outliers_removed, fEI_val, num_outliers, wAmp, wDNF)

DFA

Calculates DFA (Detrended Fluctuation Analysis) of a signal.

Parameters

Name Type Description
signal array Amplitude envelope for all channels
sampling_frequency int Sampling frequency
fit_interval list Interval (seconds) for DFA exponent fit
compute_interval list Interval (seconds) for DFA computation
overlap bool Whether to use 50% window overlap
bad_idxes array Channels to ignore from computation

Returns

tuple: (dfa_array, window_sizes, fluctuations, dfa_intercept)

hctsa

Compute hctsa (Highly Comparative Time-Series Analysis) features.

Parameters

Name Type Description
samples ndarray/list Time-series samples
hctsa_folder str Folder where hctsa is installed
workers int Number of MATLAB workers

Returns

list: hctsa features (n_samples × n_features)

compute_features

Compute features from the data using the specified method.

Parameters

Name Type Description
data pd.DataFrame Data containing time-series samples in 'Data' column
hctsa_folder str Folder where hctsa is installed (if method is 'hctsa')

Returns

pd.DataFrame: Original data with features appended

FieldPotential

Class for simulating and analyzing field potentials (e.g., LFP, EEG).

Constructor

__init__

Initialize the FieldPotential object.

Parameters
Name Type Default Description
kernel bool True Choose to compute kernels.
nyhead bool False Use the NYHeadModel for computing EEG.
MEEG str None Prepare data structures for computing EEG or MEG signals. Options are 'EEG' or 'MEG'.
CDM_shape int 15500 Number of time points in the CDM.

Methods

create_kernel

Create kernels from multicompartment neuron network descriptions.

Parameters

Name Type Description
MC_folder str Path to the folder containing the multicompartment neuron network descriptions.
output_path str Path to the output folder.
params module Network parameters module.
biophys list List of biophysical membrane properties.
dt float Time step.
tstop float Simulation time.
electrodeParameters dict Electrode parameters. If None, no LFP is computed.
CDM bool Compute the current dipole moment.

Returns

dict: Dictionary containing the kernels.

compute_MEEG

Compute EEG/MEG from a current dipole moment using the NYHeadModel or a homogeneous volume conductor model.

Parameters

Name Type Description
CDM np.array Current dipole moment.
location np.array Location of the dipole moment.
cMEG bool Compute MEG instead of EEG.

Returns

list: MEEG at the electrode/sensor locations.

compute_proxy

Compute a proxy for the extracellular signal by combining variables directly measured from network simulations.

Parameters

Name Type Description
method str Method to compute the proxy (e.g., 'FR', 'AMPA', 'GABA').
sim_data dict Dictionary containing the simulation data.
sim_step float Simulation time step in ms.

Returns

np.array: Proxy for the extracellular signal.

Inference

General-purpose class for inferring parameters from simulated or observed features using either Bayesian inference (with SBI) or regression (with sklearn).

Constructor

__init__

Initialize the Inference class with the specified model and hyperparameters.

Parameters
Name Type Default Description
model str Name of the machine-learning model to use (e.g., regression models from sklearn or NPE, NLE, NRE from SBI).
hyperparams dict None Dictionary of hyperparameters for the model.

Methods

add_simulation_data

Add features and parameters to the training data.

Parameters

Name Type Description
features np.ndarray Features.
parameters np.ndarray Parameters to infer.

initialize_sbi

Initialize the SBI inference method (NPE, NLE, or NRE) using the appropriate neural estimator.

Parameters

Name Type Description
hyperparams dict Dictionary of hyperparameters required to set up the inference method.

Returns

object: Configured SBI inference object ready for appending simulations and training.

train

Train the model using either SBI or sklearn depending on configuration.

Parameters

Name Type Default Description
param_grid list None List of dictionaries of hyperparameters to search over.
n_splits int 10 Number of splits for RepeatedKFold cross-validation.
n_repeats int 10 Number of repeats for RepeatedKFold cross-validation.
train_params dict {'learning_rate': 0.0005, 'training_batch_size': 256} Dictionary of training parameters for SBI.

predict

Predict parameters for new input features.

Parameters

Name Type Description
features np.ndarray Features to predict parameters for.

Returns

list: List of predictions.

sample_posterior

Sample from the posterior distribution for a given observation.

Parameters

Name Type Default Description
x np.ndarray Observed feature vector (1D array).
num_samples int 10000 Number of posterior samples to draw.

Returns

np.ndarray: Array of posterior samples.

Simulation

Class for managing and running simulation scripts with specified parameters and output folders.

Constructor

__init__

Initialize the Simulation class with folder paths for parameters, Python scripts, and output.

Parameters
Name Type Description
param_folder str Path to the folder containing parameter files.
python_folder str Path to the folder containing Python scripts.
output_folder str Path to the folder where the output files will be saved.

Methods

network

Run a network simulation script with the specified parameters.

Parameters

Name Type Description
script_path str Name of the Python script to run (relative to python_folder).
param_path str Name of the parameter file to use (relative to param_folder).

simulate

Run a simulation script with the specified parameters.

Parameters

Name Type Description
script_path str Name of the Python script to run (relative to python_folder).
param_path str Name of the parameter file to use (relative to param_folder).

analysis

Run an analysis script with the specified parameters.

Parameters

Name Type Description
script_path str Name of the Python script to run (relative to python_folder).
param_path str Name of the parameter file to use (relative to param_folder).