Skip to the navigation links
Last modified: 29 Jan 2010
Where are the PDFs?

Using the Output of Detect Tools

CIAO 4.2 Science Threads

[S-Lang Syntax]



Overview

Last Update: 29 Jan 2010 - updated for CIAO 4.2: changes to the ds9 region file format menu

Synopsis:

All three Detect programs have a common ouput format, the _src file; see the Output of Detect: _src Files section of the Detect Overview thread for more information. This thread shows how the source list can be displayed, edited, and used in CIAO data analysis.

Related Links:




Contents



Getting Started

This thread uses products created in the Running celldetect thread.



Displaying the Source List

The sources can easily be displayed overlaid on an image:

unix%  ds9 s3_evt2.fits &

Load the region file from the ds9 menu "Regions" → "Load Regions..." → s3_src.reg (or s3_src.fits).

Either command will produce Figure 1.

[Thumbnail image: ]

[Version: full-size]

[Print media version: ]

Figure 1: Source list overlaid on the event data

The event file is displayed at a blocking factor of 2.



Examining the Source List

The contents of the source list can be viewed with dmlist:

unix% dmlist s3_src.fits blocks
 
--------------------------------------------------------------------------------
Dataset: s3_src.fits
--------------------------------------------------------------------------------
 
     Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: PRIMARY                        Null        
Block    2: SRCLIST                        Table        31 cols x 17       rows

There are 17 sources (one per row) in the file. To see information about the individual sources:

unix% dmlist "s3_src.fits[cols RA,DEC,POS]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    RA                   DEC                  POS(X,Y)                                
 
     1       212.8640866629        52.1921374567 (     3961.1449275362,     4035.1449275362)
     2       212.8475950457        52.2255944051 (     4035.1639344262,     4279.9295081967)
     3       212.8362572403        52.2022148086 (     4085.9756097561,     4108.8536585366)
(cut)
    15       212.7874215851        52.2793561164 (     4304.6153846154,     4673.3692307692)
    16       212.7676912429        52.2989312197 (     4392.8109756098,     4816.6707317073)
    17       212.8529855660        52.3233207794 (     4011.1911764706,     4995.0073529412)

Here the RA, Dec, and sky position of each source is given. Any of the columns in the file can be used in the DM filter.



Manipulating the Source List

It is easy to delete unwanted sources from or rearrange the order of the ASCII output (region file) of the detect tools via a text editor. Using the Data Model tools, it is just as straightforward to manipulate the FITS source file as well.

Edit the List of Sources

Once the source list is overlaid on the image, you may see some sources that you want to exclude from the analysis. Currently, ds9 does not number the sources in the field of view. However, double-clicking on a source region brings up the region info box, which lists the region "ID". In Figure 2, the source on the left side of the field of view was chosen - the ID is 14. This number corresponds to the row the region occupies in the FITS file.

NOTE: this technique only works with the first region file loaded into ds9. After that, the imager starts counting up. For example, if you load region_a.fits that has 10 sources, then region_b.fits that has 6, the regions of the second file will be counted from 11 onward. One may, of course, always examine the region file visually to determine which rows to delete.

To create a new region file that doesn't have row 14 in it, dmcopy is used:

unix% dmcopy "s3_src.fits[#row=1:13,15:17]" s3_1gone_src.fits

unix% dmlist s3_1gone_src.fits blocks
 
--------------------------------------------------------------------------------
Dataset: s3_1gone_src.fits
--------------------------------------------------------------------------------
 
     Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: PRIMARY                        Null        
Block    2: SRCLIST                        Table        31 cols x 16       rows

The dmlist command shows that there are only 16 rows in the file now. This new file may be displayed in ds9 (Figure 3) to ensure that the correct source was removed.

[Thumbnail image: The source list with one source removed is displayed on the data.]

[Version: full-size]

[Print media version: The source list with one source removed is displayed on the data.]

Figure 3: Confirming a removed source

The unwanted source (blue X) is no longer present in the region file (green ellipses).

This filter was fairly simple. It is possible to make more complicated filters with the DM syntax. If you wanted to exclude rows (sources) 8, 12, and 14 from the original file:

unix% dmcopy "s3_src.fits[#row=1:7,9:11,13,15:17]" s3_3gone_src.fits

Figure 4 shows the new source list, indicating where the deleted objects used to be.

[Thumbnail image: The source list with three sources removed is displayed on the data.]

[Version: full-size]

[Print media version: The source list with three sources removed is displayed on the data.]

Figure 4: Confirming three deleted sources

The unwanted sources (blue Xs) are no longer present in the region file (green ellipses).


Sort on a Particular Column

The tool dmsort makes it possible to sort on any column in the FITS file. To order the rows by NET_COUNTS:

unix% dmlist "s3_src.fits[cols net_counts]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    NET_COUNTS  
 
     1                 60.0
     2              544.750
     3             48.81250
(cut)
    15                 47.0
    16       112.9583358765
    17              80.8750

unix% dmsort s3_src.fits s3_sorted_src.fits keys=net_counts copyall=yes

unix% dmlist "s3_sorted_src.fits[cols net_counts]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    NET_COUNTS  
 
     1        22.7142848969
     2        25.1428565979
     3        33.1428565979
(cut)
    15       112.9583358765
    16       190.2857208252
    17              544.750

The default behavior of dmsort is to organize the results in ascending order. To sort NET_COUNTS in descending order, add a dash ("-") before the column name:

unix% dmsort s3_src.fits s3_descend_src.fits keys=-net_counts copyall=yes

unix% dmlist "s3_descend_src.fits[cols net_counts]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    NET_COUNTS  
 
     1              544.750
     2       190.2857208252
     3       112.9583358765
(cut)
    15        33.1428565979
    16        25.1428565979
    17        22.7142848969

It is also possible to have several sort priorities (i.e. sort by NET_COUNTS, then NET_COUNTS_ERR); see ahelp dmsort for more information on how to sort files.


Filtering the Source List

If you are interested in only using a certain range of data in your analysis, use the DM filtering syntax to create a new source list with only those items.

To keep the sources that have 40 or more net counts:

unix% dmcopy "s3_src.fits[net_counts=40:]" s3_40cts_src.fits
unix% dmlist "s3_40cts_src.fits[cols net_counts]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    NET_COUNTS  

     1                 60.0
     2              544.750
     3             48.81250
     4             79.43750
     5             104.6250
     6             44.93750
     7       190.2857208252
     8        54.1428565979
     9                 47.0
    10       112.9583358765
    11              80.8750

or those with NET_COUNTS between 25 and 80:

unix% dmcopy "s3_src.fits[net_counts=25:80]" s3_25-80cts_src.fits
unix% dmlist "s3_25-80cts_src.fits[cols net_counts]" data
 
--------------------------------------------------------------------------------
Data for Table Block SRCLIST
--------------------------------------------------------------------------------
 
ROW    NET_COUNTS  
 
     1                 60.0
     2             48.81250
     3             79.43750
     4             44.93750
     5        39.4285697937
     6        25.1428565979
     7        33.1428565979
     8        54.1428565979
     9        37.2857131958
    10        38.4772720337
    11                 47.0

See ahelp dmfiltering for other variations on the filtering syntax.


Converting Coordinates to Sexagesimal

Often it is desirable to have the list of sources in sexagesimal format, i.e. (RA,Dec) = (hms,dms). This can be done in ds9 or with prop_precess.

  • In ds9: load the event file and display the source list on top of it. To save the regions in another format:

    1. Region → Save Regions... → Save As "s3_src_ds9.reg".
    2. After choosing "OK" in the region filename dialog, a format dialog is opened. Set the format to "CIAO" and the coordinate system to "WCS" and "Equatorial J2000".

    The output (an ASCII region file) still contains the shape definitions, but the coordinates are now given as sexagesimal:

    unix% cat s3_src_ds9.reg
    # Region file format: CIAO version 1.0
    ellipse(14:11:27.380,+52:11:31.70,0.0195851',0.0173948',45)
    ellipse(14:11:23.422,+52:13:32.14,0.0183431',0.0158548',53.264)
    ellipse(14:11:20.701,+52:12:07.98,0.0197903',0.0184924',15.4458)
    ellipse(14:11:20.530,+52:12:10.08,0.0191862',0.0170336',155.484)
    ellipse(14:11:20.387,+52:12:11.51,0.0203776',0.0173993',75.4574)
    ellipse(14:11:13.633,+52:13:41.46,0.0169192',0.0153512',12.7196)
    ellipse(14:11:30.846,+52:14:24.20,0.0390769',0.0242176',31.4398)
    ellipse(14:11:29.124,+52:13:33.01,0.0321857',0.0254928',125.887)
    ellipse(14:11:20.686,+52:14:11.97,0.03602',0.0308016',32.1849)
    ellipse(14:11:19.464,+52:14:00.94,0.0286652',0.0194748',33.3924)
    ellipse(14:10:59.522,+52:11:53.84,0.0395356',0.0245289',151.558)
    ellipse(14:10:57.363,+52:11:31.25,0.0386767',0.0297596',123.502)
    ellipse(14:11:14.499,+52:16:11.60,0.0546014',0.0455196',5.8862)
    ellipse(14:11:29.153,+52:16:43.48,0.0937733',0.0753438',149.301)
    ellipse(14:11:08.981,+52:16:45.68,0.0790725',0.0635626',174.887)
    ellipse(14:11:04.245,+52:17:56.15,0.0995391',0.089148',15.4741)
    ellipse(14:11:24.716,+52:19:23.96,0.131417',0.107319',167.549)
    

    The file may be redisplayed in ds9, as it retains the CIAO region format.

  • With prop_precess: prop_precess is a proposal tool that may be used to convert the (RA,Dec) in the FITS source list from decimal to sexagesimal format.

    unix% dmlist s3_src.fits"[cols ra,dec]" data,clean > decimal.txt
    
    unix% prop_precess f j2000/deg t j2000/hms : decimal.txt : hms.txt
    ASCDS_PROP_PREC_DATA is not set;
      default assignment to /soft/ciao/config/jcm_data has been made.
    ASCDS_PROP_PREC_DATA (for constellations) =
      /soft/ciao/config/jcm_data
    Opened input file decimal.txt
    Opened output file hms.txt
    
    unix% cat hms.txt
    RA  (J2000) Dec (J2000)                 RA  (J2000) Dec (J2000)
    212.864087    52.192137                 14 11 27.38 +52 11 31.69
    212.847595    52.225594                 14 11 23.42 +52 13 32.14
    212.836257    52.202215                 14 11 20.70 +52 12 07.97
    212.835543    52.202799                 14 11 20.53 +52 12 10.08
    212.834949    52.203197                 14 11 20.39 +52 12 11.51
    212.806805    52.228182                 14 11 13.63 +52 13 41.46
    212.878526    52.240054                 14 11 30.85 +52 14 24.19
    212.871351    52.225835                 14 11 29.12 +52 13 33.00
    212.836193    52.236656                 14 11 20.69 +52 14 11.96
    212.831104    52.233594                 14 11 19.46 +52 14 00.94
    212.748011    52.198289                 14 10 59.52 +52 11 53.84
    212.739014    52.192014                 14 10 57.36 +52 11 31.25
    212.810415    52.269889                 14 11 14.50 +52 16 11.60
    212.871475    52.278745                 14 11 29.15 +52 16 43.48
    212.787422    52.279356                 14 11 08.98 +52 16 45.68
    212.767691    52.298931                 14 11 04.25 +52 17 56.15
    212.852986    52.323321                 14 11 24.72 +52 19 23.95
    


Using the Source List in Analysis

Before beginning any analysis with the source list, be aware that the scaling of the size of each region is controlled by the ellsigma parameter in each of the detect tools. From the help files:

ellsigma is a multiplicative factor applied to sigma ... to scale the major and minor 
axes of the ellipses for each source. ellsigma affects both the outfile and the ASCII 
region file (regfile). This feature is included so that the graphics overlay will be 
more visible and under the user's control.

Carefully consider a reasonable value for ellsigma before using these regions for analyses.

Creating Individual Spectra

It is possible to create a spectrum from any of the regions in the source list without having to divide up the file. To extract a PI spectrum of the second source in the file and bin it by a factor of 5:

unix% punlearn dmextract
unix% dmextract "s3_evt2.fits[sky=region(s3_src.fits[#row=2])][bin pi=::5]" \
      spectrum_2.fits

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

The resultant spectrum can be plotted in ChIPS.

unix% chips
-----------------------------------------
Welcome to ChIPS: CXC's Plotting Package
-----------------------------------------
CIAO 4.2 Tuesday, July 6, 2010

chips> make_figure("spectrum_2.fits[cols channel,counts]","symbol.style=none");
chips> limits(X_AXIS,0,100);

Figure 5 shows the plot. This data may also be fit in Sherpa, once the proper response files have been created; see the Step-by-Step Guide to Creating ACIS Spectra for Pointlike Sources thread for more information.

[Thumbnail image: The spectrum is plotted as solid white line without symbols or errors.]

[Version: full-size, PNG]

[Print media version: The spectrum is plotted as solid white line without symbols or errors.]

Figure 5: Plot of the spectrum in ChIPS

This spectrum was created from a single source in the event file (id=2).

Quit ChIPS before continuing.

chips> quit

Creating Multiple Spectra

To create an individual spectrum for each of the sources, use the lgrid(1:n:steps) stack syntax, where n is the number of sources in the file.

For s3_src.fits, which has 17 sources in it:

unix% dmextract "s3_evt2.fits[sky=region(s3_src.fits[component=lgrid(1:17:1)])][bin pi=::5]" \
      multi_spectra_phaII.fits

The output file is a type II PHA file that has one spectrum per row:

unix% dmlist multi_spectra_phaII.fits blocks
 
--------------------------------------------------------------------------------
Dataset: multi_spectra_phaII.fits
--------------------------------------------------------------------------------
 
     Block Name                          Type         Dimensions
--------------------------------------------------------------------------------
Block    1: PRIMARY                        Null        
Block    2: SPECTRUM                       Table         7 cols x 17       rows
Block    3: GTI7                           Table         2 cols x 1        rows

For more information on working with this type of file, see the Displaying the Spectrum section of the Examining Grating Spectra and Regions: PHA2 files thread (the information in that section applies to imaging files as well).


Creating a Composite Spectrum

It is also possible to extract a composite spectrum of all the (faint) sources in a field for a single spectral analysis. This may be useful in the case where the sources might be of similar characteristics, but there are not enough counts in any given source to do individual spectra.

Here we have deleted the sources associated with 3C295 (IDs 3-5):

unix% dmcopy "s3_src.fits[#row=1:2,6:]" s3_nocore_src.fits

Now we can use dmextract to accept all the regions together and create a spectrum:

unix% dmextract "s3_evt2.fits[sky=region(s3_nocore_src.fits)][bin pi=::5]" \
      spectrum_faint.fits

Again, the resultant spectrum can be plotted in ChIPS:

unix% chips
-----------------------------------------
Welcome to ChIPS: CXC's Plotting Package
-----------------------------------------
CIAO 4.2 Tuesday, July 6, 2010

chips> make_figure("spectrum_faint.fits[cols channel,counts]","symbol.style=none");
chips> limits(X_AXIS,0,100);

Figure 6 shows the plot.

[Thumbnail image: The spectrum is plotted as solid white line without symbols or errors.]

[Version: full-size, PNG]

[Print media version: The spectrum is plotted as solid white line without symbols or errors.]

Figure 6: Composite spectrum

The composite spectrum was created by combining counts from 14 sources.

As mentioned before, this data may also be fit in Sherpa, once the proper response files have been created; see the Step-by-Step Guide to Creating ACIS Spectra for Pointlike Sources thread for more information.

Quit ChIPS before continuing.

chips> quit

Removing Unwanted Point Sources

Often it is desirable to remove point sources from an image for both cosmetic and scientific reasons. For example, if you are analyzing an extended source, an unfortunately located point source may affect the count rates in the object.

Suppose that we want to remove all the point sources from our field of view, except for the three in the core (sources 3-5). First, create a source list that excludes these three regions:

unix% dmcopy "s3_src.fits[#row=1:2,6:17]" s3_holes_src.fits

Now filter the event file with those regions:

unix% dmcopy "s3_evt2.fits[exclude sky=region(s3_holes_src.fits)]" s3_holes_evt2.fits

unix% ds9 s3_holes_evt2.fits &

The resulting image, Figure 7, has holes where the sources used to be. The Obtain and Fit a Radial Profile thread illustrates another case in which you might use this syntax (see the Removing Contaminating Point Sources section).

[Thumbnail image: The sources have been removed from the event file.]

[Version: full-size]

[Print media version: The sources have been removed from the event file.]

Figure 7: Event file with sources removed

The source regions are replaced by areas of zero counts.

A more sophisticated means of removing point sources is to use dmfilth. This tool removes the point source and then fills in the hole where the source was. See ahelp dmfilth for more information and the Identify and Remove Point Sources section of the Image of Diffuse Emission thread for an example.




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


#--------------------------------------------------------------------
#
# DMEXTRACT -- extract columns or counts from an event list
#
#--------------------------------------------------------------------
        infile = s3_evt2.fits[sky=region(s3_src.fits[#row=2])][bin pi=::5] Input event file 
       outfile = spectrum_2.fits  Enter output file name
          (bkg = )                Background region file or fixed background (counts/pixel/s) subtraction
        (error = gaussian)        Method for error determination(poisson|gaussian|<variance file>)
     (bkgerror = gaussian)        Method for background error determination(poisson|gaussian|<variance file>)
      (bkgnorm = 1.0)             Background normalization
          (exp = )                Exposure map image file
       (bkgexp = )                Background exposure map image file
      (sys_err = 0)               Fixed systematic error value for SYS_ERR keyword
          (opt = pha1)            Output file type: pha1 
     (defaults = ${ASCDS_CALIB}/cxo.mdb -> /soft/ciao-4.0/data/cxo.mdb) Instrument defaults file
         (wmap = )                WMAP filter/binning (e.g. det=8 or default)
      (clobber = no)              OK to overwrite existing output file(s)?
      (verbose = 0)               Verbosity level
         (mode = ql)              


History

03 Jan 2005 reviewed for CIAO 3.2: no changes
19 Dec 2005 updated for CIAO 3.3: default value of dmextract error and bkgerror parameters is "gaussian", screen output updated accordingly; updated files in detect data tarfile
01 Dec 2006 updated for CIAO 3.4: ChIPS version
17 Jan 2008 updated for CIAO 4.0: ChIPS plotting syntax updated; ds9 now automatically looks for the "[SRCLIST]" extension in the region file, so it doesn't have to be specified; deg2sexag.sl has not been updated for CIAO 4.0; removed data tarfile; deg2sexag.sl script replaced by prop_precess
13 Jan 2009 updated for CIAO 4.1: provided both Python and S-lang syntax for ChIPS; images are inline
29 Jan 2010 updated for CIAO 4.2: changes to the ds9 region file format menu

Return to Threads Page: Top | All | Imag

Where are the PDFs?
Last modified: 29 Jan 2010