ratal / mdfreader

Read Measurement Data Format (MDF) versions 3.x and 4.x file formats in python
Other
169 stars 73 forks source link

Not able to extract data from different devices with same channel name #192

Open motthomasn opened 3 years ago

motthomasn commented 3 years ago

Python version

Please write here the output of printing sys.version 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Platform information

Please write here the output of printing platform.platform() Windows-10-10.0.19041-SP0

Numpy version

Please write here the output of printing numpy.__version__ 1.16.5

mdfreader version

Please write here the output of printing mdfreader.__version__ 4.1

Description

This is probably more of a feature request than an issue.

Firstly, thank you very much for creating this package. It has been very useful for working with mdf files and accessing the data in different ways. Recently I began working on a project where I record data from 2off identical modules and the channel names from each module are also the same. INCA & MDA differentiate channels with the same name using the source path name but I have not been able to do this with mdfreader.

If I have a channel name "nEngine" which exists in both modules, source path names "source:1" & "source:2", and I read the mdf file using: data = mdfreader.Mdf( file, ["nEngine"], convert_after_read=False) The resulting object has a size of only 2, the time channel and one of the "nEngine" data channels. The second "nEngine" data channel is not returned.

Ideally I would like both channels to be returned with the source path name added to the channel name. This is the way that the channels are displayed in INCA. i.e. "nEngine\source:1" & "nEngine\source:2". In my files, the source path name is contained within the channel dict key "id" at index [2][2]. However, I cannot say for certain that key always exists in all mdf files.

Ultimately, I generally convert the data to Pandas dataframe using return_pandas_dataframe() and in this case, having channel names that correspond to the INCA display names would be ideal.

Do you think adding this feature may be possible without affecting the existing functionality too much? I would like to have a look through the source code myself also to see how it might be done but I am relatively new to Python so I may not be that productive.

ratal commented 3 years ago

The channel name is adjusted in mdfinfo.py mdfinfo3.py : line 210 to 233 mdfinfo4.py : in _unique_channel_name() function. In general, I estimated it was preferable to have the shortest name possible and depending of the cases of doublon, append info like dg, cg and cn numbers for mdf3 or append source for mdf4. For each channel dict, you have a 'identifier' key which value is a tuple of structure : (data group number, channel group number, channel number), (channel name, channel source, channel path), (group name, group source, group path). According to the specification, this is the only way to make sure you have unique channel description. The way Inca defines channel names I found not so nice as it has generally to be reworked, using for instance a lot of forbidden characters for several environments, especially Matlab. But you can have a look and make a proposal ?