Table Of Contents

Previous topic

misc.stats

Next topic

misc.transformers

This content refers to the previous stable release of PyMVPA. Please visit www.pymvpa.org for the most recent version of PyMVPA and its documentation.

misc.support

Module: misc.support

Inheritance diagram for mvpa.misc.support:

Support function – little helpers in everyday life

Classes

Event

class mvpa.misc.support.Event(**kwargs)

Bases: dict

Simple class to define properties of an event.

The class is basically a dictionary. Any properties can be passed as keyword arguments to the constructor, e.g.:

>>> ev = Event(onset=12, duration=2.45)

Conventions for keys:

onset
The onset of the event in some unit.
duration
The duration of the event in the same unit as onset.
label
E.g. the condition this event is part of.
chunk
Group this event is part of (if any), e.g. experimental run.
features
Any amount of additional features of the event. This might include things like physiological measures, stimulus intensity. Must be a mutable sequence (e.g. list), if present.
asDescreteTime(dt, storeoffset=False)

Convert onset and duration information into descrete timepoints.

Parameters:
  • dt (float) – Temporal distance between two timepoints in the same unit as onset and duration.
  • storeoffset (bool) – If True, the temporal offset between original onset and descretized onset is stored as an additional item in features.
Return :

A copy of the original Event with onset and optionally duration replaced by their corresponding descrete timepoint. The new onset will correspond to the timepoint just before or exactly at the original onset. The new duration will be the number of timepoints covering the event from the computed onset timepoint till the timepoint exactly at the end, or just after the event.

Note again, that the new values are expressed as #timepoint and not in their original unit!

Harvester

class mvpa.misc.support.Harvester(source, calls, simplify_results=True)

Bases: object

World domination helper: do whatever it is asked and accumulate results

XXX Thinks about:
  • Might we need to deepcopy attributes values?
  • Might we need to specify what attribs to copy and which just to bind?

Initialize

Parameters:
  • source – Generator which produce food for the calls.
  • calls (sequence of HarvesterCall instances) – Calls which are processed in the loop. All calls are processed in order of apperance in the sequence.
  • simplify_results (bool) – Remove unecessary overhead in results if possible (nested lists and dictionaries).

HarvesterCall

class mvpa.misc.support.HarvesterCall(call, attribs=None, argfilter=None, expand_args=True, copy_attribs=True)

Bases: object

Initialize

Parameters:
  • expand_args (bool) – Either to expand the output of looper into a list of arguments for call
  • attribs (list of basestr) – What attributes of call to store and return later on?
  • copy_attribs (bool) – Force copying values of attributes
call = None

Call which gets called in the harvester.

MapOverlap

class mvpa.misc.support.MapOverlap(overlap_threshold=1.0)

Bases: object

Compute some overlap stats from a sequence of binary maps.

When called with a sequence of binary maps (e.g. lists or arrays) the fraction of mask elements that are non-zero in a customizable proportion of the maps is returned. By default this threshold is set to 1.0, i.e. such an element has to be non-zero in all maps.

Three additional maps (same size as original) are computed:

  • overlap_map: binary map which is non-zero for each overlapping element.

  • spread_map: binary map which is non-zero for each element that is

    non-zero in any map, but does not exceed the overlap threshold.

  • ovstats_map: map of float with the raw elementwise fraction of overlap.

All maps are available via class members.

Nothing to be seen here.

SmartVersion

class mvpa.misc.support.SmartVersion(vstring=None)

Bases: distutils.version.Version

A bit evolved comparison of versions

The reason for not using python’s distutil.version is that it seems to have no clue about somewhat common conventions of using ‘-dev’ or ‘dev’ or ‘rc’ suffixes for upcoming releases (so major version does contain upcoming release already).

So here is an ad-hoc and not as nice implementation

parse(vstring)

Functions

mvpa.misc.support.RFEHistory2maps(history)

Convert history generated by RFE into the array of binary maps

Example:
history2maps(N.array( [ 3,2,1,0 ] ))
results in
array([[ 1., 1., 1., 1.],
[ 1., 1., 1., 0.], [ 1., 1., 0., 0.], [ 1., 0., 0., 0.]])
mvpa.misc.support.getBreakPoints(items, contiguous=True)

Return a list of break points.

Parameters:
  • items (iterable) – list of items, such as chunks
  • contiguous (bool) – if True (default) then raise Value Error if items are not contiguous, i.e. a label occur in multiple contiguous sets
Raises :

ValueError

Returns:

list of indexes for every new set of items

mvpa.misc.support.getUniqueLengthNCombinations(L, n=None, sort=True)

Find all subsets of data

Parameters:
  • L (list) – list of unique ids
  • n (None or int) – If None, all possible subsets are returned. If n is specified (int), then only the ones of the length n are returned

TODO: work out single stable implementation – probably just by fixing _getUniqueLengthNCombinations_lt3

mvpa.misc.support.idhash(val)

Craft unique id+hash for an object

mvpa.misc.support.indentDoc(v)

Given a value returns a string where each line is indented

Needed for a cleaner __repr__ output v - arbitrary

mvpa.misc.support.isInVolume(coord, shape)

For given coord check if it is within a specified volume size.

Returns True/False. Assumes that volume coordinates start at 0. No more generalization (arbitrary minimal coord) is done to save on performance

mvpa.misc.support.isSorted(items)

Check if listed items are in sorted order.

Parameters:items (iterable container) –
Returns:True if were sorted. Otherwise False + Warning
mvpa.misc.support.reuseAbsolutePath(file1, file2, force=False)

Use path to file1 as the path to file2 is no absolute path is given for file2

Parameters:force (bool) – if True, force it even if the file2 starts with /
mvpa.misc.support.transformWithBoxcar(data, startpoints, boxlength, offset=0, fx=<function mean at 0x2982c80>)

This function extracts boxcar windows from an array. Such a boxcar is defined by a starting point and the size of the window along the first axis of the array (boxlength). Afterwards a customizable function is applied to each boxcar individually (Default: averaging).

Parameters:
  • data (array) – An array with an arbitrary number of dimensions.
  • startpoints (sequence) – Boxcar startpoints as index along the first array axis
  • boxlength (int) – Length of the boxcar window in #array elements
  • offset (int) – Optional offset between the configured starting point and the actual begining of the boxcar window.
Return type:

array (len(startpoints) x data.shape[1:])

mvpa.misc.support.version_to_tuple(v)

Convert literal string into a tuple, if possible of ints

Tuple of integers constructed by splitting at ‘.’ or interleaves of numerics and alpha numbers

mvpa.misc.support.xuniqueCombinations(L, n)

Generator of unique combinations form a list L of objects in groups of size n.

# XXX EO: I guess they are already sorted. # XXX EO: It seems to work well for n>20 :)

Parameters:
  • L (list) – list of unique ids
  • n (int) – grouping size

Adopted from Li Daobing http://code.activestate.com/recipes/190465/ (MIT license, according to activestate.com’s policy)