HEKA PatchMaster¶
Support is provided for reading data and protocols from HEKA PatchMaster files in the 2x90.2 format.
PatchMaster files can contain several experiments, ordered into “groups” and
“series”. The Series class implements Myokit’s shared
myokit.formats.SweepSource interface.
Importer¶
Protocols can be imported via the PatchMasterFile class, or using the
PatchMasterImporter.
- myokit.formats.heka.importers()¶
Returns a dict of all importers available in this module.
- class myokit.formats.heka.PatchMasterImporter¶
This
Importercan import (step) protocols from “series” inside HEKA PatchMaster files.- protocol(filename, group=None, series=None)¶
Attempts to load the protocol from the file at
filename.Because PatchMaster files can contain several experiments, a further selection can be made with the arguments:
filenameThe file to read
groupThe group to read from (as a string).
seriesThe integer index of the desired series in the specified group.
- supports_protocol()¶
Returns a bool indicating if protocol import is supported.
PatchMasterFile¶
- class myokit.formats.heka.PatchMasterFile(filepath)¶
Provides read-only access to data stored in HEKA PatchMaster (“bundle”) files (
.dat), stored atfilepath.Data loading is “lazy”, meaning that data is only read when requested. This means the file stays open, and so
close()must be called after using a PatchMasterFile. To ensure this happens, usewith:with PatchMasterFile('my-file.dat') as f: for group in f: print(group.label)
Each file contains a hierarchy of
Group,Series,SweepandTraceobjects. For example, each “group” might represent a single cell, and each “series” will be a protocol (called a “stimulus”) run on that cell. Groups are named by the user. Series are named after the “stimulus” they run. Sweeps are usually unnamed (although they do have alabelproperty), and traces (channels) are named by the user.To access groups, index them by integer, or use the
group()method to find the first group with a given label:with PatchMasterFile('my-file.dat') as f: group_0 = f[0] group_x = f.group('Experiment X')
Series, sweeps, and traces are accessed with integers:
with PatchMasterFile('my-file.dat') as f: group = f.group('Experiment X') series = group[0] sweep = series[0] trace = sweep[0]
Each object in the hierarchy can be iterated over:
with PatchMasterFile('my-file.dat') as f: for group in f: for series in group: for sweep in series: for trace in sweep: ...
To see only completed series (where all sweeps were run to finish), use:
with PatchMasterFile('my-file.dat') as f: for group in f: for series in group.complete_series(): ...
The
Seriesclass implements themyokit.formats.SweepSourceinterface:with PatchMasterFile('my-file.dat') as f: for group in f: for series in group.complete_series(): log = series.log()
- amplifier_tree()¶
Returns this file’s amplifier tree (an
AmplifierFileobject), or None.
- close()¶
Closes this file: no new data can be read once this has been called.
- filename()¶
Returns this file’s filename.
- group(label)¶
Returns the first :class`Group` matching the given
label.
- path()¶
Returns the path to this PatchMaster file.
- stimulus_tree()¶
Returns this file’s stimulus tree (a
StimulusFileobject).
- version()¶
Returns this file’s version number (as a string).
Internals¶
PatchMaster files are structured as several trees.
These are read using the TreeNode class, which makes use of the
EndianAwareReader class.
- class myokit.formats.heka.TreeNode(parent)¶
Base class for objects within a PatchMaster file that form a tree.
This class may be useful when extending the patchmaster file reading, or to read other HEKA formats. To read a patchmaster file, use the
PatchMasterFileclass.For subclasses:
When reading a file,
TreeNodeobjects will be created by (1) calling the constructor with aparentbut no children. (2) Calling the method_read_properties()which should read record properties from the open file handle and update theTreeNodeaccordingly. (3) Calling the method_read_finalize(), which can handl any actions that require children to have been added.- parent()¶
Returns this tree TreeNode’s parent.
- static read(pfile, handle, levels)¶
Reads a full HEKA “Tree” structure.
Arguments:
pfilehandleAn file handle, open at the tree root.
levelsThe classes to use for each tree level.
Returns a TreeNode representing the tree’s root.
- class myokit.formats.heka.EndianAwareReader(handle, is_little_endian)¶
Used by
PatchmasterFileand its supporting classes when reading from an open file handle that may be either big or little endian.This class may be useful when extending the patchmaster file reading, or to read other HEKA formats. To read a patchmaster file, use the
PatchMasterFileclass.- read(form)¶
Read and unpack using the struct format
form.
- read1(form)¶
Returns the first item from a call to
read(form).This is useful for the many cases where a single number is read.
- str(size)¶
Read and unpack a string of at most length
size.
- time()¶
Reads a time in HEKA’s seconds-since-1990 format, converts it, and returns a
datetimeobject.