Numpy For Mac Using Fink

From NYU CCPP Wiki

Contents

Python for scientists, especially astronomers

This is a tutorial for how to get Python with Numpy (numerical python) and Scipy (scientific python) set up on your PPC Mac using Fink [1]. Numpy/Scipy supports an n-dimensional array object and many routines for data analysis and visualization. Plotting is also supported by the matplotlib package.

It turns out this was the simplest way to get NumPy/SciPy working, and everything worked the best for me with this approach. The problem is everything must be compiled, unlike the binary distros in MacPython. This was a reasonable tradeoff for me.

This page mainly written by Erin Sheldon 18:03, 2 November 2006 (EST). Other installation methods, including intel mac installs, can be found at this page Numpy_For_Mac.

Quick Version

Here is the quick version if you already have fink and XCode installed:

 fink install scipy-py24
 sudo apt-get install gettext-dev=0.10.40-25 gettext=0.10.40-25
 fink install matplotlib-py24

See below for some details.

Preliminaries

Xcode

This comes for free with OS X since at least tiger, probably before. It is on your OS X install disk. To get the latest:

Fink

Fink is an open source distribution:

It will set an extra path for you:

 /sw/bin

where fink executables are installed. If you start a new shell and still don't see the port program in your path, add this yourself. Make sure it is at the front of your path. If transitioning from an older version of fink read Fink Transitional.

One installs programs using one of the following

 sudo apt-get install package_name
 fink install package_name

apt-get only installs binary packages. Calling fink you can install either binary or from source. There is also a nice gui interface called FinkCommander that you can also install. You can get a list of available packages using

 fink list [pattern]

where [pattern] is an optional package name to search for. Also you can use the search box in FinkCommander.

Installing NumPy and SciPy

The packages you need are in the "unstable" branch. The simplest way to see this branch is to open the FinkCommander gui, go to preferences under the fink tab and check both unstable buttons.

There are packages for different versions of python. I installed for python 2.4. You can pick the one you want, but note 2.5 is relatively new.

These packages must be compiled from source. After setting unstable, you can install from the command line with

 fink install scipy-py24

or from fink commander by clicking on the upper left butt .h (binary not available). This will install all the packages you need, plus NumPy and SciPy. This will take a long time, a few hours on a Powerbook, although much less on one of the new intel machines. You will be prombted for some info at the beginning. Just take the defaults and once it starts compiling things just let it go.


iPython

Optional, but this is a much better interactive shell than the default and it understands numpy and matplotlib.

 fink install ipython-py24

Getting it all working

NUMERIX

You should set an environment variable

   setenv NUMERIX numpy

This is used by some packages that are currently moving from the older numerical packages (numarray,numeric) to distinguish your preference. In the future the default will be numpy but do this for now just in case.

Plotting with MatPlotlib

This is a matlab-style plotting package. http://matplotlib.sourceforge.net/ There is one broken dependency you need to install first:

 sudo apt-get install gettext-dev=0.10.40-25 gettext=0.10.40-25

Note the version may change in the future.

 fink install matplotlib-py24

This is the really slow one. It needs to install many things, such as gtk+ that take a long time. I make sure you have a good 4 hours on your powerbook if you are starting this install from scratch. If you already have some of this stuff it will go faster. And the new intel chips are much faster.

Plotting will work out of the box, but the TK interface for the fink install isn't as nice as the GTK. I recommend creating this file

   ~/.matplotlib/matplotlibrc

And add the following at minimum:

 numerix      : numpy  # numpy, Numeric or numarray.  Absolutely required until
                       # numpy is the default.
 backend      : GTKAgg # Use GTK for the plotting backend.
 text.usetex  : True   # use latex for all text handling.  Note this does slow things down.
                       # For faster use set to False and then turn on when you need it
                       # with pylab.rc('text',usetex=True) in your script.

You can see a full set of options by looking at this file:

 /sw/lib/python2.4/site-packages/matplotlib/mpl-data/matplotlibrc
 

The TeX is especially nice. See here for example usage of tex:

   http://www.scipy.org/Cookbook/Matplotlib/UsingTex

If you are coming from IDL where it is a nightmare trying to get plotting in X and PS to look the same, you will appreciate the "what you see is what you get" aspect of the plotting. Exactly what you see in a plot window is what comes out in a postscript file. Also, TeX notation is supported (even without TeX handling the text) if a "raw string" is sent. r'$M [$M$_{\odot}]$' would be a proper axis label. This looks even better if you use "text.usetex" in your rc file. Far better than IDL, where ! escapes are everywhere and the equivalent of \odot just doesn't exist except as a kludge.


Astro packages

pyfits

Pure python FITS reader that uses NumPy.

 http://www.stsci.edu/resources/software_hardware/pyfits
 fink install pyfits-py24

Documentation and Examples

A useful resource:

 http://www.scipy.org/Documentation

Note, there is a book being written which you can buy, but the free help at that link covers much of what you need.