wiki:CdatLite

Version 9 (modified by spascoe, 11 years ago) (diff)

--

WATCH THIS SPACE

cdat_lite-5.0 will be available soon. Below are some notes on what the new version will bring or go straight to the 4.3 documentation

cdat_lite-5.0

Version 5.0 of cdat_lite introduces many changes.

  1. It is built directly from the CDAT-5.0 codebase and version numbers are completely synchronised. CDAT-5.0 requires Python-2.5 and uses numpy rather than Numeric. See Upgrading for what you need to do to your code.
  2. It is now only distributed as a tarball. Binary distributions tended to run into library version conflicts on different versions of linux. However easy_install should still be able to compile the package automatically. See Installing. Also you can make your own binary eggs for given OSes.
  3. You now need to have the netcdf library pre-installed. Automatically building netcdf wasn't portable enough.

Installing

First satisfy a couple of dependencies.

Make sure you have the  netcdf libraries installed. If they are in a non-standard location make a note of it (you will be prompted) or set NETCDF_DIR to it's installation prefix.

Install numpy. If you aren't bothered about linear algebra optimisation this usually works with easy_install. E.g.

$ easy_install numpy

Now you are ready to install cdat_lite. On many linux systems the C compiler is incorrectly detected therefore it is safest to do:

$ CC=gcc easy_install cdat_lite

Advanced Installation

You might want more control over the installation process but you can still get easy_install to download the tarball for you:

$ easy_install -eb <dir> cdat_lite

This will download and unpack the tarball into <dir> then you can run the setup.py script directly or build a binary egg for installation elsewhere.

CDAT-lite 4.3

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.