Archive | March 2012

Concatinating measurement sets in CASA

Combining data from different spectral windows or different days is quite useful. Quite often I will image these seperately and then combine in the image domain. It is useful, however, to be able to combine these into one measurement set, its just easier to keep track of the files – and time based flagging in the case of many spectral windows is probably the same (e.g. one antenna is down, well it will be for both spectral windows). Anyway, in AIPS this was quite straightforward and it was something I did often. I’ve only just needed a reason todo this in CASA and again its fairly easy. You just need to use the task “concat”. I’ve put together a little script thats in two files from the commandline and runs this, see the code below:
from os import sys #python library to read input from command line
inputfile1 = str(sys.argv[3:][0])
inputfile2 = str(sys.argv[3:][1])
visoutfile = ‘’
print inputfile1,inputfile2,visoutfile
concat(vis=[inputfile1,inputfile2], concatvis=visoutfile)
Save this (as and run as:
casapy -c “”
Assuming the two files are different frequency ranges you will end up with a file that has two spectral windows in.

Globular cluster, M3

I occasionally use the Bradford Robotic Telescope for remote imaging… here is an image of the Ring Nebula, M3 a globular cluster in the constellation Canes Venatici:
M3 with BRT

SSH Keys and multi machine processing

A lot of my processing can be parallelised effectively by just splitting up the data and running on many machines. To accomplish this I use SSH keys so I can start jobs over the network from one bash script. Works nicely and is quite effective – the only downside is normally having to send data over NFS.
Anyway, crucial to this is the ability to install SSH keys, this can be done quite easily.
Firstly make sure that you have ssh’d from the machines you want to set this up on before. Simply just ssh into another machine, this will create a .ssh in your home directory with the proper permissions.
Now on your main machine run:
ssh-keygen -t dsa
This will generate a key. It will ask you for a passphrase. If you are hoping to spawn loads of jobs over many machines then don’t put anything here (otherwise you’ll be asked for the passphrase instead of your password!). Of course this is a security risk – so make sure you trust your network etc.
Now copy this key over to the other machines, in this case I’m using a virtual machine at, so:
scp ~/.ssh/
Now on the machine you just copied it over (in my case ssh run:
ssh-agent sh -c ‘ssh-add < /dev/null && bash'
This will add the key and allow you to effectlviely have passwordless login – and allow for some nice multi-machine processing – we do this for lots of the Arecibo data we have to deal with, allows us to effectively run on 100 cores without any fancy software just a small bash script that loops over an array of machines.

M57: the ring nebula

A short image of the Ring Nebula out at Wast Hills. It is a rather prominent planetary nebula well worth a look through a telescope:

Talk bingo generator

During my [talk on Saturday at the University of Birmingham] I played talk bingo. The idea is that as I give the talk the younger members of the audience can be entertained by playing a game that requires them to pay attention. Whenever I give a talk I tend to use a subset of words (and indeed this can be played with a rather small number of words in any extragalactic seminar) from the field of astronomy. So all I did was generate a bunch of random bingo games and I say the words the audience cross them out. Eventually they will call bingo and I offer a small prize. On Saturday, due to a bit of a mix up with computers this didn’t quite go as to plan but I think all were quite entertained. I suggested to a few that I’d put this together in a useful format.
So do you want to play talk bingo? You can use my [online talk bingo generator] on my research pages. It should be quite straight forward to use. Just provide the words (with space seperation) and a size of the grid and off you go. It produces html tables which can nicely be copied to openoffice for easy printing.
For those of you who might be interested in implementing this yourselves, here is the basic code (this is what I used for Saturday and I’ve changed it a bit to work nicely on my website, testing for max sizes and taking in input):
$random_text = array(“Telescope”,”Dish”,”Data”,”Array”,”Universe”,”MeerKat”,”LOFAR”,”Space”,”Wave”,”Moon”,”Shock”,”Life”,”Transit”,”SKA”,”Radio”,”Exoplanet”,”Aurora”,”HD209458b”,”Arecibo”,”GMRT”,”ASKAP”,”POSSUM”,”GALFACTS”,”Galaxy”,”Jupiter”,”Sun”,”Earth”,”Magnetic”,”Gas”,”Electron”,”Kepler”,”Space”,”Venus”,”Mars”,”EVLA”,”Aliens”,”WOW”,”SETI”,”Radar”);
$number_of_games = 50;
$number_elements= 25;
$elementsinrow = 5;
$intro = “”;
for ($j = 0; $j < $number_of_games; $j++) {
$rand_keys = array_rand($random_text, $number_elements);
$sizeof_arr = sizeof($random_text); //echo $sizeof_arr;
$intro .= “<table border=”1″><tr>”;
$b = 0;
for ($i = 0; $i < $number_elements; $i++) {
$intro .= “<td><font size=”6″>” .    $random_text[$rand_keys[$i]] . “</font></td>”;
$b +=1;
if ($b > 4){
$intro .= “</tr>”;
$b = 0;
$intro .= “</table><br /><br />”;
echo $intro;
As you will see its nothing particularly fancy, but darn useful

M34: an open cluster in Perseus.

M34 is an open cluster in Perseus which can be seen by the naked eye.. but you will need properly dark skies, so that means well away from urban areas. Its a nice binocular object though, even from light polluted city streets.

Setting up a Virtual Webserver

This is a quick guide on how to setup a webserver in a virtual machine. This is based on using Virtualbox and Ubuntu, so it might not work with all version of linux and though the install instructions inside the virtual machine will work with any virtualisation tool the rest of the info, of course, will not. This is as much a reminder to myself as I seem to always forget to do one thing when doing this. Its really useful being able to just create a VM and fire off testing without having to compromise your normal desktop. I do this for many different coding projects, allowing me to have the exact environment I need / users have.
Firstly, lets install virtualbox (of course you could install one of many other virtualisation products):

sudo apt-get install virtualbox

Follow the on screen instructions on how to create a guest os in virtual box, quite straight forward. I tend to use a dynamically allocated disk. Start up the OS and find the image file you wish to boot (I’ve been using Ubuntu 10.04).
Like you would do for any operating system install this to the local disk.
To make life easier lets first setup SSH to the system.

sudo apt-get install openssh-client openssh-server

Now turn off the guest OS and in virtual box go: settings > network > adapter 2 > Enable
and change to attached to: Host-only adapter using vboxnet0
Reboot the guest OS.
Now we need to edit: /etc/network/interfaces to (you need to run something like sudo pico /etc/network/interfaces/), adding:

auto eth1
iface eth1 inet static

Now to finish the network setup, run:

sudo ifup eth1

Lets now restart the network:

sudo /etc/init.d/networking restart

We should now be able to ssh in to the system using: ssh your-username@
If you don’t want to have to remember the IP address you can add this to your /etc/hosts files, with: yourvirtualos

Lets now install the important webserver tools:

sudo apt-get install apache2 php5 libapache2-mod-php5

Create a directory called “public_html” in your home directory,

mkdir public_html

and lets configure apache and get it running:

cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/userdir.conf userdir.conf
sudo ln -s ../mods-available/userdir.load userdir.load
sudo /etc/init.d/apache2 restart

sudo pico /etc/apache2/mods-available/php5.conf

change to:

<IfModule mod_php5.c>
<FilesMatch “.ph(p3?|tml)$”>
SetHandler application/x-httpd-php
<FilesMatch “.phps$”>
SetHandler application/x-httpd-php-source
# To re-enable php in user directories comment the following lines
# (from <IfModule …> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
# </IfModule>

i.e. comment out <IfModule… </IfModule>
And there you have it a webserver running in a virtual machine. Nice and straight forward really and takes about 10 minutes. Really useful for doing some web testing before uploading.
To test this just go to: on either your main desktop or in your guest OS.