Workshop aips++ Project Exercise 2

The goal of this excercise is to make a Glish script to use various aips++ tools to

Display an image
Use the cursor to mark a position location
Catch the position event that is so generated
Extract the spectrum from the event
Plot the spectrum
Fit the spectrum with a gaussian
Overplot the fit and residuals

When you have succeeded at this, you could look at the actual aips++ tool which implements this kind of functionality. It's called imageprofilefitter. You would start it with

YOu should be logged into nelle in a directory like

/DATA/NELLE_1/synwork/aips++/group1

The aips++ image to work with is called 'galaxy'

Make sure the DISPLAY environment variable points to the computer you are sitting in front of. E.g.

% setenv DISPLAY hydrus:0

Required Tools

To achieve the above goals, you will need to use a variety of aips++ tools, and write some Glish (an interpreted scripting language) to string them together. You will need to write about 50 lines of Glish in total.

You put your Glish code in a file with suffix ".g". E.g. ex2.g Then you load and run that script with

% glish -l ex2.g

The tools that you will need are all described in the User Reference Manual. This manual is structured by package, module and tool (going to finer granuality).

You will find the Image tool in the General package, in the Images module of the User Reference Manual. This tool is used to gain access to images and manipulate them. You will need the "image" constructor and the "view" function. For example

% glish 
include 'image.g'                # Include Image tool script
im := image('galaxy')            # Access image
im.view()                        # Display it

See the Glish turorial for some information on events. The event you want to catch from your image tool is called 'position'. Thus

im := image('galaxy')            # Access image
im.view()                        # Display it
whenever im->position do {       # Catch 'position' event, call function myHandleEvent with event value
  myHandleEvent ($value)
}

The $value of the event is a Glish record (see tutorial with many fields). Use the Glish function field_names(record) to find what's in it. E.g.

whenever im->position do {       # Catch 'position' event, call function myHandleEvent with event value
  rec := $value;
  print 'names of event are ', field_names(rec)
}

A Glish record is hierarchical and you will find there are many levels in the above position event record. You would need to write the function myHandleEvent above to do something with the event record.

Writing a function is easy. Just stick it at the beginning of your Glish script. E.g.

doit := function (name)                      # Define function
{
  if (name=='neil') {
     print name, ' is a very nice name'
  } else {
     print name, ' is a very silly name'
  }
}
#
f := frame()                                 # GUI frame
b := button(f)                               # BUtton
whenever b->press do {                       # Catch button press
   readline print x := 'What is you name'
   doit(x)                                   # Call function
}

To plot things, use the Pgplotter tool. It lives in the Display package and the Plotter module of the There is also a section in GettingResults With aips++ specifically on this tool. An example piece of Glish is

include 'pgplotter.g'
p := pgplotter()
x := 1:100
y := sin(x)
p.plotxy(x,y)

The last tool you will need is the one to do the fitting and evaluating of the fit. This is the gauss1dfitter tool. It lives in the Utility package, Mathematics module of the User Reference Manual.

For example

include 'gfitgauss.g'
fitter := gauss1dfitter();
x := (1:100) / 20;
y := sin(x)
estimate  := [=];
estimate.center := 1.5;
estimate.width := 1;
estimate.height := 1;
fitter.setstate(estimate)
fit := := fitter.fit(x,y)

There are also some handy functions in the Mathematics module for finding locations of peaks in arrays etc.

If you get desperate, you can find my solution to this exercise here.