Numerical Utilities#

EEGPrep includes the small numerical building blocks used by its signal and component workflows. They are standalone NumPy/SciPy functions and do not need MATLAB or an EEGLAB checkout.

Indexing and compatibility#

Array indices are zero-based. This applies to peak frames returned by abspeak, assignments returned by hungarian and matcorr, permutation vectors, matsel selections, and shuffle axes. Kernel peak coordinates remain one-based because they describe the sampled coordinate system in the EEGLAB formulas rather than Python array indices.

covary deliberately retains EEGLAB’s grand-mean centering before computing column second moments; use NumPy’s variance functions when ordinary per-column centering is intended. means uses the number of finite observations when computing standard errors and leaves single-observation sample variances undefined. This fixes the historical EEGLAB helper’s underestimated standard errors when a group contains missing values. nan_std uses a centered calculation so large constant offsets do not erase small physiological variation through catastrophic cancellation.

quantile retains the midpoint empirical-probability rule used by the current EEGLAB tests. Integer counts, axes, permutations, and selections must be exact integers; fractional values are rejected instead of silently selecting the wrong samples. Functions that have a meaningful complex-valued contract, including PCA, interpolation, peak phase, and NaN-aware means, preserve complex data. Real-only functions reject complex input instead of discarding its imaginary component.

vectdata supports linear, cubic, and nearest-neighbor interpolation. MATLAB’s legacy biharmonic griddata v4 mode has no well-defined one-dimensional SciPy equivalent and raises NotImplementedError rather than substituting a different interpolator.

Peaks, summaries, and transforms#

eegprep.abspeak(data[, frames_per_epoch])

Return absolute peaks, zero-based frames, and signs for each epoch.

eegprep.averef(data[, weights, sphere, ...])

Average-reference channel-major data and optionally transform ICA weights.

eegprep.covary(data)

Return EEGLAB's globally centered, unbiased column second moment.

eegprep.datlim(data)

Return the minimum and maximum of a nonempty numeric array.

eegprep.eucl(coordinates[, other])

Compute pairwise Euclidean distances between rows of point arrays.

eegprep.means(data[, groups])

Return per-group means, standard errors, variances, and group IDs.

eegprep.nan_mean(data[, axis])

Return means while ignoring NaNs along the selected dimension.

eegprep.nan_std(data[, axis])

Return sample standard deviations while ignoring NaNs.

eegprep.quantile(data, probabilities[, axis])

Return quantiles using MATLAB's midpoint empirical-probability rule.

eegprep.vectdata(data, times, *, timesout[, ...])

Interpolate along the final data axis and optionally smooth first.

Kernels#

eegprep.gauss(frames, standard_deviations)

Return an EEGLAB-compatible Gaussian window with a unit peak.

eegprep.gauss2d(rows, columns[, sigma_rows, ...])

Return an EEGLAB-compatible two-dimensional Gaussian kernel.

eegprep.gauss3d(rows, columns, depth[, ...])

Return an EEGLAB-compatible three-dimensional Gaussian kernel.

eegprep.gabor2d(rows, columns[, frequency, ...])

Return a sinusoidal carrier under an anisotropic Gaussian envelope.

eegprep.laplac2d(rows, columns[, sigma, ...])

Return EEGLAB's sampled two-dimensional Laplacian kernel.

Matching and component projections#

eegprep.hungarian(cost_matrix)

Return a zero-based column-to-row assignment and its total cost.

eegprep.mapcorr(first, second, ...[, ...])

Match rows after aligning map columns by common channel labels.

eegprep.matcorr(first, second[, ...])

Match rows of two matrices by absolute cosine correlation.

eegprep.matperm(first, second, ...)

Reorder and sign-correct rows of first into second row order.

eegprep.pcsquash(data[, components])

Compress channel-major data into its leading principal components.

eegprep.pcexpand(projections, eigenvectors, ...)

Expand component projections back into channel space.

eegprep.perminv(permutation)

Return the inverse of a zero-based permutation vector.

eegprep.uniquef(groups[, sort])

Return finite unique values, counts, and zero-based first indices.

Low-level compatibility helpers#

eegprep.celltomat(cells)

Convert a rectangular nested sequence of numeric scalars to an array.

eegprep.eyelike(matrix)

Permute and scale rows so the output diagonal is one.

eegprep.fastif(condition, if_true, if_false)

Return if_true when condition is truthy, otherwise if_false.

eegprep.matsel(data, frames_per_epoch, frames)

Select zero-based channels, within-epoch frames, and epochs.

eegprep.mattocell(matrix)

Convert a NumPy-compatible matrix to nested Python scalar lists.

eegprep.scanfold(folder[, ignore, max_depth])

Return MATLAB filenames below folder and EEGLAB's -a text.

eegprep.shuffle(data[, axis, rng])

Shuffle one zero-based axis and return permutation and inverse indices.