ROMS/TOMS Developers

Algorithms Update Web Log

kate - April 17, 2010 @ 16:17
Hacker’s Dream (Python for ROMS, part 0)- Comments (0)

A friend told me he can always count on me to do something outside the norm. All my colleagues use Matlab? Well, I can dream of a world in which we can do all the ROMS pre- and post-processing in an Open Source manner. I’ve played a bit with NCL and I really like some aspects of it. However, it doesn’t allow you to build tools that have a gui (graphical user interface). Grid generation and land-mask editing are two examples where a gui is really, really nice.

Rob Hetland and others have been working with Python to build up a toolbox for working with ROMS NetCDF files. Before we get to the tools, let’s talk about what they require:

  • Python itself. You will need a version between 2.4 and 2.6, inclusive. There is a newer 3.x series, but it is incompatible and therefore not to be trusted just yet.
  • numpy. Get a version that’s reasonably new, don’t count on the version 1.0.1 that you found already on the system. How do you tell the version? At the interactive prompt from python, type “import numpy” then “numpy.__version__”.
  • scipy.
  • matplotlib. This is a plotting package to reproduce the Matlab plotting, complete with everything you might not like about Matlab plotting. This also contains the gui tools, but it depends on an underlying gui package, be that tk, wx, X11, or qt. If it can’t find any of them, you are out of luck.
  • basemap. These are the map tools for Python, complete with etopo2 in the examples directory (user beware).
  • netCDF4. This sits on top of the hdf5 and netcdf4 libraries.
  • ipython. Fred Castruccio recommends using “ipython -pylab” for interactive fun. It preloads both numpy and the matplotlib pylab package.

So how does one go about acquiring all this stuff? There are choices, from a prebuilt package with everything from Enthought, to fetching each as a package for your OS, to building everything from scratch. I’ve honestly had a bit of a challenge for various reasons, but here are a few things I’ve learned:

  • Python 2.6.5 does not compile on the Mac with either gcc-4.0.1 or gcc-4.4.0, but requires gcc-4.5.0 to get around an internal compiler error when building the datetime module. Matplotlib will not load without datetime.
  • Python itself uses the “standard” method of “configure; make; make install”, but after that, all packages play by the Python rules.
  • The python rules are:
    1. In the directory of the package you want to install, type “python setup.py build”. This puts files into a local build directory.
    2. Type “python setup.py install” with an optional “–prefix={dir}” option.
    3. Type “python setup.py config” to see stuff like what guis matplotlib has found.
    4. If you use the optional non-standard directory, tell Python about it with the PYTHONPATH environment variable.
    5. If you want to link to packages that are themselves in a nonstandard place, use the environment variables CPPFLAGS=-I{dir} and LDFLAGS=-L{dir}. This adds to the list of places it will look – I don’t know how to take away from the list.
  • The Python package for Mac comes as a “universal binary”, working on both ppc and i386 architectures. That means that any other libraries that are involved, such as hdf5 and netcdf4, also have to be compiled this way or you will get an error.
  • If you get rough packages from Fred, make sure to delete the pre-existing build directory and any other binary object files you might find.

See? It really is a hacker’s dream, with fifty ways to mess up. 😉

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.