Project

General

Profile

CDO and Julia - Watch out, Romeo!

Added by Ralf Mueller over 3 years ago

hi folks!

Some people have asked me if CDO can be used from Julia. So here is a little summary of how to do this.

First of all: It works pretty much the same way as it works with Python and Ruby. And as a bonus (for me) I don't have to write anything new. Instead the PyCall module can be used to load the installed python bindings like this

using PyCall                                                                                                     
pycdo = pyimport("cdo")                                                                                          
cdo   = pycdo.Cdo()

cdo is an object very similar to the python version. Like many Julia packages PyCall can be installed with
import Pkg
Pkg.add("PyCall")

Now you can use the cdo object the usual way:
cdo.topo("global_5", options = "-f nc", output="t.nc")
"t.nc" 

cdo.outputkey("value",input="-stdatm,0,10000")
5-element Array{String,1}:
 "#   value" 
 "1013.25" 
 "271.9125" 
 "288" 
 "240.591" 

In addition the option to return numpy or xarray arrays is still present because PyCall developers took this into account:

numpy_data  = cdo.topo(returnArray="topo")
xarray_data = cdo.topo(returnXArray="topo")                                                                     

# or in a chain:
cdo.setrtomiss(-100000,0,input="-expr,'logTopo=log(abs(topo)+0.1)' -topo,r10x10", returnArray="logTopo")

For more, please refer to the official docu of CDO and have a look at the python related tests. That should provide a good insight in what you can to with it.

Don't hesitate to ask right here!

cheers + bye, Romeo!
ralf