FITS for the web

If you've ever used a telescope with a CCD camera you've probably encountered FITS files. FITS, or Flexible Image Transport System, is a file format used widely in astronomy to share images.

As an astronomy student I remember finding FITS files a little mysterious. Their large file sizes made them seem antiquated compared to JPEG and PNG image formats but they do have some advantages: they store useful astronomical information about your observation (e.g. coordinates on the sky, details about the instrument, observer etc); they have a larger dynamic range (PDF link); and they can store more than just images*.

A few years ago, whilst testing some astronomical radiometers, I had to work out how to output time-series data in FITS format from a C program. It was a steep learning curve for someone who had never processed binary data with code. A week or so ago I was talking to Jon Yardley about how good it would be to be able to work with FITS files in a web browser. Web browser manufacturers don't support FITS files but during the conversation I realised that I had the tools to do it without the need for extra browser plugins.

Last year I experimented with reading astronomy visualisation metadata (AVM) from JPEGs. That made use of Jacob Seidelin's Javascript library for reading binary files and lets you read them byte by byte. More recently I've learnt how to draw in the browser using HTML5's <canvas>. The result is that I can now display a FITS file in a web page. The code is available if you want to have a play with it. It is a bit slow but that is mostly due to the time it takes to transfer a 2.2 MB FITS file over the internet; processing and drawing the image is actually pretty quick (tested in Firefox 4 beta). It even works on my Android phone!

Last night I thought about completing the circle; to save a FITS file as a JPEG image with AVM headers created from the FITS file headers. I couldn't see that it was possible to attach EXIF tags to a <canvas> element (although the canvas element can be saved as a PNG in Firefox 4 beta) but I discovered that somebody has written a library to encode JPEGs with Javascript. Over the next few days (or weeks) I'll look into that library and see if it will provide the solution.

I realise that specific software exists to process FITS files and ESA/ESO/NASA's FITS Liberator makes it possible for those with Photoshop. However, these have always been slightly detached from the web itself and require separate software to run. Web browsers are increasingly ubiquitous and increasingly capable (yes, even Internet Explorer) so finally FITS files can start to get out onto the web proper.

* They can hold tables as well as data cubes with up to 999 dimensions!