illing2005 / cdo-bindings

Language bindings for CDO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cdo.{rb,py} - Use Ruby/Python to access the power of CDO

This package contains the module Cdo, which implements a ruby/python style access to the Climate Data operators CDO. CDO is a command line tool for processing gridded data. Its main focus if climate data, but it can by used for other purposes to. It accepts input formats GRIB1, GRIB2, NetCDF and several Fortran binary formats.

Installation

Ruby Installation

Download and install cdo.rb via rubygems:

gem install cdo

Python Installation

Download and install cdo.py via pypi:

pip install cdo

Requirements

Cdo.{rb,py} requires a working CDO binary, but has not special requirement to ruby or python. For returning multi-dimensional arrays (numpy for python, narray for ruby) addtional netcdf-io modules are needed. These are scipy/netcdf4 for python and ruby-netcdf for ruby.

Usage

Run operators

The Ruby module can be used directly after loading it. For python an instance has to be created first

cdo = Cdo()
  • File information

    Cdo.infov(:input => ifile)       (ruby)
    Cdo.showlevels(:input => ifile)
    
    cdo.infov(input=ifile)         (python)
    cdo.showlevels(input=ifile)
  • Operators with user defined regular output files

    Cdo.timmin(:input => ifile ,:output => ofile) (ruby)
    cdo.timmin(input = ifile,output = ofile)    (python)
  • Use temporary output files

    tminFile = Cdo.timmin(:input => ifile) (ruby)
    tminFile = cdo.timmin(input = ifile) (python)
  • Operators with options

    Cdo.remap([gridfile,weightfile],:input => ifile, :output => ofile) (ruby)
    cdo.remap([gridfile,weightfile],input => ifile, output => ofile) (python)
  • Set global CDO options

    Cdo.copy(:input => ifile, :output => ofile,:options => "-f nc4") (ruby)
    cdo.copy(input = ifile, output = ofile,options = "-f nc4")     (python)
  • Set environment variables

    Cdo.splitname(:input => ifile.join(' '), :output => 'splitTag',:env {'CDO_FILE_SUFFIX' => '.nc'}) (ruby)
    or Cdo.env = {'CDO_FILE_SUFFIX' => '.nc'}
    cdo.splitname(input = ' '.join(ifiles) ,  output =  'splitTag', env={"CDO_FILE_SUFFIX": ".nc"})   (python)
    or Cdo.env = {'CDO_FILE_SUFFIX': '.nc'}
  • Return multi-dimension arrrays

    temperatures = Cdo.fldmin(:input => ifile,:returnArray => true).var('T').get   (rb, version < 1.2.0)
    temperatures = cdo.fldmin(input = ifile,returnArray = True).variables['T'][:] (py, version < 1.2.0)
    temperatures = Cdo.fldmin(:input => ifile,:returnCdf => true).var('T').get    (rb, version >= 1.2.0)
    temperatures = cdo.fldmin(input = ifile,returnCdf = True).variables['T'][:]   (py, version >= 1.2.0)*
    temperatures = Cdo.fldmin(:input => ifile,:returnArray => 'T')                (rb, version >= 1.2.0)
    temperatures = cdo.fldmin(input = ifile,returnArray = 'T')                   (py, version >= 1.2.0)

*) If you use scipy >= 0.14 as netcdf backend, you have use following code instead to avoid possible segmentation faults:

cdf = cdo.fldmin(input = ifile,returnCdf = True)
temperatures = cdf.variables['T'][:]

More examples can be found in test/cdo-examples.rb and on the homepage: code.zmaw.de/projects/cdo/wiki/Cdo%7Brbpy%7D

Tempfile helpers

Cdo.{rb,py} includes a simple tempfile wrapper, which make live easier, when write your own scripts

Support, Issues, Bugs, …

Please use the forum or ticket system of CDOs official web page: code.zmaw.de/projects/cdo

Changelog

  • next:

    - return arrays/lists of output files, which are created by split* operators
      suggestion from Karl-Hermann Wieners
  • 1.3 (upcomming)

    - require ruby-2.*
    - support object interface in the ruby version (easy setup of options during initializaion, thread safety)
    - allow environment variables set with external JSON file
  • 1.2.7

    - Added class interface for ruby version 2.x
  • 1.2.6

    - bugfix for autocompletion in interactive usage [python-only]
  • 1.2.5

    - bugfix for environment handling (Thanks philipp) [python-only]
    - add logging [ruby-only]
  • 1.2.4

    - support python3: Thanks to @jhamman
    - bugfix for scipy: Thanks to @martinclaus
    - docu fixes: Thanks to @guziy
    - allow environment setting via call and object construction (see test_env in test_cdo.py)
  • 1.2.3

    - bugfix release: adjust library/feature check to latest cdo-1.6.2  release
  • 1.2.2

    - allow arrays in additions to strings for input argument
    - add methods for checking the IO libraries of CDO and their versions
    - optionally return None on error (suggestion from Alex Loew, python only)
  • 1.2.1:

    - new return option: Masked Arrays
      if the new keyword returnMaArray is given, its value is taken as variable
      name and a masked array wrt to its FillValues is returned
      contribution for python by Alex Loew
    - error handling: return stderr in case of non-zero return value + raise exception
      contribution for python from Estanislao Gonzalez
    - autocompletion and built-in documentation through help() for interactive use
      contribution from Estanislao Gonzalez [python]
    - Added help operator for displaying help interactively [ruby]
  • 1.2.0: API change:

    - Ruby now uses the same keys like the python interface, i.e. :input and :output
      instead of :in and :out
    - :returnArray will accept a variable name, for which the multidimesional
      array is returned
  • 1.1.0: API change:

    - new option :returnCdf : will return the netcdf file handle, which was formerly
      done via :returnArray
    - new options :force : if set to true the cdo call will be run even if the given
      output file is presen, default: false

License

Cdo.{rb,py} makes use of the GPLv2 License, see COPYING


Other stuff

Author

Ralf Mueller <stark.dreamdetective@gmail.com>

Requires

CDO version 1.5.x or newer

License

Copyright 2011-2015 by Ralf Mueller Released under GPLv2 license. See the COPYING file included in the distribution.

About

Language bindings for CDO

License:GNU General Public License v2.0


Languages

Language:Jupyter Notebook 74.0%Language:Ruby 15.7%Language:Python 10.3%