This class acts as a proxy for the MDF2, MDF3 and MDF4 classes. All attribute access is delegated to the underlying _mdf attribute (MDF2, MDF3 or MDF4 object). See MDF3 and MDF4 for available extra methods (MDF2 and MDF3 share the same implementation).
An empty MDF file is created if the name argument is not provided. If the name argument is provided then the file must exist in the filesystem, otherwise an exception is raised.
The best practice is to use the MDF as a context manager. This way all resources are released correctly in case of exceptions.
with MDF(r'test.mdf') as mdf_file:
# do something
asammdf.mdf.
MDF
(name=None, memory='full', version='4.10')[source]¶Unified access to MDF v3 and v4 files. Underlying _mdf’s attributes and methods are linked to the MDF object via setattr. This is done to expose them to the user code and for performance considerations.
Parameters: | name : string
memory : str
version : string
|
---|
convert
(to, memory='full')[source]¶convert MDF to other version
Parameters: | to : str
memory : str
|
---|---|
Returns: | out : MDF
|
cut
(start=None, stop=None, whence=0)[source]¶cut MDF file. start and stop limits are absolute values or values relative to the first timestamp depending on the whence argument.
Parameters: | start : float
stop : float
whence : int
|
---|---|
Returns: | out : MDF
|
export
(fmt, filename=None)[source]¶export MDF to other formats. The MDF file name is used is available, else the filename aragument must be provided.
Parameters: | fmt : string
filename : string
|
---|
filter
(channels, memory='full')[source]¶return new MDF object that contains only the channels listed in channels argument
Parameters: | channels : list
memory : str
|
---|---|
Returns: | mdf : MDF
|
Examples
>>> from asammdf import MDF, Signal
>>> import numpy as np
>>> t = np.arange(5)
>>> s = np.ones(5)
>>> mdf = MDF()
>>> for i in range(4):
... sigs = [Signal(s*(i*10+j), t, name='SIG') for j in range(1,4)]
... mdf.append(sigs)
...
>>> filtered = mdf.filter(['SIG', ('SIG', 3, 1), ['SIG', 2], (None, 1, 2)])
>>> for gp_nr, ch_nr in filtered.channels_db['SIG']:
... print(filtered.get(group=gp_nr, index=ch_nr))
...
<Signal SIG:
samples=[ 1. 1. 1. 1. 1.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
<Signal SIG:
samples=[ 31. 31. 31. 31. 31.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
<Signal SIG:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
<Signal SIG:
samples=[ 12. 12. 12. 12. 12.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
iter_channels
(skip_master=True)[source]¶generator that yields a Signal for each non-master channel
Parameters: | skip_master : bool
|
---|
merge
(files, outversion='4.10', memory='full')[source]¶merge several files and return the merged MDF object. The files must have the same internal structure (same number of groups, and same channels in each group)
Parameters: | files : list | tuple
outversion : str
memory : str
|
---|---|
Returns: | merged : MDF
|
Raises: | MdfException : if there are inconsistencies between the files
|
resample
(raster, memory='full')[source]¶resample all channels using the given raster
Parameters: | raster : float
memory : str
|
---|---|
Returns: | mdf : MDF
|
select
(channels, dataframe=False)[source]¶retreiv the channels listed in channels argument as Signal objects
Parameters: | channels : list
dataframe: bool
|
---|---|
Returns: | signals : list
|
Examples
>>> from asammdf import MDF, Signal
>>> import numpy as np
>>> t = np.arange(5)
>>> s = np.ones(5)
>>> mdf = MDF()
>>> for i in range(4):
... sigs = [Signal(s*(i*10+j), t, name='SIG') for j in range(1,4)]
... mdf.append(sigs)
...
>>> # select SIG group 0 default index 1 default, SIG group 3 index 1, SIG group 2 index 1 default and channel index 2 from group 1
...
>>> mdf.select(['SIG', ('SIG', 3, 1), ['SIG', 2], (None, 1, 2)])
[<Signal SIG:
samples=[ 1. 1. 1. 1. 1.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
, <Signal SIG:
samples=[ 31. 31. 31. 31. 31.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
, <Signal SIG:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
, <Signal SIG:
samples=[ 12. 12. 12. 12. 12.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
]
whereis
(channel)[source]¶get ocurrences of channel name in the file
Parameters: | channel : str
|
---|---|
Returns: | ocurrences : tuple |
Examples
>>> mdf = MDF(file_name)
>>> mdf.whereis('VehicleSpeed') # "VehicleSpeed" exists in the file
((1, 2), (2, 4))
>>> mdf.whereis('VehicleSPD') # "VehicleSPD" doesn't exist in the file
()
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
chanel_dependencies : list of ChannelDependency objects in a 1-to-1 relation with the channel 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
sorted : bool flag to indicate if the source file was sorted; it is used when memory is low or minimum
size : data block size; used for lazy laoding of measured data
record_size : dict of record ID -> record size pairs
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.
asammdf.mdf_v3.
MDF3
(name=None, memory='full', version='3.30')[source]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
memory : str
version : string
|
---|
Attributes
channels_db | (dict) used for fast channel access by name; for each name key the value is a list of (group index, channel index) tuples |
file_history | (TextBlock) file history text block; can be None |
groups | (list) list of data groups |
header | (HeaderBlock) mdf file header |
identification | (FileIdentificationBlock) mdf file start block |
masters_db | (dict) used for fast master channel access; for each group index key the value is the master channel index |
memory | (str) memory optimization option |
name | (string) mdf file name |
version | (str) mdf version |
add_trigger
(group, timestamp, pre_time=0, post_time=0, comment='')[source]add trigger to data group
Parameters: | group : int
timestamp : float
pre_time : float
post_time : float
comment : str
|
---|
append
(signals, acquisition_info='Python', common_timebase=False)[source]Appends a new data group.
For channel dependencies type Signals, the samples attribute must be a numpy.recarray
Parameters: | signals : list
acquisition_info : str
common_timebase : bool
|
---|
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')
close
()[source]if the MDF was created with memory=’minimum’ and new channels have been appended, then this must be called just before the object is not used anymore to clean-up the temporary file
configure
(read_fragment_size=None, write_fragment_size=None)[source]configure read and write fragment size for chuncked data access
Parameters: | read_fragment_size : int
write_fragment_size : int
|
---|
extend
(index, signals)[source]Extend a group with new samples. The first signal is the master channel’s samples, and the next signals must respect the same order in which they were appended. The samples must have raw or physical values according to the Signals used for the initial append.
Parameters: | index : int
signals : list
|
---|
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']
>>> 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')
>>> t = np.array([0.006, 0.007, 0.008, 0.009, 0.010])
>>> mdf2.extend(0, [t, s1, s2, s3])
get
(name=None, group=None, index=None, raster=None, samples_only=False, data=None, raw=False)[source]Gets channel samples. Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurances for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurances for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
raster : float
samples_only : bool
data : bytes
raw : bool
|
---|---|
Returns: | res : (numpy.array | Signal)
|
Raises: | MdfException : * if the channel name is not found * if the group index is out of range * if the channel index is out of range |
Examples
>>> from asammdf import MDF, Signal
>>> import numpy as np
>>> t = np.arange(5)
>>> s = np.ones(5)
>>> mdf = MDF(version='3.30')
>>> for i in range(4):
... sigs = [Signal(s*(i*10+j), t, name='Sig') for j in range(1, 4)]
... mdf.append(sigs)
...
>>> # first group and channel index of the specified channel name
...
>>> mdf.get('Sig')
UserWarning: Multiple occurances for channel "Sig". Using first occurance from data group 4. Provide both "group" and "index" arguments to select another data group
<Signal Sig:
samples=[ 1. 1. 1. 1. 1.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # first channel index in the specified group
...
>>> mdf.get('Sig', 1)
<Signal Sig:
samples=[ 11. 11. 11. 11. 11.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # channel named Sig from group 1 channel index 2
...
>>> mdf.get('Sig', 1, 2)
<Signal Sig:
samples=[ 12. 12. 12. 12. 12.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # channel index 1 or group 2
...
>>> mdf.get(None, 2, 1)
<Signal Sig:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> mdf.get(group=2, index=1)
<Signal Sig:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
get_channel_comment
(name=None, group=None, index=None)[source]Gets channel comment. Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurances for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurances for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
|
---|---|
Returns: | comment : str
|
get_channel_name
(group, index)[source]Gets channel name.
Parameters: | group : int
index : int
|
---|---|
Returns: | name : str
|
get_channel_unit
(name=None, group=None, index=None)[source]Gets channel unit.
Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurances for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurances for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
|
---|---|
Returns: | unit : str
|
get_master
(index, data=None, raster=None)[source]returns master channel samples for given group
Parameters: | index : int
data : (bytes, int)
raster : float
|
---|---|
Returns: | t : numpy.array
|
info
()[source]get MDF information as a dict
Examples
>>> mdf = MDF3('test.mdf')
>>> mdf.info()
iter_get_triggers
()[source]generator that yields triggers
Returns: | trigger_info : dict
|
---|
save
(dst='', overwrite=False, compression=0)[source]Save MDF to dst. If dst is not provided the the destination file name is the MDF name. If overwrite is True then the destination file is overwritten, otherwise the file name is appended with ‘_<cntr>’, were ‘<cntr>’ is the first counter that produces a new file name (that does not already exist in the filesystem).
Parameters: | dst : str
overwrite : bool
compression : int
|
---|---|
Returns: | output_file : str
|
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
- name_addr : channel name
- comment_addr : channel comment
channel group : list of dictionaries that contain TextBlock objects ralated to each channel group
- acq_name_addr : channel group acquisition comment
- comment_addr : channel group comment
conversion_tab : list of dictionaries that contain TextBlock objects related to TABX and RTABX channel conversions
- text_{n} : n-th text of the VTABR conversion
- default_addr : default text
conversions : list of dictionaries that containt TextBlock obejcts related to channel conversions
- name_addr : converions name
- unit_addr : channel unit_addr
- comment_addr : converison comment
- formula_addr : formula text; only valid for algebraic conversions
sources : list of dictionaries that containt TextBlock obejcts related to channel sources
- name_addr : source name
- path_addr : source path_addr
- comment_addr : source comment
The file_history attribute is a list of (FileHistory, TextBlock) pairs .
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.
asammdf.mdf_v4.
MDF4
(name=None, memory='full', version='4.10')[source]If the name exist it will be memorised otherwise an empty file will be created that can be later saved to disk
Parameters: | name : string
memory : str
version : string
|
---|
Attributes
attachments | (list) list of file attachments |
channels_db | (dict) used for fast channel access by name; for each name key the value is a list of (group index, channel index) tuples |
file_comment | (TextBlock) file comment TextBlock |
file_history | (list) list of (FileHistory, TextBlock) pairs |
groups | (list) list of data groups |
header | (HeaderBlock) mdf file header |
identification | (FileIdentificationBlock) mdf file start block |
masters_db | (dict) used for fast master channel access; for each group index key the value is the master channel index |
memory | (str) memory optimization option |
name | (string) mdf file name |
version | (str) mdf version |
append
(signals, source_info='Python', common_timebase=False)[source]Appends a new data group.
For channel dependencies type Signals, the samples attribute must be a numpy.recarray
Parameters: | signals : list
source_info : str
common_timebase : bool
|
---|
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')
attach
(data, file_name=None, comment=None, compression=True, mime='application/octet-stream')[source]attach embedded attachment as application/octet-stream
Parameters: | data : bytes
file_name : str
comment : str
compression : bool
mime : str
|
---|
close
()[source]if the MDF was created with memory=False and new channels have been appended, then this must be called just before the object is not used anymore to clean-up the temporary file
configure
(read_fragment_size=None, write_fragment_size=None)[source]configure read and write fragment size for chuncked data access
Parameters: | read_fragment_size : int
write_fragment_size : int
|
---|
extend
(index, signals)[source]Extend a group with new samples. The first signal is the master channel’s samples, and the next signals must respect the same order in which they were appended. The samples must have raw or physical values according to the Signals used for the initial append.
Parameters: | index : int
signals : list
|
---|
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']
>>> 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')
>>> t = np.array([0.006, 0.007, 0.008, 0.009, 0.010])
>>> mdf2.extend(0, [t, s1, s2, s3])
extract_attachment
(index)[source]extract attachment index data. If it is an embedded attachment, then this method creates the new file according to the attachment file name information
Parameters: | index : int
|
---|---|
Returns: | data : bytes | str
|
get
(name=None, group=None, index=None, raster=None, samples_only=False, data=None, raw=False)[source]Gets channel samples. Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurances for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurances for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
raster : float
samples_only : bool
data : bytes
raw : bool
|
---|---|
Returns: | res : (numpy.array | Signal)
|
Raises: | MdfException : * if the channel name is not found * if the group index is out of range * if the channel index is out of range |
Examples
>>> from asammdf import MDF, Signal
>>> import numpy as np
>>> t = np.arange(5)
>>> s = np.ones(5)
>>> mdf = MDF(version='4.10')
>>> for i in range(4):
... sigs = [Signal(s*(i*10+j), t, name='Sig') for j in range(1, 4)]
... mdf.append(sigs)
...
>>> # first group and channel index of the specified channel name
...
>>> mdf.get('Sig')
UserWarning: Multiple occurances for channel "Sig". Using first occurance from data group 4. Provide both "group" and "index" arguments to select another data group
<Signal Sig:
samples=[ 1. 1. 1. 1. 1.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # first channel index in the specified group
...
>>> mdf.get('Sig', 1)
<Signal Sig:
samples=[ 11. 11. 11. 11. 11.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # channel named Sig from group 1 channel index 2
...
>>> mdf.get('Sig', 1, 2)
<Signal Sig:
samples=[ 12. 12. 12. 12. 12.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> # channel index 1 or group 2
...
>>> mdf.get(None, 2, 1)
<Signal Sig:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
>>> mdf.get(group=2, index=1)
<Signal Sig:
samples=[ 21. 21. 21. 21. 21.]
timestamps=[0 1 2 3 4]
unit=""
info=None
comment="">
get_channel_comment
(name=None, group=None, index=None)[source]Gets channel comment.
Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurrences for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurrences for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
|
---|---|
Returns: | comment : str
|
get_channel_name
(group, index)[source]Gets channel name.
Parameters: | group : int
index : int
|
---|---|
Returns: | name : str
|
get_channel_unit
(name=None, group=None, index=None)[source]Gets channel unit.
Channel can be specified in two ways:
using the first positional argument name
- if there are multiple occurrences for this channel then the group and index arguments can be used to select a specific group.
- if there are multiple occurrences for this channel and either the group or index arguments is None then a warning is issued
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
group : int
index : int
|
---|---|
Returns: | unit : str
|
get_master
(index, data=None, raster=None)[source]returns master channel samples for given group
Parameters: | index : int
data : (bytes, int)
raster : float
|
---|---|
Returns: | t : numpy.array
|
get_valid_indexes
(group_index, channel, fragment)[source]get invalidation indexes for the channel
Parameters: | group_index : int
channel : Channel
fragment : (bytes, int)
|
---|---|
Returns: | valid_indexes : iterable
|
info
()[source]get MDF information as a dict
Examples
>>> mdf = MDF4('test.mdf')
>>> mdf.info()
save
(dst='', overwrite=False, compression=0)[source]Save MDF to dst. If dst is not provided the the destination file name is the MDF name. If overwrite is True then the destination file is overwritten, otherwise the file name is appened with ‘_<cntr>’, were ‘<cntr>’ is the first conter that produces a new file name (that does not already exist in the filesystem)
Parameters: | dst : str
overwrite : bool
compression : int
|
---|---|
Returns: | output_file : str
|
asammdf.signal.
Signal
(samples=None, timestamps=None, unit='', name='', conversion=None, comment='', raw=False)[source]¶The Signal represents a hannel described by it’s samples and timestamps. It can perform aritmethic operations agains other Signal or numeric types. The operations are computed in respect to the timestamps (time correct). The non-float signals are not interpolated, instead the last value relative to the current timestamp is used. samples, timstamps and name are mandatory arguments.
Parameters: | samples : numpy.array | list | tuple
timestamps : numpy.array | list | tuple
unit : str
name : str
conversion : dict
comment : str
raw : bool
|
---|
astype
(np_type)[source]¶returns new Signal with samples of dtype np_type
Parameters: | np_type : np.dtype
|
---|---|
Returns: | signal : Signal
|
cut
(start=None, stop=None)[source]¶Cuts the signal according to the start and stop values, by using the insertion indexes in the signal’s time axis.
Parameters: | start : float
stop : float
|
---|---|
Returns: | result : Signal
|
Examples
>>> new_sig = old_sig.cut(1.0, 10.5)
>>> new_sig.timestamps[0], new_sig.timestamps[-1]
0.98, 10.48
extend
(other)[source]¶extend signal with samples from another signal
Parameters: | other : Signal |
---|---|
Returns: | signal : Signal
|
By default when the MDF object is created all data is loaded into RAM (memory=’full’). This will give you the best performance from asammdf.
However if you reach the physical memory limit asammdf gives you two options:
- memory=’low’ : only the metadata is loaded into RAM, the raw channel data is loaded when needed
- memory=’minimum’ : only minimal data is loaded into RAM.
Advantages
Disadvantages
Use case
Advantages
Disadvantages
Note
it is advised to use the MDF context manager in this case
Use case
Note
See benchmarks for the effects of using the flag
Advantages
Disadvantages
Note
See benchmarks for the effects of using the flag