Measured Data Format file reader module for version 3.x
With Unix and Windows for python 2.6+ and 3.2+
| Author: | Aymeric Rateau |
|---|
Created on Sun Oct 10 12:57:28 2010
Bases: dict
DATA class is organizing record classes itself made of recordchannel. This class inherits from dict. Keys are corresponding to channel group recordID A DATA class corresponds to a data block, a dict of record classes (one per channel group) Each record class contains a list of recordchannel class representing the structure of channel record.
Attributes
| fid | (io.open) file identifier |
| pointerToData | (int) position of Data block in mdf file |
Methods
| addRecord(record) | Adds a new record in DATA class dict |
| read(channelList, zip=None) | Reads data block |
| loadSorted(record, zip=None, nameList=None) | Reads sorted data block from record definition |
| load(nameList=None) | Reads unsorted data block, not yet implemented |
Adds a new record in DATA class dict
| Parameters: | record class
|
|---|
not yet implemented
Reads sorted data block from record definition
| Parameters: | record class
zip : bool, optional
channelList : list of str, optional
|
|---|---|
| Returns: | numpy recarray of data |
Reads data block
| Parameters: | channelList : list of str, optional
zip : bool, optional
|
|---|
function returning numpy style string from channel data type and number of bits Parameters —————- signalDataType : int
channel data type according to specification
| Returns: | dataType : str
|
|---|
function returning C format string from channel data type and number of bits
| Parameters: | signalDataType : int
numberOfBits : int
|
|---|---|
| Returns: | dataType : str
|
apply exponential conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
apply formula conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
Notes
Requires sympy module
apply linear conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
apply logarithmic conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
Bases: dict
mdf file version 3.0 to 3.3 class
Attributes
| fileName | (str) file name |
| VersionNumber | (int) mdf file version number |
| masterChannelList | (dict) Represents data structure: a key per master channel with corresponding value containing a list of channels One key or master channel represents then a data group having same sampling interval. |
| multiProc | (bool) Flag to request channel conversion multi processed for performance improvement. One thread per data group. |
| convertAfterRead | (bool) flag to convert raw data to physical just after read |
| filterChannelNames | (bool) flag to filter long channel names from its module names separated by ‘.’ |
| author | (str) |
| organisation | (str) |
| project | (str) |
| subject | (str) |
| comment | (str) |
| time | (str) |
| date | (str) |
Methods
| read3( fileName=None, info=None, multiProc=False, channelList=None, convertAfterRead=True) | Reads mdf 3.x file data and stores it in dict |
| getChannelData3(channelName) | Returns channel numpy array |
| convertChannel3(channelName) | converts specific channel from raw to physical data according to CCBlock information |
| convertAllChannel3() | Converts all channels from raw data to converted data according to CCBlock information |
| write3(fileName=None) | Writes simple mdf 3.3 file |
converts specific channel from raw to physical data according to CCBlock information
| Parameters: | channelName : str
|
|---|---|
| Returns: | numpy array
|
Converts all channels from raw data to converted data according to CCBlock information Converted data will take more memory.
converts specific channel from raw to physical data according to CCBlock information
| Parameters: | channelName : str
|
|---|
Returns channel numpy array
| Parameters: | channelName : str
|
|---|
Notes
This method is the safest to get channel data as numpy array from ‘data’ dict key might contain raw data
Reads mdf 3.x file data and stores it in dict
| Parameters: | fileName : str, optional
info : mdfinfo3.info3 class
multiProc : bool
channelList : list of str, optional
convertAfterRead : bool, optional
|
|---|
Writes simple mdf 3.3 file
| Parameters: | fileName : str, optional
|
|---|
Notes
All channels will be converted to physical data, so size might be bigger than original file
apply polynomial conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
Put raw data from buf to a dict L and processes nested nBit channels
| Parameters: | Q : multiprocessing.Queue, optional
buf : DATA class
info : info class
dataGroup : int
channelList : list of str, optional
multiProc : bool
|
|---|---|
| Returns: | Q : multiprocessing.Queue
L : dict
|
apply rational conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
Bases: list
record class lists recordchannel classes, it is representing a channel group
Attributes
| recordLength | (int) length of record corresponding of channel group in Byte |
| numberOfRecords | (int) number of records in data block |
| recordID | (int) recordID corresponding to channel group |
| recordIDsize | (int) size of recordID |
| dataGroup | (int:) data group number |
| channelGroup | (int) channel group number |
| numpyDataRecordFormat | (list) list of numpy (dtype) for each channel |
| dataRecordName | (list) list of channel names used for recarray attribute definition |
| master | (dict) define name and number of master channel |
| recordToChannelMatching | (dict) helps to identify nested bits in byte |
| channelNames | (list) channel names to be stored, useful for low memory consumption but slow |
Methods
| addChannel(info, channelNumber) | |
| loadInfo(info) | |
| readSortedRecord(fid, pointer, channelList=None) | |
| readUnsortedRecord(buf, channelList=None) |
add a channel in class
| Parameters: | info : mdfinfo3.info3 class channelNumber : int
|
|---|
gathers records related from info class
| Parameters: | info : mdfinfo3.info3 class |
|---|
reads record, only one channel group per datagroup Parameters —————- fid : float
file identifier
| Returns: | rec : numpy recarray
|
|---|
Notes
If channelList is None, read data using numpy.core.records.fromfile that is rather quick. However, in case of large file, you can use channelList to load only interesting channels or only one channel on demand, but be aware it might be much slower.
Not implemented yet, no reference files available to test it
recordChannel class gathers all about channel structure in a record
Attributes
| name | (str) Name of channel |
| channelNumber | (int) channel number corresponding to mdfinfo3.info3 class |
| signalDataType | (int) signal type according to specification |
| bitCount | (int) number of bits used to store channel record |
| nBytes | (int) number of bytes (1 byte = 8 bits) taken by channel record |
| dataFormat | (str) numpy dtype as string |
| CFormat | (struct class instance) struct instance to convert from C Format |
| byteOffset | (int) position of channel record in complete record in bytes |
| bitOffset | (int) bit position of channel value inside byte in case of channel having bit count below 8 |
| RecordFormat | (list of str) dtype format used for numpy.core.records functions ((name,name_title),str_stype) |
| channelType | (int) channel type |
| posBeg | (int) start position in number of bit of channel record in complete record |
| posEnd | (int) end position in number of bit of channel record in complete record |
Methods
| __init__(info, dataGroup, channelGroup, channelNumber, recordIDsize) | constructor |
| __str__() | to print class attributes |
apply Tabular conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
apply Tabular interpolation conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |
apply text range table conversion to data
| Parameters: | data : numpy 1D array
conv : mdfinfo3.info3 conversion block (‘CCBlock’) dict |
|---|---|
| Returns: | converted data to physical value |