Last modified: 17 Dec 2014


An Estimated Background Image

CIAO 4.12 Science Threads



This thread shows one method for making an estimated background image for a dataset. The resulting image can be used with any data analysis tool that takes a background image, e.g. wavdetect or dmextract.

Run this thread if:

you want to create a background image for an ACIS or HRC imaging observation. This method is suited to fields which contain a few point sources; it will not work well with very large extended objects.

Last Update: 17 Dec 2014 - Reviewed for CIAO 4.7; no changes


Get Started

Download the sample data: 578 (ACIS-S, 3C 295)

Early dataset

The data used in this thread was taken very early in the Chandra mission. It was not included in the bulk reprocessing metioned in the Watchout page. The keywords required for analysis with CIAO need to be added by running chandra_repro or r4_header_update.

Make an Image of the Chip

The event data filtered on energy and is binned into an image, using the field of view file to select the desired chips. For this example, ACIS-S3 (ccd_id=7) is selected:

tcsh% set energy = "energy=300:7000"
tcsh% set ccd = "ccd_id=7"
tcsh% set sky = "sky=region(7_fov.fits)"

bash> energy="energy=300:7000"
bash> ccd="ccd_id=7"
bash> sky="sky=region(7_fov.fits)"


unix% dmcopy "acisf00578_000N003_fov1.fits[${ccd}]" 7_fov.fits
unix% dmcopy "acisf00578N003_evt2.fits[${energy},${ccd},${sky}][bin sky=2]" 578_img.fits

Filtering this way ensures that the edge of the detector is stored in the image and can be used by later processing tools.

Convolve the Image

The counts image is first convolved with a 3 pixel sigma Gaussian by aconvolve to smooth out the zero-value pixels. This will produce better results from the median-value filter applied in the next step.

unix% punlearn aconvolve
unix% pset aconvolve infile=578_img.fits
unix% pset aconvolve outfile=578_convolved_img.fits
unix% pset aconvolve kernelspec="lib:gaus(2,5,1,3,3)"
unix% pset aconvolve meth=fft

unix% aconvolve
Input file name (578_img.fits):
Kernel specification (lib:gaus(2,5,1,3,3)):
Output file name (578_convolved_img.fits):

The contents of the parameter file may be checked using plist aconvolve.

Filter the Image

A "median ring" filter is applied to the file. The median is the middle value from the array of pixel values. Note that dmimgfilt uses a slightly non-standard median: if the number of points is even, then the lower value is used rather than the mean of the two middle values.

The radii of the annulus should chosen be such that the region is big enough to exclude any structure you want removed (e.g. point sources) and small enough so that you're not sampling data too far away from the current pixel. In this example, an inner radius of 20 pixels and outer radius of 22 pixels are used.

unix% punlearn dmimgfilt
unix% pset dmimgfilt infile=578_convolved_img.fits
unix% pset dmimgfilt outfile=578_bg.fits
unix% pset dmimgfilt function=median
unix% pset dmimgfilt mask="annulus(0,0,20,22)"

unix% dmimgfilt
Input image file name (578_convolved_img.fits):
Output file name (578_bg.fits):
Filter function (min|max|mean|median|...|rms) (median):
masking filter (annulus(0,0,20,22)):

The contents of the parameter file may be checked using plist dmimgfilt.

The file 578_bg.fits can be used as input to wavdetect, dmextract, or any data analysis tool that uses a background image. The final background image is shown in Figure 1.

Figure 1: Estimated background image compared to source

[Thumbnail image: The background (right frame) is primarily flat with some brighter features where the extended emission is in the original observation. An image of the source is in the left frame.]

[Version: full-size]

[Print media version: The background (right frame) is primarily flat with some brighter features where the extended emission is in the original observation. An image of the source is in the left frame.]

Figure 1: Estimated background image compared to source

The background image (578_bg.fits) is in the right frame. The left frame is the source image (578_img.fits) created in the Make an Image of the Chip section and the center image is the smoothed version.

Using with wavdetect

If the purpose of creating the background file is to be input as wavdetect's bkginput parameter then additional processing steps are needed.

The bkginput requires that the background be exposure normalized, meaning that exposure variations have already been removed but remains in units of "counts". This is done by dividing the background file by a unit-amplitude exposure map (exposuremap divided by maximum pixel value).

We assume that you have already created an exposure map using fluximage or following the Single Chip ACIS Exposure Map and Exposure-corrected Image. Be sure that the energy or spectrum used matches that of the background energy filter.

First we make sure that the images are the same size using reproject_image. Because we are regridding an exposure map, we need to be sure to use the average of the regridded pixels.

unix% reproject_image 578_broad_thresh.expmap 578_bg.fits 578.emap method=average

Now, because the dmimgfilt operation is essentially a kind of smoothing, we also need to be sure that the exposure map is smoothed on the same spatial scale. For the counts image, we used a median filter to suppress outliers; for the exposure map we should use the mean or average value with the same size annulus.

unix% dmimgfilt 578.emap 578_sm.emap mean "annulus(0,0,20,22)" clob+ 

Next we need to get the maximum pixel value in the regridded exposure map

unix% dmstat 578_sm.emap cen- sig- med-
    min:        0             @:        ( 3508.3409617 3677.8790118 )
    max:        7234120               @:        ( 4288.3409617 4121.8790118 )
   mean:        3716584.5422 
    sum:        1.7952032485e+12 
   good:        483025 
   null:        0 

Then we can use dmimgcalc to exposure normalize the background file.

unix% dmimgcalc 578_bg.fits,578_sm.emap  none 578_nbkg.fits op="imgout=img1/(img2/7234120)"
warning: CONTENT has 1 different values.
warning: DETNAM has different value...Merged...

where img1 is the first file in the stack, the background file, and img2 is the second file in the stack, the smoothed exposure map. The output image Figure 2 shows that the edges of the background image have been flatten where the exposure has fallen off.

Figure 2: Exposure Normalized Background

[Thumbnail image: (Right) Background image without exposure correction, and (Left) background image after exposure normalization.]

[Version: full-size]

[Print media version: (Right) Background image without exposure correction, and (Left) background image after exposure normalization.]

Figure 2: Exposure Normalized Background

(Right) Background image without exposure correction, and (Left) background image after exposure normalization.

This file can then be used as input to wavdetect.

Parameters for /home/username/cxcds_param/aconvolve.par

        infile = 578_img.fits     Input file name
       outfile = 578_convolved_img.fits Output file name
    kernelspec = lib:gaus(2,5,1,3,3) Kernel specification
  (writekernel = no)              Output kernel
   (kernelfile = ./.)             Output kernel file name
     (writefft = no)              Write fft outputs
      (fftroot = ./.)             Root name for FFT files
       (method = fft)             Convolution method
        (edges = wrap)            Edge treatment
        (const = 0)               Constant value to use at edges with edges=constant
          (pad = no)              Pad data axes to next power of 2^n
       (center = no)              Center FFT output
   (normkernel = area)            Normalize the kernel
      (clobber = no)              Clobber existing output
      (verbose = 0)               Debug level
         (mode = ql)

Parameters for /home/username/cxcds_param/dmimgfilt.par

        infile = 578_convolved_img.fits Input image file name
       outfile = 578_bg.fits      Output file name
      function = median           Filter function
          mask = annulus(0,0,20,22) masking filter
      (numiter = 1)               Number of iterations to loop over
    (lookupTab = ${ASCDS_CALIB}/dmmerge_header_lookup.txt -> /soft/ciao/data/dmmerge_header_lookup.txt) lookup table
      (verbose = 0)               Tool verbosity
      (clobber = no)              Clobber existing output?
         (mode = ql)
         (box3 = box(0,0,3,3))    Box: 3x3
         (box5 = box(0,0,5,5))    Box: 5x5
         (box7 = box(0,0,7,7))    Box: 7x7
      (circle3 = circle(0,0,3))   Circle: r=3
      (circle5 = circle(0,0,5))   Circle: r=5
      (circle7 = circle(0,0,7))   Circle: r=7
   (annulus5_3 = annulus(0,0,3,5)) Annulus: o=5,i=3
   (annulus7_5 = annulus(0,0,5,7)) Annulus: o=7,i=5
   (annulus7_3 = annulus(0,0,3,7)) Annulus: o=7,i=3
      (bann5_3 = box(0,0,5,5)-box(0,0,3,3)) Box Annulus: o=5,i=3
      (bann7_3 = box(0,0,7,7)-box(0,0,3,3)) Box Annulus: o=7,i=3
      (bann7_5 = box(0,0,7,7)-box(0,0,5,5)) Box Annulus: o=7,i=5


13 Jul 2009 New for CIAO 4.1
05 Feb 2010 reviewed for CIAO 4.2: no changes
13 Jan 2011 reviewed for CIAO 4.3: no changes
10 Jan 2012 reviewed for CIAO 4.4: no changes
03 Dec 2012 Review for CIAO 4.5; cleanup of version info (skyfov) and frequency of multiple asol files per observation (few).
30 Apr 2013 Added a section on using with wavdetetect tool. Simplify dmcopy example and add an energy filter.
26 Nov 2013 Review for CIAO 4.6; noted early data and need to run chandra_repro or r4_header_update.
17 Dec 2014 Reviewed for CIAO 4.7; no changes