Screen information using CDO in Python
Added by Joey Molenk almost 9 years ago
Dear All,
I'm running a python script in cygwin. The script runs well, but I'm not getting the usual information provided by CDO commands e.g. "cdo(2) selyear: Started child process "setgrid,BC_rot_pole tas_2011_2070.nc (pipe2.1)"
I tried using debug mode, but the information provided is not the same.
Please, could someone let me know what is the option needed for displaying the information?
Thank you in advance,
Joey
Replies (8)
RE: Screen information using CDO in Python - Added by Ralf Mueller almost 9 years ago
Could you provide the script or the call?
RE: Screen information using CDO in Python - Added by Joey Molenk almost 9 years ago
Yes, this is the core part of the script:
import cdo
from cdo import *
cdo = Cdo(logging=True, logFile='cdo_commands.log')
cdo.ymonmean(input = "-selyear,2021/2050 -setgrid,mygrid_BC_rot_pole " + ifile, output = ofile)
Thank you,
Joey
RE: Screen information using CDO in Python - Added by Ralf Mueller almost 9 years ago
I also need the input file, the gridfile mygrid_BC_rot_pole
and the release version of CDO
I did a quick test with cdo-1.7.1/cdo.py-1.3.0
from cdo import *
cdo = Cdo(logging=True, logFile='cdo_commands.log')
ifile = '-settaxis,2000-01-01,0,1years -for,1,5000' # this emulates a yearly data set of 5000 years
cdo.yearmonmean(input="-selyear,2021/2050 "+ifile,output = 'ofile')
This runs without error and the ofile contains of
ram@luthien:~ cdo sinfov ofile [15:10:59|16-04-11] File format : GRIB -1 : Institut Source Steptype Levels Num Points Num Dtype : Parameter name 1 : unknown unknown instant 1 1 1 1 P0 : var1 Grid coordinates : 1 : lonlat : points=1 (1x1) lon : 0 degrees_east lat : 0 degrees_north Vertical coordinates : 1 : surface : levels=1 Time coordinate : unlimited steps YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss 2021-01-01 00:00:00 2022-01-01 00:00:00 2023-01-01 00:00:00 2024-01-01 00:00:00 2025-01-01 00:00:00 2026-01-01 00:00:00 2027-01-01 00:00:00 2028-01-01 00:00:00 2029-01-01 00:00:00 2030-01-01 00:00:00 2031-01-01 00:00:00 2032-01-01 00:00:00 2033-01-01 00:00:00 2034-01-01 00:00:00 2035-01-01 00:00:00 2036-01-01 00:00:00 2037-01-01 00:00:00 2038-01-01 00:00:00 2039-01-01 00:00:00 2040-01-01 00:00:00 2041-01-01 00:00:00 2042-01-01 00:00:00 2043-01-01 00:00:00 2044-01-01 00:00:00 2045-01-01 00:00:00 2046-01-01 00:00:00 2047-01-01 00:00:00 2048-01-01 00:00:00 2049-01-01 00:00:00 2050-01-01 00:00:00
The command log has only a single line
2016-04-11 15:07:32,643 - INFO - cdo yearmonmean -selyear,2021/2050 -settaxis,2000-01-01,0,1years -for,1,5000 ofile
RE: Screen information using CDO in Python - Added by Joey Molenk almost 9 years ago
Dear Ralf,
My script runs without errors.
The problem is that when running on Python the information that would be printed by cdo in the console screen when running on sh is not printed.
Thus, I don't know if there are warning, errors or other messages from CDO during the running of the script. Running on Python the script ends successfully BUT without providing any information. For instance, if I use the command cdo.diff ifile1 ifile2 I don't get any information in the python screen.
CDO version 1.7.0
Python 2.7.10 (on cygwin)
Thank you for your time,
Joey
RE: Screen information using CDO in Python - Added by Ralf Mueller almost 9 years ago
do you use cdo.py version 1.3.0?
RE: Screen information using CDO in Python - Added by Ralf Mueller almost 9 years ago
Ok, I guess I now have understood your question.
All operators, which write to stdout (diff,show,info,...) return a list of strings in python.
For diff
this means: is the list is empty, the difference is zero. I uploaded a small test to illustrate this (doesn't need any input data).
If the command fails, you'll get an error message like this
cdo.ksjhdflkshgdf(input='-topo')
Traceback (most recent call last):
File "t.py", line 14, in <module>
cdo.ksjhdflkshgdf(input='-topo')
File "/home/ram/.local/lib/python2.7/site-packages/cdo.py", line 265, in __getattr__
raise AttributeError("Unknown method '" + method_name +"'!")
AttributeError: Unknown method 'ksjhdflkshgdf'!
shell returned 1
RE: Screen information using CDO in Python - Added by Ralf Mueller almost 9 years ago
debugging lines which usually go to stderr are omitted, only stdout is returned
RE: Screen information using CDO in Python - Added by Joey Molenk almost 9 years ago
Yes! With the "print" option the script produces the information, at least for the operators that write to stdout.
All the best and thank you,
Joey