用python nptdms读取TDMS文件,无法打开tdms文件

时间:2018-03-26 12:17:01

标签: python

我遇到了使nptdms模块的基本功能正常工作的问题。 首先,我只是尝试打开TDMS文件并打印特定组中特定通道的内容。 使用python 2.7和nptdms快速启动here

在此之后,我将把这些特定的数据片段写入新的TDMS文件中。然后,我的最终目标是能够获取一组源文件,打开每个文件,并写入(追加)到新文件。源数据文件包含所需的更多信息,因此我将细节分解为自己的文件。 我遇到的问题是我无法通过一个基本错误。 运行此代码时,我得到:

Traceback (most recent call last):
  File "PullTDMSdataIntoNewFile.py", line 27, in <module>
    tdms_file = TdmsFile(r"C:\\Users\daniel.worts\Desktop\this_is_my_tdms_file.tdms","r")
  File "C:\Anaconda2\lib\site-packages\nptdms\tdms.py", line 94, in __init__
    self._read_segments(f)
  File "C:\Anaconda2\lib\site-packages\nptdms\tdms.py", line 119, in _read_segments
    object._initialise_data(memmap_dir=self.memmap_dir)
  File "C:\Anaconda2\lib\site-packages\nptdms\tdms.py", line 709, in _initialise_data
    mode='w+b', prefix="nptdms_", dir=memmap_dir)
  File "C:\Anaconda2\lib\tempfile.py", line 475, in NamedTemporaryFile
    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
  File "C:\Anaconda2\lib\tempfile.py", line 244, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 2] No such file or directory: 'r\\nptdms_yjfyam'

这是我的代码:

from nptdms import TdmsFile
import numpy as np
import pandas as pd

#set Tdms file path
tdms_file = TdmsFile(r"C:\\Users\daniel.worts\Desktop\this_is_my_tdms_file.tdms","r")

# set variable for TDMS groups
group_nameone = '101'
group_nametwo = '752'

# set objects for TDMS channels
channel_dataone = tdms_file.object(group_nameone 'Payload_1') 
channel_datatwo = tdms_file.object(group_nametwo, 'Payload_2')

# set data from channels
data_dataone = channel_dataone.data
data_datatwo = channel_datatwo.data

print data_dataone
print data_datatwo

非常感谢之前可能遇到此问题并且可以帮助指出我所缺少的人。 最好, - 丹

编辑: 通过删除“&#39;”解决了读取数据问题。来自文件路径的参数。

现在我还有另一个错误,我在尝试写时无法追踪。

from nptdms import TdmsFile, TdmsWriter, RootObject, GroupObject, ChannelObject
import numpy as np
import pandas as pd

newfilepath = r"C:\\Users\daniel.worts\Desktop\Mined.tdms"

datetimegroup101_channel_object = ChannelObject('101', DateTime, data_datetimegroup101)

with TdmsWriter(newfilepath) as tdms_writer:
    tdms_writer.write_segment([datetimegroup101_channel_object])

返回错误:

Traceback (most recent call last):
  File "PullTDMSdataIntoNewFile.py", line 82, in <module>
    tdms_writer.write_segment([datetimegroup101_channel_object])
  File "C:\Anaconda2\lib\site-packages\nptdms\writer.py", line 68, in write_segment
    segment = TdmsSegment(objects)
  File "C:\Anaconda2\lib\site-packages\nptdms\writer.py", line 88, in __init__
    paths = set(obj.path for obj in objects)
  File "C:\Anaconda2\lib\site-packages\nptdms\writer.py", line 88, in <genexpr>
    paths = set(obj.path for obj in objects)
  File "C:\Anaconda2\lib\site-packages\nptdms\writer.py", line 254, in path
    self.channel.replace("'", "''"))
AttributeError: 'TdmsObject' object has no attribute 'replace'

0 个答案:

没有答案