Archive | Computing RSS for this section

Python: Julian date

An example of a nice mathematical use of functions in python.

Testing if a file exists in python

A really simple but important piece of testing that should always be incorporated.

Dual booting is fun!

Why not dual boot linux and windows? I’ve been doing this happily for years however my recent upgrade to Ubuntu 14.04┬á has meant a change to how the bootloader works, yes I was running a very old version of Ubuntu. I like stability. Anyway, I got annoyed that I had to build a simple pack from source as the repo didn’t exist so upgraded. I found that Grub2 was a bit different to edit and continuing the laziness I found an excellent tool to alter this. I want windows to boot my default as I’ll be using this more at school than home.

Anyway grub-customizer is the way to go:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer


Turning my raspberry pi into a NAS

I’ve never had a network storage system at home. Now with all of our wireless devices it really makes sense, both for backup and to access media. With a samba share and an external USB drive I’ve been easily able to turn my raspberry pi (running retropie) into a wireless media centre too. Its great, I just have to use a samba music player on my phone or tablet and boom there is my music ­čÖé I realised we weren’t listening to enough of our collection of music. So this will open a whole new world of our old music. Very much looking forward to this.

All I did for this was to edit the already configured raspberry pi settings for samba and added my own section to correctly load the samba share on my external drive. Edit: sudo nano /etc/samba/smb.conf

comment = music2
path = /media/usb0/Music
writeable = yes
guest ok = yes
create mask = 0644
directory mask = 0755
force user = pi
writeable= yes

You need to restart samba:  sudo /etc/init.d/samba restart

All worked nice and easily. Of course, this isn’t a proper NAS at the moment as it has no redundancy and I’ve not setup any rsync script to fetch/get data to backup. That’s the next task – once I’ve decided if I need to replace my old bulky external hard drive with a lower powered smaller one (I already have one but need a powered hub as the pi doesn’t give out enough to the USB ports).

If you want a more comprehensive guide that takes you all the way through to the drive mirroring look at

Raspberry Pi fun

— This post is mostly for me to show my Year 10 computer science students so might seem trivial or boring but hopefully not to any of them, if they ever read this bit —

So I got a raspberry pi at long last. After many years of being indecisive I decide that it would be ideal. I had originally intended to get it to play around with coding and to try out XBMC on it. If you’ve never tried XBMC its worth it. I decided in the end that my smart TV + TiVo box + Xbox was enough for my media needs.

In the end of decided what would be better to show off the power the raspberry pi than have it emulate tons of old consoles. Luckily some nice people have done all of the work there and even but a binary release together! Retropie is an excellent piece of software that I’ve very much loved using. That said installing version 1 from source was a mistake that I shouldn’t have been so nOOb to make. I guess, even the most hardened software developers sometimes copy the wrong repository link.

Retropie allows you, with the right ROMS, to emulate tons of ┬ádifferent consoles including my favourite childhood consoles (it uses emulationstation) – Atari 2600, SNES and Sega Master System. I was very pleased to find the first in there. Though I’m sure my wife wasn’t too pleased with me playing centipede quite loudly…

It is a very simply process to get this up and running and all the instructions can be found over on the retropie site. Alternatively you could look at using the instructions found on lifehacker. This is useful as it also gives direct instructions on how to setup a wired xbox controller.

Other useful things to setup include SSH. This can be enabled via the script. This is really useful. If you then type ifconfig you will get your IP address and via windows you can login using many tools. Good ones include PuTTY and WinSCP (a video guide to the later can be found here). This will then allow you to transfer over your ROMS and bobs your uncle you are good to play, this is what I started with:

Game playing on my raspberry pi :)

Have you Pynterferometer’d yet?

So you want to have a play with a radio telescope? Why not do it at home using a virtual array of telescopes. A while back I mentioned Pynterferometer and now we are pleased to be able to say that there is now a version for most operating systems. If you run Linux, Mac or Windows you can now use our tool. Pynterferometer is a graphical interface designed to demonstrated the techniques of radio interferometry used by telescopes like, ALMA, e-Merlin, the JVLA and SKA, in a manner accessible to the general public. For further information take a look at the tool’s webpage:


Oh and if you want to read all about the background to the tool and have an introduction to radio intereferometry take a look at our paper.

Making mosaics

For the [ALMA Summer Science Exhibition blog] I wanted to make a [big mosaic] of all the images taken – you’ll probably see this on the [post below] (unless its fallen off the bottom of the page!). To do this was really quite straight forward using python (well matplotlib mostly).
The below script takes in a list of png files and then setups a canvas – something I’d already figured out the dimensions for via the figure size of 12 by 12 inches and a 400dpi – that gives me 400 pixels for each inch and nicely each image is a 400×400 pixel square. I’d also already figured out the loop limits that were required to get all of my images in (if I get chance I might make these command line options and package this up as a little tool but I’m sure many better ones already exist – this is more a quick and dirty way of doing this).

import matplotlib.pyplot as plt
import Image
import numpy as np
import os
from scipy import ndimage

xtemp = os.popen("ls *png") #all files

xtemp2 = ('n'))

files = len(xtemp2)-1 #number of files.

stepsize = 400 #this is the image size in x,y

fig = plt.figure(num=None, figsize=(12, 12), facecolor='k', edgecolor='none')

k = 0

j = 0

i = 0

while k< 5000:

j = 0

while j < 5000:

im =[i])

im = np.array(im).astype(np.float) / 255

#im = ndimage.rotate(im, 90) #if we need to rotate

fig.figimage(im, k, j) #, zorder=i)

print k, j, i

i +=1

j +=stepsize

k +=stepsize

plt.subplots_adjust(left=0.00, right=1.0, top=0.9, bottom=0.0)

fig.savefig('outputprint.png',figsize=(12, 12),dpi=400, facecolor='k', edgecolor='k')

Overplotting with matplotlib

For the [ALMA SSE] I had to code up some overlays using matplotlib. This was so visitors to our stand at the exhibit could take away a printed copy of themselves as “seen through ALMA’s eyes” – and this involved some simple overlaying with maplotlib. Now, given I tend to forget useful things like this I thought I’d post it here and here is an example of the output:
ALMA SSE output image
It turns out that a combination of the python packages numpy, imager and matplotlib is a really quick way to do the overlaying:

import matplotlib.pyplot as plt
import Image
import numpy as np
im ='logo.png')
height = im.size[1]
# Need array of floats between 0-1, not a uint8 array between 0-255
im = np.array(im).astype(np.float) / 255
fig = plt.figure()
plt.plot(np.arange(10), 4 * np.arange(10))
rect = fig.patch
plt.text(-1, 30, 'Some lovely text n ', style='italic',
bbox={'facecolor':'blue', 'alpha':0.5, 'pad':10}, rotation=90)
# can use zorder here rather than hide behind it (e.g. zorder=1)
fig.figimage(im, 0, fig.bbox.ymax - height)
im ='logo2.png')
height = im.size[1]
im = np.array(im).astype(np.float) / 255
fig.figimage(im, fig.bbox.ymin, 0)
# Saving with the same dpi as the screen default
fig.savefig('temp.png', dpi=80, facecolor=fig.get_facecolor(), edgecolor='none')

Installing casacore 1.5.0

Casacore no longer uses the scons system so you have to use cmake (make sure you have a new-ish version).
Dependencies that you probably just can’t get from apt or yum: wcslib
install wcslib
tar -xf wcslib.tar.bz2
cd wcslib-4.13.4
./configure --prefix=/import/apgpu02/sgeorge/wcslib/
make -j4 && make install

now make casacore
cd /import/apgpu02/sgeorge/
tar -xf casacore-1.5.0.tar.bz2
cd casacore-1.5.0
mkdir build
cd build
mkdir /import/apgpu02/sgeorge/casacore1.5/
cmake .. -DMODULE=all -DBLAS_LIBRARIES=/usr/lib64/ -DLAPACK_LIBRARIES=/usr/lib64/ -DREADLINE_LIBRARY=/usr/lib64/ -DFFTW3_LIBRARIES=/usr/lib64/ -DCFITSIO_LIBRARIES=/usr/lib64/ -DCMAKE_INSTALL_PREFIX=/import/apgpu02/sgeorge/casacore1.5/ -DWCSLIB_ROOT_DIR=/import/apgpu02/sgeorge/wcslib/lib -DBUILD_SHARED_LIBS=OFF -DWCSLIB_LIBRARY=/import/apgpu02/sgeorge/wcslib/lib/
make -j4 && make install

ALMA at the SSE imaging

We’ve been working on a bunch of things for the upcoming ALMA Summer Science Exhibition stand including a hands on ALMA simulator.
I’ve just finished adding our “Send to twitter” function with a bit of windows based commandline wizardy – I’m actually very pleased with it. So here is a bit of an Easter egg, me through the eyes of the ALMA SSE Imager – a bit of Earth rotation really brings out my features – can you guess what is on my t-shirt?
me through ALMA imager