Spitzer Documentation & Tools
Spitzer Data Analysis Cookbook


Recipe 22.            MOPEX/APEX: MIPS 24um mosaic of a z=0.7 cluster

For each MIPS observation, three types of files are available for download from the Spitzer archive: Raw, BCD (Basic Calibrated Data), and post-BCD. Each represents a different stage of processing. As explained in the MIPS Instrument Handbook, the pipeline that produces the BCD products is appropriate for most science programs. However, you may find that the post-BCD pipeline does not remove all instrumental artifacts (e.g. jailbars). If this is the case, then you may wish to start with the BCD products and carry out any further processing on your own. This tutorial provides an example for a MIPS staring-mode observation (a z=0.7 galaxy cluster), describing how to recognize artifacts in your post-BCD data and how to remove these artifacts from your BCD products using flatfield.pl, a perl script shipped with MOPEX. The tutorial then goes on to show you how to mosaic your corrected BCD frames using MOPEX, and how to perform source extraction using APEX, which is distributed with MOPEX.

22.1            Requirements

You must intstall MOPEX (http://irsa.ipac.caltech.edu/data/SPITZER/docs/dataanalysistools/tools/mopex/) in order to follow along with this recipe.


You will need 281 Mb disk space to hold the downloaded data. Download data from the Spitzer archive (see Recipe 1): BCD, post-BCD, and calibration data associated with AOR 13810432.


If you run MOPEX and wish to keep all the intermediate data files, this will require another 400 Mb of disk space. If you do not wish to keep the intermediate data files (only possible if you are using the command-line version of MOPEX; see below), this will be significantly reduced, to about 50 Mb.

22.2            Recognizing artifacts in the Post-BCD data

Let's take a look at the post-BCD data to get a sense of what our science data look like. In the directory r13811456/, there is only one subdirectory, called "ch1/". This is the directory where the 24 microns data are stored (the 24 microns data are channel 1, while the 70 and 160 microns data are channels 2 and 3, respectively). Within the ch1/ directory are three subdirectories corresponding to the data types you selected for download: "bcd/", "cal/", and "pbcd/". These hold the BCD, calibration, and post-BCD data products, respectively.


For a quick look at the data, cd into the pbcd/ directory. There is one file in this directory that ends in "maic.fits". This is the mosaic image made from the individual pointings. Below is a JPEG of this mosaic:




The JPEG above shows the attempt made by the post-BCD pipeline to mosaic together the BCDs for this pointing. As mentioned above, the post-BCD pipeline may not be optimized for every science program. Indeed the image above contains instrumental artifacts that we will attempt to remove. A full list of these, along with methods for mitigating their effects, can be found in the MIPS Instrument Handbook. Particularly noticeable are the jailbars, which appear as vertical stripes. Also present are bright and dark latents, which make the background appear splotchy. Since the sources in this field are all rather faint, these latents are likely caused by previous observations of bright sources.

22.3            Self-calibration to remove artifacts

To remove the artifacts seen in the mosaics that come out of the post-BCD pipeline, we first need to create a frame which consists only of the artifacts. We can then use this frame to divide out the artifacts in each BCD image. These steps can be performed with the perl script flatfield.pl, which comes with MOPEX, but has not yet been ported to the GUI. For each BCD file, flatfield.pl performs background subtraction, source detection on the background-subtracted images, stacking of background-subtracted images to create a flat while masking out detected sources and bad pixels, and flatfielding of the BCD images.


The user can achieve the functionality of flatfield.pl with a combination of SExtractor (for the detection step) and IRAF or IDL (for all of the other steps).


The inputs to flatfield.pl are:

  1. A namelist file, which allows the user to set some tunable parameters. For this example, we suggest you use this heavily commented namelist, http://irsa.ipac.caltech.edu/data/SPITZER/docs/dataanalysistools/cookbook/files/flatfield_24_ediscs.nl. You should make a directory called r13810432/ch1/cdf/ and put this file in it.

Note that if you have limited diskspace, you could change the line that currently reads "delete_intermediate_files = 0" to "delete_intermediate_files = 1".

  1. A list of input images, a list of sigma images, and a list of Dmask images. MIPS 24 microns data suffer from the "First-frame Effect", where the first frame of every commanded sequence of observations (data with the keyword DCENUM=0) has a shorter exposure time and is depressed in response by 10-15%. The MIPS instrument support team recommends discarding this first frame. In addition, the second and even third BCDs (DCENUM=1,2) also appear to have a reduced signal (~2%). If you have enough data then you may also want to consider discarding these. For this example, we suggest you discard the first frames:

cd r13810432/ch1

mkdir firstframes

cd bcd

mv SPITZER*_000*_0000*.fits ../firstframes

ls FULLPATH/r13810432/ch1/bcd/SPITZER*bcd.fits > InputImageList.txt

ls FULLPATH/r13810432/ch1/bcd/SPITZER*bunc.fits > SigmaList.txt

ls FULLPATH/r13810432/ch1/bcd/SPITZER*bbmsk.fits > DmaskList.txt

Here, FULLPATH is not literal but represents the entire path to your download directory.

To run flatfield.pl, first place the above *.txt files in the r13810432/ch1/ directory. Then:

cd r13810432/ch1


source /Applications/mopex/mopex-script-env.csh

flatfield.pl -n flatfield_24_ediscs.nl

This should take less than 2 minutes to run to completion. The script will have created a new subdirectory called mopex_flat/, since that is the directory specified by the namelist file. By entering the mopex_flat/ directory, you can examine the flat (named flat.fits) created by flatfield.pl. With a hard stretch, it should look something like this:




Note that flat consists only of artifacts, since the sources have been masked out. These artifacts include permanently-damaged pixels (which look somewhat like point sources and are additionally masked by MOPEX during mosaic creation), as the bright and dark latents mentioned above. Jailbars are also present, but are at a very low level.


The contents of the subdirectories created by flatfield.pl are as follows (if delete_intermediate_files = 0 in the namelist file):


Medfilter/: This directory contains background images and background-subtracted images corresponding to each of your input BCDs.


Detector/: This directory contains mask files, so that certain pixels in each image will be excluded in the creation of the flatfield image. The masked pixels are associated with sources detected in the background-subtracted input images.


Correct/: This directory contains the flatfielded input images. These are the images you will use to make your new mosaic, as described in the next section.

22.4            Make a new mosaic using your self-calibrated BCDs

The final step is to re-create the post-BCD mosaic using your self-calibrated BCDs. There are two ways you can do this. You can either use the script mopex.pl that comes packaged with MOPEX, or you can use the MOPEX GUI. We illustrate both methods below.


To make the mosaic from the command line:

Download this namelist file: http://irsa.ipac.caltech.edu/data/SPITZER/docs/dataanalysistools/cookbook/files/mosaic_24_ediscs.nl and put it in the directory r13810432/ch1/cdf/.


Note that if you have limited diskspace, you could change the line that currently reads  

"delete_intermediate_files = 0" to "delete_intermediate_files = 1".

cd r13810432/ch1

csh source /Applications/mopex/mopex-script-env.csh

mosaic.pl -n mosaic_24_ediscs.nl

While you are waiting for mosaic.pl to finish executing, you can read about exactly what is doing in our online documentation for the mosaic outlier.


Once the above command has finished executing, you will notice that a new directory called pbcd/ has been created. Within this directory are several subdirectories. The most important of these is the Combine/ subdirectory, which contains the new, self-calibrated mosaic you just made. We show it next to the automatic mosaic created by the post-BCD pipeline without self-calibration, so you can see the improvement.




BEFORE: the mosaic created automatically by the post-BCD pipeline, r13810432/ch1/pbcd/SPITZER_M1_13810432_0000_3_E3189129_maic.fits



AFTER: the mosaic created by you after self-calibrating the BCDs, r13810432/ch1/pbcd/Combine/mosaic.fits


To use the MOPEX GUI:

Start up the MOPEX GUI. A new window will pop up, but it will be empty. In the main MOPEX menu, click on File --> New Mosaic Pipeline. You will be asked to select a template. Select "Mosaic, MIPS 24 microns". The previously-empty MOPEX window will now be filled, and will look something like this:




Instead of feeding the MOPEX GUI a namelist like the one you used for the command-line version, you can click on various menus in the GUI to control how your data are reduced.


The mosaic pipeline consists of two main sections: "Initial Setup" followed by "Mosaic". Below is a listing of which parameters to set in each.


1. Set the parameters which should be changed from the template defaults:


Image Stack File           r13810432/ch1/mopex_flat/Correct/correct_InputImageList.txt


Output Directory                 To differentiate this run from the command-line run, first create a directory called "pbcd_gui" for the output files to be written to:

cd r13810432/ch1

mkdir postbcd_gui

Then, in the MOPEX GUI, select



Optional Input & Mask Files:


Sigma List File             SigmaList.txt


DCE Status Mask List DmaskList.txt

and leave the "Fatal Mask Bit Pattern" at the template default

Pmask FITS File           cal/mips24_pmask.fits

and leave the "Fatal Mask Bit Pattern" at the template default


2. Run MOPEX

At the top of the MOPEX screen you will see a green right-pointing arrow:




Click on it to run MOPEX. You will be able to watch as MOPEX progresses through the flow.

22.5            Perform source extraction on your new mosic

Now we will demonstrate how to use the post-BCD tool APEX to produce a catalog of sources in the mosaic you made in the previous steps.


APEX has two pipelines: single-frame point source extraction and multi-frame point source extraction.


In this example, we will run APEX in single-frame mode, using the mosaic we created using the MOPEX GUI, and the 24 microns PRF provided with MOPEX. The basic steps are outlined below:


1. Start a new APEX single-frame pipeline. After starting up MOPEX, go to the main menu and select File-->New Apex Single-Frame Pipeline. In the window that pops up, select "APEX 1frame, MIPS 24 microns". The previously-empty MOPEX window will now be filled with a module flow consisting of "Initial Setup" and "APEX single frame". It will look like this:



2. Set parameters.


Only the parameters that require a change from the template default are listed below.


Initial Settings:

Input File Name    r13810432/ch1/pbcd/Combine/mosaic.fits

Sigma File Name   r13810432/ch1/pbcd/Combine/mosaic_unc.fits

Coverage Map      r13810432/ch1/pbcd/Combine/mosaic_cov.fits

Output Directory   r13810432/ch1/apex_output


APEX single frame settings:

PRF File Name      /Applications/mopex/cal/mips24_prf_mosaic_2.45_4x.fits

You will have to modify your path to reflect your mopex installation directory


Aperture Photometry:

Number of Apertures   Five

Number of circular apertures to draw around each source, between 1 and 5.


Aperture Radius 1, 2, 3       1.0, 1.5, 2.0, 2.6, 3.0

Radius of aperture N in pixels.



This module creates the final table by applying user-specfied constraints and copying user-specified columns. The Settings window in the MOPEX GUI looks like this:




Columns Selection

Click on the columns you would like to appear in your final output table. On macs, use the COMMAND key to select more than one column. On PCs and machines running Solaris, use CNTRL.

Condition Builder

You can retain only certain objects in your catalog, based on their measured properties. For instance, you may wish to keep only sources with signal-to-noise ratios greater than 2. In that case, you would first remove the template condition SNR > 5. To do this, go to the "Selected Condition(s)" section of the GUI, and click on "SNR > 5.0". Then click on "Remove". To add your new condition, set the following options just above:


Available Columns = SNR

Operator = >

Value = 2


And then click "Add". Under "Selected Condition(s):", your new condition will appear as "SNR > 2.0".


For a complete list of all of the parameters associated with this module, open the "Help" window from the main MOPEX menu, and then scroll down the menu on the left-hand side to choose "Select". Alternatively, you can close the Settings window and click on the question mark that appears next to the Settings button.


3. Run APEX. Click on the green arrow at the top of the MOPEX window. When it has finished running (it should be very quick), you will find your output photometry table in the directory:




The final extraction table is called




If we plot all of the sources in this table on top of the image, it looks like this:




The above image was made using ds9 regions files, but you can visualize the extracted catalog on top of the mosaic using MOPEX. To do so, click on Images-->Fits File Image. Then select the same image mosaic you used as input to APEX. In this case, the image is


The image will appear in the MOPEX window, but it will be quite small. The upper left-hand corner of the MOPEX window will look like this:



You can click on the top button on the left-hand side to zoom in.


Then, to overlay the catalog you just created, click on Overlays-->Catalog File. Then choose




Each detected source will be indicated with a red X by default, but a variety of symbols and colors are available.