【问题标题】:Reading tdms files with python and notebook på Azure使用 python 和 notebook 读取 tdms 文件 på Azure
【发布时间】:2021-07-05 08:48:22
【问题描述】:

我正在尝试将 tdms 文件从一个 Azure 数据湖读取到另一个数据湖,并同时将它们转换为镶木地板。我设法在 Azure 数据工厂中安装包 nptdms 并运行下面的代码行

  1. 从 nptdms 导入 TdmsFile

但我不知道如何在第二个或第三个代码行中给出值 path_to_file。
2. tdms_file = TdmsFile.read("path_to_file.tdms") Azure 数据湖中的每个文件都有一个 URL 作为文件路径,格式如下: https://xxxyyy.blob.core.windows.net/name_of_file.tdms

它没有工作。我相信 nptdms 包只是为本地编写的,它不适用于云语法

我想知道有没有人可以分享在 Azure 平台上阅读 tdms.files 的经验。

【问题讨论】:

  • 您必须使用urllib.request.urlopen 访问网址。
  • 嗨@NizamMohamed,非常感谢您的帮助。当我的文件在 Azure 中具有如下 URL 时,您将如何重写我的 tdms_file = TdmsFile.read("path_to_file.tdms"):xxxyyy.blob.core.windows.net/name_of_file.tdms?你用 nptdms 包让它工作了吗?

标签: python


【解决方案1】:

由于文件可能较大,您应该下载并将其存储在一个临时文件中,以便您可以将文件路径传递给TdmsFile.openTdmsFile.read

tmp_file.name 是它的路径。

from shutil import copyfileobj
from urllib.request import urlopen
from tempfile import NamedTemporaryFile
from nptdms import TdmsFile


with urlopen('http://www-personal.acfr.usyd.edu.au/zubizarreta/f/exampleMeasurements.tdms') as response:
    with NamedTemporaryFile(delete=False) as tmp_file:
        copyfileobj(response, tmp_file)

tdms_file = TdmsFile.open(tmp_file.name)


for group in tdms_file.groups():
    group_name = group.name
    print(f'Group name: {group_name}')
    for channel in group.channels():
        channel_name = channel.name
        print(f'Channel name: {channel_name}')

【讨论】:

  • 您好 Nizam,我测试了您的代码,它按您说的那样工作。但我的问题是我的文件位于 Azure 上的文件共享中,当我使用从文件共享中获得的 URL 进行尝试时,使用 urlopen('storageaccountname.file.core.windows.net/fileshare/…) 作为响应:使用 NamedTemporaryFile(delete=False) 作为 tmp_file: copyfileobj(response , tmp_file) 它失败并显示以下消息:HTTP 错误 400:HTTP 标头之一的值格式不正确。您是否尝试过使用 Azure 文件共享?我做错什么了?你有更好的方法吗?
  • Azure 文件共享需要身份验证。你最好使用 Python SDK。看到这个问题stackoverflow.com/questions/49874783/…
猜你喜欢
  • 2018-06-11
  • 2014-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 2019-08-04
相关资源
最近更新 更多