Difference between revisions of "PyCDF"

From SourceWiki
Jump to navigation Jump to search
Line 55: Line 55:
  
 
The next time you open a new shell, your '''PYTHONPATH''' will be set automatically, and you won't need to bother with all that '''source ..''' malarky.
 
The next time you open a new shell, your '''PYTHONPATH''' will be set automatically, and you won't need to bother with all that '''source ..''' malarky.
 +
 +
=Checking that it Works=
 +
 +
OK, let's make sure that everything is hunky dori.  Move back to your home directory and start python:
 +
 +
<pre>
 +
cd
 +
python
 +
</pre>
 +
 +
You'll see a prompt such as:
 +
 +
<pre>
 +
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
 +
[GCC 4.3.3] on linux2
 +
Type "help", "copyright", "credits" or "license" for more information.
 +
>>>
 +
</pre>
 +
 +
Now, import the module, by typing:
 +
 +
<pre>
 +
import pycdf
 +
</pre>
 +
 +
If you get no errors, all is well.

Revision as of 21:00, 12 August 2009

PyCDF: a handy python module you'll need

Introduction

This is a module that you will need when you come to the exercise when you add a module to GLIMMER-CISM. It's not available through the Ubuntu package manager, so you will install it yourself into your own filespace.

Compiling the Module

OK, first thing's first, let's get the source code. Open a terminal, stay in (move to) your home directory and cut and paste the following:

wget http://sourceforge.net/projects/pysclint/files/pycdf/pycdf-0.6.3b/pycdf-0.6-3b.tar.gz/download

Now, we'll unpack the tarball, and move into the appropriate directory:

tar -xzf pycdf-0.6-3b.tar.gz
cd pycdf-0.6-3b

You will need to edit the file called setup.py to reflect where you installed your NetCDF libraries:

elif USE == NUMPY:
    from numpy.distutils.misc_util import get_numpy_include_dirs
    _pycdf_ext = Extension(extName,
                           sources   = CCode,
                           #library_dirs=["non standard path where libs live"],                       
                           library_dirs=["/home/PSU/pdx05933/installs/netcdf-4.0.1/lib"],
                           include_dirs = get_numpy_include_dirs(),
                           libraries = ["netcdf"])

Once you've done that, you can compile and install the module with the command:

python setup.py install --prefix=~/py

Setting your PYTHONPATH

We will need to make the new module available to your python installation. A good way to do this is to add the following to your shell start-up file, called ~/.bashrc (the ~ indicating that the file is in your home directory):

export PYTHONPATH=$PYTHONPATH:$HOME/py/lib/python2.6/site-packages

then, in order to re-read that start-up file, you will need to type:

source ~/.bashrc

The next time you open a new shell, your PYTHONPATH will be set automatically, and you won't need to bother with all that source .. malarky.

Checking that it Works

OK, let's make sure that everything is hunky dori. Move back to your home directory and start python:

cd
python

You'll see a prompt such as:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Now, import the module, by typing:

import pycdf

If you get no errors, all is well.