Measured Data Format file reader main module
With Unix and Windows for python 2.6+ and 3.2+
Author: | Aymeric Rateau |
---|
Created on Sun Oct 10 12:57:28 2010
Removes non allowed characters for a Matlab variable name
Parameters: | channel : string
|
---|---|
Returns: | string
|
Bases: mdf3reader.mdf3, mdf4reader.mdf4
mdf class
Notes
mdf class is a nested dict Channel name is the primary dict key of mdf class At a higher level, each channel includes the following keys :
‘data’ : containing vector of data (numpy)
‘unit’ : unit (string)
‘master’ : master channel of channel (time, crank angle, etc.)
‘description’ : Description of channel
- ‘conversion’: mdfinfo nested dict for CCBlock.
Exist if channel not converted, used to convert with getChannelData method
Examples
>>> import mdfreader
>>> yop=mdfreader.mdf('NameOfFile')
>>> yop.keys() # list channels names
>>> yop.masterChannelList() # list channels grouped by raster or master channel
>>> yop.plot('channelName') or yop.plot({'channel1','channel2'})
>>> yop.resample(0.1) or yop.resample(channelName='master3')
>>> yop.exportoCSV(sampling=0.01)
>>> yop.exportNetCDF()
>>> yop.exporttoHDF5()
>>> yop.exporttoMatlab()
>>> yop.exporttoExcel()
>>> yop.exporttoXlsx()
>>> yop.convertToPandas() # converts data groups into pandas dataframes
>>> yop.keepChannels({'channel1','channel2','channel3'}) # drops all the channels except the one in argument
>>> yop.getChannelData('channelName') # returns channel numpy array
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. |
author | (str) |
organisation | (str) |
project | (str) |
subject | (str) |
comment | (str) |
time | (str) |
date | (str) |
Methods
read( fileName = None, multiProc = False, channelList=None, convertAfterRead=True, filterChannelNames=False ) | reads mdf file version 3.x and 4.x |
write( fileName=None ) | writes simple mdf 3.3 file |
getChannelData( channelName ) | returns channel numpy array |
convertAllChannel() | converts all channel data according to CCBlock information |
getChannelUnit( channelName ) | returns channel unit |
plot( channels ) | Plot channels with Matplotlib |
resample( samplingTime = 0.1, masterChannel=None ) | Resamples all data groups |
exportToCSV( filename = None, sampling = 0.1 ) | Exports mdf data into CSV file |
exportToNetCDF( filename = None, sampling = None ) | Exports mdf data into netcdf file |
exportToHDF5( filename = None, sampling = None ) | Exports mdf class data structure into hdf5 file |
exportToMatlab( filename = None ) | Exports mdf class data structure into Matlab file |
exportToExcel( filename = None ) | Exports mdf data into excel 95 to 2003 file |
exportToXlsx( filename=None ) | Exports mdf data into excel 2007 and 2010 file |
convertToPandas( sampling=None ) | converts mdf data structure into pandas dataframe(s) |
keepChannels( channelList ) | keeps only list of channels and removes the other channels |
mergeMdf( mdfClass ): | Merges data of 2 mdf classes |
copy() | copy a mdf class |
Converts all channels from raw data to converted data according to CCBlock information Converted data will take more memory.
converts mdf data structure into pandas dataframe(s)
Parameters: | sampling : float, optional
|
---|
Notes
One pandas dataframe is converted per data group Not adapted yet for mdf4 as it considers only time master channels
copy a mdf class
Exports mdf data into CSV file
Parameters: | filename : str, optional
sampling : float, optional
|
---|
Notes
Data saved in CSV fille be automatically resampled as it is difficult to save in this format data not sharing same master channel Warning: this can be slow for big data, CSV is text format after all
Exports mdf data into excel 95 to 2003 file
Parameters: | filename : str, optional
|
---|
Notes
xlwt is not fast for even for small files, consider other binary formats like HDF5 or Matlab If there are more than 256 channels, data will be saved over different worksheets Also Excel 203 is becoming rare these days
Exports mdf class data structure into hdf5 file
Parameters: | filename : str, optional
sampling : float, optional
|
---|
Notes
The maximum attributes will be stored Data structure will be similar has it is in masterChannelList attribute
Export mdf data into Matlab file format 5, tentatively compressed
Parameters: | filename : str, optional
|
---|
Notes
This method will dump all data into Matlab file but you will loose below information: - unit and descriptions of channel - data structure, what is corresponding master channel to a channel. Channels might have then different lengths
Exports mdf data into netcdf file
Parameters: | filename : str, optional
sampling : float, optional
|
---|
Exports mdf data into excel 2007 and 2010 file
Parameters: | filename : str, optional
|
---|
Notes
It is recommended to export resampled data for performances
Return 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
Returns channel unit string Implemented for a future integration of pint
Parameters: | channelName : str
|
---|---|
Returns: | str
|
keeps only list of channels and removes the other channels
Parameters: | channelList : list of str
|
---|
Merges data of 2 mdf classes
Parameters: | mdfClass : mdf
|
---|
Notes
both classes must have been resampled, otherwise, impossible to know master channel to match create union of both channel lists and fill with Nan for unknown sections in channels
Plot channels with Matplotlib
Parameters: | channels : str or list of str
|
---|
Notes
Channel description and unit will be tentatively displayed with axis labels
reads mdf file version 3.x and 4.x
Parameters: | fileName : str, optional
multiProc : bool
channelList : list of str, optional
convertAfterRead : bool, optional
filterChannelNames : bool, optional
|
---|
Notes
If you keep convertAfterRead to true, you can set attribute mdf.multiProc to activate channel conversion in multiprocessing. Gain in reading time can be around 30% if file is big and using a lot of float channels
Resamples all data groups into one data group having defined sampling interval or sharing same master channel
Parameters: | samplingTime : float
**or** masterChannel : str
|
---|
Notes
1. resampling is relatively safe for mdf3 as it contains only time series. However, mdf4 can contain also distance, angle, etc. It might make not sense to apply one resampling to several data groups that do not share same kind of master channel (like time resampling to distance or angle data groups) If several kind of data groups are used, you should better use pandas to resample
2. resampling will convert all your channels so be careful for big files and memory consumption
Writes simple mdf 3.3 file
Parameters: | fileName : str, optional
|
---|
Notes
All channels will be converted, so size might be bigger than original file
Bases: dict
Examples
>>> import mdfreader
>>> FILENAME='toto.dat'
>>> yop=mdfreader.mdfinfo(FILENAME)
or if you are just interested to have only list of channels
>>> yop=mdfreader.mdfinfo() # creates new instance f mdfinfo class
>>> yop=mdfreader.listChannels(FILENAME) # returns a simple list of channel names
Attributes
fileName | (str) file name |
mdfversion | (int) mdf file version number |
Methods
readinfo( fileName = None, filterChannelNames=False ) | Reads MDF file and extracts its complete structure |
listChannels( fileName = None ) | Read MDF file blocks and returns a list of contained channels |
Read MDF file blocks and returns a list of contained channels
Parameters: | fileName : string
|
---|---|
Returns: | nameList : list of string
|
Reads MDF file and extracts its complete structure
Parameters: | fileName : str, optional
filterChannelNames : bool, optional
|
---|