Hyperion, FSPS, and FSPS-python

Reinstalling OSX has me spending too much time figuring out what I’m missing.  Hyperion isn’t tricky, but I don’t feel like scrambling for instructions next time so here we go:

Hyperion

First thing’s first, nab and install gfortran. Next you’ll need to make sure you have HDF5 compiled and installed with fortran support, I covered this topic in this post. Next we’ll want to nab the hyperion tarball and move into the directory. This should be a basic configure, make, and make install:
> ./configure --prefix=/Users/bob/local/hyperion
> make
> make install
It is very important that you do *not* use ‘make -jN’; make must be ran serialized! Now we can build the python part via:
> python setup.py build
> python setup.py install
Easy enough right? Ok, well now we can move on to FSPS and Python-FSPS!

FSPS & Python bindings

Download the FSPS tarball via svn:
> svn checkout http://fsps.googlecode.com/svn/trunk/ fsps
You’ll need to add a new environment variable to your .bash_profile or .bashrc:
SPS_HOME=/Users/bob/research/codes/fsps
and point it to wherever the directory is you just downloaded. Then a simple ‘make’ should take care of everything as long as your gfortran is properly installed. Now nab python-fsps from github and cd into the downloaded directory. The build method is a little unconventional for most python packages:
> python setup.py build_fsps
> python setup.py develop

Testing FSPS

We should now be able to test FSPS and produce some stellar spectra. The metallicity input boils down to a table of values where you have to pass in the closest index. here’s an example script:
 import fsps
 import random
 import fsps

 random.seed('test')

 ZSUN = 0.0190
 METALS = [0.1,1,1.5] ## array of metals for our stars
 AGE = 5. ## maximum age

## table from FSPS
 ZMET =
 asarray([0.0002,0.0003,0.0004,0.0005,0.0006,0.0008,0.0010,0.0012,
 0.0016,0.0020,0.0025,0.0031,0.0039,0.0049,0.0061,0.0077,
 0.0096,0.0120,0.0150,0.0190,0.0240,0.0300])

## loop through each star and calculate the spectrum based on its age
 and metallicity
 for i in range(0,len(METALS)):
 zmetindex = (abs(ZMET-(METALS[i]*ZSUN))).argmin() + 1 ## determine
 index of ZMET
 sp = fsps.StellarPopulation(imf_type=1, zmet=zmetindex) ## calculate
 stellar population
 spectrum = sp.get_spectrum(tage=random.random()*AGE) ## get the
 spectrum

## plot the results
 loglog(spectrum[0],spectrum[1],label=r'%0.2fZsun' % METALS[i],
 ls=LINES[i])

legend()
 show()
All of that produces this:
stuff

compiling OpenMPI & HDF5 with Fortran support

Fortran…why on Earth would I want something with Fortran support? Apparently it’s fast; and when something is fast people still use it. I’m currently looking into the radiative transfer code Hyperion and it requires both MPI and HDF5 to be compiled with fortran support. It’s fairly simple to do, but can be a pain in the neck to find the syntax if you don’t know exactly where to look. Let’s start with OpenMPI which is currently on version 1.6.5.
?> ./configure --prefix=/Users/bob/local/openmpi-1.6.5 F77=gfortran FC=gfortran
?> make
?> make install
For HDF5 the syntax is similar:
?> ./configure CC=mpicc --enable-fortran --enable-hl --prefix=/Users/bob/local/hdf5-1.8.11 FC=gfortran
?> make
?> make install
And that should do it. To get hyperion to see these you just add the /bin dirs to your $PATH and the lib dirs to your $LD_LIBRARY_PATH. To check if the MPI-fortran bindings worked you can type mpif90 and mpi77 at the terminal and gfortran should error out saying that there are no input files.
Lastly once you recompile OpenMPI you may have to reconfigure/recompile/reinstall mpi4py if you’re using it. This is also super simple, but on OSX it can be troublesome. Before the compilation you have to redirect it to the proper SDK directory; the install should look like so:
?> export SDKROOT=/
?> python setup.py build
?> python setup.py install
I usually end up with an error at the end, but it installs and seems to run without any problems.