Table Of Contents

Previous topic

misc.fx

Next topic

misc.io.eepbin

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.io.base

Module: misc.io.base

Inheritance diagram for mvpa.misc.io.base:

Some little helper for reading (and writing) common formats from and to disk.

Classes

ColumnData

class mvpa.misc.io.base.ColumnData(source, header=True, sep=None, headersep=None, dtype=<type 'float'>, skiplines=0)

Bases: dict

Read data that is stored in columns of text files.

All read data is available via a dictionary-like interface. If column headers are available, the column names serve as dictionary keys. If no header exists an articfical key is generated: str(number_of_column).

Splitting of text file lines is performed by the standard split() function (which gets passed the sep argument as separator string) and each element is converted into the desired datatype.

Because data is read into a dictionary no two columns can have the same name in the header! Each column is stored as a list in the dictionary.

Read data from file into a dictionary.

Parameters:
  • source (basestring or dict) – If values is given as a string all data is read from the file and additonal keyword arguments can be sued to customize the read procedure. If a dictionary is passed a deepcopy is performed.
  • header (bool or list of basestring) – Indicates whether the column names should be read from the first line (header=True). If header=False unique column names will be generated (see class docs). If header is a python list, it’s content is used as column header names and its length has to match the number of columns in the file.
  • sep (basestring or None) – Separator string. The actual meaning depends on the output format (see class docs).
  • headersep (basestring or None) – Separator string used in the header. The actual meaning depends on the output format (see class docs).
  • dtype (type or list(types)) – Desired datatype(s). Datatype per column get be specified by passing a list of types.
  • skiplines (int) – Number of lines to skip at the beginning of the file.
getNColumns()

Returns the number of columns.

getNRows()

Returns the number of rows.

ncolumns

Returns the number of columns.

nrows

Returns the number of rows.

selectSamples(selection)

Return new ColumnData with selected samples

tofile(filename, header=True, header_order=None, sep=' ')

Write column data to a text file.

Parameters:
  • filename (basestring) – Target filename
  • header (bool) – If True a column header is written, using the column keys. If False no header is written.
  • header_order (None or list of basestring) – If it is a list of strings, they will be used instead of simply asking for the dictionary keys. However these strings must match the dictionary keys in number and identity. This argument type can be used to determine the order of the columns in the output file. The default value is None. In this case the columns will be in an arbitrary order.
  • sep (basestring) – String that is written as a separator between to data columns.

DataReader

class mvpa.misc.io.base.DataReader

Bases: object

Base class for data readers.

Every subclass has to put all information into to variable:

self._data: ndarray
The data array has to have the samples separating dimension along the first axis.
self._props: dict
All other meaningful information has to be stored in a dictionary.

This class provides two methods (and associated properties) to retrieve this information.

Cheap init.

data

Data array

getData()

Return the data array.

getPropsAsDict()

Return the dictionary with the data properties.

props

Property dict

SampleAttributes

class mvpa.misc.io.base.SampleAttributes(source, literallabels=False, header=None)

Bases: mvpa.misc.io.base.ColumnData

Read and write PyMVPA sample attribute definitions from and to text files.

Read PyMVPA sample attributes from disk.

Parameters:
  • source (basestring) – Filename of an atrribute file
  • literallabels (bool) – Either labels are given as literal strings
  • header (None or bool or list of str) – If None, [‘labels’, ‘chunks’] is assumed. Otherwise the same behavior as of ColumnData
getNSamples()

Returns the number of samples in the file.

nsamples

Returns the number of samples in the file.

toEvents(**kwargs)

Convert into a list of Event instances.

Each change in the label or chunks value is taken as a new event onset. The length of an event is determined by the number of identical consecutive label-chunk combinations. Since the attributes list has no sense of absolute timing, both onset and duration are determined and stored in #samples units.

Parameters:kwargs – Any keyword arugment provided would be replicated, through all the entries.
tofile(filename)

Write sample attributes to a text file.

SensorLocations

class mvpa.misc.io.base.SensorLocations(*args, **kwargs)

Bases: mvpa.misc.io.base.ColumnData

Base class for sensor location readers.

Each subclass should provide x, y, z coordinates via the pos_x, pos_y, and pos_z attrbibutes.

Axes should follow the following convention:

x-axis: left -> right y-axis: anterior -> posterior z-axis: superior -> inferior

Pass arguments to ColumnData.

locations()

Get the sensor locations as an array.

Return type:(nchannels x 3) array with coordinates in (x, y, z)

TuebingenMEGSensorLocations

class mvpa.misc.io.base.TuebingenMEGSensorLocations(source)

Bases: mvpa.misc.io.base.SensorLocations

Read sensor location definitions from a specific text file format.

File layout is assumed to be 7 columns:

1: sensor name 2: position on y-axis 3: position on x-axis 4: position on z-axis 5-7: same as 2-4, but for some outer surface thingie.

Note that x and y seem to be swapped, ie. y as defined by SensorLocations conventions seems to be first axis and followed by x.

Only inner surface coordinates are reported by locations().

Read sensor locations from file.

Parameters:source (filename of an attribute file) –

XAVRSensorLocations

class mvpa.misc.io.base.XAVRSensorLocations(source)

Bases: mvpa.misc.io.base.SensorLocations

Read sensor location definitions from a specific text file format.

File layout is assumed to be 5 columns:

  1. sensor name
  2. some useless integer
  3. position on x-axis
  4. position on y-axis
  5. position on z-axis

Read sensor locations from file.

Parameters:source (filename of an attribute file) –

Functions

mvpa.misc.io.base.design2labels(columndata, baseline_label=0, func=<function <lambda> at 0x86b8668>)

Helper to convert design matrix into a list of labels

Given a design, assign a single label to any given sample

TODO: fix description/naming

Parameters:
  • columndata (ColumnData) – Attributes where each known will be considered as a separate explanatory variable (EV) in the design.
  • baseline_label – What label to assign for samples where none of EVs was given a value
  • func (functor) – Function which decides either a value should be considered
Output :

list of labels which are taken from column names in ColumnData and baseline_label

mvpa.misc.io.base.labels2chunks(labels, method='alllabels', ignore_labels=None)