Last modified: 5 February 2024

URL: https://cxc.cfa.harvard.edu/ciao/gallery/apertures.html

Gallery: Apertures

Return to thumbnail page.

Examples

  1. [New]ROI (Regions of Interest) excluding overlaps
  2. [New] ROI ignoring overlaps
  3. [New] ROI creating groups
  4. [New] Assigning roi region overlaps
  5. [New]PSF enclosed counts fraction circular apertures
  6. [New] PSF contour based apertures
  7. [New] Background regions with fixed counts

1) [New]ROI (Regions of Interest) excluding overlaps

CIAO has several tools that can be used to automatically generate source and background aperture regions. These apertures may be based on the output from one of the source detection algorithm or by evaluation of the Chandra PSF at certain locations.

The roi tool is a flexible utility that creates source and background regions typically based on the output from one of the detect tools. It has options for dealing with overlapping source regions: excluding any overlap area, ignoring overlap, or simply grouping all overlapping sources into one. It also has options for how to create the background as either a single co-located annulus (with nearby sources excluded) or as a set of annuli around each source in the group. It also has options to adjust how the background regions are scaled and offset for the source region, options to include the edge of the detector via the field-of-view file, exclude readout streaks, and more.

In this example show just five sources detected in a merged data of NGC 6752. The other, clearly visible nearby sources have been omitted just to simplify this example.

In the first example we show the most common usage of the roi tools which is to simply exclude the area between overlapping sources.

apertures.roi.exclude
roi ngc6752_broad_thresh.center.src outsrcfile="ngc6752_%02d.exclude.reg" group=exclude targetbkg=target radiusmode=mul bkgradius=3 clob+ mode=h

The following commands can be used to visualize the output

ds9  -log ngc6752_broad_thresh.img -region ngc6752_01.exclude.reg ngc6752_broad_thresh.img -region ngc6752_02.exclude.reg ngc6752_broad_thresh.img \
    -region ngc6752_03.exclude.reg ngc6752_broad_thresh.img -region ngc6752_04.exclude.reg ngc6752_broad_thresh.img -region ngc6752_05.exclude.reg \
    -pan to  4120 4105  physical -zoom to 6 -match frame wcs -tile mode column -view multi no

In this example we see each of the 5 source aperture region files created by the roi tool. There is one single included ellipse in each frame with any other ellipses excluded from it. It is important to note that the excluded, overlapping area is not included in any of the source regions. We can see this if we create a mask file consisting of 1's and 0's and overlap the masks onto the image

dmimgcalc ngc6752_broad_thresh.img none unit.img op="imgout=((img1-img1)+1)" clob+
dmcopy "unit.img[sky=region(ngc6752_01.exclude.reg)]" msk1.img clob+
dmcopy "unit.img[sky=region(ngc6752_02.exclude.reg)]" msk2.img clob+
dmcopy "unit.img[sky=region(ngc6752_03.exclude.reg)]" msk3.img clob+
dmcopy "unit.img[sky=region(ngc6752_04.exclude.reg)]" msk4.img clob+
dmcopy "unit.img[sky=region(ngc6752_05.exclude.reg)]" msk5.img clob+

ds9 ngc6752_broad_thresh.img -mask transparency 50 \
-mask color red -mask msk1.img \
-mask color orange -mask msk2.img \
-mask color yellow -mask msk3.img \
-mask color violet -mask msk4.img \
-mask color blue -mask msk5.img \
-scale log -pan to  4120 4105  physical -zoom to 6

autogenerated

It is clear from the mask overlays that the area between the overlapping sources is not included in any of the sources. These types of regions are useful when doing analysis where the "confused", overlapping events from the spatially blended sources could affect the results. That is it can sometimes be better to work with fewer events if you expect them to be truly independent rather than have more events where some fraction of them are known to be confused with another source.


2) [New] ROI ignoring overlaps

The next roi option is to include the overlap area but identify the overlapping sources. This can be useful when you wish to include the effects of overlapping sources and need to know the fraction of the PSF from once source that is included in another source's aperture.

apertures.roi.individual
roi ngc6752_broad_thresh.center.src outsrcfile="ngc6752_%02d.indi.reg" group=individual targetbkg=target radiusmode=mul bkgradius=3 clob+ mode=h

The following commands can be used to visualize the output

ds9  -log ngc6752_broad_thresh.img -region ngc6752_01.indi.reg ngc6752_broad_thresh.img -region ngc6752_02.indi.reg ngc6752_broad_thresh.img -region \
    ngc6752_03.indi.reg ngc6752_broad_thresh.img -region ngc6752_04.indi.reg ngc6752_broad_thresh.img -region ngc6752_05.indi.reg -pan to  4120 4105 \
    physical -zoom to 6 -match frame wcs -tile mode column -view multi no

As before we see each of the 5 source aperture regions created by roi using the group=individual option. The term individual here is a bit of a misnomer; the region file contains the source region for each individual source plus all source regions that overlap it.

From the previous example we determine the source number: source number 4 is at the top, next down is number 1, followed by numbers 2, 3, and the source 5 is isolated by itself. Given this we can determine which sources overlap each other by looking at the SRC_#### keywords in the roi output files:

dmlist ngc6752_01.indi.reg keys,clean | grep ^SRC
SRC_0000             1
SRC_0001             2
SRC_0002             4

dmlist ngc6752_02.indi.reg keys,clean | grep ^SRC
SRC_0000             2
SRC_0001             1
SRC_0002             3

We see that source 1 overlaps sources 2 and 4. Source 2 overlaps sources 1 and 3; 3 overlaps 2, 4 overlaps 1, and 5 do not overlap any other sources.

A key feature of the roi output in this mode is that the first shape listed is the individual source. So the first shape listed in the 01.indi.reg file is source number 1. The first shape listed in the 02.indi.reg file is source number 2; and so on. This makes it easy to use a datamodel #row filter to access to individual sources aperture regions.

dmlist "ngc6752_*.indi.reg[#row=1][cols x,y]" data,clean
4116.6497326203 4120.1657754011
4119.6347346657 4114.9152308753
4122.1592649311 4107.9502297090
4120.7733333333 4124.9303703704
4126.4942345924 4094.2600397614

3) [New] ROI creating groups

Knowing which individual sources overlap is useful, but it can also be useful to simply group all the overlapping source apertures together. This can be done using the roi group=group option.

apertures.roi.group
roi ngc6752_broad_thresh.center.src outsrcfile="ngc6752_%02d.group.reg" group=group targetbkg=all radiusmode=mul bkgradius=3 clob+ mode=h

The following commands can be used to visualize the output

ds9  -log ngc6752_broad_thresh.img -region ngc6752_01.group.reg ngc6752_broad_thresh.img -region ngc6752_05.group.reg -pan to  4120 4105  physical \
    -zoom to 6 -match frame wcs -tile mode column -view multi no

As is shown here, there are only two groups of sources. The first group contains the 4 overlapping source apertures, and the 2nd group contains the single isolated source aperture. Note that the number used in the file names is based on the ID of the first source in the group; so in this example source ID 1 and 5 are the first sources in their respective groups.


4) [New] Assigning roi region overlaps

In the first example we see how roi can exclude overlapping source area from all aperture regions and explained how this can be useful in some situations. However, in other situations users may wish to assign overlapping source area (and the counts they include) to one source region aperture or another. The rank_roi can be used to do this. Users can decided to assign the overlapping region area based on one of several metrics: maximum total counts, minimal total counts, largest area, smallest area, brightest pixel, or faintest pixel. In this example we assign the overlapping area to the source with the most counts using method=max.

apertures.rank_roi.max
roi ngc6752_broad_thresh.center.src outsrcfile="ngc6752_%02d.exclude.reg" group=exclude targetbkg=target radiusmode=mul bkgradius=3 clob+ mode=h
rank_roi ngc6752_broad_thresh.img roifile="ngc6752_*.exclude.reg" outfile="ngc6752_{:02d}.ranked_max.reg" method=max clob+

The following commands can be used to visualize the output

ds9  -log ngc6752_broad_thresh.img -region ngc6752_01.ranked_max.reg ngc6752_broad_thresh.img -region ngc6752_02.ranked_max.reg \
    ngc6752_broad_thresh.img -region ngc6752_03.ranked_max.reg ngc6752_broad_thresh.img -region ngc6752_04.ranked_max.reg ngc6752_broad_thresh.img \
    -region ngc6752_05.ranked_max.reg -pan to  4120 4105  physical -zoom to 6 -match frame wcs -tile mode column -view multi no

Shown here are the 5 source aperture regions after any overlapping source area has been assigned the source with the maximum number of counts. Source region 1 looks the same; it has the least counts of the 2 overlapping apertures. Source 2 is the brighest of the two overlapping aperatures and now contains that overlapping area from sources 1 and 3. Source 3 looks the same as it is fainter than source 2. Source 4 is brighter than source 1 so it now has the overlapping area assigned to it. Isolate source 5 is unchanged.


5) [New]PSF enclosed counts fraction circular apertures

The aperture regions created so far has been based on the output from one of the source detect tools. Regions can also be created based on the PSF. An tabulation of a circularly symmetrical approximation of the Chandra PSF is included in the Chandra CALDB and accessible using the CIAO PSF module. The psfsize_srcs script uses this interface to lookup the size of a circle needed to enclose a specified fraction of the PSF at the specified energy and generates a region file.

apertures.psfsize_srcs
psfsize_srcs ngc6752_19014_broad_thresh.img ngc6752_broad_thresh.center.src psfecf.reg energy=1.0 ecf=0.95 clob+

The following commands can be used to visualize the output

ds9  ngc6752_broad_thresh.img -log -region psfecf.reg -pan to  4120 4105  physical -zoom to 6

In this example we have created circular regions that are expected to enclose approximately 95% of the PSF at 1.0keV at each of the 5 source positions.

[IMPORTANT]
Single Observation vs Merged datasets

An observant users will notice that the input file has changed from the merged counts image to the image for a single observation (OBS_ID 19014). This is because the PSF depends on specific per-observation values such as the pointing (RA_PNT, DEC_PNT, ROLL_PNT) and SIM location (SIM_X, SIM_Y, SIM_Z). As these values are rarely identical between observations, the are often omitted from merged products.

It is generally recommended that users extract results from individual observations, such as spectra, lightcurves, or counts for photometry, and then combine those products rather than try to extract results from merged datasets.

The output from psfsize_srcs is a single region file similar to the output from the source detect tools. The psfsize_srcs output can be feed into the roi tool to create source and background aperture regions.


6) [New] PSF contour based apertures

The psfsize_srcs script creates source regions based on a circular approximation of the PSF size. The psf_contour script creates source regions by simulating the Chandra PSF using MARX and then generating source regions using one of several contouring algorithms.

The psf_contour script handles overlapping regions differently than roi. Rather than exclude the overlapping region, the algorithm works by first reducing the overall size of overlapping sources to include a smaller fraction of the PSF. The regions are "shrunk" until they no longer overlap. This may be advantageous over simply excluding the overlapping area because it happens essentially symmetrically around the PSF; where as excluding the overlap generally happens on one side which may skew results like if computing centroids.

The psf_contour has several options for creating contours around the simulated PSF. Several of these create many sided polygons rather than simple circle or elliptical shaped apertures.

apertures.psf_contour
psf_contour ngc6752_19014_broad_thresh.img outroot=psf_contour pos=ngc6752_broad_thresh.center.src method=contour energy=1.0 fraction=0.95 flux=0.005 clob+

The following commands can be used to visualize the output

ds9  ngc6752_broad_thresh.img -log -region psf_contour_i0001_src.reg  -region psf_contour_i0002_src.reg -region psf_contour_i0003_src.reg -region \
    psf_contour_i0004_src.reg -region psf_contour_i0005_src.reg -pan to  4120 4105  physical -zoom to 6

The five source regions created by using psf_contour to create regions that enclose 95% of the PSF at 1.0 keV. Each region is a contour polygon (created using dmcontour. The regions are created so that they do not overlap as described above. Each region is a separate polygon.

The different contouring algorithms are discussed in the help file and are shown below:

for method in lasso fit ecf convex;
do
psf_contour ngc6752_19014_broad_thresh.img outroot=psf_$method pos=ngc6752_broad_thresh.center.src method=$method energy=1.0 fraction=0.95 flux=0.005 clob+
done

ds9 -geometry 906x512 -view info no \
-view panner no -view buttons no -view magnifier no \
ngc6752_broad_thresh.img -log \
-region color red -region psf_contour_i0005_src.reg \
ngc6752_broad_thresh.img -log \
-region color orange -region psf_lasso_i0005_src.reg \
ngc6752_broad_thresh.img -log \
-region color yellow -region psf_convex_i0005_src.reg \
ngc6752_broad_thresh.img -log \
-region color blue -region psf_fit_i0005_src.reg \
ngc6752_broad_thresh.img -log \
-region color violet -region psf_ecf_i0005_src.reg \
-pan to 4126.5 4094.5 physical -zoom to 32 \
-match frame wcs -tile mode grid

autogenerated

The different contouring algorithms are, starting from top-left: contour (red), lasso (orange), convex hull (yellow), fitted ellipse (blue), and ECF ellipse (violet).


7) [New] Background regions with fixed counts

So far we have focused on the source region apertures. The roi tool also creates background region apertures that are stored in the 2nd extension of each output file; the extension in named BKGREG

dmlist ngc6752_05.exclude.reg blocks | cat

--------------------------------------------------------------------------------
Dataset: ngc6752_05.exclude.reg
--------------------------------------------------------------------------------

Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: PRIMARY                        Null
Block    2: SRCREG                         Table         5 cols x 1        rows
Block    3: BKGREG                         Table         5 cols x 3        rows

These can either be a single ellipse just around the individual source, or can be a collection of ellipses around each source included or excluded from the source region. Overlapping sources are excluded from the background. The size of the background is multiplicative or additive factor of the source size.

Depending on the field, the background created by roi may not have a statistically significant number of counts for some sources. While users can increase the multiplicative or additive factor but that affects all sources and may be undesirable.

The bkg_fixed_counts script can alternatively be used to create background regions that contain a minimum number of counts. A background annulus is created at each source location. The inner radius is related to the size of the PSF and the outer radius is allowed to increase until it encloses a specified number of counts, while excluding any source regions (including the source region at that particular location).

apertures.bkg_fixed_counts
psf_contour ngc6752_19014_broad_thresh.img outroot=psf_contour pos=ngc6752_broad_thresh.center.src method=contour energy=1.0 fraction=0.95 flux=0.005 clob+
bkg_fixed_counts ngc6752_19014_reproj_evt.fits"[energy=500:7000]" outroot=bfc pos=ngc6752_broad_thresh.center.src min_counts=50 src_reg="psf_contour_i*src.reg" inner_ecf=0.97 clob+

The following commands can be used to visualize the output

ds9  -log ngc6752_19014_broad_thresh.img -region bfc_i0001_bkg.reg ngc6752_19014_broad_thresh.img -region bfc_i0002_bkg.reg \
    ngc6752_19014_broad_thresh.img -region bfc_i0003_bkg.reg  ngc6752_19014_broad_thresh.img -region bfc_i0004_bkg.reg ngc6752_19014_broad_thresh.img \
    -region bfc_i0005_bkg.reg -pan to  4120 4105  physical -zoom to 6 -match frame wcs -tile mode column -view multi no

In this example we used the bkg_fixed_counts script to create background annulus apertures that enclose at least 50 counts. This script requires the input event file which we provided including the necessary energy filter matching the energy band used in the rest of the analysis. The inner radius of each annulus corresponds to the radius of a circle needed to enclose 97% of the PSF at 1.0 keV.

The five different background region apertures are shown as before. The outer radius is determined such that it includes at least 50 counts after excluding all the overlapping sources. Consider for example source 5 in the right most frame. Even though the source region is isolated, the background region overlap source 3 and so it has been excluded from the background.