是否可以在FTP服务器上调用xarray open_mfdataset?

问题描述

我正在尝试下载北大西洋的每日海洋温度再分析产品(GLORYS2V4 from CMEMS),但是唯一的下载选项是使用大型(2GB)全局文件进行FTP访问。是否可以在FTP目录上使用open_mfdataset来获取我需要的子集,而无需将所有数据下载到本地计算机上?如果是这样,我该如何设置路径或网址?

当前,我正在连接到FTP,然后尝试为xarray提供url,但是它将URL解释为工作目录中的路径。例如。如果我只想为2000年1月1日打开一个文件

ftp = FTP("my.cmems-du.eu",username,password)
sample_directory = '/Core/GLOBAL_REANALYSIS_PHY_001_031/global-reanalysis-phy-001-031-grepv2-daily/2000/01'
ftp.cwd (sample_directory)

ftp_path = 'ftp://my.cmems-du.eu/Core/GLOBAL_REANALYSIS_PHY_001_031/global-reanalysis-phy-001-031-grepv2-daily/2000/01/grepv2_daily_20000101.nc'
ds = xr.open_dataset (ftp_path)

这将产生FileNotFoundError:[Errno 2] No such file or directory: b'U:\\Documents\\conda_dir\\ftp:\\my.cmems-du.eu\\Core\\GLOBAL_REANALYSIS_PHY_001_031\\global-reanalysis-phy-001-031-grepv2-daily\\2000\\01\\grepv2_daily_20000101.nc',其中“ U:\ Documents \ conda_dir”是我的工作目录。

解决方法

通常不会。我不知道该特定文件格式。即使您找到了可以使用该特定文件格式并可以用于远程FTP存储的库,也很难在不下载整个文件的情况下过滤内容。

唯一的例外是,如果格式具有某种索引(库可以下载该索引),找到文件所需的部分,然后仅下载这些部分。例如,通过这种方式,您可以download only some files from a remote ZIP archive。但是对于大多数文件格式,这是不可能的。

,

您将无法使用xarray通过ftp访问CMEMS数据。如果只想提取数据的空间子集,则最好使用Wekeo服务,该服务可以通过Python访问。在这里阅读:https://wekeo.eu/web/guest/home

您还可以使用motuclient:https://marine.copernicus.eu/faq/what-are-the-motu-and-python-requirements/