What is Python, and why are we so enthusiastic about it?

Return to CSC Home

Flexible climate modeling requires two things: a well designed toolkit, and a package allowing easy assembly of the tools into a complete model. We have adopted Python as our means of building models from their components.

Python is an object oriented interpreted language. If you know what c++ is, you won't be far wrong if you think of Python as a simplified and interpreted version of c++ with all the hard parts and gotchas left out -- but with most of the power left in. "Interpreted" means you don't need to compile in order to run something. You just type a command, and get instant gratification. Or, if something is wrong, you know right away.

Python has several compelling advantages. The first is that it is object oriented, but very easy to learn. This means that neophyte programmers, or tough and hardened climate modellers from the Fortran world, can gain an easy and pleasant entry into the world of modern software development methods. It is literally possible to gain a useful command of Python, including basic notions of classes and objects, in about two hours. Unlike other simple languages, though, Python is not something you outgrow. It continues to become more and more useful as you learn more of it. Further, Python offers a nice blend of access to operating system services and powerful data structures, with mathematical orientation. This makes it ideal for complex tasks like building data structures for keeping track of task assignments on parallel computers such as Linux Beowulf clusters. Python has very deep support in the open source community, with many powerful extension modules already available and more on the way each day. There is already considerable experience in using Python in scientific problems.

Python is open source, and runs or can be made to run, on virtually any machine. Further, it is in the public domain, so that it can easily be used in classes and labs without incurring onerous licensing fees.

Python is being used as the common programming language for our advanced undergraduate and beginning graduate climate dynamics class (geosci 232). Check the course web page for examples of use of Python in class, in labs and in problem sets.

We have a number of Python modules under development for climate modeling and data analysis problems. As these become ready for prime time, you'll find them posted under the "Tools" section of our home page. Additional examples of the use of Python in climate dynamics and data analysis can be found on our "Projects" page. Although our original interest in Python stemmed from it's potential role as glue for building components into a general circulation model, as we gain more experience with the language we find more and more uses for it. We have used it for a range of idealized climate models, for data analysis, for building web pages, for running asynchronously coupled models, and as a versatile scripting language supplanting Perl and shell scripts.

Interpreted languages are great for flexibility, but are much slower than compiled code at numerically intensive tasks. This is where another of Python's desirable features come in. Python is very easily extensible. One can write c or c++ or Fortran code to do numerically intensive things like finding eigenvalues or timestepping an array, and then make these routines callable from within Python. Doing this by hand is tedious, but fortunately, there is an automated interface builder, known as SWIG, that makes it a snap to build Python modules out of compiled libraries. SWIG does not actually directly interface to Fortran. There is a solution for that, known as PyFort, but we have found it easier to stick with SWIG and write c-stubs for Fortran routines. More information on SWIG, together with downloads of the SWIG software, can be found at www.swig.org .

Python Resources

Our experiences in using Python in climate research are encapsulated in the Climate Systems Center Python Lectures, also listed on the Tutorial page.

There are many excellent books on Python. One that we find especially useful is our own David Beazley's book, Python Essential Reference (New Riders Publishing). Python 2.1 Bible, by Brueck and Tanner (Hungry Minds Publishing) is also very good. You can find many Python resources, and Python implementations for most of the world's operating systems (including Palm OS) at python.org.

Return to CSC Home