laurens

MATLAB

SEREEGA

SEREEGA is a modular, general-purpose, free and open-source MATLAB-based toolbox to generate simulated toy data mimicking event-related electroencephalography (EEG) data. It uses EEGLAB for some of its functions.

Starting with a forward model obtained from a head model or pre-generated lead field, dipolar brain components can be defined. Each component has a specified position and orientation in the brain. Different activation signals can be assigned to these components. EEG data is simulated by projecting all activation signals from all components onto the scalp and summing them together.

SEREEGA is modular in that different head models and lead fields are supported, as well as different activation signals. Currently, SEREEGA supports the New York Head (ICBM-NY) pre-generated lead field, the Pediatric Head Atlases pre-generated lead fields, and FieldTrip custom lead field generation. Four types of activation signals are provided: ERP (event-related potential, i.e. systematic deflections in the time domain), ERSP (event-related spectral perturbation, i.e. systematic modulations of oscillatory activations), noise (stochastic processes in the time domain), and signals based on an autoregressive model. A final data class allows the inclusion of any already existing time series as an activation signal.

SEREEGA is intended as a tool to generate data with a known ground truth in order to evaluate neuroscientific and signal processing methods, e.g. blind source separation, source localisation, connectivity measures, brain-computer interface classifier accuracy, derivative EEG measures, et cetera.

As an example, the following code produces an EEGLAB dataset containing 100 epochs of 64-channel EEG data, each consisting of the summed activity of 64 simulated sources spread across the brain. The final dataset includes a ground-truth ICA decomposition that can be used to verify the accuracy of newly calculated decompositions.

% configuring for 100 epochs of 1000 ms at 1000 Hz config = struct('n', 10, 'srate', 1000, 'length', 1000); % obtaining a 64-channel lead field from ICBM-NY leadfield = lf_generate_fromnyhead('montage', 'S64'); % obtaining 64 random source locations, at least 2.5 cm apart sourcelocs = lf_get_source_spaced(leadfield, 64, 25); % each source will get the same type of activation: brown coloured noise signal = struct('type', 'noise', 'color', 'brown', 'amplitude', 1); % packing source locations and activations together into components components = utl_create_component(sourcelocs, signal, leadfield); % simulating data data = generate_scalpdata(components, leadfield, config); % converting to EEGLAB dataset format, adding ICA weights EEG = utl_create_eeglabdataset(data, config, leadfield); EEG = utl_add_icaweights_toeeglabdataset(EEG, components, leadfield);

Links:

SEREEGA on GitHub

SEREEGA manuscript preprint on bioRxiv

MATLAB

permutationTest

A permutation test (aka randomisation test) for MATLAB, supporting one- and two-tailed tests and capable of visualising the outcome using a histogram. Provides a p-value, the observed difference, and the effect size. It is also possible to perform exact tests, during which all possible combinations are considered.

For example, the following tests two samples (n=5000 each) from normal distributions against each other, one shifted .1 to the right (two-tailed, 10000 permutatinos). It produces the subsequent plot.

sample1 = randn(1,5000); sample2 = randn(1,5000) + .1; permutationTest(sample1, sample2, 10000, 'plot', 1);

permutationTest

Links:

permutationTest on GitHub

permutationTest on MATLAB Central

MATLAB

multigradient

This script allows you to generate a colour scale (as for colormap, colorbar) using any number of custom colours, and allows you to arrange these colours by adjusting their relative positions with respect to each other, much like you may be used to creating gradients in e.g. Adobe Photoshop or CorelDRAW. It will automatically interpolate the colours in between the indicated anchor points. Interpolation can be done in both RGB and HSV space.

In its most basic form, simply call the script using an n-by-3 matrix of RGB values, and it will generate the colour map accordingly. For example, multigradient([1 0 0; 1 1 0; 0 1 0]) will return a map that blends from red through yellow to green, of the same size as the current figure's color map. Further tricks are optional.

multigradient

Links:

multigradient on GitHub

multigradient on MATLAB Central

You may also be interested in:

Kenneth Moreland's colour map advice for scientific visualisation and his page on diverging colour maps. Note: the suggested luminance restrictions are not currently implemented in multigradient.

MATLAB

plot_erp

plot_erp is a MATLAB-based script to plot event-related potentials (ERPs) from any number of given epoched datasets (in EEGLAB format), for a single channel. For each ERP curve, any number of datasets can be given. It can optionally calculate and plot a difference wave, standard errors, and permutation-based statistics (using permutationTest). Mean curves and statistics can be calculated either within or between datasets.

For example: Two ERPs plus their difference, standard error of the mean for all curves, and statistics highlighting significant differences, using the default colour scheme.

multigradient

Or: ERPs for eight groups of 19 datasets each with custom colours, labels, and x scale indicator position.

multigradient

Link:

plot_erp on GitHub

MATLAB

maptorange

MATLAB script to map values from one range onto another range, either linearly or along a given exponential curve. Also supports inverse ranges, and can extrapolate. This is perhaps a small feat but I've found it to be highly useful in a range of scenarios.

For example, we may map the values in a source range from 10 to 15 to their corresponding values in a target range between 0 and .5, where 10 becomes .5 and 15 becomes 0, with an exponential curve falloff using the power of 5.

maptorange

Links:

maptorange on GitHub

maptorange on MATLAB Central

Python

Multi-Dimensional Image Browser

maptorange

This has made the analysis of some visual data a little easier for me. Rather than browsing through image files in alphabetical order, this script allows them to be browsed through in a multi-dimensional fashion. Take for example the following files:

apple-brown.jpg banana-brown.jpg apple-green.jpg banana-green.jpg apple-yellow.jpg banana-yellow.jpg pear-brown.jpg plum-brown.jpg pear-green.jpg plum-green.jpg pear-yellow.jpg plum-yellow.jpg

Regular alphabetical ordering would have you browse first through all apples, colour by colour, then through the bananas, colour by colour, and then the pears and plums. These files, however, contain two dimensions: fruit type, and fruit colour. This script makes it possible to jump from the green banana to the green apple with one button, and from the green apple to the yellow apple with another.

Simply supply it with a directory and a file pattern, and the script automatically extracts and orders all dimension values.

File names should be consistent except for the variable parts, and the variable parts should be separated somehow. A variable part of the file names representing one dimension is indicated using an asterisk (*). For the above example, the pattern would be:

*-*.jpg

The script then allows you to browse through the available dimensions using the keyboard. The keys for the first dimension are under the "1", i.e. on a QWERTY keyboard, "q" for one up in this dimension, and "a" for one down. "w" and "e" increase and decrease the second dimension, respectively, and "o" and "l" represent the ninth dimension. The first two dimensions can additionally be controlled by the arrow keys.

Dimensions are numbered in the order that they appear in the file names.

Keyboard shortcuts include shift+D to set the directory, and shift+P for the pattern. Enter applies, escape exits.

Link:

Multi-Dimensional Image Browser on GitHub

Python

Regex Dictionary Search

This scripts extracts word entries from text files (e.g. plain text dictionaries, word lists, etc.) and then allows case-insensitive regular expression searches to be performed on those entries, for those occassions where you need to find words or terms fitting a specific pattern. German words of exactly 35 characters, for example, or funny words in the English dictionary that twice contain either bb or dd:

Pattern: ^\S{35}$     Hochdruckflüssigkeitschromatografie     Schnittstellenanpassungseinrichtung Pattern: (([db])\2).*\1     coddymoddy     flibbertigibbet     hoddydoddy

Works on MY machine!

The results of the searches are both shown in the console and written to a text file.

14 dictionaries and word lists are included. Additional dictionaries can be added by simply adding the corresponding names and extraction expressions to the dictionaries array. Encode the files in UTF-8 without BOM.

Empty input either exits the script (when in dictionary selection mode) or goes back to dictionary selection.

Link:

Python Regex Dictionary Search on GitHub

PHP

Noctifer Gallery

A small, single-file PHP script that handles everything you need in order to turn a directory into an online image gallery. It contains both a thumbnail browser and an image viewer. The browser shows thumbnails for supported image files (currently jpg, png, gif), and lists subdirectories for navigation. It automatically creates thumbnails of new files (given appropriate writing permissions). The image viewer can show images at 100% of their size, or fit them to the screen, and can be controlled by keyboard. Two colour schemes are included, which can be easily customised.

Links:

This online example uses the dark colour scheme.

Noctifer Gallery on GitHub