ratal / mdfreader

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

How to read multiple .dat files with mdf reader? #190

Closed Fourka11 closed 3 years ago

Fourka11 commented 3 years ago

Python version

3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Platform information

Windows-10-10.0.16299-SP0

Numpy version

1.16.5

mdfreader version

4.1

Description

Hello,

i would like to select .dat files using the explorer and read them with the mdfreader. The next step should be to print all the channels of the selected files. After that i would like to plot some channels. So far my code works for only one file. But when it comes to read multiple files i get the following error:

File "C:\Program Files\Anaconda3\lib\site-packages\mdfreader\mdf.py", line 683, in _open_mdf fid = open(file_name, 'rb')

TypeError: expected str, bytes or os.PathLike object, not tuple

My code:

import tkinter as tk from tkinter import filedialog import mdfreader as mdf import numpy as np filepath = tk.filedialog.askopenfilenames(initialdir = '"C:\Users\SFOURKA\Desktop\Abgasmessungen"', filetypes=((".dat files", ".dat"), ("all files", ".")), title = 'Choose A File') datFile = mdf.Mdf(filepath) for channel in datFile: print(channel)

Does anyone have any idea how to read multiple files and print the channels of the selected files using the explorer. The selected files have the same channel names. I would be happy about an answer because I am new to programming.

ratal commented 3 years ago

Hi, You can have only one mdfreader object per file, 1:1 mapping. So I would advise you to store all those objects in a dictionary or a list inside a for loop iterating on your filepath (I guess filepath is a tuple, not accepted by mdfreader as input argument, expecting string, you should iterate on its items)

Fourka11 commented 3 years ago

Thanks for replying. I have two files with exactly the same channelnames. Do you have an idea how I can plot the same two channels in one figure? Thanks a lot.

ratal commented 3 years ago

Hi, you can have a look at #131 and its last comments

Fourka11 commented 3 years ago

Hi, I read the comments but unfortunately i don't understand what's to do. Could you please help? Thanks Fourka

ratal commented 3 years ago

import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plt.plot(datFile.get_channel_data(datFile.get_channel_master('channelName')), datFile.get_channel_data('channelName')) ax.plt.plot(dat2File.get_channel_data(dat2File.get_channel_master('channelName')), dat2File.get_channel_data('channelName'))

ratal commented 3 years ago

I guess I answered your questions, closing