Project

General

Profile

Problem using cdo.py in Cygwin

Added by Joey Molenk over 6 years ago

Dear All,

I have CDO (v 1.9.0) for Cygwin. It works properly in the Cygwin shell.

However, when using CDO.py (1.3.5) in python (v 2.7.8) I get the error described below.
I included in the python script some lines for getting information about the version and operators. This seems to be OK, but the output operators list is empty.

I have a Windows 10 PC with 64-bit system.

Script:

from cdo import *
cdo = Cdo()

print(cdo.__version__())
print(cdo.version())
print(cdo.operators[0:10])

cdo.debug=True

ifile = "/cygdrive/e/works/tas.nc" 
cdo.info(input=ifile)

This is the output:

1.3.5
1.9.0
[u'abs']
# DEBUG - start =============================================================
CALL  :cdo -h info
STDOUT:
STDERR:
'cdo' is not recognized as an internal or external command,
operable program or batch file.

# DEBUG - end ===============================================================
Traceback (most recent call last):
  File "test1_forum.py", line 11, in <module>
    cdo.info(input=ifile)
  File "C:\Python27\ArcGIS10.3\lib\site-packages\cdo.py", line 299, in __getattr__
    raise AttributeError("Unknown method '" + method_name +"'!")
AttributeError: Unknown method 'info'!

I tested other cdo commands and the result is always the same.

Any advice will be greatly appreciated.

Joey


Replies (5)

RE: Problem using cdo.py in Cygwin - Added by Karin Meier-Fleischer over 6 years ago

Hi Joey,

I'm sorry I don't have Cygwin but running your script with some test data works well.

from cdo import *

ifile = "rectilinear_grid_2D.nc" 

cdo = Cdo()     #-- make it easier

print(cdo.__version__())
print(cdo.version())
print(cdo.operators[0:10])

cdo.debug=True

cdo.info(input=ifile)
> py cdo_python_test.py 
1.3.3
1.9.2
[u'abs', u'acos', u'add', u'addc', u'adipot', u'adisit', u'aexpr', u'aexprf', u'after', u'afterburner']
# DEBUG - start =============================================================
CALL  :cdo -h info
STDOUT:
NAME
    info, infon, map - Information and simple statistics

SYNOPSIS
    <operator>  infiles

DESCRIPTION
    This module writes information about the structure and contents 
    of all input files to standard output.  All input files need to have 
    the same structure with the same variables on different timesteps.
    The information displayed depends on the chosen operator.

OPERATORS
    info   Dataset information listed by parameter identifier
           Prints information and simple statistics for each field of all
           input datasets. For each field the operator prints one line with 
           the following elements:
           - Date and Time
           - Level, Gridsize and number of Missing values
           - Minimum, Mean and Maximum \
           The mean value is computed without the use of area weights!
           - Parameter identifier
    infon  Dataset information listed by parameter name
           The same as operator info but using the name instead of the
           identifier to label the parameter.
    map    Dataset information and simple map
           Prints information, simple statistics and a map for each field of all input
           datasets. The map will be printed only for fields on a regular lon/lat grid.

STDERR:
# DEBUG - end ===============================================================
Found method:info
# DEBUG - start =============================================================
CALL  :cdo -O info rectilinear_grid_2D.nc
STDOUT:
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
     1 : 2001-01-01 00:00:00       0    18432       0 :      221.79      276.76      313.94 : 169.128       
     2 : 2001-01-01 00:00:00       0    18432       0 :  1.4714e-18  2.7047e-05  0.00098652 : 4.128     
........

-Karin

RE: Problem using cdo.py in Cygwin - Added by Ralf Mueller over 6 years ago

this is a strange error because the cdo binary seems to work. Could you rerun it with

cdo.debug = True
being set as early as possible like
from cdo import *
cdo = Cdo()
cdo.debug=True
print(cdo.__version__())
print(cdo.version())
print(cdo.operators[0:10])

RE: Problem using cdo.py in Cygwin - Added by Ralf Mueller over 6 years ago

you seem to use a native windows-version of python (C:\Python27\ArcGIS10.3\lib\site-packages) within the cygwin-environment. TBH, I would not do this. Since the cdo binary works, I guess the reason for that error is the the native python cannot execute the cygwin binary. it seem to work partly because operators can be listen (cdo.operators).

I cross-checked with

  • a fresh win10 and cygwin
  • python2 and python2-pip from cygwin
  • installed cdo bindings with pip
  • extracted the cdo.exe into C:/cygwin64/bin/

script works fine with that. so my recommondation is: use cygwin packages as much as possible.

hth
ralf

RE: Problem using cdo.py in Cygwin - Added by Joey Molenk over 6 years ago

Dear Ralf,

Thank you for your reply.
Yes, that was the reason why cdo.py was not working properly.

In any case, after some editing in the cdo.py from an expert python colleague it works fine with my python 2.7 for windows.

Kind regards and many thanks for the support,

Joey

RE: Problem using cdo.py in Cygwin - Added by Ralf Mueller over 6 years ago

thx for letting me know - would be great if you could share how you set it up to work in that setup. Might be of value for others,too.

best wishes
ralf

    (1-5/5)