Mac OS X comes with Python already installed, but there are a number of packages that need to be added in order to make Python a power tool for atmospheric and oceanic sciences (AOS) users.
The Easy Way (Intel)
The easiest way is to install the Enthought Python Distribution (EPD), which bundles Python with over 75 modules and packages in an easy to install package. The distribution is free to employees and students of academic institutions, as is the trial version which is fully functional for 30 days. Commercial users have to pay money.
The Easy Way (Power PC)
If you don’t have an Intel Mac, you can find pre-compiled binaries for Python on a Power PC Mac at Pythonmac.org. There are a lot few packages available here, compared to EPD, and you’re looking at older version of Python and OS X.
The Almost as Easy Way
Jeff Whitaker has put together a “batteries included” Mac OS X Python distribution pre-installed with packages of interest to atmospheric and oceanic scientists. It requires git and Xcode, but that’s it! The README tells you all you need to know. Very nice!
The Not Quite as Easy But Still Fairly Easy Way
Although EPD is one-stop shopping, you might find it preferable to use a package manager (like fink, which I’ll assume you’re using in the rest of this post) to install Python and your desired packages. This way, you can use your package manager to access updates and manage your software. Also, since you won’t be downloading packages you aren’t interested in, it may install faster.
Your Core Installation
So what packages should you have? Of course, this depends upon what your needs are. Most AOS users will be fine starting out with a core set of numerical packages, a visualization suite, a input/output routines with core scientific data formats, and the ability to interface with Fortran. There are many packages (see the Packages pages for a more complete list) one can use to accomplish all these tasks, but here’s one set that works pretty well:
- The Python 2.5 interpreter: You can also use Python 2.6, but my own experience is that more of the packages I’m interested in are available for 2.5
- Matplotlib: A powerful 2-D plotting package
- Basemap: Map projection routines that work with matplotlib
- NumPy: The standards array processing package for Python
- SciPy: A robust suite of numerical functions
- PyTables: A very powerful dataset manager that includes routines for HDF access
- Scientific: One of the earlier scientific computing packages, but I like its netCDF interface
- f2py: Enables you to access Fortran routines and memory space, from Python
Mac OS X, unfortunately, does not come with fink installed. While we’re at it, it doesn’t come with the compilers you’ll need to build programs, and older versions of Mac OS X do not have X11 installed. Here’s how to fix this:
- X11: It comes installed with 10.5 and up. If you’re running 10.4, you’ll have to install it from the OS X CDs, otherwise you won’t be able to open plot windows.
- Compilers: Download XCode from Apple. You’ll have to register, but it doesn’t cost you anything.
- Fink: The fink installation instructions are quite good, and the installation FAQ covers nearly every circumstance you could encounter during installation. I installed fink from binary, and haven’t had any significant problems.
You will also need to configure fink to look into its unstable tree to find packages. While many of the packages you’ll need are now considered stable, some (e.g., Basemap) are not.
Once you have fink installed and configured, the following command-line sequence will install the packages needed for nearly all those functions:
fink --use-binary-dist install python25
fink --use-binary-dist install matplotlib-py25
fink --use-binary-dist install matplotlib-basemap-py25
fink --use-binary-dist install matplotlib-basemap-data-py25
fink --use-binary-dist install scipy-py25
fink --use-binary-dist install pytables-py25
fink --use-binary-dist install scientificpython-py25
Installing SciPy automatically gives you NumPy. And NumPy automatically includes f2py. The
--use-binary-dist flag looks for a pre-compiled binary, if available, and if not, does a source build.
Here are some other packages which, while not required to do the tasks described above, nonetheless help complete my scientific computing environment:
- epydoc: An automatic documentation generator for Python
- g95: A Fortran compiler; I’ve had better luck with g95 than gfortran, but that was quite a while ago, and so things might be different now
- Subversion: A nice version control system
- tetex: A TeX/LaTeX distribution
And here is the command-line sequence using fink that installed them:
fink --use-binary-dist install epydoc-py25
fink --use-binary-dist install g95
fink --use-binary-dist install svn
fink --use-binary-dist install tetex
Fine-Tuning Your Installation
Very quickly, you will find you will want the ability to access a number of AOS-focused routines that are not available in SciPy. We provide a list of these AOS-focused packages, with links, in the Packages section. Only Climate Data Analysis Tools (CDAT), of these packages, is installable using fink; for the rest, you will have to go to the site for each package, download the tarball (or other file that the package comes in), and follow the installation instructions. Here are a few general considerations:
- Climate Data Analysis Tools (CDAT): For AOS users, this is an extremely powerful package of routines tailored for climate analysis. Need anomalies? Bang! No sweat. The package, however, is quite large, and in its recommended form, is installed into its own copy of Python. This makes it more difficult for you to use CDAT along with packages you may have installed into other copies of Python. CdatLite is one way around this issue: Being a subset of CDAT, it is smaller and easier to integrate into an existing Python setup. My recommendation: First try a build using fink (
fink --use-binary-dist install cdat), and if that doesn’t work, then build from source using the instructions described above.
- PyNGL: Matplotlib is a great plotting package, but you may find you need the AOS-specialized routines found in the NCAR Graphics Language. PyNGL then is for you.
- PyNIO: Have to read/write a GRIB file? PyNIO is what you need. It also handles netCDF and HDF.