Skip to content

Latest commit

 

History

History
756 lines (556 loc) · 17.5 KB

reference.rst

File metadata and controls

756 lines (556 loc) · 17.5 KB

Reference

Data Classes

eelbrain

Primary data classes:

Dataset Factor Var NDVar Datalist

Model classes (not usually initialized by themselves but through operations on primary data-objects):

Interaction Model

NDVar dimensions (not usually initialized by themselves but through load functions):

Case Categorial Scalar Sensor SourceSpace VolumeSourceSpace Space UTS

File I/O

eelbrain

Eelbrain objects can be pickled. Eelbrain's own pickle I/O functions provide backwards compatibility for Eelbrain objects (although files saved in Python 3 can only be opened in Python 2 if they are saved with protocol<=2):

save.pickle load.unpickle load.arrow save.arrow load.update_subjects_dir

Import

Functions and modules for loading specific file formats as Eelbrain object:

load.wav load.tsv load.eyelink load.fiff load.txt load.besa

Export

Dataset with only univariate data can be saved as text using the ~Dataset.save_txt method. Additional export functions:

save.txt save.wav

Sorting and Reordering

align align1 Celltable choose combine shuffled_index

NDVar Initializers

gaussian powerlaw_noise

NDVar Operations

NDVar objects support the native abs and round functions. See also NDVar methods.

Butterworth complete_source_space concatenate convolve correlation_coefficient cross_correlation cwt_morlet dss filter_data find_intervals find_peaks frequency_response label_operator labels_from_clusters maximum minimum morph_source_space neighbor_correlation psd_welch resample segment set_parc set_time set_tmin xhemi

Reverse Correlation

boosting BoostingResult epoch_impulse_predictor event_impulse_predictor

Tables

eelbrain

Manipulate data tables and compile information about data objects such as cell frequencies:

table.cast_to_ndvar table.difference table.frequencies table.melt table.melt_ndvar table.repmeas table.stats

Statistics

eelbrain

Univariate statistical tests:

test.Correlation test.TTestOneSample test.TTestIndependent test.TTestRelated test.ANOVA test.pairwise test.ttest test.correlations test.pairwise_correlations test.MannWhitneyU test.WilcoxonSignedRank test.lilliefors

Mass-Univariate Statistics

eelbrain

testnd.TTestOneSample testnd.TTestRelated testnd.TTestIndependent testnd.TContrastRelated testnd.ANOVA testnd.Correlation testnd.Vector testnd.VectorDifferenceRelated

By default the tests in this module produce maps of statistical parameters along with maps of p-values uncorrected for multiple comparison. Using different parameters, different methods for multiple comparison correction can be applied (for more details and options see the documentation for individual tests):

1: permutation for maximum statistic (samples=n)

Look for the maximum value of the test statistic in n permutations and calculate a p-value for each data point based on this distribution of maximum statistics.

2: Threshold-based clusters (samples=n, pmin=p)

Find clusters of data points where the original statistic exceeds a value corresponding to an uncorrected p-value of p. For each cluster, calculate the sum of the statistic values that are part of the cluster. Do the same in n permutations of the original data and retain for each permutation the value of the largest cluster. Evaluate all cluster values in the original data against the distributiom of maximum cluster values (see1).

3: Threshold-free cluster enhancement (samples=n, tfce=True)

Similar to (1), but each statistical parameter map is first processed with the cluster-enhancement algorithm (see2). This is the most computationally intensive option.

Two-stage tests

Two-stage tests proceed by estimating parameters for a fixed effects model for each subject, and then testing hypotheses on these parameter estimates on the group level. Two-stage tests are implemented by fitting an ~testnd.LM for each subject, and then combining them in a ~testnd.LMGroup to retrieve coefficients for group level statistics (see exa-two-stage example).

testnd.LM testnd.LMGroup

References

Plotting

eelbrain

Plot univariate data (Var objects):

plot.Barplot plot.BarplotHorizontal plot.Boxplot plot.PairwiseLegend plot.Correlation plot.Histogram plot.Regression plot.Timeplot

Color tools for plotting:

plot.colors_for_categorial plot.colors_for_oneway plot.colors_for_twoway plot.soft_threshold_colormap plot.two_step_colormap plot.Style plot.ColorBar plot.ColorGrid plot.ColorList

Plot uniform time-series:

plot.LineStack plot.UTS plot.UTSClusters plot.UTSStat

Plot multidimensional uniform time series:

plot.Array plot.Butterfly

Plot topographic maps of sensor space data:

plot.TopoArray plot.TopoButterfly plot.Topomap plot.TopomapBins

Plot sensor layout maps:

plot.SensorMap plot.SensorMaps

xax parameter

Many plots have an xax parameter which is used to sort the data in y into different categories and plot them on separate axes. xax can be specified through categorial data, or as a dimension in y.

If a categorial data object is specified for xax, y is split into the categories in xax, and for every cell in xax a separate subplot is shown. For example, while

>>> plot.Butterfly('meg', ds=ds)

will create a single Butterfly plot of the average response,

>>> plot.Butterfly('meg', 'subject', ds=ds)

where 'subject' is the xax parameter, will create a separate subplot for every subject with its average response.

A dimension on y can be specified through a string starting with .. For example, to plot each case of meg separately, use:

>>> plot.Butterfly('meg', '.case', ds=ds)

General layout parameters

Most plots that also share certain layout keyword arguments. By default, all those parameters are determined automatically, but individual values can be specified manually by supplying them as keyword arguments.

h, w : scalar

Height and width of the figure. Use a number ≤ 0 to defined the size relative to the screen (e.g., w=0 to use the full screen width).

axh, axw : scalar

Height and width of the axes.

nrow, ncol : None | int

Limit number of rows/columns. If neither is specified, a square layout is produced

margins : dict

Absolute subplot parameters (in inches). Implies tight=False. If margins is specified, axw and axh are interpreted exclusive of the margins, i.e., axh=2, margins={'top': .5} for a plot with one axes will result in a total height of 2.5. Example:

margins={
    'top': 0.5,  # from top of figure to top axes
    'bottom': 1,  # from bottom of figure to bottom axes
    'hspace': 0.1,  # height of space between axes
    'left': 0.5,  #  from left of figure to left-most axes
    'right': 0.1,  # from right of figure to right-most axes
    'wspace': 0.1,  # width of space between axes
}
ax_aspect : scalar

Width / height aspect of the axes.

frame : bool | str

How to frame the axes of the plot. Options:

  • True (default): normal matplotlib frame, spines around axes
  • False: omit top and right spines
  • 't': draw spines at x=0 and y=0, common for ERPs
  • 'none': no spines at all
name : str

Window title (not displayed on the figure itself).

title : str

Figure title (displayed on the figure).

tight : bool

Use matplotlib's tight_layout to resize all axes to fill the figure.

right_of : eelbrain plot

Position the new figure to the right of this figure.

below : eelbrain plot

Position the new figure below this figure.

Plots that do take those parameters can be identified by the **layout in their function signature.

GUI Interaction

By default, new plots are automatically shown and, if the Python interpreter is in interactive mode the GUI main loop is started. This behavior can be controlled with 2 arguments when constructing a plot:

show : bool

Show the figure in the GUI (default True). Use False for creating figures and saving them without displaying them on the screen.

run : bool

Run the Eelbrain GUI app (default is True for interactive plotting and False in scripts).

The behavior can also be changed globally using configure.

By default, Eelbrain plots open in windows with enhance GUI features such as copying a figure to the OS clip-board. To plot figures in bare matplotlib windows, configure Eelbrain with eelbrain.configure(frame=False).

Plotting Brains

eelbrain

The plot.brain module contains specialized functions to plot NDVar objects containing source space data. For this it uses a subclass of PySurfer's surfer.Brain class. The functions below allow quick plotting. More specific control over the plots can be achieved through the ~plot._brain_object.Brain object that is returned.

plot.brain.brain plot.brain.butterfly plot.brain.cluster plot.brain.dspm plot.brain.p_map plot.brain.annot plot.brain.annot_legend ~plot._brain_object.Brain plot.brain.SequencePlotter plot.GlassBrain plot.GlassBrain.butterfly

In order to make custom plots, a ~plot._brain_object.Brain figure without any data added can be created with plot.brain.brain(ndvar.source, mask=False).

Surface options for plotting data on fsaverage:

white

surf_white

smoothwm

surf_smoothwm

inflated_pre

surf_inflated_pre

inflated

surf_inflated

inflated_avg

surf_inflated_avg

sphere

surf_sphere

GUIs

eelbrain

Tools with a graphical user interface (GUI):

gui.select_components gui.select_epochs gui.load_stcs

Controlling the GUI Application

Eelbrain uses a wxPython based application to create GUIs. This GUI appears as a separate application with its own Dock icon. The way that control of this GUI is managed depends on the environment form which it is invoked.

When Eelbrain plots are created from within iPython, the GUI is managed in the background and control returns immediately to the terminal. There might be cases in which this is not desired, for example when running scripts. After execution of a script finishes, the interpreter is terminated and all associated plots are closed. To avoid this, the command gui.run(block=True) can be inserted at the end of the script, which will keep all gui elements open until the user quits the GUI application (see gui.run below).

In interpreters other than iPython, input can not be processed from the GUI and the interpreter shell at the same time. In that case, the GUI application is activated by default whenever a GUI is created in interactive mode (this can be avoided by passing run=False to any plotting function). While the application is processing user input, the shell can not be used. In order to return to the shell, quit the application (the python/Quit Eelbrain menu command or Command-Q). In order to return to the terminal without closing all windows, use the alternative Go/Yield to Terminal command (Command-Alt-Q). To return to the application from the shell, run gui.run. Beware that if you terminate the Python session from the terminal, the application is not given a chance to assure that information in open windows is saved.

gui.run

Formatted Text

eelbrain

The fmtxt submodule provides tools for exporting results. Most eelbrain functions and methods that print tables in fact return fmtxt objects, which can be exported in different formats, for example:

>>> ds = datasets.get_uts()
>>> table.stats('Y', 'A', 'B', ds=ds)
           B
     ---------------
     b0       b1
--------------------
a0   0.8857   0.4525
a1   0.3425   1.377
>>> type(table.stats('Y', 'A', 'B', ds=ds))
eelbrain.fmtxt.Table

This means that the result can be exported as formatted text, for example:

>>> fmtxt.save_pdf(table.stats('Y', 'A', 'B', ds=ds))

See available export functions and the module documentation for details:

fmtxt fmtxt.copy_pdf fmtxt.copy_tex fmtxt.save_html fmtxt.save_pdf fmtxt.save_rtf fmtxt.save_tex

Experiment Pipeline

eelbrain.pipeline

The MneExperiment class provides a template for analyzing EEG and MEG data. The objects for specifying the analysis are all in the pipeline submodule.

For the guide on working with the MneExperiment class see experiment-class-guide.

MneExperiment

Result containers:

ROITestResult ROI2StageResult

Participant groups:

Group SubGroup

Pre-processing:

RawSource RawFilter RawICA RawMaxwell RawReReference RawApplyICA

Event variables:

EvalVar GroupVar LabelVar

Epochs:

PrimaryEpoch SecondaryEpoch SuperEpoch

Tests:

ANOVA TTestOneSample TTestIndependent TTestRelated TContrastRelated TwoStageTest

Brain parcellations:

SubParc CombinationParc FreeSurferParc FSAverageParc SeededParc IndividualSeededParc

Datasets

eelbrain

Datasets for experimenting and testing:

datasets.get_loftus_masson_1994 datasets.get_mne_sample datasets.get_uts datasets.get_uv datasets.simulate_erp

Configuration

configure


  1. Maris, E., & Oostenveld, R. (2007). Nonparametric statistical testing of EEG- and MEG-data. Journal of Neuroscience Methods, 164(1), 177-190. 10.1016/j.jneumeth.2007.03.024

  2. Smith, S. M., and Nichols, T. E. (2009). Threshold-Free Cluster Enhancement: Addressing Problems of Smoothing, Threshold Dependence and Localisation in Cluster Inference. NeuroImage, 44(1), 83-98. 10.1016/j.neuroimage.2008.03.061