wiki:CdatLite

Version 3 (modified by spascoe, 13 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?.

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 [entry-points]. During installation easy-install will create a stub script to execute cdscan on the command line
    • cdat_lite.test: contains a test suite.

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.

Installation

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.
  2. Install  setuptools. This includes the easy_install script.
  3. 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 no

t in <cdat-release>.

  1. The cdunifpp version is stated in long_description not in the version. An

y change to the cdunifpp version naturally triggers a new <cdat-lite-version

.

Testing the installation

A small set of unit tests are included with in the cdat_lite egg for verifying the installation is working. To run the tests do:

>>> from cdat_lite import test
>>> test.main()
......cdat_lite/test/testpp.pp is a 32-bit PP-file
.
----------------------------------------------------------------------
Ran 7 tests in 0.553s

OK

Of course you may uncover a bug not tested for. If so please email Stephen Pascoe

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.