Surveying the Universe
Computing
MNRAS line wrapping in authors lists
May 7th
In case anyone else using the MNRAS LaTeX class has been tearing their hair out inserting line breaks manually into long author (and institution) lists, using \newauthor, here’s how I did it:
\author[J.~Bloggs et al.] {\parbox{\textwidth}{J.~Bloggs,$^{1}$\thanks{E-mail: \texttt{j.bloggs@no.where}} J.~Bloggs,$^{2,3}$ J.~Bloggs,$^{3}$ J.~Bloggs,$^{4}$ J.~Bloggs,$^{5}$ J.~Bloggs,$^{6}$ %... J.~Bloggs$^{99}$ and J.~Bloggs$^{100}$}\vspace{0.4cm}\\ \parbox{\textwidth}{$^{1}$Department of Something, Somewhere\\ $^{2}$Department of Something, Somewhere\\ $^{3}$Department of Something, Somewhere\\ $^{4}$Department of Something, Somewhere\\ $^{5}$Department of Something, Somewhere\\ $^{6}$Department of Something, Somewhere\\ %... $^{99}$Department of Something, Somewhere\\ $^{100}$Department of Something, Somewhere}}
Next: a Python script to generate the above from a simple list of authors and affiliations.
Astropython
Jan 19th
You (both of you) might well be interested in the new Astropython site, which looks excellent. Here’s the site’s own description:
Research in astronomy includes the analysis of astronomical images, parsing and manipulation of large catalogs, statistical yet often visual inference, and the creation of data visualizations for publication and dissemination of results.
The purpose of this web site is to act as a community knowledge base for performing this research with the open source Python language. It provides a forum for general discussion, advice, or relevant news items, collecting lists of useful resources, users’ code snippets or scripts, and longer tutorials on specific topics. The topics within these pages are presented in a list view with the ability to sort by date or topic. A traditional “blog” view of the most recently posted topics is visible from the site Home page.
Visualizing noisy images
May 13th
You have an image. Each pixel has a value with some uncertainty. How do you visualize the uncertainty in each pixel? Like this:
Here’s the Python code
import numpy as np from matplotlib import pyplot as plt class FlickerImage(object): def __init__(self, im, err): self.im = im.copy() self.err = err.copy() finite = np.isfinite(self.im + self.err) self.vmin = (self.im - 2 * self.err)[finite].min() self.vmax = (self.im + 2 * self.err)[finite].max() self.im[np.invert(finite)] = self.vmax self.err[np.invert(finite)] = 0 def flicker(self): fg = plt.imshow(np.zeros(self.im.shape), interpolation='nearest', vmin=self.vmin, vmax=self.vmax) while True: ran = np.random.normal(size=im.shape) fg.set_data(im + err * ran) plt.draw()
And here’s an example script:
import pyfits f = pyfits.open('file.fits') im = f["IMAGE"].data err = f["ERROR"].data flicker_image = FlickerImage(im, err) flicker_image.flicker()
Python, FITS and DS9
Apr 1st
Here’s an easy way to display FITS images (or any array) in DS9 using Python (with PyFITS, NumPy and Numdisplay, which is part of stsci_python). First launch DS9, then in Python:
import numdisplay import pyfits arr = pyfits.getdata('file.fits') numdisplay.display(arr)
Easy!
Alternatively, the Kapteyn package seems excellent, and uses Python’s matplotlib for displaying images. It requires WCSLIB to run, though, so the installation process is a bit longer.
A third option is to use python-sao:
import pysao import pyfits ds9 = pysao.ds9() f = pyfits.open('file.fits') ds9.view(f[0])
Easy again! And the WCS information is preserved, which doesn’t seem to be the case with Numdisplay.
PSFs in IDL
Mar 18th
Two methods of approximating a point-spread function in IDL:
1. StarFinder seems to do a great job at finding point sources in crowded fields. It includes a routine for generating the Airy pattern. For a 51 x 51 array, with the peak at [25, 25], and an FWHM of 8.0 pixels, this is the command:
psf = airy_pattern(51, 51, 25, 25, 2./8.0) isurface, psf
The output looks something like this:

2. The IDL Astronomy User’s Library contains a routine, psf_gaussian, that produces a Gaussian PSF. To produce the same as above, the command would be:
psf = psf_gaussian(npix=51, fwhm=8.0, /double) isurface, psf
… which produces something like this:

The eclipse of IDL 7
Mar 3rd
I’ve finally made the transition from IDL 6.4 to IDL 7. Here are my handy hints…
- IDL Workbench rocks! (This is because it is basically Eclipse, which is a proper development environment, unlike that hideous old IDLDE.)
- Another reason for using IDL Workbench (for me at least, and for now) is that IDL help doesn’t seem to work if Java 6 is the default (as it is on my Mac), but the help does work if launched through the IDL Workbench.
To transition to IDL Workbench:
- Import your code as described on David Fanning’s page – fret not, it’s easy and harmless
- Preferences -> IDL -> Startup file, if you have one, and
- Preferences -> IDL -> Paths -> Insert… for me it was just my idl folder, including all sub-folders, to mimic my $IDL_PATH environment variable.
pIDLy: IDL within Python
Jan 31st
Now Python and IDL can talk to each other (okay, Python talks to IDL and IDL does what it’s told), using pIDLy (pronounce as you please). I experimented with a few other solutions available online but couldn’t get them to work. So I cobbled this one together with surprisingly little trouble, thanks largely to pexpect.
IDL code miscellany
Jan 28th
IDLdoc 3.0 (more info here) gives my badly-written bits of IDL the deceptive appearance of being well designed, useful and user-friendly. So I’ve made a few available here for your enjoyment.

I am a research fellow in