New paper and Pyflation software package

PyflationMy latest paper has just hit the arXiv and is now available. The paper builds on the numerical work I previously completed on cosmological perturbations beyond linear order. The new results do not assume slow-roll in the calculation of the source term for the second order equations of motion and so allow a much greater range of potentials to be analysed. The paper is called “Second Order Perturbations During Inflation Beyond Slow-roll” and already has a record on SPIRES and Inspire Beta.

Accompanying the paper is the release of the software package used to create the results. Pyflation is a Python package which calculates the first and second order perturbation results including the source term required at each time step. It requires Numpy, Scipy and PyTables and a fairly recent version of Python. The full calculation for a large range of Fourier wavemodes takes a long time on a single CPU, but there is support for splitting the calculation into many separate jobs which can be queued on a multi-core or cluster based setup. Alternatively there is also support for calculating the second order results for a single wavemode, which significantly reduces the execution time.

The Pyflation website contains all the details and download links, installation notes and links to the relevant papers. We’ve released the package under a very liberal open source license (modified BSD license) but as citations are increasingly the oil that greases the wheels of academia we ask that anyone who uses results they have obtained with Pyflation to please cite one or more of the related papers.

 

Minor Tick Labels in Matplotlib

This is a slightly more technical post than usual but having figured out how to do something quite esoteric in Matplotlib I thought I would write it down to save me remembering.

I have been making quite a few plots recently for a paper which should hit the arXiv very soon. The Python plotting package Matplotlib has been indispensable in this regard, especially as I took the effort of creating a script which creates all the plots. This meant that redoing all the graphs for new results or with changed sizes etc. was a simple as rerunning the script.

Quite a few of the plots use log axes and while Matplotlib performs admirably there was one problem I had with certain plots. By default, the log plots only show tick labels for each order of magnitude. Tick labels are the numbers on the x or y axis telling you the corresponding numerical value, and when the figure is zoomed in it is possible to lose the major tick label at say 10-4 because you only want to plot values from 0.3×10-4 and 0.5×10-4. Obviously this removes all sense of scale from the plot. A very mediocre solution is to just zoom out until a major tick label is back in the plot but this is obviously unsatisfactory.

I looked through the Matplotlib documentation, which has very detailed information about the API and has a lot of examples, but unfortunately didn’t address this exact point. After a bit of searching I found a useful conversation on the users mailing list which got me close but didn’t use the LaTeX labels which are really essential for publication quality graphs (in my opinion anyway!). The tick labels documentation along with the major-minor ticks example led me to the Formatter classes, especially LogFormatter and LogFormatterMathtext. This looked like the right answer but unfortunately LogFormatterMathtext writes the minor tick labels in a very unusual way. Instead of 0.3×10-4 it only writes an exponent, so 10-4.52.

I finally settled on extending the pyplot.LogFormatter class which controls the text for the tick labels. My subclass is as follows:

import re
import pylab

class LogFormatterTeXExponent(pylab.LogFormatter, object):
    """Extends pylab.LogFormatter to use 
    tex notation for tick labels."""
    
    def __init__(self, *args, **kwargs):
        super(LogFormatterTeXExponent, 
              self).__init__(*args, **kwargs)
        
    def __call__(self, *args, **kwargs):
        """Wrap call to parent class with 
        change to tex notation."""
        label = super(LogFormatterTeXExponent, 
                      self).__call__(*args, **kwargs)
        label = re.sub(r'e(\S)0?(\d+)', 
                       r'\\times 10^{\1\2}', 
                       str(label))
        label = "$" + label + "$"
        return label

It is provided as is, but there shouldn’t be too much wrong with it. One odd thing is that the LogFormatter class is an old style class, so I inherited from object to make it my subclass a new style class. This might be dangerous and cause some unexpected problems.

To use the class you can do something like the following:

import pylab
import numpy as np

fig = pylab.figure()
pylab.semilogy(np.logspace(-6,-5))
ax = fig.gca()
ax.yaxis.set_minor_formatter(
    LogFormatterTeXExponent(base=10, 
     labelOnlyBase=False))
pylab.draw()

Below are three different figures showing the current default situation, the result of using LogFormatterMathtext and the result of the new class. I hope this will be of use to someone who has been struggling with this problem as I have.

As I mentioned, this came up because of a paper that is very nearly completed and should be available soon. Along with the paper we should have the long promised release of the code I have been working on which solves cosmological perturbation equations during inflation. More on that soon.

 

Numerical Calculation of Second Order Perturbations

My new paper, written with Karim Malik, has just been released into the wild. We show that it is possible to numerically simulate second order perturbations for a single scalar field with a canonical action. I’ve been working on this for a long time and learned a lot about the mechanics of inflation in the process. I’ve also churned out quite a lot of python code, and learned some rudimentary parallel programming. We hope to be able to release the code in some form in the future, probably after publication. In the meantime the paper describes the numerical process in some detail.

Now that we have finished the preprint version I can concentrate solely on writing up my PhD thesis. It’s going to be a long few months!

 
Bear