我正在尝试从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谢谢!
发布于 2019-02-08 10:17:28
所以在找到这个问题之后: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)https://stackoverflow.com/questions/54582350
复制相似问题