MDF3¶
asammdf tries to emulate the mdf structure using Python builtin data types.
The header attibute is an OrderedDict that holds the file metadata.
The groups attribute is a dictionary list with the following keys:
data_group : DataGroup object
channel_group : ChannelGroup object
channels : list of Channel objects with the same order as found in the mdf file
channel_conversions : list of ChannelConversion objects in 1-to-1 relation with the channel list
channel_sources : list of SourceInformation objects in 1-to-1 relation with the channels list
data_block : DataBlock object
texts : dictionay containing TextBlock objects used throughout the mdf
channels : list of dictionaries that contain TextBlock objects ralated to each channel
- long_name_addr : channel long name
- comment_addr : channel comment
- display_name_addr : channel display name
channel group : list of dictionaries that contain TextBlock objects ralated to each channel group
- comment_addr : channel group comment
conversion_tab : list of dictionaries that contain TextBlock objects ralated to VATB and VTABR channel conversions
- text_{n} : n-th text of the VTABR conversion
The file_history attribute is a TextBlock object.
The channel_db attibute is a dictionary that holds the (data group index, channel index) pair for all signals. This is used to speed up the get_signal_by_name method.
The master_db attibute is a dictionary that holds the channel index of the master channel for all data groups. This is used to speed up the get_signal_by_name method.
API¶
-
class
asammdf.mdf3.
MDF3
(name=None, load_measured_data=True, compression=False, version='3.20')¶ If the name exist it will be loaded otherwise an empty file will be created that can be later saved to disk
Parameters: name : string
mdf file name
load_measured_data : bool
load data option; default True
- if True the data group binary data block will be loaded in RAM
- if False the channel data is read from disk on request
compression : bool
compression option for data group binary data block; default False
version : string
mdf file version (‘3.00’, ‘3.10’, ‘3.20’ or ‘3.30’); default ‘3.20’
Attributes
name (string) mdf file name groups (list) list of data groups header (OrderedDict) mdf file header file_history (TextBlock) file history text block; can be None load_measured_data (bool) load measured data option compression (bool) measured data compression option version (int) mdf version channels_db (dict) used for fast channel access by name; for each name key the value is a (group index, channel index) tuple masters_db (dict) used for fast master channel access; for each group index key the value is the master channel index Methods
append
get
get_channel_data
get_master_data
info
remove
save
-
append
(signals, acquisition_info='Python')¶ Appends a new data group.
Parameters: signals : list
list on Signal objects
acquisition_info : str
acquisition information; default ‘Python’
Examples
>>> # case 1 conversion type None >>> s1 = np.array([1, 2, 3, 4, 5]) >>> s2 = np.array([-1, -2, -3, -4, -5]) >>> s3 = np.array([0.1, 0.04, 0.09, 0.16, 0.25]) >>> t = np.array([0.001, 0.002, 0.003, 0.004, 0.005]) >>> names = ['Positive', 'Negative', 'Float'] >>> units = ['+', '-', '.f'] >>> info = {} >>> s1 = Signal(samples=s1, timstamps=t, unit='+', name='Positive') >>> s2 = Signal(samples=s2, timstamps=t, unit='-', name='Negative') >>> s3 = Signal(samples=s3, timstamps=t, unit='flts', name='Floats') >>> mdf = MDF3('new.mdf') >>> mdf.append([s1, s2, s3], 'created by asammdf v1.1.0') >>> # case 2: VTAB conversions from channels inside another file >>> mdf1 = MDF3('in.mdf') >>> ch1 = mdf1.get("Channel1_VTAB") >>> ch2 = mdf1.get("Channel2_VTABR") >>> sigs = [ch1, ch2] >>> mdf2 = MDF3('out.mdf') >>> mdf2.append(sigs, 'created by asammdf v1.1.0')
-
get
(name=None, group=None, index=None, raster=None)¶ Gets channel samples. Channel can be specified in two ways:
- using the first positional argument name
- using the group number (keyword argument group) and the channel number (keyword argument index). Use info method for group and channel numbers
If the raster keyword argument is not None the output is interpolated accordingly
Parameters: name : string
name of channel
group : int
0-based group index
index : int
0-based channel index
raster : float
time raster in seconds
Returns: vals, t, unit, conversion : (numpy.array, numpy.array, string, dict | None)
The conversion is None exept for the VTAB and VTABR conversions. The conversion keys are:
for VTAB conversion:
- raw - numpy.array for X-axis
- phys - numpy.array of strings for Y-axis
- type - conversion type = CONVERSION_TYPE_VTAB
for VTABR conversion:
- lower - numpy.array for lower range
- upper - numpy.array for upper range
- phys - numpy.array of strings for Y-axis
- type - conversion type = COONVERSION_TYPE_VTABR
The conversion information can be used by the append method for the info argument
Raises: MdfError :
* if the channel name is not found
* if the group index is out of range
* if the channel index is out of range
-
get_channel_data
(name=None, group=None, index=None, data=None, return_info=False)¶ get channel values. The channel is identified by name (name argument) or by the group and channel indexes (group and index arguments). data argument is used internally by the get method to avoid double work. By defaulkt only the channel values are returned. If the return_info argument is set then name, unit and conversion info is returned as well
Parameters: name : str
channel name in target group
group : int
group index
index : int
channel index
data : bytes
data groups’s raw channel data
return_info : bool
enables returning extra information (name, unit, conversion)
Returns: vals : numpy.array
channel values; if return_info is False
vals, name, conversion, unit : numpy.array, str, dict, str
channel values, channel name, channel conversion, channel unit: if return_info is True
-
get_master_data
(name=None, group=None, data=None)¶ get master channel values only. The group is identified by a channel name (name argument) or by the index (group argument). data argument is used internally by the get method to avoid double work.
Parameters: name : str
channel name in target group
group : int
group index
data : bytes
data groups’s raw channel data
Returns: t : numpy.array
master channel values
-
info
()¶ get MDF information as a dict
Examples
>>> mdf = MDF3('test.mdf') >>> mdf.info()
-
remove
(group=None, name=None)¶ Remove data group. Use group or name keyword arguments to identify the group’s index. group has priority
Parameters: name : string
name of the channel inside the data group to be removed
group : int
data group index to be removed
Examples
>>> mdf = MDF3('test.mdf') >>> mdf.remove(group=3) >>> mdf.remove(name='VehicleSpeed')
-
save
(dst=None)¶ Save MDF to dst. If dst is None the original file is overwritten