Friday, April 8, 2011

Making overlays

Hi there! Today I'd like to tell you about the techniques that I use to create overlays of astronomical data. Usually I want to compare two or more maps, taken with different telescopes and different resolution. Examples would be to mark all the stars detected on an optical image on a near-infrared of the same area. Or to show an optical image of a spiral galaxy and overlay contours of the molecular gas (from observations of CO).

Enough said, lets get started. To create overlays the data need to be in the FITS format for all these techniques to work. FITS-files are astronomical images that have information about the area of the sky that has been observed. Most astronomical data are distributed as fits files, and other formats can be inverted into fits.

The Data
For this presentation I decided to use two images of the Starburst galaxy M82. First, I downloaded a Hubble Space Telescope image from HLA (Hubble Legacy Archive). Most data are public so you can download lots of beautiful images. I got the ACS image in filter F435 (4350 Angstrom or 0.44 micron) which looks like this:


I also found the Spitzer image taken with the IRAC instrument (3.6 micron or 36000 Angstrom) from the Spitzer Heritage Archive. It looks like this:


 (the strange shape of the observed region is due to the way that Spitzer observes: it observes several "patches" of the area and then stitches them together).

Ok, now we have some data, let's see how we can check how well the two maps correspond.


DS9
SAOimage DS9 is a program that is powerful, but tricky to use. In my opinion, the manual is hard to read and does not include all features in the software. There are some sources on the web (see the link above or http://casa.colorado.edu/~ginsbura/ds9tips.htm#body5).

Let's go through how to make an overlay. We represent the HST image as a pixel image (since it has the highest resolution), and the IRAC image as contours. To load the images in DS9, they need each to be in separate "frames".


  1. Open the first image ( File -> Open
  2. Normally, the default image scaling makes it impossible to see the faint structures in these images. Change scaling to something more useful, with the buttons in the main DS9 window or the meny items. Click on "scale" button and the "zscale" ( or Scale -> zscale in the menues).
  3. Make a second frame by clicking on the "frame" button followed by "new".
  4. Load the second image in this frame in the same way as the first. 
  5. To see both images, click the "tile" button. You should now have the two images side by side.
  6. To make sure that we are showing the same area, click (Frame -> Math -> Frame -> WCS)
  7. Start by making the contours of the Spitzer image. Click (Analysis -> Contours) and choose the number of contours and spacing. I got something looking as the second image below. 
  8. Finally, we copy the contours to the HST image. Clock on the frame where the Spitzer image is (You may have to click the menu (Edit -> Pointer) first. Bring up the contour window again, and click File -> Copy contours.
  9. Click in the HST frame. Go back to the contours window and click File -> Paste contours. A dialog appears where you choose coordinate system, colour and linewidth. Use always the WCS system and any color you like. 
  10. The contours are copied, and the image looks like below.

Images loaded in two frames

Contours on the Spitzer image

Final overlay. See the good astrometric correspondance on the bright star in the lower right part.

That was a short guide to making overlays in DS9. DS9 is useful for data analysis, but when preparing figures for publication many clicks are needed to create the graphs. It is possible to use scripts to speed up the generation of graphs, but the final appearance is not the best. For publication-level graphs I prefer the Karma program, but that will be the focus of another post.

Tuesday, April 5, 2011

Making good-looking Matlab figures

One of the reasons why I like Matlab so much is that you can do everything there; from simulations, data processing, calculations all the way to making graphs and figures to show your results. Everything in one package!

But frankly, the graphs that Matlab spits out with the default settings are pretty ugly. Let me make an example. I generated some data ( y = log10(x)*x ) and added some noise. The plot shows the theoretical curve and the "data".

This looks ok, but to me, the lines are too thin and the font does not look good. First, let's change the size of the output. 

I have learned that it is much easier to set the size of a Matlab figure in physical sizes (centimeters) than the default. The following code sets the figure to be 15x12 centimeters.

    set(gcf, 'PaperUnits', 'centimeters');
    set(gcf, 'PaperSize', [15 12]);
    set(gcf, 'PaperPositionMode', 'manual');
    set(gcf, 'PaperPosition', [0 0 15 12]);

Applying this to our figure we get

Looks better, right? Now, let's change the font-size, the line-width and the length of the tickmarks.

Change the ticklength. Use a value close to [0.02 0.025], but you may have to experiment with smaller or larger values for the first parameter (between 0.015 to 0.025) to make it look good.
set(gca, 'TickLenght', [0.02 0.025]);
Change the font size. For a figure of this size, 10 points looks good.
set(gca, 'FontSize', 10);
Change the linewidths of the axes and of the objects plotted.

 set(gca, 'Linewidth',1);
and the same for the other handles.
Compared with the first graph, this is a clear improvement. 

This will be all for now. In this post I used png files. When making figures for research papers it is required that they use the eps format. There are a few more tweaks that can be made to such figures. 

Monday, April 4, 2011

Transparent figures in Matlab

If you want to make an overlay between two images in a program like keynote, powerpoint, pages, illustrator and want the images to be transparent, how would you achieve the transparency? Being a heavy Matlab user, I recently had to export my Matlab data, in the form of two spectra, with a transparent background. 

A quick google query showed that I was not alone with having this question. I found as many answers as there were questions, but finally there was one which actually worked for me. 

The excellent package export_fig can be downloaded from the Matlab central. With export_fig, making a transparent background comes down to three (!) simple steps.

  • Make the image as you want it to look 
  • Set the background of the current figure and axes to none
  • set(gcf, 'color', 'none); set(gca, 'color', 'none');  
  • Export the figure to a png (this works well, eps or pdf might work too)
  • export_fig figname.png
  • This png file is now transparent.
An example of such a figure is shown below (for the interested it shows two molecular transitions from the CO molecule in a faraway galaxy, but I won't tell you which ! ). The blogger style seems to make the background slightly grey, but the png is really transparent. More Matlab tips are coming!



Find your Latex symbol

When writing a paper or thesis in Latex, I have many times had to search through long lists of symbols names to find out how one write ## insert random greek or math symbol ##.  CTAN has the COMPREHENSIVE LATEX SYMBOL LIST, which has everything you'll ever need (and much more). 
In Swedish there is a shorter guide by Einar Steingrimsson (symbols.pdf) which is easier to read. But still, it requires searching through long lists.

The solution to the problem is Detexify2
This lovely web service lets you draw your symbol in a window and an algorithm then suggest the best matches. I tried it with a few symbols and it seems to work very well. Worth a try at least!


(thanks to Saad, T. "LaTeX Symbols - Detexify". Weblog entry from Please Make A Note. http://pleasemakeanote.blogspot.com/2010/07/latex-symbols-detexify.html)






Friday, April 1, 2011

First post

My first blog post ever. I don't intend to write stories about how my day has been, about stuff that I cook, about the state in the world, about politics, music, culture. There are already a lot of those kinds of blogs out there that do it much better than I possibly would.

Instead, this blog will be about the (computer) tools we use today in astronomy research. Currently at the stage of finishing my PhD studies I have worked with data from different telescopes, and used various software to reduce and analyze the data. I will try to give examples of how I have solved problems , made graphs for publications, written scripts and so on. This is also my way to give back to the people on the web where one can almost always find answers to questions. Hopefully this will be useful for someone! Stay tuned