Skip to content

Commit

Permalink
release 2.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Dec 18, 2017
2 parents cb6e0d2 + 753ddf2 commit 3845160
Show file tree
Hide file tree
Showing 44 changed files with 2,875 additions and 1,468 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ ENV/

# mypy
.mypy_cache/

test-reports/
canape*.ini

_build/
debug/
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
# command to install dependencies
install:
- pip install -r pip_requirements_readthedocs.txt
- pip install -r pip_requirements_tests.txt
# command to run tests
script:
- set -e
- python --version
- python test/run_all.py
- python -m sphinx -nW -b html documentation documentation/_build/html

after_success:
4 changes: 4 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ Please write here the output of printing ``platform.platform()``
Please write here the output of printing ``asammdf.__version__``

# Description
<<<<<<< HEAD
Please describe the issue here.
=======
Please describe the issue here.
>>>>>>> development
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[![PyPI version](https://badge.fury.io/py/asammdf.svg)](https://badge.fury.io/py/asammdf) [![Documentation Status](http://readthedocs.org/projects/asammdf/badge/?version=master)](http://asammdf.readthedocs.io/en/master/?badge=stable) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a3da21da90ca43a5b72fc24b56880c99)](https://www.codacy.com/app/danielhrisca/asammdf?utm_source=github.com&utm_medium=referral&utm_content=danielhrisca/asammdf&utm_campaign=badger)

[![Build Status](https://travis-ci.org/danielhrisca/asammdf.svg?branch=master)](https://travis-ci.org/danielhrisca/asammdf)


*asammdf* is a fast parser/editor for ASAM (Associtation for Standardisation of Automation and Measuring Systems) MDF (Measurement Data Format) files.

*asammdf* supports MDF versions 2 (.dat), 3 (.mdf) and 4 (.mf4).

*asammdf* works on Python 2.7, and Python >= 3.4
*asammdf* works on Python 2.7, and Python >= 3.4 (Travis CI tests done with Python 2.7 and Python >= 3.5)


Project goals
Expand Down
203 changes: 99 additions & 104 deletions README.rst

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion asammdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
""" asammdf is a parser and editor for ASAM MDF files """
from .mdf2 import MDF2
from .mdf3 import MDF3
from .mdf4 import MDF4
from .mdf import MDF
from .mdf import MDF, SUPPORTED_VERSIONS
from .signal import Signal
from .version import __version__

Expand All @@ -11,9 +12,11 @@
'__version__',
'configure',
'MDF',
'MDF2',
'MDF3',
'MDF4',
'Signal',
'SUPPORTED_VERSIONS',
]


Expand Down Expand Up @@ -43,6 +46,7 @@ def configure(
"""

if integer_compacting is not None:
MDF2._compact_integers_on_append = bool(integer_compacting)
MDF3._compact_integers_on_append = bool(integer_compacting)
MDF4._compact_integers_on_append = bool(integer_compacting)

Expand All @@ -53,5 +57,6 @@ def configure(
MDF4._split_data_blocks = bool(split_data_blocks)

if overwrite is not None:
MDF2._overwrite = bool(overwrite)
MDF3._overwrite = bool(overwrite)
MDF4._overwrite = bool(overwrite)
86 changes: 61 additions & 25 deletions asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import csv
import os
from collections import defaultdict
from warnings import warn
from functools import reduce
from struct import unpack
Expand All @@ -14,18 +15,19 @@
from .mdf3 import MDF3
from .mdf4 import MDF4
from .utils import MdfException
from .v2blocks import Channel as ChannelV2
from .v3blocks import TextBlock as TextBlockV3
from .v3blocks import Channel as ChannelV3
from .v4blocks import TextBlock as TextBlockV4


MDF2_VERSIONS = ('2.14',)
MDF2_VERSIONS = ('2.00', '2.14')
MDF3_VERSIONS = ('3.00', '3.10', '3.20', '3.30')
MDF4_VERSIONS = ('4.00', '4.10', '4.11')
SUPPORTED_VERSIONS = MDF2_VERSIONS + MDF3_VERSIONS + MDF4_VERSIONS


__all__ = ['MDF', ]
__all__ = ['MDF', 'SUPPORTED_VERSIONS']


class MDF(object):
Expand All @@ -40,13 +42,13 @@ class MDF(object):
* if *full* the data group binary data block will be loaded in RAM
* if *low* the channel data is read from disk on request, and the
metadata is loaded into RAM
metadata is loaded into RAM
* if *minimum* only minimal data is loaded into RAM
version : string
mdf file version ('3.00', '3.10', '3.20', '3.30', '4.00', '4.10',
'4.11'); default '4.10'
mdf file version from ('2.00', '2.14', '3.00', '3.10', '3.20', '3.30',
'4.00', '4.10', '4.11'); default '4.10'
"""
def __init__(self, name=None, memory='full', version='4.10'):
Expand Down Expand Up @@ -139,8 +141,8 @@ def convert(self, to, memory='full'):
Parameters
----------
to : str
new mdf version from ('3.00', '3.10', '3.20', '3.30', '4.00',
'4.10', '4.11')
new mdf version from ('2.00', '2.14', '3.00', '3.10', '3.20',
'3.30', '4.00', '4.10', '4.11')
memory : str
memory option; default `full`
Expand Down Expand Up @@ -274,22 +276,22 @@ def export(self, fmt, filename=None):
can be one of the following:
* `csv` : CSV export that uses the ";" delimiter. This option
will generate a new csv file for each data group
(<MDFNAME>_DataGroup_<cntr>.csv)
will generate a new csv file for each data group
(<MDFNAME>_DataGroup_<cntr>.csv)
* `hdf5` : HDF5 file output; each *MDF* data group is mapped to
a *HDF5* group with the name 'DataGroup_<cntr>'
(where <cntr> is the index)
a *HDF5* group with the name 'DataGroup_<cntr>'
(where <cntr> is the index)
* `excel` : Excel file output (very slow). This option will
generate a new excel file for each data group
(<MDFNAME>_DataGroup_<cntr>.xlsx)
generate a new excel file for each data group
(<MDFNAME>_DataGroup_<cntr>.xlsx)
* `mat` : Matlab .mat version 5 export, for Matlab >= 7.6. In
the mat file the channels will be renamed to
'DataGroup_<cntr>_<channel name>'. The channel group master
will be renamed to 'DataGroup_<cntr>_<channel name>_master'
( *<cntr>* is the data group index starting from 0)
the mat file the channels will be renamed to
'DataGroup_<cntr>_<channel name>'. The channel group master
will be renamed to 'DataGroup_<cntr>_<channel name>_master'
( *<cntr>* is the data group index starting from 0)
filename : string
export file name
Expand Down Expand Up @@ -503,18 +505,46 @@ def filter(self, channels, memory=None):

# group channels by group index
gps = {}
excluded_channels = defaultdict(list)
for ch in channels:
if ch in self.channels_db:
for group, index in self.channels_db[ch]:
if group not in gps:
gps[group] = []
gps[group].append(index)
gps[group] = set()
gps[group].add(index)
if self.version in MDF2_VERSIONS + MDF3_VERSIONS:
dep = group['channel_dependencies'][index]
if dep:
for ch_nr, gp_nr in dep.referenced_channels:
if gp_nr == group:
excluded_channels[group].append(ch_nr)
else:
grp = self.groups[group]
dependencies = grp['channel_dependencies'][index]
if dependencies is None:
continue
if all(dep['id'] == b'##CN' for dep in dependencies):
channels = grp['channels']
for ch in dependencies:
excluded_channels[group].append(channels.index(ch))
else:
for dep in dependencies:
for ch_nr, gp_nr in dep.referenced_channels:
if gp_nr == group:
excluded_channels[group].append(ch_nr)
else:
message = ('MDF filter error: '
'Channel "{}" not found, it will be ignored')
warn(message.format(ch))
continue

for group in excluded_channels:
excluded_indexes = excluded_channels[group]
if group in gps:
for index in excluded_indexes:
if index in gps[group]:
gps[group].remove(index)

if memory is not None:
if memory not in ('full', 'low', 'minimum'):
memory = self.memory
Expand Down Expand Up @@ -567,7 +597,7 @@ def merge(files, outversion='4.10', memory='full'):
Raises
------
MdfException : if there are inconsistances between the files
MdfException : if there are inconsistencies between the files
merged MDF object
"""
if not files:
Expand Down Expand Up @@ -606,7 +636,7 @@ def merge(files, outversion='4.10', memory='full'):
if memory == 'minimum':
names = []
for file in files:
if file.version in MDF3_VERSIONS:
if file.version in MDF2_VERSIONS + MDF3_VERSIONS:
grp = file.groups[i]
if grp['data_location'] == 0:
stream = file._file
Expand All @@ -624,10 +654,16 @@ def merge(files, outversion='4.10', memory='full'):
)
name = block['text']
else:
channel = ChannelV3(
address=grp['channels'][j],
stream=stream,
)
if file.version in MDF2_VERSIONS:
channel = ChannelV2(
address=grp['channels'][j],
stream=stream,
)
else:
channel = ChannelV3(
address=grp['channels'][j],
stream=stream,
)
name = channel['short_name']
name = name.decode('latin-1').strip(' \r\n\t\0')
else:
Expand Down
Loading

0 comments on commit 3845160

Please sign in to comment.