Tuesday, March 11, 2014

Let's be Negative (sometimes): Image Subtraction (Week 5)

This week, I decided to continue (sort of) last week's post about technology - I will be going through a routine I wrote for image subtraction line-by-line and explaining the process, hopefully elucidating more about how IRAF works.


Essentially, image subtraction is exactly what it sounds like - we take one image and subtract another one from it. More exactly, the value of each pixel in the subtrahend is removed from the value of each pixel in the minuend (so subtracted images need to have the same amount of pixels). Image subtraction can allow us to see changes in an image. Below is a sample routine for performing image subtraction in IRAF.


Lines 1 and 2 open the necessary packages in IRAF to execute the rest of the code. The "images" package contains a lot of functionality for manipulating images, including the "imgeom" package which houses image geometry packages and routines. In line 4, we start by removing any subtrahend images that might have existed beforehand - running this code is usually an iterative process, with small changes being made to both the science and subtraction images. big_09igB_sub.fits is the name I gave to the subtraction image for images from the Bigelow telescope in the B filter of SN2009ig, while bok_09ig_sub.fits is the name for the subtraction image for Bok images in the B filter. We need two files because the Bigelow and Bok CCDs have different sizes, resulting in different image dimensions.

Line 5 magnifies our original image of the galaxy before the supernova (here UGC_02124:I:B:d1996.fits) by a factor of 0.734 in each dimension (the x and the y) and spits out the image big_09ig_sub.fits.

A portion of UGC_02124:I:B:d1996.fits. The full image is longer in the x direction.

The number 0.734 in the magnification factor is determined by examining the science image and the above image to determine which is bigger. Line 7 removes all images that start with "temp1" and have a capital "B" just before the .fits extension, because these images will be created in the next step. IRAF cannot overwrite images. Line 8 rotates the image big_09ig_sub.fits through 0.4 radians and spits out the image temp1_big_100224_09igB.fits. The 100224 refers to the date; 10 is 2010, 02 is February, 24 is 24. This specific rotated image will be used to subtract the science image from February 24th, 2010, shown below.

This file is 100224_09igB.fits. The supernova lives in the green circle, which does not exist in real life.
Line 10 removes all images of the form sci*B.fits, because again IRAF cannot overwrite images. In line 11, we copy a region (375 to 775 in the x, 486 to 766 in the y) of the original science image (100224_09igB.fits) and write the file sci_100224_09igB.fits, so if we make a mistake we still have the original around. The region we choose depends on the object; in the case of a supernova, it is usually convenient to leave just the area around the host galaxy, which is what we chose to do here. In line 12, we copy the region [400:800,2:282] of the rotated subtraction image temp1_big_100224_09igB.fits and spit out the file temp1b_big_100224_09igB.fits. The region we choose here has to result in an image that matches exactly the dimensions of the science image we are going to subtract from. It also has to include the same objects otherwise the exercise is pointless.

The block of code between lines 15 and 17 first removes images that would be overwritten, and then convolves our subtraction image temp1b_big_100224_09igB.fits to a Gaussian fit with a sigma of 1.2 (you can think of this as blurring the image by a factor of 1.2) and outputs a temp2 file. The next line multiplies the value of every pixel in the temp2 image by 1.15 and gives us our temp3 file.

The final block of code is where the actual subtraction takes place. First, we remove image files that would be overwritten and the special sh.db file ("shifts database" or something like that). The xregister command we call into effect takes our two images and registers them around a region of our choosing, with the goal of matching up the position of their pixels exactly. The box we want to align them around is [250:420,180:320]. xregister outputs a shifts database file that tells us what the shift between the images is, and also the image xr_100224_09igB.fits, which we finally subtract from sci_100224_09igB.fits to obtain the final subtracted image final_big_100224_09igB.fits displayed below.
The supernova is the obvious white dot. The blackish part is where the galaxy was slightly oversubtracted due to saturation issues with the CCD, and a star that doesn't quite match up is seen to the left.
The code then logs out of the IRAF session. We run the code from a terminal with the command cl < do_imsub_B.cl (the name of the file).


The final image allows us to perform photometry of the supernova on a flat field, giving us a better and more accurate idea of how bright the supernova is alone. Were we to perform science on the original image, we would almost certainly have galaxy light contaminating our data. This image subtraction must be repeated for every image in every filter on every night of observation, and all of the boxes, shifts, multiplications, Gaussians, and rotations are confirmed by hand. Apparently there exists a software called ISIS (short for Image Subtraction Sofware, somehow, and named for the Egyptian goddess of magic) that can do it all automatically.
Magic indeed. No need to look so smug, Isis.
ISIS, unfortunately, is somewhat of a black box. You put in two images and you get one out without knowing exactly what happened inside. For that reason, Dr. Milne and I choose to go through and do it by hand. If for some reason we aren't able to get satisfactory results, we can always plug our data into ISIS and get (hopefully) better results. For now, though, my time is dominated by doing image subtraction.


That's all I have for this week, lovely readers. Until next time!

No comments:

Post a Comment