Skip to content

Lyman α radiative transfer in galaxies simulated with adaptive mesh refinement.


Notifications You must be signed in to change notification settings


Repository files navigation


Lyman α radiative transfer in galaxies simulated with adaptive mesh refinement.


This is the very first attempt at publishing MoCaLaTA, the Lyα RT code I built during my Ph.D. At the moment, it is mostly meant to be used by collaborators. Hence the lack of documentation. If you find this page and would like to know more, don't hesitate to contact me.

The version of MoCaLaTA is slightly different from my "own" version, but will be updated along the way. It's serial, i.e. it isn't parallelized. Written in Fortran 95/2003 in one, big chunk, the idea is that MoCaLaTA should be virtually a plug-and-play code, requiring no installation, make'ing or anything beyond compiling (e.g. with gfortran).


The code is free for anyone to use, copy, modify, distribute, and so on, as desribed in the License. If your work leads to a publication, I'd like you to cite

Laursen, Razoumov, & Sommer-Larsen (2009, ApJ, 696, 853)

where the code is described, tested, and applied. The implementation of dust in the code is described in Laursen, Sommer-Larsen, & Andersen (2009, ApJ, 704, 1640).

Previous use cites

MoCaLaTA has previously been used in the following publications. If you use it, please let me know and I can put you on the list.

The code

MoCaLaTA assumes an adaptively refined grid, and is thus best for AMR simulations (or regular grids). If your simulation is SPH, the physical properties of the particles must first be interpolated onto a grid. One way to do this is to use the visualization tool SPLASH which can at least interpolate to a regular grid, and possibly also an AMR grid; I'll get back to that.

The AMR format assumed by MoCaLaTA is a fully threaded grid, further described in the documentation for the IGM Lyα RT code IGMtransfer. At the moment, I provide a code to convert the output from SPLASH to a (regular) grid readable by MoCaLaTA.

The name

MoCaLaTA stands for "Monte Carlo Lyman alpha Transfer with AMR", referring to the fact that the Lyα photons are transferred in an AMR grid using a Monte Carlo scheme.

The basics

That is, photons are emitted from random locations (with the probability of being emitted from a given location proportional to the Lyα luminosity in that location) and random directions, travel a random distance through the interstellar (and intergalactic) medium (given by the optical depth), are absorbed/re-emitted by hydrogen atoms (or dust grains) in random directions (given by the phase function), thus scattering stochastically until they either escape or are absorbed by dust.

The input

In each of the cells of MoCaLaTA's grid, the following physical parameters are needed

  • HI number density
  • Temperature
  • 3D velocity
  • Lyα luminosity (these data are used for calculating initial positions of photons, but are not stored during runtime)
  • Metallicity (optional)
  • HII number density (optional)

The metallicity and the HII density are used for calculating the dust density, which is an optional feature of MoCaLaTA.

The output

The photons that escape form an image and a spectrum of the galaxy. The galaxy may be "observed" simultaneously from six different directions (along the Cartesian axes).

Quick start


I usually use the gfortran compiler. For the auxiliary codes, you can just replace the gfortran with ifort, if that's your compiler, but for MoCaLaTA.f90 it's a slightly different syntax. In all cases, I call the executables *.x.

Compile auxiliary codes with

gfortran -O3 splash2jesper.f90     -o splash2jesper.x
gfortran -O3 buildAMR.f90          -o buildAMR.x
gfortran -O3 initialEmission.f90   -o initialEmission.x

Compile MoCaLaTA.f90 with one of the following lines

gfortran -O3 -x f95-cpp-input -Ddust -DAMR MoCaLaTA.f90 -o MoCaLaTA.x
ifort -O3 -fpp -Ddust -DAMR MoCaLaTA.f90 -o MoCaLaTA.x

Preparing the input data

Converting SPLASH output to MoCaLaTA input

Assuming SPH data interpolated onto a regular grid with SPLASH, each physical parameter is written to a file in the form

do k=1,nk
  do j=1,nj
    write(*,*) (dat(i,j,k),i=1,ni)

A series of test SPLASH files may be created in a directory testdir/ using


These SPLASH data files are converted to MoCaLaTA-readable format with

./splash2jesper.x   # Convert test data to a binary called "Jesper.bin"

In the above, is an input file containing the size of the computational box, as well as the names of the SPLASH files. is the input file containing all relevant information for the "real" MoCaLaTA run — i.e. in- and output file names, gas and photon parameters, cosmology, etc.

Build the grid and calculate photon emission sites

In order for MoCaLaTA not to spend memory on storing the luminosity data, this is used first to calculate the initial position of all photons, after which the luminosity isn't used. First the grid is built, and then the positions are calculated:

./buildAMR.x <        # Build the grid from Jesper.bin, creating "RawData.bin"
./initialEmission.x < # Calculate emission locations, creating "CellData.bin"



(notice that in this case, you shouldn't use the < redirector.)

As the code is running, some output is generated along the way. This can be redirected into a log file instead, using ./MoCaLaTA.x > test.log


A text file containing information about each escaping photon is generated, along with up to six "IFU" cubes representing an "observation" of the galaxy along the Cartesian axes.

Analyzing the output

A Python code (under development) is provided. Currently, it can do two things

  • generate an image and a spectrum from an IFU cube, and
  • shows the anisotropic escape of the photons (using a Mollweide projection)

Image and spectrum

The IFU cubes are saved in the directory DataDir/SubDir/, and are called xm.bin (for the view along the $x$ axis in the negtive direction), xp.bin, etc. The keywords DataDir and SubDir are set in the input file ( in the example), where you can also set a keyword outlabel, which is appended to the basename of the files, just before the extension .bin.

To "observe" the galaxy in the example above from the positive direction of the $x$ axis, do (in Python):

>>> import analyzeMoCaLaTA as am
>>> am.showobs('testdir','xp')

This should produce something like the following figure


To extract only the spectrum of the pixels inside an circular aperture of radius r kpc centered on [x0,y0] (also in kpc), use

>>> am.showobs('testdir','xp',ap=[x0,y0,r])

Anisotropic escape

In addition to the IFU cubes, MoCaLaTA also spits out a text file with some information about each photon packet




Lyman α radiative transfer in galaxies simulated with adaptive mesh refinement.







No releases published


No packages published