DS9

CXC Science Data Systems

Regions

Regions are geometric shapes that can be defined interactively in DS9, or read in from a DS9 ascii region file or from a CIAO FITS region file.

The most common DS9 region is a circle (other region types are described below). It can be created interactively when the DS9 edit mode is Edit - Region, or can be specified in a region file which is loaded from the region menu.

Many regions can be defined in a single frame. A subset of them can be 'selected' (by clicking on them) and certain actions apply to selected regions.

Command:-
Menu:-
Description:KEYBOARD SHORTCUT: Shift-Drag: define a rectangle, select all regions within that rectangle.

DS9 Region files

DS9 region files are text files with a particular syntax. The simplest region file is just a single line containing a shape description, for example

circle(4096.5,4096.5,8.2)

When you save the region to a file from DS9 you get some additional metadata

# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman"
 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical
circle(4096.5,4096.5,8.2)

A region file can contain multiple regions

# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman"
 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical
circle(4096.5,4096.5,8.2)
box(1268,1151,100,200)
or
# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman"
 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical;circle(4096.5,4096.5,8.2);box(1268,1151,100,200)
or
# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman"
 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical
circle 4096.5 4096.5 8.2
box 1268 1151 100 200

The parentheses forms of the shape specifications are what DS9 will use when saving a region to a file; the forms without parentheses are supported for back compatibility. Semicolons are equivalent to a newline.

The first line of the file, beginning with a hash symbol, describes the version of the file format. This line is optional.

The second line, beginning with 'global', defines region properties that will apply to all regions in the file.

The third line defines the coordinate system in which the coordinate values in the region are expressed.

Fourth and subsequent lines specify the individual region shapes. Shape definitions are of the form

+shape(param,param,...param) # prop=value prop=value prop=value
so that each shape has a set of parameters, and a set of properties whose values may be set. Parameters are required; properties may be omitted to choose their default values. If no properties are specified the hash mark may be omitted.

The leading + has no effect and is usually omitted. A leading minus sign indicates the region is meant to be excluded rather than included. For example

# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman"
 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical
circle(4096.5,4096.5,8.2)
-box(4100,4100,10,10)

denotes a circle with the part that overlaps with the box excluded.

Some `display-only' shapes instead use the syntax

# shape(param,param,...param) prop=value prop=value prop=value
with the hash mark before instead of after the shape section.

Lines with a leading hash mark # which are not recognized as valid display-only shapes are ignored and treated as comments.

Other supported region formats

Command:-
Menu:Edit - Preferences - Region - Default Format
Description: allows the default output region file formatto be 'ds9' (default, DS9/Funtools); 'XML', 'CIAO', or obsolete legacy formats 'SAOtng', 'SAOimage', 'IRAF Pros',or an unannotated 'X Y' format.

DS9 can also read CIAO FITS region binary tables.

Region mode

Command:mode none
Menu:Edit - None
Description:Left mouse button has its default behaviour.

Command:mode region
Menu:Edit - Region
Description:In this mode, which was the default in early versions of DS9,the left button allows the user to create and edit regions.Regions can be either 'selected' or 'unselected'; certain actions applyto currently selected regions only.

Details of button actions in region mode:

The Region menu also has entries controlling region selection:

Command:region select all
Menu:Region - All
Description: selects all the regions currently defined

Command:region select none
Menu:Region - None
Description: deselects all regions

Command:region select invert
Menu:Region - Invert
Description: deselects all currently selected regions and selects all currently unselected regions

Command:region select front|back
Menu:Region - Front, Back
Description:Selects the first or the last region in the list.

Command:region move front|back
Menu:Region - Move To Front/Back
Description: moves the selected region to the beginning or end of the list.

Region coordinate systems

The allowed coordinate system names in a region file are

Name System Default unit Meaning
image image pix Pixel coordinates of the current image
physical physical scaled pix Original pixel coords of instrument, as defined by CRPIXnP/CDELTnP or the IRAF keywords LTM/LTV
icrs ICRS deg ICRS celestial coords, using WCS keywords in image
fk4 FK4,B1950 deg FK4/B1950 coords
fk5 FK5/J2000 deg FK5/J2000 coords
galactic IAU galactic deg l(II), b(II) in degrees
ecliptic ICRS ecliptic deg Ecliptic lon and lat, degrees
wcs WCS Whatever coord system is specified by the file's primary WCS
wcsa WCSA Whatever coord system is specified by the file's secondary 'A' WCS
linear LINEAR Linear coord system specified by the file's primary WCS

If no coordinate system is specified, `physical' or `WCS' is assumed depending on the formatting (decimal or sexagesimal) of the coordinate values.

Region coordinate value, length and angle formats

Coordinate value formats

Values in these coordinate systems can be expressed in a variety of ways.

Syntax Example Interpretation
[num] 5.8 Coordinate value in pixels for IMAGE,PHYSICAL, else in degrees
[num]d 243.3d Degrees
[num]r 1.745r Radians
[num]p 1024.3p Pixels in PHYSICAL system
[num]i 512.0i Image pixel number
[num]:[num]:[num] 14:07:28.8 hr:min:s for long-like coords, deg:min:s for lat-like coords
[num]h[num]m[num]s 10h20m15.1s hr:min:s
[num]d[num]m[num]s -00d20m15.1s deg:min:s

Coordinate length formats

Arguments like circle radius or box length can use the following formats:

Syntax Example Interpretation
[num] 5.8 Coordinate value in pixels for IMAGE,PHYSICAL, else in degrees
[num]d 243.3d Degrees
[num]r 1.745r Radians
[num]p 1024.3p Pixels in PHYSICAL system
[num]i 512.0i Image pixel number
[num]" 20.4" Arcseconds
[num]' 20.4' Arcmin



Command:-
Menu:Edit - Preferences - Region - Default Length
Description:The default length unit is set; it may be Degrees (default), ArcMin or ArcSec.

Angle formats

Angles (e.g. for the orientation of an ellipse) are always expressed as a simple number, interpreted as degrees.

Region shapes

Here I define the region shape types, their parameters, and the properties that are specific to those shapes; I also discuss how to create them interactively. As noted earlier, region creation is done either by reading a region file, or by selecting Edit - Region and then left clicking at the location you want the region to be at.

Command:-
Menu:Region - Color - Fill
Description:If this flag is set, the newly created region is displayed as filled, otherwise as an outline.

Command:-
Menu:Region - Region Parameters - Auto Plot Statistics
GUI Default:Edit - Preferences - Region - Auto Plot - Statistics
Description:If this flag is set, upon region creation a popup window appears showingvarious statistics of the image pixels within the region.

Command:-
Menu:Region - Region Parameters - Auto Plot 2D
Description:If this flag is set, upon region creation a popup window appears showinga line plot of the pixel values vs coordinate.

Command:-
Menu:Region - Region Parameters
Description:This menu lets you control some display properties that newly created regionswill have. It does not affect previously created regions.

Command:region epsilon [value]
Menu:Edit - Preferences - Region - Mouse Click Epsilon
Description:Interactive region creation look and feel can be modified by changing epsilonfrom the default value of 3 pixels to a value between 2 and 10 pixels. This `epsilon' determines how close to the region the pointer position must beto successfully select it by clicking.Example: xpaset -p ds9 region epsilon 5

Basic shapes

Command:region shape [value]
Menu:Region - Shape
Description:Select the shape to be created when you click in the image

Command:region open
Menu:Region - Get Information
Description:Bring up the region shape dialog box. This can also be done by double clicking on a region.

Command:region close
Menu:Region - [shape] - Close
Description:Close the region shape dialog box.

Command:region selected
Menu:-
Description:Used with xpaget; `xpaget ds9 region selected' writes the region details to standard output.

There are four region types that define areas on the image.

Vector shapes

Four additional shapes allow a set (vector) of regions to be defined.

Display-only shapes

Other region types are purely for illustrations and analysis. They define a line or curve on the image which can be used to generate a 2D plot, or for 3D data a 3D plot. The Region Parameters - Auto Plot 2D/Auto Plot 3D menu options, or alternatively Edit - Preferences - Region - Auto Plot - 2d/3d, determine whether or not the plot is shown.

Command:region analysis plot2d open
Menu:[shap] - Analysis - Plot2D
Description:If a currently selected region is a display-only region, this will pop up aplot with the pixel values vs distance along the region

Composite regions

One may also define a `composite region' by selecting multiple regions (e.g. using the shift-click to select second and subsequent regions) and then the Region/ Composite Region / Create menu entry. The composite region can then be moved around as a unit. It can be saved to a DS9 region file; an example is:

# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=
1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
physical
# composite(3988.5,4200,0) || composite=1
circle(4105,4153,46.6119) ||
circle(3872,4247,20)
circle(4253,4207,20)

Here the '# composite(x,y,angle)" directive and the || after the first circle region specify that the first two circle entries form a composite region; the third circle in this example is an independent region not part of the composite.

Region File syntax:composite
# composite (3988.5,4200.0) || composite=1
Command:region composite
Menu:Region- Composite Region - Create
Description:Creates a composite region.

Command:region dissolve
Menu:Region - Composite Region - Dissolve
Description:Dissolve a composite region

Template (Footprint) regions

In the GUI region menu, the Region - Instrument FOV entry allows the user to specify one of a set of template regions defined relative to the WCS pointing direction. Supported examples include the Chandra ACIS instrument footprint.

These regions are defined in terms of component regions (polygons, boxes etc). Saving such a region to a file saves the template as a composite region made up of these component regions.

Users may define their own templates and load them via the Region - Template menu.

Command:region template [filename]
Menu:Region - Template
Description:Open a template region file.

Command:region template [filename] at [x y coordsys]
Menu:Region - Template
Description:Open a template region and relocate it. Example:region template foo.tpl at 13:29:55.92 +47:12:48.02 fk5

Command:region savetemplate [filename]
Menu:Region - Template
Description:Save a template region to a file.

Generic region properties

These properties may be associated with a region in the properties section of a region file entry; most of the following properties may also be specified in the 'global' line of a region file, and they may be set in the interactive GUI in the Region menu (submenus Color, Properties, Font, etc).

First some properties that change the display of the region:

Region File syntax:color
# color=green# color=#48f
Command:region color [value]
Menu:Region - Color
Description:Changes the region color. Values may be color names or hex values with 3, 6 or 9 digits.The default region color is green.

Region File syntax:fill
# fill = 1
Command:region fill yes|no
Menu:Region - Fill
Description:Determines if the region is displayed as an outline shape (fill=0) or a shapefilled with the current region color (fill=1). In the GUI the fill value may be checked (1) orunchecked (0) in the Region - Color menu.

Region File syntax:width
# width=2
Command:region width [value]
Menu:Region - Width
Description:Determines the width of the line used to render the region outline. Default 1, valuesallowed are 1 to 4.

Region File syntax:dash
# dash=1
Command:region dash yes|no
Menu:Region - Width - Dash
Description:Lines will be dashed, using the current dashlist value. (Default 0).

Region File syntax:dashlist
#dashlist=a b#dashlist=4 2
Command:-
Menu:-
Description:Dashlist. Sets the dash sequence to use if the dash property is set.The first parameter is the length of the dash, the second is the length of the inter-dash gap.Can only be set in the region file itself.

Region File syntax:text
# text={This message has both a " and ' in it}
Command:-
Menu:-
Description:Text. Draws the given text next to the region as a label.

Region File syntax:font
# font="times 12 bold italic"
Command:region font [value]
Menu:Region - Font
Description:Determines the font family of any text used. Example: region font times.The default is 'helvetica 10 normal roman'. Options are times, helvetica, courier.

Region File syntax:font
# font="times 12 bold italic"
Command:region fontsize [value]
Menu:Region - Font - Size
Description:Determines the font size of any text used. Example: xpaset -p ds9 region fontsize 12.Predefined menu options are 9, 10, 12, 14, 16, 20, 20, 30, 36, 72; there isan option for `other font size' where a numerical integer value can be entered.

Region File syntax:font
# font="times 12 bold italic"
Command:region fontweight [value]
Menu:Region - Font - Weight
Description:Determines the font weight for any text used. Example: xpaset -p ds9 region fontweight boldOptions are: normal, bold.

Region File syntax:font
# font="times 12 bold italic"
Command:region fontslant [value]
Menu:Region - Font - Slant
Description:Determines the font slant for any text used. Example: xpaset -p ds9 region fontslant italic.Options are: roman, italic

Region File syntax:source|background
# source# background
Command:region source|background
Menu:Region - Properties - Source/Background
Description:Properties that associate a region as being either source or background,or have more specific 'tags' associated.These are not used by DS9 directly, but other applications may use them and thexpaget command can test them: 'xpaget ds9 region background' tests if the currentlyselected region is a background one.KEYBOARD SHORTCUT: s (set source property); b (set background property for selected region).

Region File syntax:include
global include = 0
Command:region include|exclude
Menu:Region - Properties - Include/Exclude
Description:This may only be used in the 'global' line; include=1 or include=0 areset in the individual region lines using the leading + or -. Default is include=1.KEYBOARD SHORTCUT: i (set include =1); e (set include = 0).

Another set of properties control the interactive behaviour:

Region File syntax:fixed
# fixed = 1
Command:region fixed yes|no
Menu:Region - Properties - Fixed In Size
Description:fixed: if this is set to 1, changes to the image magnification do not scale the region sizeaccordingly. Default is 0.

Region File syntax:select
# select = 0
Command:-
Menu:-
Description:select: if this is set to 0, mouse actions can neither select, edit, nor move the region.Default is 1.

Region File syntax:highlite
# highlite = 0
Command:-
Menu:-
Description:highlite: if this is set to 0, selecting the region does not make the `edit handles' visible.Default is 1.

Region File syntax:edit
# edit = 0
Command:region edit yes|no
Menu:Region - Properties - Can Edit
Description:edit: if this is set to 0, mouse actions do not allow the region to be edited even when selected.Default is 1.

Region File syntax:delete
# delete = 0
Command:region delete yes|no
Menu:Region - Properties - Can Delete
Description:delete: if this is set to 0, mouse actions do not allow the region to be deleted.Default is 1.

Region File syntax:move
# move = 0
Command:-
Menu:Region - Properties - Can Move
Description:move: if this is set to 0, mouse actions do not allow the region to be moved even when selected.Default is 1.

Region File syntax:rotate
# rotate = 0
Command:region rotate yes|no
Menu:Region - Properties - Can Rotate
Description:rotate: if this is set to 0, mouse actions do not allow the region to be rotated even whenselected.Default is 1.

Regions can be copied and pasted using xpaset:

Command:region copy|cut|paste
Menu:-
Description:Copy, cut or paste seleted region. The paste commandtakes the coordsys as the argument, e.g. xpaset -p ds9 region paste wcs

Region tags

Region File syntax:tag
# tag ={Group 1}# tag={Quasars} tag={PointSrcs}
Command:region group [tag] new
Menu:Region - New Group
Description:A way to group relatedregions. A single region line may have multiple tags associated.To select multiple regions, shift-click on thesecond and subsequent regions, or click-drag to select all regions within a rectangle.KEYBOARD SHORTCUT: g (create a new group). Shift-g (create a new group with default name).

Command:region group [tag] select
Menu:-
Description:Select all regions in a tag group

Command:region group [tag] update
Menu:-
Description:Update a tag group. For example : select the group. Now deselect some regions or select additional ones. Then 'update' willupdate the group membership list.

Command:region group [tag] color [value]
Menu:-
Description:Set color for regions in a tag group

Command:region group [tag] font [string]
Menu:-
Description:Set font for regions in a tag group. Example: region group foo font {times 14 bold}

Command:region group [tag] cut|copy|delete
Menu:-
Description:Copy, cut, delete regions in a tag group

Command:region group [tag] move [dx] [dy]
Menu:-
Description:Adjust position of all regions in a tag group

Command:region group [tag] movefront|moveback
Menu:-
Description:Move all regions in a group to the front or back

Command:region group [tag] property [name] yes|no
Menu:-
Description:Set the named property for all regions in a group. Example: region group foo property fill yes

Command:region groups
Menu:Region - Groups
Description:Brings up a dialog which lists the named groups. Clicking on the name of a group selects all the regionsin that group. The same region can belong to more than one group.

Special region directives for complicated data

Region I/O

Command:region load [filename]
Menu:Region - Open
Description:This menu item puts up a file manager dialog to allow loading of region files from disk.By default only files with names ending in '.reg' are displayed in the dialog; you can click'All' for all files to be displayed. The filename to be loaded is shown in a selection text box,and you can edit this name.On selecting a filename with 'ok', a new dialog pops up allow you to controlthe file format to be read and whether it goes in the current frame or all frames. Youcan also override the region colors here. Usually you'll just want to click OK again.

Command:region save [filename]
Menu:-
Description:Allows you to save all currently defined regions to a file.The first dialog is similar to that from Region - Open and allows you to edit the filename.It will warn you if you are overwriting an existing file. The second dialog allows you to selectthe output format and coordinate system.

Command:region format ds9|xml|ciao|saotng|saoimage|pros|xy
Menu:Region - Save - Save Regions - Format
Description:Specify region file format flavour to save the regions in

Command:region system image|physical|wcs|wcsa-z
Menu:Region - Save - Save Regions - Coordinate System
Description:Specify coordinates for output region file

Command:region sky fk4|fk5|icrs|galactic|ecliptic
Menu:Region - Save - Save Regions - Coordinate System
Description:Specify celestial coordinates for output region file

Command:region skyformat degrees|sexagesimal
Menu:Region - Save - Save Regions - Coordinate System
Description:Specify celestial coordinate representation for output region file

Command:region save select [filename]
Menu:Region - Save Selection
Description:This is like Region - Save but only writes out the currently selectedregions.

Command:region delete
Menu:Region - Delete All
Description: deletes all currently defined regions.

Command:region delete select
Menu:Region - Delete Selection
Description: deletes all currently selected regions. KEYBOARD SHORCUT: Del

Command:region delete load [filename]
Menu:Region - Delete All and Open
Description: is simply a combination of Region - Delete All followed byRegion - Open.

Command:region command [string]
Menu:-
Description:Add a region. Example: 'region command {circle 100 100 20}

Region information

Command:region strip yes|no
Menu:-
Description:Display only selected regions (yes) or all regions (no, default)

Command:region show yes|no
Menu:-
Description:Regions are or are not visible on the display

Command:region showtext yes|no
Menu:-
Description:Region text labels are or are not visible on the display

Command:region list
Menu:Region - List
Description:lists all currently defined regions. It pops up the dialog to chooseformat and coordinate system to list the regions in. On pressing OK, it then raises a windowshowing what would be written to the region file if you did 'Region - Save'.

Command:region list select
Menu:Region - List Selection
Description: is like Region - List but only lists the selected regions.

Command:-
Menu:Region - Get Information
Description: pops up dialogs, one for each currently selected region,allowing access to the region edit properies (position, color, etc). This menu entry isreally 'Region - Allow Me To Edit It'.

Command:region [-options]
Menu:-
Description:Access region information via xpaget.Options are of the form "-opt value" and include:-format ds9, ciao, saotng, saoimg, pros, xy-system image, physical, wcs, wcsa...z-sky fk4, fk5, icrs, galactic ecliptic-skyformat degrees, sexagesimal-delim nl-delim [character]-prop select, edit, move, rotate, delete, fixed, include, source 1, source 0-group [tag]-strip yes|no-wcs yes|noExample: xpaget ds9 region -format ds9 -system wcs -sky fk5 -skyformat sexagesimal -prop edit 1 -group foo

Command:region centroid
Menu:Region - Centroid
Description:Calculates the centroid of the data near the middle of the selected region andadjusts the region to be centered at that point, redisplaying it.A circle of radius r (default 10) pixels is used around the region center, and n (default 30) iterations are done.

Command:region centroid radius|iteration [value]
Menu:Region - Region Parameters - Centroid Parameters - Radius/Iteration
GUI Default:Edit - Preferences - Region - Centroid - Radius/Iteration
Description:Control r or n parameter for centroiding

Command:region centroid auto yes|no
Menu:Region - Region Parameters - Auto Centroid
Description:If set, a newly created region executes this procedureautomatically.

Command:region analysis stats open|close
Menu:Region - Get Information - Analysis - Statistics
Description:open a dialog showing various statistics on the pixel values within the region.

Command:region analysis stats save
Menu:Region - Get Information - Analysis - Statistics - File - Save Data
Description:write the stats info to a file

Command:region analysis histogram open|close
Menu:Region - Get Information - Analysis - Histogram
Description:open a plot showing a histogram of the pixel values within the region.

Command:region analysis histogram save
Menu:Region - Get Information - Analysis - Histogram - File - Save Data
Description:write the histogram to a file

Command:region analysis plot3d open|close
Menu:Region - Get Information - Analysis - Plot3D
Description:For a data cube, open a plot showing a histogram of the pixel values within the regionas a function of the z slice number

Command:region analysis plot3d open|close
Menu:Region - Get Information - Analysis - Plot3D - File - Save Data
Description:For a data cube, save a histogram of the pixel values within the regiona a function of slice number