首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NCO/pynco: ncea无法从Python中找到文件

NCO/pynco: ncea无法从Python中找到文件
EN

Stack Overflow用户
提问于 2019-02-08 05:11:15
回答 1查看 126关注 0票数 2

我正在尝试从python内部运行ncea,从多年的数据中获取每日文件的月平均值。

命令:

代码语言:javascript
复制
ncea -v analysed_sst,sea_ice_fraction /mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc 200301-gp-monthly.nc

在终端上运行良好。

但在Python中,我得到了以下错误:

代码语言:javascript
复制
call(["ncea","-v","analysed_sst,sea_ice_fraction","/mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc",monthly_file])
ncea: ERROR file /mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc neither exists locally nor matches remote filename patterns

我也试过了:

代码语言:javascript
复制
nco.ncea(input="/mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc",output=monthly_file).variables['analysed_sst','sea_ice_fraction']

并得到相同的错误。

我不知道这是NCO的问题还是Python的问题。

当我只使用两个文件来查看问题是否来自通配符时,我得到了相同的错误。

例如:

代码语言:javascript
复制
input_string="/mnt/r01/data/goes-poes_ghrsst/daily/20030201000000-STAR-L4_GHRSST-SSTfnd-Geo_Polar_Blended_Night-GLOB-v02.0-fv01.0-0-360.nc /mnt/r01/data/goes-poes_ghrsst/daily/20030202000000-STAR-L4_GHRSST-SSTfnd-Geo_Polar_Blended_Night-GLOB-v02.0-fv01.0-0-360.nc"


call(["ncea","-v","analysed_sst,sea_ice_fraction",input_string,monthly_file])
ncea: ERROR file /mnt/r01/data/goes-poes_ghrsst/daily/20030201000000-STAR-L4_GHRSST-SSTfnd-Geo_Polar_Blended_Night-GLOB-v02.0-fv01.0-0-360.nc,/mnt/r01/data/goes-poes_ghrsst/daily/20030202000000-STAR-L4_GHRSST-SSTfnd-Geo_Polar_Blended_Night-GLOB-v02.0-fv01.0-0-360.nc neither exists locally nor matches remote filename patterns

我不知道语法应该是什么。如果我这样做,我会得到相同的错误:

代码语言:javascript
复制
input_string="file1,file2"
input_string="file1 file2"
input_string="file1\ file2"

如果我尝试使用列表,就像glob.glob返回的那样:

代码语言:javascript
复制
input_string=["file1","file2"]

我得到了:

代码语言:javascript
复制
TypeError: expected str, bytes or os.PathLike object, not list

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2019-02-08 10:17:28

所以在找到这个问题之后:Using all elements of a list as argument to a system command (netCDF operator) in a python code

我终于想通了:

代码语言:javascript
复制
input_string="/mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc"
monthly_file="200301-gp-monthly.nc"
list1=['ncea','-v','analysed_sst,sea_ice_fraction']
list2=glob.glob(input_string)
command=list1+list2+[monthly_file]
subprocess.run(command)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54582350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档