cdo supress original global attributes when run from subprocess python
Added by Olivier Titaud almost 5 years ago
Dear all,
I get different behavior of cdo when I run the following command direclty in the shell or from a python subprocess call: in the second case, the origina global attributes of the input file are not conserved and are replaced by those of cdo.
1. The shell command:
cdo --history -O -z zip_4 sellonlatbox,-180,180,-90,90 infile.nc outfile.nc
2. The same command but from python
command_line = "cdo --history -O -z zip_4 sellonlatbox,-180,180,-90,90 infile.nc outfile.nc"
args = shlex.split(command_line)
p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE)
out,err = p.communicate()
4. original global attributes of infile.nc
// global attributes: :title = "Gobal ocean low trophic levels biomass" ; :Conventions = "CF-1.4" ; :resolution = "008x1d" ; :domain = "global" ; :history = "Created on 2020-03-26" ; :date_field = "19980101" ;
5. global attributes of outfile.nc when cdo is run from the shell directly:
// global attributes: :CDI = "Climate Data Interface version 1.7.2 (http://mpimet.mpg.de/cdi)" ; :history = "Created on 2020-03-26" ; :Conventions = "CF-1.4" ; :title = "Gobal ocean low trophic levels biomass" ; :resolution = "008x1d" ; :domain = "global" ; :date_field = "19980101" ; :CDO = "Climate Data Operators version 1.7.2 (http://mpimet.mpg.de/cdo)" ;
6. global attributes of outfile.nc when cdo is run from a python subprocess call:
// global attributes: :CDI = "Climate Data Interface version 1.7.2 (http://mpimet.mpg.de/cdi)" ; :Conventions = "CF-1.4" ; :CDO = "Climate Data Operators version 1.7.2 (http://mpimet.mpg.de/cdo)" ;
Any idea ?
Best regards,
Olivier
Replies (3)
RE: cdo supress original global attributes when run from subprocess python - Added by Ralf Mueller almost 5 years ago
hi Oliver!
I can just guess here, but it could be that your shell environment holds additional values not present when using cdo through a python subprocess. if you upload the input, I could do more checks on my own, though
cheers
ralf
RE: cdo supress original global attributes when run from subprocess python - Added by Olivier Titaud almost 5 years ago
It is not the good file !
Sorry. Here is the good one.
Can we delete messages in this forum ?
Thanks,
Olivier
RE: cdo supress original global attributes when run from subprocess python - Added by Ralf Mueller almost 5 years ago
I can delete them, no problem