gpt4 book ai didi

python-3.x - 从 Azure 文件存储读取 NetCDF 文件

转载 作者:行者123 更新时间:2023-12-03 03:07:34 25 4
gpt4 key购买 nike

我已将文件上传到我的 Azure 文件存储帐户并创建了 SAS(共享访问签名)。让我们假设有问题的文件名为 fileA.nc

现在,使用 Python3,我尝试读取 fileA.nc:

from netCDF4 import Dataset

url ='https://<my-azure-resource-group>.file.core.windows.net/<some-file-share>/fileA.nc<SAS-token>';
dataset = Dataset(url)

print(dataset.variables.keys())

上面的代码不起作用,而是给我以下错误:

Traceback (most recent call last): File "yadaYadaYada/test.py", line 8, in dataset = Dataset(url) File "netCDF4/_netCDF4.pyx", line 1848, in netCDF4._netCDF4.Dataset.init (netCDF4/_netCDF4.c:13983) OSError: NetCDF: Malformed or unexpected Constraint

这是第 8 行:

 dataset = Dataset(url)

我知道提供的 URL 有效。如果我将其粘贴到浏览器中,文件就会下载...

我已经检查了netCDF4 documentation ,其中写着:

Remote OPeNDAP-hosted datasets can be accessed for reading over http if a URL is provided to the Dataset constructor instead of a filename. However, this requires that the netCDF library be built with OPenDAP support, via the --enable-dap configure option (added in version 4.0.1).

但是,我不知道如何判断 Pycharms 安装 netcdf4 时是否使用了 --enable-dap 参数,但我无法想象为什么它不会。此外,如果我坚持指向某些 HTML 的 url,我会在错误转储中获取 HTML,因此我会认为 netcdf4 实际上正在尝试加载远程数据集,因此问题出在其他地方。

我非常感谢这里的一些帮助。也许有人知道另一个 Python 3 netCDF 库,它允许我从 Azure 加载数据集?

更新

好的,我现在可以 confirm python netcdf4 库确实启用了 --OPenDAP:

Hello again, netCDF4 1.0.4 with OpenDAP support is now available in the conda respoitory on Unix. To install: $ conda install netcdf4

  • Ilan

最佳答案

我已经找到解决办法了。事实证明,您无法直接从 Azure 文件共享读取数据,即使当您将链接粘贴到浏览器中的文件时,文件就会开始下载。

我需要做的是在我的操作系统上安装文件共享。就我而言,我使用的是 Windows,但也可以使用 Linux 来完成。应相应修改以下代码,然后将其放入命令提示符中:

net use <drive-letter>: \\<storage-account-name>.file.core.windows.net\<share-name>

example :
net use z: \\samples.file.core.windows.net\logs

安装文件共享后,您可以从中读取数据,就像它是外部 HDD 一样。您可能需要添加权限,但我没有。

以下是安装文件共享的文档链接:Documentation

关于python-3.x - 从 Azure 文件存储读取 NetCDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43034037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com