Analysis

Each file type known to DS9 can have user-defined analysis commands associated with it. These analysis commands are defined at start-up time , or loaded by the user, by means of an ASCII analysis description file. The analysis commands are available for execution, either via the Analysis Menu or the XPA point Analysis. In addition, commands may be bound to events, such as keystrokes or mouse clicks. This type of command is called a bind command.

DS9 searches for an analysis file named ds9.ans or ds9.analysis in the current directory and $HOME to be loaded at startup. In addition, DS9 will search the following directories for any analysis files to be loaded at startup in the form of *.ds9: the current directory, $HOME/bin, /usr/local/bin, /opt/local/bin, and /soft/saord/bin. Finally, the user may specify analysis files to be loaded at startup in the preferences analysis panel. The user may also load or clear current analysis commands via command line options or the Analysis menu.

When activated, either from the menu, XPA, or bound event, an analysis command first is macro-expanded to fill in user-defined arguments and then is executed externally. Results may be displayed in a separate text window, plot window, or in a image frame.

Syntax
Command Type
Macros
Help
Parameters
Hierarchical Menus
Sample

Syntax

The analysis file that defines the known analysis commands consists of one or more file descriptors, each of which has the following format:
Menu label to be used
A space separated list of file templates
Command type [menu | bind <event>]
The command line for the analysis program

Task names may contain space characters. All lines may be indented. Also, the '#' character is a comment character. A separator can be inserted in the menu by specifying the following sequence '---'.

Example:
# this will insert a menu separator
---

Command Type

The third line indicates the type of command.

menu

A menu command creates an menu option under the Analysis menu option, and can be invoked by the user via the GUI or XPA.

Example:
# Menu command example
My Analysis Task
*.fits
menu
$data | doit | $text

bind

A bind command is a command that is bound to an event. When the event occurs, the command is executed. Types of events available include all TK events, including all keystrokes and mouse clicks. If a command is bound to an event other that a keystroke, care must be taken to not to interfere with other internal DS9 events.

To bind to a key stroke, use the following command type:

bind <keystroke>
Example:
# Bind command example
Print coordinates
*.fits
bind x
echo "$x $y" | $text

web

A web command allows the user to invoke the internal web browser from the analysis menu.

Example:
# web command example
HTTP based
*
web
http://hea-www.harvard.edu/RD/ds9/ref/index.html

File based
*
web
file:/home/joye/index.html

Macros

The following macros are macro-expanded to fill in user-defined arguments before the command is executed. Strings that contain $<macroname> that user does not want to be expanded may be escaped by using $$<macroname>. All strings that contain $<string>  that are not a macro name will not be affected.

For example:

echo "$$data $foo" | $text

will display a text dialog that contains "$data $foo"

$width
$height
$depth

Substitute the width, height, or depth of the data file in the command line.

Syntax:
    $width

    $height

Example:
    echo "$width $height $depth" | $text

$bitpix

Substitute the bitpix of the data file in the command line.

Syntax:
    $bitpix


Example:
    echo "$bitpix" | $text

$data

Data from the current frame becomes the input data to the command string. This data is in the form of a FITS image. This macro can only used at the beginning of the command string.

Syntax:
    $data


Example:
    $data | dosomething | $text

$entry

Display an entry modal dialog. The returned string is substituted. If cancel is selected, the command line is not executed.

Syntax:
    $entry(<message>)


Example:
    echo "$entry(Enter something here)" | $text

$env

Substitute the value of a shell environment variable.

Syntax:
    $env(<shell variable>)


Example:
    echo "$env(PATH)" | $text

$filedialog

Display the standard file dialog. Substitutes the returned pathname. Argument specifies if an open file or save file dialog is invoked.

Syntax:
    $filedialog([open|save])


Example:
    echo "$filedialog(open)" | $text

$filename

Substitute the filename of the data file in the command line. A full filename includes any absolute or relative path. A root filename contains no path. A (2D) subsection defines a subimage from xmin,ymin to xmax,ymax. For Frame3D, a 2D subsection will also include the current slice (PLANE=) parameter if not 1. A 3D subsection defines a subimage from xmin,ymin,zmin to xmax,ymax,zmax and no PLANE parameter.

Syntax:
    $filename # filename with extname, (2d) subsections, filters

    $filename(root|root,base) # root filename withwith extname,no subsections, no filters)
    $filename(full|full,base) # full filenamewith extname,no subsections, no filters)

Example:
    dosomething $filename | $text

    dosomething $filename(root) | $text

$filename[$regions]

Combination of $filename and $regions macros. Generates a series of filenames, each with a region.

Syntax:
    $filename[$regions]

    $filename[$regions(<options>)]

Example:
    dosomething $filename[$regions] | $text

$geturl

This macro differs from all other macros, including $url, in that no subprocess pipe is created. Only HTTP is supported. The contents of the url are retrieved and sent to $text, $plot, or $image. No other processing is allowed. The primary purpose of this macro is to support external analysis for the Windows platform, which has no subprocess support.

Syntax:
    $geturl(http://<hostname>:<port>/<query>)


Example:
    $geturl(http://foo.bar.edu/foo.html) | $text

$image

The resulting image data is display in a DS9 frame. This macro should be the last macro of a command line. Optional parameter indicates if a new frame and what type of frame is created for the new data. The macro is removed from the command line before execution.

Syntax:
    $image

    $image([new|rgb|3d|current])

Example:
    doit | $image(new)

$message

Display a message dialog box, with option buttons.  After displaying the message, the macro is removed from the command line before execution. If cancel or no is selected, the command line is not executed.

Syntax:
    $message(<message>)

    $message([ok|okcancel|yesno],<message>)

Example:
    $message(okcancel,This is a Message)| doit | $text

$messageok

Display a message dialog box, with option buttons.  After displaying the message, the button selected is substituted in the command line.

Syntax:
    $messageok(<message>)

    $messageok([ok|okcancel|yesno],<message>)

Example:
    echo "$messageok(okcancel,This is a Message)" | $text

$null

Expect no output or results from analysis task. Note: no error message will be returned if the analysis task fails to execute correctly.

Syntax:
    $null


Example:
    echo "Hello, world" > foo | $null

$pan

Substitute current pan location of the particular data file are returned. The default coordinate system is physical.

Syntax:
    $pan
    $pan(<coordinate system>,<format>)

where:

    coordinate system = [image|physical|detector|amplifier|wcs|wcsa...wcsz]
    sky frame         = [fk4|fk5|icrs|galactic|ecliptic]
    sky format        = [hms|sexagesimal|degrees]

Example:
    echo $pan(fk5,sexagesimal) | $text

$plot

Display data in plot window. This macro should be the last macro of a command line. The data is read via STDIN and consist of a pair of coordinates, with option error values. (xy, xyex, xyey, xyexey) Default dimension is xy. The macro is removed from the command line before execution.

For $plot(stdin) only:

The title, x axis label, and y axis label are assumed to be on the first line of input, delimited with a new-line. However, if the data starts with $BEGINTEXT, all text between $BEGINTEXT and $ENDTEXT will be removed from the data and displayed in a separate text dialog window, with the remaining data, including the title, x axis label, and y axis label, will be displayed in a plot window. Furthermore, if the data contains the string $ERROR, an error is assumed to have occurred and a text dialog window is displayed only.

Syntax:
    $plot

    $plot(,,,)
    $plot(<title>,<x axis label>,<y axis label>,[xy|xyex|xyey|xyexey])
    $plot(stdin)

Example:
    doit | $plot(This is aTitle,X Axis,Y Axis)
    doit | $plot(stdin)

$regions

Substitute region definition in specified region format, coordinate system, and coordinate format. The default coordinate system is physical, default coordinate format degrees, and default region format DS9. Arguments may appear in any order, as long as they are separated by ',' and no spaces. If one or  more properties are specified, only regions with all of the specified properties will be substituted.

Syntax:
    $regions

    $regions(<options>)

where options are one of the following:

    regions format    = [ds9|ciao|saotng|saoimage|pros|xy]
    property          = [include|exclude|source|background]
    coordinate system = [image|physical|detector|amplifier|wcs]
    sky frame         = [fk4|fk5|icrs|galactic|ecliptic]
    sky format        = [sexagesimal|degrees]

also, the old SAOTNG formats are also supported:

    $regions_pixels
    $regions_degrees
    $regions_hms
    $include_regions
    $include_regions_pixels
    $include_regions_degrees
    $include_regions_hms
    $exclude_regions
    $exclude_regions_pixels
    $exclude_regions_degrees
    $exclude_regions_hms

Example:
    dosomething $regions | $text

    dosomething $regions(pros) | $text
    dosomething $regions(source,wcs,fk5) | $text
    dosomething $regions(saotng,background,exclude,ecliptic,sexagesimal) | $text

$text

Display text in a text dialog window. This macro should be the last macro of a command line. To display text from only STDOUT use '|' as the pipe command. To display text from both STDOUT and STDERR, use '|&' as the pipe command. No parameters are required. The macro is removed from the command line before execution.

Syntax:
    $text


Example:
    doit | $text # stdout
    doit |& $text # stdout and stderr

$url

URLs are processed and stored in a temporary file. Only HTTP and anonymous FTP are supported.

Syntax:
    $url(http://<hostname>:<port>/<query>)

    $url(ftp://<hostname>/<filename>)

Example:
    $url(http://legacy.gsfc.nasa.gov/rosat/data/p000s26b.img.Z) | uncompress | $image

    $url(ftp://legacy.gsfc.nasa.gov/rosat/data/hri/images/rh100193_img.fits) | $image

$vo_method

Returns the vo method.

Syntax:
    $vo_method


Example:
    echo '$vo_method' | $text

$value

Substitute the value at the location of the cursor of an bind event.

Syntax:
    $value

Example:
    echo "$value" | $text

$x
$y
$z

Substitute coordinates of an bind event. When a bind event is triggered, the x,y coordinates of the mouse of the particular data file are returned. The default coordinate system is physical. This macro is only available for bind commands. For datacubes, the z coordinate is returned based on the current slice selected.

Syntax:
    $x

    $x(<coordinate system>,<format>)
    $y
    $y(<coordinate system>,<format>)
    $z
    $z(<coordinate system>)

where:

    coordinate system = [image|physical|detector|amplifier|wcs|wcsa...wcsz]
    sky frame         = [fk4|fk5|icrs|galactic|ecliptic]
    sky format        = [hms|sexagesimal|degrees]

Example:
    echo "$x $y" | $text
    echo "$x $y $z" | $text
    echo "$x(fk5,sexagesimal) $y(fk5,sexagesimal)" | $text
    echo "$x(wcs) $y(wcs) $z(wcs)" | $text

$xpa

Returns the xpa access point name.

Syntax:
    $xpa


Example:
    echo '$xpa' | $text

$xpa_method

Returns the xpa method.

Syntax:
    $xpa_method


Example:
    echo '$xpa_method' | $text

Help

The user may define his own HELP message. This message will be available to the user as a menu item. An optional label maybe specified. The default label is Help. When invoked, an text dialog window will appear, containing the message. Multiple HELP items maybe defined within a menu or across hierarchical menus.

Example:
help Main Help
A help message may contain
multiple lines of description of the tasks
in the menu or menus
endhelp

Parameters

The user may define his own macros or parameters to be evaluated before the command line is executed. To do this, the user defines a parameter segment that is referenced in the command line. Parameters maybe displayed in a notebook style via use of the 'tab' 'endtab' keywords. The parameter definition has the follow format:

param <name>
  <variable> <entry|text|checkbox|menu|open|save> <title> <default> <{comment}>
  ...
endparam
param <name>
  tab <text>
  <variable> <entry|text|checkbox|menu|open|save> <title> <default> <{comment}>
  ...
endtab
tab <text>
  <variable> <entry|text|checkbox|menu|open|save> <title> <default> <{comment}>
 ...
endtab
endparam

or

param <name>
@<iraf param filename>
end

The definition either consisted of a number of variables, one per row, or the name of a IRAF style parameter file. DS9 will look for the IRAF parameter file in:

./<filename>
$UPARM/<filename>
$HOME/iraf/<filename>

The following macros are supported if encounted in the default field:

$width
$height
$depth
$bitpix
$filename
$filename[region]
$env

Example:

param foo
  var1 entry {Variable 1} {default} {this is a entry}
  var2 text {Variable 2} {static} {this is text}
  var3 checkbox {Variable 3} 1 {this is a checkbox}
  var4 menu {Variable 4} {AAA|BBB|CCC} {this is a menu}
  var5 open {Variable 5} {default} {this is a open file dialog}
  var6 save {Variable 6} {default} {this is a save file dialog}
endparam

param bar
  tab {First Params}
    var1 entry {Variable 1} {default} {this is a entry}
    var2 text {Variable 2} {static} {this is text}
    var3 checkbox {Variable 3} 1 {this is a checkbox}
    var4 menu {Variable 4} {AAA|BBB|CCC} {this is a menu}
  endtab
  tab {Second Params}
    var5 open {Variable 5} {default} {this is a open file dialog}
    var6 save {Variable 6} {default} {this is a save file dialog}
  endtab
endparam

param foobar
  var1 entry {filename} {$filename} {image filename}
  var2 text {width} {$width} {image width}
  var3 text {height} {$height} {image height}
  var4 text {depth} {$depth} {image depth}
  var5 entry {bitpix} {$bitpix} {image bitpix}
endparam

To use parameters, specify the param name at the beginning of your command line:

Parameter Test
*
menu
$param(foobar); echo "$var1 $var2 $var3 $var4 $var5" | $text

When the menu item is selected, the user will be presented with a dialog box that contains entry, text, open, save, checkbox, or menu choices for each variable specified. If the user clicks ok, the values are substituted in the command line before execution.

Hierarchical Menus

The user may define hierarchical menus. Use this to organized crowded menus. To do this, frame menu entries with hmenu <label> and endhmenu. Hierarchical menu labels may contain spaces. Multiple levels maybe implemented.

Example:
hmenu Stuff
  hello
  *
  menu
  echo "Hello" | $text

  world
  *
  menu
  echo "World" | $text

  hmenu More Stuff
    hello world
    *
    menu
    echo "Hello World" | $text
  endhmenu
endhmenu

Will create an hierarchical menu with two members, hello and world.

Sample

# Analysis command descriptions:
#  menu label
#  file templates
#  menu/bind
#  analysis command line

param foo
  var1 entry {Variable 1} {default} {this is a entry}
  var2 text {Variable 2} {static} {this is text}
  var3 checkbox {Variable 3} 1 {this is a checkbox}
  var4 menu {Variable 4} {AAA|BBB|CCC} {this is a menu}
  var5 open {Variable 5} {default} {this is a open file dialog}
  var6 save {Variable 6} {default} {this is a save file dialog}
endparam

param bar
  tab {First Params}
    var1 entry {Variable 1} {default} {this is a entry}
    var2 text {Variable 2} {static} {this is text}
    var3 checkbox {Variable 3} 1 {this is a checkbox}
    var4 menu {Variable 4} {AAA|BBB|CCC} {this is a menu}
  endtab
  tab {Second Params}
    var5 open {Variable 5} {default} {this is a open file dialog}
    var6 save {Variable 6} {default} {this is a save file dialog}
  endtab
endparam

param foobar
  var1 entry {filename} {$filename} {image filename}
  var2 text {width} {$width} {image width}
  var3 text {height} {$height} {image height}
  var4 text {depth} {$depth} {image depth}
  var5 entry {bitpix} {$bitpix} {image bitpix}
endparam

param barfoo
    @analysis.par
endparam

# Help Main Help

help Main Help
These menus contain a test for each possible feature

supported by the ds9 (blank line above)
endhelp
---

hmenu Test Web
  help Web Help
  Help for web features
  endhelp

  Web Test url
  *
  web
  http://hea-www.harvard.edu/RD/ds9/

  Web Test file
  *
  web
  file:/home/joye/saods9/ds9/tests/hv.html
endhmenu

hmenu Test Basics
  help Basic Help
  Help for basic features
  endhelp
  ---
  Test escape char # this is a comment
  *
  menu
  echo "this is not a macro $$xpa" | $text

  Test pass thru # this is a comment
  *
  menu
  echo "this is not a macro $foo" | $text

  Test $xpa # this is a comment
  *
  menu
  echo $xpa | $text

  Test $xpa_method
  *
  menu
  echo $xpa_method | $text

  Test $vo_method
  *
  menu
  echo $vo_method | $text

  Test $filename
  *.fits
  menu
  echo $filename | $text

  Test $filename(root)
  *.fits
  menu
  echo $filename(root) | $text

  Test $xdim $ydim $bitpix
  *.fits
  menu
  echo "$xdim $ydim $bitpix" | $text

  Test $xcen $ycen
  *.fits
  menu
  echo "$xcen $ycen" | $text

  Test $env
  *
  menu
  echo $env(PATH) | $text
endhmenu

hmenu Test Regions
  help Regions Help
  Help for regions features
  endhelp
  ---
  Test $regions
  *.fits
  menu
  echo "$regions ds9_s:$regions(ds9,source,image) ciao_b:$regions(ciao,background) saotng_i:$regions(saotng,include,wcs,fk5) pros_e:$regions(pros,exclude,wcs,fk5,sexagesimal) xy_be:$regions(xy,background,exclude,wcs,fk4,hms)" | $text

  Test $regions wcs
  *.fits
  menu
  echo "$regions(ds9,wcs) $regions(ds9,wcs,fk5,sexagesimal) $regions(ds9,wcsa) " | $text

  Test $include_regions_pixels
  *.fits
  menu
  echo "ds9_s: $source_regions ds9_b: $background_regions_pixels ds9_i: $include_regions_degrees ds9_e: $exclude_regions_hms" | $text

  Test $filename $regions
  *.fits
  menu
  echo "$filename[$regions]" | $text

  Test $filename $regions()
  *.fits
  menu
  echo "$filename[$regions()]" | $text
endhmenu

hmenu Test Output
  help Output Help
  Help for output features
  endhelp
  ---
  Test $null
  *
  menu
  echo "This is Text" >/dev/null | $null

  Test $text
  *
  menu
  echo "This is Text" | $text

  Test $text stderr
  *
  menu
  ls foofoofoo | $text

  Test $plot
  *
  menu
  cat xy.dat | $plot

  Test $plot(title,x,y,xyey)
  *
  menu
  cat xye.dat | $plot(Title,X Axis,Y Axis,xyey)

  Test $plot(title,x,y,xyexey)
  *
  menu
  cat xyee.dat | $plot(Title,X Axis,Y Axis,xyexey)

  Test $plot(title,x,y,4)
  *
  menu
  cat xyey.dat | $plot(Title,X Axis,Y Axis,4)

  Test $plot(title,x,y,5)
  *
  menu
  cat xyeye.dat | $plot(Title,X Axis,Y Axis,5)

  Test $plot(stdin)
  *
  menu
  cat xye.stdin.dat | $plot(stdin)

  Test $plot(stdin) text
  *
  menu
  cat xye.stdin.text.dat | $plot(stdin)

  Test $plot(stdin) error
  *
  menu
  cat xy.stdin.error.dat | $plot(stdin)

  Test $data
  *.fits
  menu
  $data | $image(new)

  Test $image
  *
  menu
  cat img16.fits | $image
endhmenu

hmenu Test Dialogs
  help Dialogs Help
  Help for dialog features
  endhelp
  ---
  Test $message(message)
  *
  menu
  $message(ok,This is a Message) | echo "hello" | $text

  Test $message(ok,message)
  *
  menu
  $message(ok,This is a Message) | echo "World" | $text

  Test $entry(message)
  *
  menu
  echo "$entry(Enter Something)" | $text
endhmenu

hmenu Test Params
  help Param Help
  Help for param features
  endhelp
  ---
  Test $param
  *
  menu
  $param(foo);echo "$var1 $var2 $var3 $var4 $var5 $var6" | $text

  Test $param tab
  *
  menu
  $param(bar);echo "$var1 $var2 $var3 $var4 $var5 $var6" | $text

  Test $param macro
  *
  menu
  $param(foobar);echo "$var1 $var2 $var3 $var4 $var5" | $text

  Test $param @file
  *
  menu
  $param(barfoo);echo "$var1 $var2 $var3" | $text
endhmenu

hmenu Test Network
  help Network Help
  Help for network features
  endhelp
  ---
  Test $url(http://)
  *
  menu
  $url(http://legacy.gsfc.nasa.gov/FTP/rosat/data/cdrom/vol1/IMAGES/00h/p000s26b.img.Z) | gunzip | $image

  Test $url(ftp://)
  *
  menu
  $url(ftp://legacy.gsfc.nasa.gov/rosat/data/hri/images/fits/rh100193_img.fits) | $image

  Test $geturl $text
  *
  menu
  $geturl(http://hea-www.harvard.edu/RD/saord-cgi/funtools?funcnts+$filename+$regions(source,,)+$regions(background,,))|$text

  Test $geturl $plotstd
  *
  menu
  $param(ltc);$geturl(http://hea-www.harvard.edu/RD/saord-cgi/funtools?funhist_plot+$filename[$regions]+time+$bins)|$plot(stdin)
endhmenu

hmenu Test Other
  help Other Help
  Help for other features
  endhelp
  ---
  hmenu Test MultiLevel
    test
    *
    menu
    echo "Hello World" | $text
  endhmenu
endhmenu

$x $y
*.fits
bind x
echo "$x $y" | $text

$x(fk5,hms) $y(fk5,hms)
*.fits
bind y
echo "$x(fk5,hms) $y(fk5,hms)" | $text

$x(wcs,fk5,hms) $y(wcs,fk5,hms)
*.fits
bind z
echo "$x(wcs,fk5,hms) $y(wcs,fk5,hms)" | $text