NCO/pynco: ncea can't find files from within Python

213 views Asked by At

I am trying to run ncea from within python to make monthly averages from daily files over many years of data.

The command:

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

runs fine in the terminal.

But in Python, I get the following error:

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

I also tried:

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

and get the same error.

I can't figure out if this is an NCO problem or a Python thing.

I get the same error when I use only two files to see if the issue comes from the wildcard.

For example:

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

I can't figure out what the syntax should be. I get the same error if I do:

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

And if I try a list instead, like what glob.glob would return:

input_string=["file1","file2"]

I get:

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

Thanks!

1

There are 1 answers

0
melhawaii On

So after finding this question: Using all elements of a list as argument to a system command (netCDF operator) in a python code

I finally figured it out:

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)