Planetarium program tutorial 1

Believe it or not my grandma got me into computer programming when I was about six years old when she bought me two issues of the magazine Input. I fondly remember (I’m kind of a nerd) the tutorials and programming listings in ZX spectrum magazines such as Your Sinclair. It’s no wonder that people have difficulty in getting into programming. Most machines from PC World nowadays don’t come with easily accessible beginners programming tools. Back when I was at school everyone could type:

10 PRINT "Hello world"
20 GOTO 10.

Now to even do that in a language like C requires a bit more effort.

I’ve benefited a lot over the past 25 odd years from people writing tutorials and given that this is the year that everyone is supposed to learn to code (even the mayor of New York is learning to code) I thought I might try to write a computer programming tutorial.

So what will I aim to do with this. So my thought was to write a mini planetarium program that you can use to find out what is in the sky on a given day/time from a particular place on Earth. Not only is this fairly useful but also its something that needs a bit of thought and can be extended to suit to abilities of anyone following this tutorial. Although of course it wouldn’t replace something like Stellarium! A screenshot from Stellarium is shown below and so this should give you an idea for what I’m aiming for – except perhaps more basic imagery… I’ll be doing this tutorial in the programming language BASIC, which stands for Beginners All-purpose Symbolic Instruction Code. It’s designed for people to pick up easily and for doing a wide variety of things. It’s fallen out of fashion of late but I think it’s a nice little language. This also has the advantage that you don’t need to install any software because I found a BASIC interpreter online that you can use in your web browser called Ready BASIC. It’s perhaps a little rough around the edges but it works well.

I have a slightly ulterior motive for doing this. Whenever I give talks and want to point out where to find Jupiter or Saturn in the sky that night I usually have to resort to a screen capture from Stellarium. But on projectors these captures often look washed out. So for a while I’ve wanted my own program to draw nice high quality drawings of parts of the night sky. So this serves two purposes at once. So in due course I’ll also post some code written in a language other than BASIC.

I don’t just want to teach programming but also program design. So this program should be able to show the position of the stars, Moon, planets, and various deep sky objects in the sky at a given date/time/location. So we want to be able to specify the time, the date, the location (as a latitude and longitude) and then get a map on the screen of the sky showing the Moon, planets, stars and deep sky objects. We want to be able to zoom in on a particular part of the sky so we’ll need to specify the ranges in azimuth and altitude on the screen. This all tells us what we want the program to do – not how to do it.

In the next blog post on this I’ll talk a bit more about how to do things, break down the job into manageable chunks, and show how to do the first thing: make a star chart from a freely available star catalogue.

In defence of art

“…14-year-olds … would never imagine that a professional scientist would spend so much time drawing, sketching, and writing.”

I spend a lot of my time working on figures and illustrations. More than the person-on-the-street might imagine. During GCSEs and A-levels I didn’t see the point of the canonical “Draw a labelled diagram” but now it’s the sort of thing I often end up writing as comments on other peoples’ work. Making these sorts of illustrations can take a lot of work – especially to make something that is publication quality which conveys some important point. In my opinion a picture conveys a thousand words isn’t a strong enough statement when communicating science, as long as its a good picture. If you’ve ever tried to describe a picture in your head for someone to draw out you’ll know how difficult it is to convey visual ideas in words.

Publishers want graphics in a vector format – so they can be scaled without loss of quality – which usually means PDF or EPS (Encapsulated Postscript). They often have a long set of guidelines for the production of figures, for example journals published by AGU, Springer, and Elsevier. For line drawings I typically use OpenOffice Draw, although I haven’t found its EPS export to be that great, and Inkscape. But I know plenty of people who use Adobe Illustrator and Corel Draw. Often a hybrid solution is called for – so rather than trying to draw some complicated shape using Bezier curves I will make a plot and then import that into Inkscape and merge it in with the rest of the figure. This is the sort of thing that can consume time. For prettier 3D graphics I’ve taken to using Pov-ray – this is what I used to make the figure on the right – but since it isn’t in a vector format the image needs to be rendered at a high enough resolution for print.

Back as an undergrad we had a lecture on not using Excel to make our plots – the main reason being the lack of control and the effort required to produce a publication quality figure – dealing with similar journal issues as described above. I spend a lot of my time writing computer programmes to make plots for papers, using tools such as Matlab, IDL, and I know lots of colleagues who use PGPLOT. Back as an undergrad make my plots by sending plot commands to a vector drawing package on the Amiga using a scripting language (ARexx). The advantage of these approaches is that if you have some sort of script to make your figure then it’s a simple matter to change some aspect of the figure and then redraw it. Similar effort goes into making beautiful images that we enjoy from the Hubble Space Telescope. “Hubble images are made, not born.” You can see this at work in a movie made for the Hubble YouTube channel which shows someone producing an image of NGC 3982 over the course of three weeks (in time-lapse of course).

Throughout my scientific eduction I’ve been encouraged to draw.  Throughout my software engineering training I had to draw flow charts, PERT charts, Gantt charts, JSP diagrams, class diagrams, use cases, and more. My PhD supervisor encouraged me to sketch in order to explore physical problems – especially those in three-dimensions. I can also still recall my work experience placement, seeing A3 sheets of paper stuck to desks that would slowly fill up with doodles, sketches, notes, phone numbers etc. over the course of a working week. I do something similar now. I also use drawing/sketching/doodling as a tool for thinking, laying out ideas, and considering different approaches to problems. In the course of writing this blog post I came across another blog post on drawing as a tool for thinking and largely agree with what was written there – although my sketching tends to be more freeform. Unstructured sketching anyone?? Sketching is something I encourage in my students although I worry about cognitive styles different to my own.

Of course these aspects contain different approaches, or rationales for drawing. The first is as a cognitive aid, the other is to communicate ideas. Sometimes my thinking-related sketches will somehow end up forming the core of an illustration for a paper, other times they might just be another page in my lab book.

Looking back on my education, a GCSE in Art or Graphic Design (both offered by the secondary school I attended) would have been useful in my future career. Just like more emphasis on writing. But 14-year-olds who are interested in computers and science would never imagine that a professional scientist would spend so much time drawing, sketching, and writing.


As a starting point, I feel that this blog is incomplete without some form of welcome post – a bit like answering your front door and walking back inside without so much as an acknowledgement. So welcome – come in – take a load off. Fancy some tea and cake?

As I say in my about page I’m planning on blogging about planetary science, STEM, software engineering, science and its politics and methods, physics, and space missions, but in truth there’ll be a certain amount of improvisation and meandering… I’d like to blog about the stories behind the news – to give you a flavour of how scientific results have been found, where the uncertainties are, and how they fit into the big picture. Needless to say the thoughts I express here are my own and don’t represent those of UCL, NASA, ESA, the National Maritime Museum, or any other organisation I work for/with – unless explicitly stated of course. I’m going to be blogging about non-work stuff, like gaming, running, coding, eating etc., at Life is a Bowl of Chillis.

I’ve got a bit of a bee in my bonnet about computer programming. I was a trained programmer before I started in the world of science and I think it has really helped in my career. Believe it or not, professional scientists can spend a lot of time programming computers! So I’m planning on a set of programming tutorial-type blog posts over the coming year. I’ve been exploring this option a little over the last few days so watch this space! I hope to post the first tutorial-type post in the next week or so.

Hope you enjoy reading!