f2n - fits to net

Ocotber 2009 : f2n.py released !
f2n is now ported to python ! Read on here, and forget about the rest of this page.

December 2008 : deprecation warning ...
I played with f2n to experiment with my own grayscale mappings for special tasks. This simplified release of f2n works fine and I still use it in a pipeline, but do not expect further development. All this can/should/will be done directly from within python in future !
Note that you might now also consider STIFF from Emmanual Bertin, or some tools from imcat to perform similar tasks.

About

f2n is a tiny standalone program to "convert" fits images into png, with options about the grayscale (or colour) scaling.

It's particularly useful to call f2n from a script, applying it to a set of images, and then generate html pages using the png files, or combine/resize/annotate them with ImageMagick, or make MPEG movies or gif animations, or all this at the same time. Actually I'm using f2n a lot !

Negative, full range

Linear scale, crosshair, auto cutoffs

Fixed "contours"

Log with coloured cutoffs

Special PSF scale

Usage

[maltembp:~/Desktop] mtewes% f2n
-------------------------------------------------------------------------

       f2n - fits to net
I convert images from fits to png
    version 0.9.1, December 2008
        malte.tewes at ...

Usage :   f2n p/n ztrans in.fits out.png [z1 z2]

Example : f2n p f in.fits out.png -10 2000

   p/n =
p: positive output
n: negative (inverse video) output

   ztrans =
l: lin scale  (lc : same but with coloured cutoffs)
e: log centered on 0.0
f: log scale as in IRAF's display (fc : coloured cutoffs)
p: lin from z1 to -z1, then log up to z2 (my fav for dec.fits)
c: log with color countours around 1.0 (my fav for sm residuals)
r: pseudocolour log hsv
s: somewhere over the rainbow (exprimental)

   z1 z2 =
the lower and upper cutoffs to use. Give either none or both.
(not given) : min and max cutoffs (same as m m, see below)
-1.2e-5 : hard cutoff (for example)
m : extremal (min or max) cutoff
a : super intelligent auto cutoff (experimental but not that bad)
You can also mix them. Examples : "-10.0 a", "a m", "a a", "0 1"

You can use file.fits[a:b,c:d] to select a region of the input file.
(In case of trouble use quotes : "file.fits[a:b,c:d]")

-------------------------------------------------------------------------
[maltembp:~/Desktop] mtewes% f2n p f "wfpc2.fits[20:319,50:349]" out.png m a
+++ region of wfpc2.fits[20:319,50:349] : 300 x 300 pixels
+++ calculating auto cutoffs ...
+++ z1 = min = 23.000000
+++ z2 = auto = 125.000000
+++ (max value is 3400.000000)
+++ positive output image
+++ using IRAF log scale
+++ f2n : done
[maltembp:~/Desktop] mtewes% 

Get it

If you are working at the Observatoire de Sauverny (hey, chances are not that bad if you are reading this), I suggest to directly alias my binaries : /home/epfl/tewes/bin/f2n_linux for "obsds20"-like servers, and just f2n for the Sun computers like "obssf8" etc.

If not, or if you want to run it on your laptop, you will have to go the hard way and compile it.

Code & Compilation

f2n is plain procedural C code, written as I couldn't find anything similar at that time ([sic] - something like this for sure already exists out there; all those survey websites can generate pngs or jpgs on demand but they probably use functions of larger packages and not tiny apps...), but I also wanted to tweak the grayscale mapping by myself. In principle there would be ImageMagick, as convert can handle FITS files, but it didn't suit my needs.

Using C for this task is a product of ignorance. I would now use python, which would be much easier. And as I love playing with pixels, I might rewrite something similar in python one day. Anyway, for now it works in C.

f2n_091.tar
In the box : the source and a small fits file to play with.

The usual warning first : the code is quick, dirty, and certainly not optimal, don't blame me please :-) You'll need the libraries libpng and cfitsio. BTW both are part of ESO's scisoft distribution.
I've currently installed :
libpng 1.2.25
cfitsio 3.040
but older versions will work as well.

So, tweak the includes at the top of the source, (i.e. give the absolute path to fitsio.h and png.h in the source if you need), and compile using a call to gcc like

> gcc f2n_091.c -o f2n -lm /scisoft/i386/lib/libcfitsio.a /scisoft/i386/lib/libpng.a

Just to give some inspiration about options, here are the lines I used on the workstations at work :
> cc f2n_091.c ../cfitsiolinux/libcfitsio.a -lpng -lm -lnsl -o f2n_linux
> cc f2n_091.c ../cfitsio2420/libcfitsio.a -lpng -lm -lnsl -lsocket -o f2n

Version history

0.9.1 : December 2008 : no-brainer change to allow for larger filenames.
0.9.0 : first "release".

Enjoy !

And don't hesitate to ask me if you have questions or trouble running/installing it.
Malte