Skip to main content
 首页 » 编程设计

python之士官/pynco : ncea can't find files from within Python

2024年11月24日13findumars

我正在尝试从 python 中运行 ncea,以根据多年数据的每日文件计算月平均值。

命令:

ncea -v analysed_sst,sea_ice_fraction /mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc 200301-gp-monthly.nc 

在终端中运行良好。

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

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 

我也试过:

nco.ncea(input="/mnt/r01/data/goes-poes_ghrsst/daily/200301*.nc",output=monthly_file).variables['analysed_sst','sea_ice_fraction'] 

并得到同样的错误。

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

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

例如:

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 

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

input_string="file1,file2" 
input_string="file1 file2" 
input_string="file1\ file2" 

如果我改用列表,比如 glob.glob 会返回什么:

input_string=["file1","file2"] 

我得到:

TypeError: expected str, bytes or os.PathLike object, not list 

谢谢!

请您参考如下方法:

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

我终于明白了:

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)