Input/Output Functions#
This section documents the input/output functions for loading and saving EEG data in various formats.
BIDS Loading#
- eegprep.pop_load_frombids(filename, *, bidsmetadata=True, bidschanloc=True, bidsevent='replace', eventtype=None, infer_locations=None, dtype=<class 'numpy.float32'>, numeric_null=array([], dtype=float64), return_report=False, verbose=True)
Load an EEG data file of a supported format from a BIDS dataset.
Supported formats are EDF, BrainVision, EEGLAB SET, BDF.
Parameters#
- filenamestr
Path to the EEG data file in a BIDS dataset.
- bidsmetadatabool
Whether to override any metadata in the EEG file with metadata from BIDS.
- bidschanlocbool
Whether to override any channel information (incl. locations) in the EEG file with channel information from BIDS.
- bidseventbool or str
Whether to load in and override any event data in the EEG file with event data from BIDS. Can be one of the following:
"replace"/True: replace events from EEG file with those from the BIDS event file."merge": selectively override events from EEG file with those from the BIDS event file."append": append events from the BIDS event file to those from the EEG file. This mode can result in duplicate events; use with caution.False/None: do not load events from BIDS; keep those from the EEG file.
- eventtypestr or None
Optionally the column name in the BIDS events file to use for event types; if not set, will be inferred heuristically.
- infer_locationsbool or str or None
Whether to infer channel locations if necessary from the channel labels (if 10-20 labeling system).
True: infer locations from channel labels and override existing locations if any.False: leave locations as-is, even if missing.None: infer only if no channels have locations.str: filename of a locations file to infer locations from. See files inresources/montages; this can disambiguate alternative montages that use the same naming system.
- dtypenp.dtype
The data type to use for the EEG data.
- numeric_nullAny
The value to use for empty numeric fields in the EEG data.
The default is
np.array([])for MATLAB/pop_loadset compatibility.- return_reportbool
whether to return an import report dictionary as a second output
- verbosebool
whether to log verbose output
Returns#
- EEGdict
A dictionary containing the EEG data and metadata.
- Reportdict, optional
optionally the import report to return, if desired.
- eegprep.pop_importbids(path, *, return_com=False, **kwargs)
Load one or more EEG files from a BIDS dataset.
- eegprep.pop_exportbids(EEG, output_dir, *, subject='01', task='eeg', return_com=False)
Export EEG dataset(s) as BIDS-like EEGLAB files and sidecars.
Generic Import#
- eegprep.pop_importdata(*args, return_com=False, **kwargs)
Import data from an array or supported file into an EEG dataset.
- eegprep.pop_fileio(filename, *, return_com=False, **kwargs)
Import a supported EEG data file with MNE/File-IO-style readers.
- eegprep.pop_biosig(filename, *, return_com=False, **kwargs)
Import BIOSIG-style EDF/BDF/GDF files.
- eegprep.pop_importevent(EEG, *args, return_com=False, **kwargs)
Import events from a text table or record array.
- eegprep.pop_importepoch(EEG, filename=None, fieldlist=None, *args, return_com=False, **kwargs)
Import per-epoch metadata from a text table.
- eegprep.pop_chanevent(EEG, chan, *args, return_com=False, **kwargs)
Import events from rising, falling, or both edges of data channels.
- eegprep.pop_importpres(EEG, filename=None, *, return_com=False, **kwargs)
Import a Presentation LOG file using EEGPrep’s generic event importer.
Channel Locations#
- eegprep.pop_readlocs(filename=None, *args, return_com=False, **kwargs)
Read channel locations and return an EEGPrep
chanlocslist.
- eegprep.pop_writelocs(chans, filename=None, *args, return_com=False, **kwargs)
Write channel locations and return a replayable history command.
- eegprep.readlocs(filename, *args, return_outputs=False, **kwargs)
Read a channel-location file or structure into EEGPrep dictionaries.
- eegprep.writelocs(chans, filename, *args, **kwargs)
Write channel locations to an EEGLAB-compatible text file.
- eegprep.convertlocs(chans, command='auto', *args, verbose='off', **kwargs)
Return channel locations with requested coordinate fields filled in.
- Parameters:
chans (Any) – EEG dictionary, channel-location dictionary, or channel-location sequence.
command (str) – EEGLAB conversion command such as
"cart2all","sph2topo","topo2cart", or"auto".*args (Any) – Optional EEGLAB-style key/value arguments. Only
verboseis accepted for parity with EEGLAB.verbose (str) –
"on"or"off". Present for API parity.**kwargs (Any) – Optional keyword arguments. Only
verboseis accepted.
- Returns:
A deep-copied object in the same broad shape as
chans.- Return type:
- eegprep.chancenter(x, y, z, center=(0.0, 0.0, 0.0))
Return XYZ coordinates centered around a known or fitted sphere center.
- eegprep.pop_chancenter(chans, center=None, omitchans=None, *, gui=False, renderer=None, return_com=False)
Recenter channel locations using a known or optimized sphere center.
- eegprep.pop_chancoresp(chans1, chans2, *args, return_com=False, **kwargs)
Return 1-based channel correspondences by label.
- eegprep.readegilocs(EEG, fileloc=None)
Return
EEGwith EGI channel locations from packaged montages.
- eegprep.readelp(filename)
Read a Polhemus
.elpelectrode-position file.
Long-Tail Import Helpers#
- eegprep.pop_loadbci(filename, srate=256.0, *, return_com=False)
Import a BCI2000-style file into an EEG dictionary.
- eegprep.pop_snapread(filename, gain=1.0, *, return_com=False)
Import a SnapMaster
.SMAfile.
- eegprep.snapread(filename, seekframes=0, *, event_channel=1, event_thresh=2.3)
Read a SnapMaster
.SMAfile into data, params, events, and header.
- eegprep.floatread(filename, size, format=None, offset=0)
Read a binary float32 matrix using MATLAB/EEGLAB column ordering.
EEGLAB Format#
- eegprep.pop_loadset(file_path=None, *args, loadmode='all', memmap=None, **kwargs)
Load EEGLAB dataset from .set or .mat file.
Parameters#
- file_pathstr
Path to the EEGLAB .set file.
Returns#
- dict
EEGLAB dataset dictionary.
- eegprep.pop_loadset_h5(file_name)
Load EEG data from HDF5 file.
Parameters#
- file_namestr
Path to the HDF5 file
Returns#
- EEGdict
EEG data structure
- eegprep.pop_saveset(EEG, file_name=None, *args, **kwargs)
Save EEG data to file.
Parameters#
- EEGdict
EEG data.
- file_namestr, optional
File name. EEGLAB-style
filename/filepath/savemodekeyword arguments are also accepted.
pop_saveset(..., savemode="twofiles") writes a .set header plus
.fdt float32 sidecar. EEG_OPTIONS["option_savetwofiles"]
uses that layout by default, and EEG_OPTIONS["option_memmapdata"] makes
pop_loadset expose sidecar data through a NumPy-compatible memory map. See
Large-Dataset Storage for storedisk session behavior and limitations.
Text And External Export#
- eegprep.pop_export(EEG, filename, *args, **kwargs)
Export EEG data or ICA activity to a delimited text file.
pop_export supports text export options including ICA export,
time/electrode rows, transpose, ERP averaging, precision, separator, and a
standalone numeric expr transform applied to the exported array x.
Most expression function calls are positional; clip and nan_to_num also
accept documented safe numeric keywords. Power operators require small constant
exponents.
- eegprep.pop_expica(EEG, filename, matrix='weights')
Export the ICA weight matrix or inverse weight matrix.
- eegprep.pop_expevents(EEG, filename)
Export
EEG.eventas a tab-delimited text file.
History And STUDY Files#
- eegprep.pop_saveh(allcoms, filename='eegprephist.m', filepath='.')
Save dataset or session command history to a script file.
- eegprep.pop_runscript(filename, namespace=None)
Run a Python history script selected by the user.
The selected Python file is executed in-process; MATLAB
.mscripts are not run by EEGPrep.
- eegprep.pop_study(STUDY=None, ALLEEG=None, *args, name=None, task=None, notes=None, design=None, commands=None, rmclust=None, gui=None, renderer=None, return_com=False, **kwargs)
Create or edit a STUDY structure from loaded EEG datasets.
- eegprep.pop_studywizard(filenames, *, name='EEGPrep study', return_com=False)
Load selected datasets and create a STUDY.
- eegprep.pop_studyerp(ALLEEG=None, *, return_com=False)
Create a STUDY marked as a simple ERP design.
- eegprep.pop_studydesign(STUDY, ALLEEG, designind=None, *args, gui=None, renderer=None, return_com=False, **kwargs)
Edit STUDY designs and select the current design.
- eegprep.pop_loadstudy(filename=None, *args, filepath=None, load_datasets=True, return_com=False, **kwargs)
Load a STUDY JSON file saved by
pop_savestudy.
- eegprep.pop_savestudy(STUDY, EEG=None, *args, filename=None, filepath=None, savemode=None, resavedatasets='off', return_com=False, **kwargs)
Save a STUDY structure as an EEGPrep JSON
.studyfile.
- eegprep.pop_precomp(STUDY, ALLEEG, chanorcomp='channels', *args, gui=None, renderer=None, return_com=False, **kwargs)
Precompute STUDY channel or component measures.
- eegprep.pop_chanplot(STUDY=None, ALLEEG=None, *, channels=None, components=None, measure='erp', mode='channels', gui=False, renderer=None, return_com=False)
Plot precomputed STUDY channel or component measures.
- eegprep.std_editset(STUDY, ALLEEG, *args, name=None, task=None, notes=None, filename=None, filepath=None, commands=None, updatedat='on', return_com=False, **kwargs)
Modify STUDY metadata and datasetinfo entries.
- eegprep.std_checkset(STUDY, ALLEEG, *, return_com=False)
Normalize a STUDY dict and refresh dataset/design consistency metadata.
- eegprep.std_checkdatasetinfo(STUDY, ALLEEG)
Return STUDY.datasetinfo consistency checks for loaded datasets.
- eegprep.std_checkconsist(STUDY, *args, uniform=None, return_counts=False, **kwargs)
Check whether each value of a STUDY factor has the same subject count.
- eegprep.std_checkdesign(STUDY, designind=None)
Return 1 when a design has no continuous variables or multi-valued extras.
- eegprep.std_makedesign(STUDY, ALLEEG, designind=1, *args, name=None, variable1=None, values1=None, vartype1='categorical', variable2=None, values2=None, vartype2='categorical', variable3=None, values3=None, vartype3='categorical', variable4=None, values4=None, vartype4='categorical', subjselect=None, filepath='', datselect=None, delfiles='off', defaultdesign='on', return_com=False, **kwargs)
Create or replace a 1-based STUDY design.
Design metadata and factor selections are stored.
delfilescontrols cached measure arrays:'on'or'limited'clear them on the design change, while'off'preserves any precomputedchangrp/clustermeasures attached to the redefined design.- Parameters:
designind (int)
args (Any)
name (str | None)
variable1 (str | None)
values1 (Any)
vartype1 (str)
variable2 (str | None)
values2 (Any)
vartype2 (str)
variable3 (str | None)
values3 (Any)
vartype3 (str)
variable4 (str | None)
values4 (Any)
vartype4 (str)
subjselect (Any)
filepath (str)
datselect (Any)
delfiles (str)
defaultdesign (str)
return_com (bool)
kwargs (Any)
- Return type:
- eegprep.std_addvarlevel(STUDY, designind=None)
Return
STUDYwithone/twodesign-variable levels.EEGLAB marks variables from per-trial metadata as first-level (
"one") and stable dataset/subject metadata as second-level ("two"). Dataset metadata that changes within one subject is first-level because it cannot be modeled as an inter-subject factor.
- eegprep.std_builddesignmat(design, trialinfo, expanding=False)
Build a design matrix from a STUDY design and trial metadata.
The output mirrors EEGLAB’s helper: categorical factors are encoded as 1-based level numbers, continuous factors keep their numeric values, and a constant column is appended at the end.
- eegprep.std_limodesign(factors, trialinfo, *args, splitreg='off', interaction='off', desconly='off', filepath='', return_com=False, **kwargs)
Create LIMO-compatible categorical and continuous design matrices.
- eegprep.std_getindvar(STUDY, mode='both', scandesign=False)
Return STUDY factor names, values, subject groupings, and pairing flags.
- eegprep.std_indvarmatch(value, valuelist)
Return 1-based indices where an independent-variable value matches.
This mirrors the useful EEGLAB behavior for strings, scalar numeric values, numeric vectors, and cell/list-valued variables while returning Python lists of EEGLAB-facing 1-based indices.
- eegprep.std_selectdataset(STUDY, ALLEEG, indvar='', indvarvals=None, verboseFlag='verbose')
Return selected 1-based dataset indices and trial indices.
Dataset-level variables are matched against
STUDY.datasetinfo. If the variable is not a dataset field, trial-level values are matched againstSTUDY.datasetinfo[*].trialinfoand dataset indices with at least one matching trial are returned.
- eegprep.std_gettrialsind(trialinfo, *args, return_values=False, **kwargs)
Return 1-based trial indices matching all requested trialinfo values.
trialinfomay be a list of trial dictionaries or a dictionary with atrialinfofield. MATLAB.matfilename loading is intentionally not part of the standalone runtime; pass loaded trialinfo rows instead.
- eegprep.std_maketrialinfo(STUDY, ALLEEG)
Populate
STUDY.datasetinfo[*].trialinfofrom loaded EEG metadata.
- eegprep.std_combtrialinfo(datasetinfo, inds, trials=None)
Return trial rows enriched with selected
datasetinfofields.
- eegprep.std_rebuilddesign(STUDY, ALLEEG=None, designind=None, *, return_com=False)
Refresh STUDY design variables after dataset metadata changes.
- eegprep.std_saveindvar(STUDY, *, return_com=False)
Save factor descriptors under
STUDY.etc.eegprep.independent_variables.
- eegprep.pop_addindepvar(varlist, fig=None, var=None, values=None, *, vartype=None, return_com=False)
Return
(variable, values, categorical_flag)for STUDY designs.EEGPrep implements the workflow-supporting non-GUI behavior of EEGLAB’s helper. Callback strings and MATLAB figure mutation are intentionally not emulated.
- eegprep.pop_importgroupvar(STUDY, designind=1, *, variable, values=None, filepath=None, vartype='categorical', return_com=False)
Attach one imported variable value per STUDY subject.
Values may be a
{subject: value}mapping, a sequence in design subject order, or a text file containing one value per subject.
- eegprep.pop_listfactors(des, *args, return_com=False, **kwargs)
Return factor descriptors for one STUDY or design structure.
- eegprep.std_precomp(STUDY, ALLEEG, chanorcomp='channels', *args, erp='off', spec='off', ersp='off', itc='off', scalp='off', allcomps='off', recompute='off', design=None, erpparams=None, specparams=None, erspparams=None, return_com=False, **kwargs)
Precompute ERP, spectrum, ERSP, and ITC measures for a STUDY.
Measures are stored directly in
STUDY.changrpfor channels and in the parentSTUDY.clusterentry for components. Field names follow EEGLAB’s cached-measure names while avoiding EEGLAB sidecar files at runtime.
- eegprep.std_readdata(STUDY, ALLEEG=None, *, datatype='erp', channels=None, clusters=None, components=None, design=None, timerange=None, freqrange=None, subject=None, infotype=None, **kwargs)
Read precomputed STUDY measures from EEGPrep’s in-memory cache.
- Parameters:
- Return type:
- eegprep.std_readerp(STUDY, ALLEEG=None, **kwargs)
Read cached STUDY ERP measures.
- eegprep.std_readspec(STUDY, ALLEEG=None, **kwargs)
Read cached STUDY spectrum measures.
- eegprep.std_readersp(STUDY, ALLEEG=None, **kwargs)
Read cached STUDY ERSP measures.
- eegprep.std_readitc(STUDY, ALLEEG=None, **kwargs)
Read cached STUDY ITC measures.
- eegprep.std_readtopo(STUDY, ALLEEG=None, *, clusters=None, components=None, **_kwargs)
Read cached STUDY component scalp topographies.
- eegprep.std_readpac(STUDY, ALLEEG=None, *, channels=None, channels1=None, channels2=None, clusters=None, clusters1=None, clusters2=None, components=None, design=None, timerange=None, freqrange=None, condition=None, onepersubj=None, forceread=None, recompute=None, **kwargs)
Read EEGPrep-owned cached STUDY PAC data when present.
- eegprep.std_pac(EEG_or_STUDY, ALLEEG=None, *args, components1=None, components2=None, channels1=None, channels2=None, outputfile='', plot='off', recompute='off', getparams='off', timerange=None, freqrange=None, padratio=1, freqs=None, cycles=None, freqphase=None, cyclephase=None, interp=None, rmcomps=None, freqscale='log', return_com=False, **kwargs)
Compute phase-amplitude coupling for an EEG dataset or STUDY.
Single-dataset calls return
(pacdata, times, freqs, parameters). STUDY calls return(STUDY, ALLEEG)and store the computed cache underSTUDY.changrp[*].pacdatausing EEGPrep’s in-memory measure contract.
- eegprep.std_pacplot(STUDY, ALLEEG, *args, channels=None, channels1=None, clusters=None, components=None, design=None, noplot='off', plotmode='normal', return_com=False, **kwargs)
Read and optionally plot precomputed STUDY PAC measures.
- eegprep.std_prepare_neighbors(STUDY, ALLEEG, *args, force='off', channels=None, method='distance', neighbordist=None, return_com=False, **kwargs)
Prepare a FieldTrip-like neighbor list and LIMO adjacency matrix.
- eegprep.std_interp(STUDY, ALLEEG, chans=None, method='spherical', *args, return_com=False, **kwargs)
Interpolate selected missing channels into every STUDY dataset.
- eegprep.std_dipplot(*args, **kwargs)
Report the standalone boundary for STUDY-level source plotting.
- eegprep.std_dipoleclusters(*args, **kwargs)
Report the standalone boundary for STUDY dipole-cluster workflows.
- eegprep.std_savedat(tmpfile, structure)
Save a measure structure as JSON or MATLAB-compatible MAT data.
- eegprep.std_checkfiles(STUDY, ALLEEG=None, *, return_report=False)
Check loaded STUDY data and cached measures for standalone EEGPrep.
- eegprep.std_checkdatasession(STUDY, ALLEEG=None, *, return_report=False)
Check dataset/session alignment for a STUDY and loaded ALLEEG.
- eegprep.std_uniformfiles(STUDY, ALLEEG)
Return
1for uniform channels,0for mismatch,-1for missing files.
- eegprep.std_uniformsetinds(STUDY)
Return
1when STUDY channel group set indices are uniform.
- eegprep.std_findsameica(ALLEEG, icathreshold=0.0002)
Group 1-based dataset indices with near-identical ICA weights*sphere.
EEGPrep keeps cross-subject decompositions in separate groups because subject labels are a STUDY grouping boundary for downstream workflows.
- eegprep.std_selsubject(data, subject, setinds, allsubjects, optndims=None)
Return cached-measure cells with only the requested subject columns.
- eegprep.std_substudy(STUDY, ALLEEG, *args, dataset=None, subject=None, condition=None, group=None, rmdat='on', return_com=False, **kwargs)
Return a STUDY/ALLEEG subset using EEGLAB-facing 1-based selectors.
- eegprep.std_rmdat(STUDY, ALLEEG, *args, datinds=None, chanrange=(0, inf), pntsrange=(0, inf), sraterange=(0, inf), trialrange=(1, inf), checkeventtype=None, numeventrange=1, subjectind=None, rmvarvalues=None, keepvarvalues=None, return_com=False, **kwargs)
Remove datasets from STUDY/ALLEEG and return removed 1-based indices.
- Parameters:
- Return type:
- eegprep.std_rmalldatafields(STUDY, chanorcomp='both')
Return STUDY without cached measure/data fields for the requested target.
- eegprep.std_erpplot(STUDY, ALLEEG, *args, **kwargs)
Read and plot precomputed STUDY ERP measures.
- eegprep.std_specplot(STUDY, ALLEEG, *args, **kwargs)
Read and plot precomputed STUDY spectrum measures.
- eegprep.std_erspplot(STUDY, ALLEEG, *args, **kwargs)
Read and plot precomputed STUDY ERSP measures.
- eegprep.std_itcplot(STUDY, ALLEEG, *args, **kwargs)
Read and plot precomputed STUDY ITC measures.
- eegprep.optimal_kmeans(clustdata, clusnum, *, random_state=0)
Run k-means for a range and choose the best silhouette score.
- eegprep.robust_kmeans(data, clus_num, STD=3.0, MAXiter=10, method='kmeans', *, random_state=0)
Cluster rows and iteratively mark distant rows as outliers.
- eegprep.std_apcluster(clustdata, *, maxits=200, convits=100, dampfact=0.9, dist='euclidean')
Cluster rows using deterministic affinity propagation updates.
- eegprep.std_centroid(data, labels=None)
Return centroids for all rows or for each positive label.
- eegprep.std_findoutlierclust(data, labels=None, *, threshold=3.0)
Return 1-based row indices farther than
thresholdcluster spreads.
- eegprep.pop_limo(*args, **kwargs)
Report that standalone EEGPrep does not run external LIMO workflows.
- eegprep.pop_limoresults(*args, **kwargs)
Report that standalone EEGPrep does not browse external LIMO results.
Format Conversion#
- eegprep.eeg_eeg2mne(EEG)
Convert EEG data structure to MNE Raw object.
Parameters#
- EEGdict
EEG data structure
Returns#
- rawmne.io.Raw
MNE Raw object