Spitzer Documentation & Tools
Spitzer Data Analysis Cookbook


Recipe 10.             CUBISM: Spectrum Extraction of M51

In this recipe, we will run through the steps necessary to reduce Spitzer IRS Long-Low (LL) Mapping Data of NGC 5194 (M51).

10.1            Requirements

To follow along with this recipe, you must install the software package CUBISM (http://irsa.ipac.caltech.edu/data/SPITZER/docs/dataanalysistools/tools/cubism/). In order to run CUBISM, you must have  IDL installed and make sure you have the latest version of the IDL Astronomy User's Library (http://idlastro.gsfc.nasa.gov/).


You will need to download the example data set using the Spitzer Archive. For this example the AORs needed are 16801536 and 16801792, all wavelengths, BCD data. See Recipe 1 for details on downloading the data. We will assume you will download and work on the data in the directory yourdatadirectory/.


Finally, you may wish to look at the following documents:


  • Brunner et al. (2008, ApJ, 675..316), which discusses Spitzer IRS Maps of M51.
  • The CUBISM Manual.
  • The CUBISM paper by Smith et al. (2007, PASP, 119, 1133).

10.2             Create a new CUBISM project

Once you start up CUBISM, a "Load Cube Project" window will pop up. Click on "Create New Cube Project" near the bottom.




Once you give the project a name of your choice (here we choose "m51_LL2"), a CUBISM Project Window will appear:




Click on "Import AOR" near the bottom of this window. Navigate to yourdatadirectory/ and click on "OK".


CUBISM will look for all AORs in any subdirectories of yourdatadirectory/. Then it will ask you to verify the BCD data it finds. Check the boxes next to the "LL" options and click on "OK".


When asked, choose the most recent calibration file.

Now your Project Window should contain information about the BCD data that you just uploaded.



10.3            Visualize your AORs

CUBISM allows you to visualize the AORs you just uploaded. To try it out, first go to the main CUBISM Project Window and select "Cube"-->"Set Cube Build Order"-->2. This sets the Cube Build Order to LL2. Next select "Record"-->"Visualize AORs" in the Project Window. You will be prompted to select a Visualization Image. For this demonstration, select the 24 micron image of M51 which you downloaded previously. The file you want is called




The image you just loaded will appear in a new CubeView window. However, it will be difficult to see, so you will need to adjust the scaling. Near the top of the CubeView window, click on the histogram scaling button:



Now use your mouse to make a box anywhere in the image area. You will see the color scale change. Adjust the size and location of the box until you can see M51 properly.


Now you will notice that M51 takes up only a small part of the image area. To zoom in, click on the zoom button:




Then click anywhere on the image to zoom in and center on that spot. (Right-click to zoom out again, or command-click if you're using a Mac.)


You should see something like this:




The orange rectangles are the LL2 slits.

10.4            Background Subtraction

As can be seen in the above visualization, most of the time, the LL2 slit was place somewhere on M51. However, the LL2 observations also extend off of the galaxy. This is fortunate, because we can use these off-source positions to subtract a background from the on-source positions.


To select the background positions, simply click on the "Select BCD" Button in the CubeView Window:




and then use your cursor to click and drag over the orange rectangles that do not fall on the galaxy. They will turn white, and the corresponding entries in the Project Window will become highlighted. Since the rectangles are overlapping, it can be difficult to select the bottom layer. You can select additional records in the ProjectWindow itself. As you click on the record entries, you'll see the corresonding AORs turn white in the CubeView Window. For this example, you should select 20 records in total for the background.


To compute a background from these selected records, go to the Project Window and click on "Background"-->"Set Background from Rec(s)". In the window that pops up, check the box next to "Average + Min/Max Trim", and click "OK".


Let's save the background records so that we don't have to go through the selection process again. In the Project Window, select "Background"-->"Save Background Rec(s)", and select the output directory.


Next disable these records so that CUBISM won't take the time to build them into the cube. In the Project Window, select "Record"-->"Disable". Now the records you selected will have a line through them to indicate that they have been disabled.

10.5            Build initial cube

In the main CUBISM Project window, click on "Build Cube" near the bottom. You will see a progress window pop up. It will look like this once the cube has finished building:




The white lines represent the output cube pixels. The colored boxes represent the input BCD pixels (or fractions thereof).


Now is a good time to save your cube. In the Project Window, select "File", "Save As" and select an output directory and filename.

10.6            Visualize cube

Now that your cube has been created, CUBISM allows you to visualize it. To do this, click on the "View Cube" button near the bottom of the CUBISM Project Window. You'll see something like this:




The image you are looking at is a picture of M51 at the wavelength 14.2666 microns. You can click the "Next" button near the bottom of the window to step through bins of increasing wavelength.

10.7            Extract spectrum

Cubism allows you to extract spectra over circular and polygonal apertures. Non-rectangular regions must be specified as ds9 regions files and then uploaded into Cubism. Fore more information, please see Section 6.1.2 of the Cubism manual.


To extract a spectrum over a rectangular region, in the CubeView Window, click on the "Extract Button", which looks like this:




Using your mouse, define a box in the CubeView window. This is the aperture over which your spectrum will be extracted. A "CubeSpec" Window will pop up to show you the extracted spectrum. If you selected the entire region, your spectrum should look like this:



10.8            Remove bad pixels automatically

Some of the spikes in the above spectrum are real, physical features. Others are just bad pixels in the individual BCDs that need to be removed. CUBISM has a method for automatically detecting bad pixels.


In the CUBISM Project Window, choose "BadPix"-->"Auto-Gen Global Bad Pixels", then click "OK". You will be presented with two parameters which you are free to adjust: Sigma-Trim and MinBad-Frac. These parameters are described in Section 4.5 of Smith et al. (2007, PASP, 119, 1133). Briefly, for each output cube pixel, the contributing pixel residuals are tested against an estimate of the contributing pixel deviation. If a pixel is an outlier (defined by Sigma-Trim), it is tentatively marked bad. If the same pixel is so marked at least a fraction of the times (defined by MinBad-Frac) it appears in the cube, it is flagged. To avoid removing spectral lines, start with high values of Sigma-Trim and high values of MinBad-Frac. As you decrease these values, the bad pixel removal will become more aggressive, and you may start removing real features.


After you have clicked "OK" in the AutoBadPix Window, "QuickBuild" your cube. This will go much faster than the original build. Your extracted spectrum will be automatically updated:



Notice that the spike at 19.5 microns went away! Also try "BadPix"-->"Auto-Gen Record Bad Pixels". Your spectrum will not change very much.

10.9            Remove bad pixels by hand

CUBISM also allows us to remove bad pixels interactively. You can do this either instead of or in addition to the automatic bad pixel rejection described in the previous section.


In our example, let's first undo the automatic bad pixel rejection so we can examine the spike at 19.5 microns in detail. In the Project Window, select "BadPix"-->"Clear All Bad Pixels", then click on "Yes". You can do a "QuickBuild" to see the spike come back.


Now let's inspect the image of M51 near the wavelength 19.5 microns. To do this, click repeatedly on the "Next" button in the CubeView Window until the wavelength reads 19.4931 microns. You should be able to see several vertical stripes in this image.




Vertical stripes like this are an indication that there is a bad pixel in one of the input BCDs. As the sky is mapped, a given bad pixel is dragged over the sky, resulting in stripes in the output cube. CUBISM's pixel backtracking tool is useful for finding the offending BCD pixels. You can activate this tool from the CubeView Window by pressing on the button that looks like this:




Once you've clicked on this button, you can place your cursor over any cube pixel in the CubeView Window to see which input BCD pixels contributed to it. Try clicking on a cube pixel in the rightmost vertical strip. You will see a green 'x' appear on that pixel and the BackTracking Window will freeze, looking something like this:




You can see that pixels (62, 19) and (62,20) in one BCD is very large, and both have bmask flags of 7. Back in the CubeView Window, right-click on the green 'x' you made, and it will disappear. Once again, you can run the cursor over any pixel and the BackTracking Window will update. Running the cursor over cube pixels within all three stripes, you will see that these particular BCD pixels are bad in several of them.


To mark these pixels as bad, do the following:


1. Click on one of the cube pixels in the stripe in the CubeView window.


2. Go to the Backtracking window, and click on the line for the pixel (62,19) to highlight it.


3. Right-click (command-click for Mac users) on the highlighted line.


4. You'll be asked whether to set the pixel to a "global", "this record" or "these records" bad pixel. In this case, the pixel is bad throughout, so we will set it to a global bad pixel. Check the Bad Pixel (Global) box. The flag will change to "BP[7]".


5. Repeat for pixel (62,20).


If you do a quick build of the cube, you will see the negative spike disappear in the extracted spectrum, and the stripes disappear in the CubeView Window at that wavelength.


If you end up marking a lot of bad pixels by hand, you will probably want to save your bad pixel list. To do this, go to the CUBISM Project Window and click on "BadPix"-->"Save Bad Pixels".

10.10       Make a filter-specific map

In addition to making a map at a given wavelength, CUBISM can make a map using a given filter. In the CubeSpec Window, select "Maps". You will see that several options are available. None of these fall entirely within the LL2 wavelength coverage, but you can select "IRS Blue Peak-Up 16um" to see what happens. The CubeSpec window will show the 16 microns filter curve in red, and the CubeView Window will now show a map integrated over that curve:



10.11       Save your work

To save the cube project again (cpj file), go to the CUBISM Project Window, click on "File"-->"Save".


You may also want to save the cube as a fits file. To do this, go the CUBISM Project Window and click on "File"-->"Write Fits Cube".