2

我正在尝试从 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

谢谢!

4

1 回答 1

1

所以在找到这个问题之后: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)
于 2019-02-08T02:17:28.393 回答