wiki:CdatLite

Version 8 (modified by spascoe, 12 years ago) (diff)

--

CDAT-lite

cdat-lite is a simple repackaging of the I/O layer of the  Climate Data Analysis Tools (CDAT) as a Python Egg?. A short article on the reasons behind cdat-lite and some of the design decisions made can be found  here on  Stephen Pascoe's blog.

Features

  • Includes cdscan from the comand-line or from within python using the cdat_lite.scripts.cdscan module.
  • Includes the latest version of the British Atmospheric Data Centre's cdunifpp module which provides read access to UK Met. Office PP files.
  • Downloads and installs Numeric on demand. If you have Numeric installed already but the package doesn't have an egg-info directory easy-install will re-install Numeric for you unless you use the --no-deps switch.
  • Currently focused on providing NetCDF and PP format support. DRS, HDF and DODS (OpeNDAP) are disabled in the default egg build.

Package Overview

  • CDAT core packages:
    • cdms, cdtime, cdutil, genutil, Properties, regrid, unidata, xmgrace These top-level packages can be used in the same way you would with a full CDAT installation. E.g.
      >>> import cdms
      >>> f = cdms.open('dataset.nc')
      
  • cdat_lite support packages: These packages support the cdat_lite egg installation.
    • cdat_lite.clib: libraries and headers used to build CDAT source: libcdms and libnetcdf.
    • cdat_lite.scripts: contains a version of cdscan suitable for declaring as a setuptools entry-point. During installation easy-install will create a stub script to execute cdscan on the command line
    • cdat_lite.test: contains a test suite.

Installation

Cdat-lite uses  easy_install as it's installation mechanism. This makes downloading and installing the software a one-step process, once you've installed the  setuptools package (itself very easy to install).

Binary eggs and the source tarball of cdat_lite are available from http://ndg.nerc.ac.uk/dist. It is also registered at the  Python Cheeseshop so should be discovered automatically by easy_install.

  1. Start with a python 2.4+ installation with distutils. You cannot build or run the egg without distutils. If your python has been installed by a unix package manager then you may have to install the python-devel package. To check you've got distutils type the following at the Python prompt:
    >>> import distutils
    >>>
    
  2. Install  setuptools. This includes the easy_install script. The setuptools website has detailed installation instructions but if you have write-permission to your python installation the following should work:
    $ wget http://peak.telecommunity.com/dist/ez_setup.py
    $ python ez_setup.py
    
  3. Now your ready to install cdat_lite. Simply type:
    $ easy_install cdat_lite
    
  4. Alternatively, if you want to install into a local directory $EGG_DIR, ensure $EGG_DIR exists and is on your $PYTHONPATH then type:
    $ easy_install -d $EGG_DIR cdat_lite
    
  5. For more installation options see the  easy_install documentation

Versioning

cdat-lite versioning is complicated as it is a repackage of CDAT with an updated cdunifpp module. There are therefore 3 version numbers to consider: CDAT, cdunifpp and cdat-lite. Once we start using versions of CDAT from the PCMDI SVN the version string could become very long indeed therefore the following strategy is used:

  1. Eggs are quoted with the version: <cdat-release>-<cdat-lite-version>
  2. If a PCMDI SVN version of CDAT is used it is stated in long_description not in <cdat-release>.
  3. The cdunifpp version is stated in long_description not in the version. Any change to the cdunifpp version naturally triggers a new <cdat-lite-version>.

Using CDMS scripts

cdat_lite includes the libcdms script cdscan within the egg. You have several options to get at it.

The stub script

When you install the egg with easy_install a script stub is created automatically which calls cdscan within the egg. Therefore you should be able to use cdscan as usual. If you've installed the egg in a local directory the script stub will be in that directory.

Import cdscan as a module from within python

>>> import cdat_scripts.cdscan as cdscan
>>> cdscan.main(['cdscan', '-x', 'dataset.xml', filename, ...])

The argument to main() must be the equivilent of sys.argv when run from the command line, i.e. the first element should be a pseudo command name.

Import a cdscan entry point using the pkg_resources API.

This is the way scripts are supposed to be found from within eggs and is used by easy_install to automatically create script stubs.

>>> import pkg_resources
>>> cdscan = pkg_resources.load_entry_point('cdat_lite', 'console_scripts', 'cdscan')
>>> cdscan()

In this case sys.argv must be set to the arguments you want.