slowe / jsFITS

A Javascript library to read and display FITS files in a browser
http://lcogt.net/user/slowe/dev/fits/
13 stars 4 forks source link

jsFITS

FITS is the Flexible Image Transport System and is widely used in astronomy for holding observation data. There are many FITS I/O libraries available in a variety of languages. This is an attempt to build a FITS library for Javascript to allow FITS files to be displayed in a modern web browser. Given that FITS files have no compression they are quite large so I imagine this library will be more useful when run locally. By displaying the image using in the browser, it will be very easy to save a FITS image as a standard graphics file.

Dependencies

For this library to work it has two dependencies:

Limitations

Due to web browser cross-domain security issues, any FITS file you want to read must be hosted on the same domain as the code.

Usage

You need to include the appropriate Javascript files:

<script src="https://github.com/slowe/jsFITS/raw/master/binaryajax.js"></script>
<script src="https://github.com/slowe/jsFITS/raw/master/excanvas.js"></script>
<script src="https://github.com/slowe/jsFITS/raw/master/fits.js"></script>

Following those you can define your FITS object:

var fits = new FITS();

Next we define what happens on load:

fits.bind("load",function(){

    // Display some values
    document.getElementById('bitpix').innerHTML = this.header.BITPIX;
    document.getElementById('depth').innerHTML = this.depth;
    document.getElementById('z').value = 0;

    this.draw("FITSimage")  // Draw the image to the element with id=FITSimage
})

We can also bind some other events (which are chainable) e.g.:

fits.bind("click",function(e){
    e.y = this.height - e.y
    var value =this.image[e.y*this.width+e.x];
    document.getElementById('status').innerHTML ='click=('+ e.x+','+e.y+')='+value;
}).bind("mousemove",function(e){
    e.y = this.height - e.y
    var value =this.image[e.y*this.width+e.x];
    document.getElementById('status').innerHTML ='move=('+ e.x+','+e.y+')='+value;
})

Finally, load the FITS file. We've already defined the load event above:

fits.load("WFPC2u5780205r_c0fx.fits");

FITS files

The example makes use of several FITS files. You can get these at:

Author

Stuart Lowe works for the Las Cumbres Observatory Global Telescope. LCOGT is a private operating foundation, building a global network of telescopes for professional research and citizen investigations.

Some improvements have been suggested by anonymous contributors.