Search CASA
Lattice Expression Language
Subsections
Interface to LEL
There are two interfaces to LEL. One is from Glish and the other from C++. It depends upon your needs which one you access. Most high level users of AIPS++ will access LEL only via the Glish interface.
Glish Interface
The LEL interface in Glish is provided by the Image tool (loaded with the script image.g) imagecalc constructor, and through the calc tool function. These can be used to compose and/or execute a LEL expression.
Simple String Expressions
The imagecalc constructor evaluates the
expression and stores the result and mask in an output image. If you
specify the output image name, it is written to a disk file of that
name. If you don't give it, the output image is never written out; it
is evaluated every time an action (like
statistics) is requested.
im := imagecalc(outfile='outimage', pixels='inimage1+inimage2'); im.statistics();
The first command creates an image file outimage filling
it with the sum of the input images. The second command does
statistics on that new image.
Writing it as
im := imagecalc(pixels='inimage1+inimage2'); im.statistics();would do the same with the exception of creating the output image. Instead the created image is transient; it only lives as an expression and each time it is used the expression is evaluated.
We can use the function calc on an already existing image. Thus
im := image('ngc1213'); im.calc('ngc1213^2');would replace the pixels by the square of their value.
Sometimes you need to double quote the file names in your expression.
For example, if the images reside in a different directory as in
this example.
im := imagecalc ('"dir1/im1" + "/nfs/data/im2"');
Symbol (or tool) substitution
Images created/opened in Glish can be used with their Glish name
in a LEL expression. Similarly a region created in Glish with the
Regionmanager can be used with its Glish name.
It is also possible to embed other Glish variables and expressions in
a LEL command using the syntax $variable and
$(expression). A variable can be a standard numeric scalar.
An expression has to result in a numeric scalar.
E.g. one can make a Glish function like
img1 := image('"/data/inimage'"); img2 := imagecalc(pixels='min($img[$someregion], $clipvalue)');to return a transient image formed by a region in an image clipped at the given clipvalue.
The substitution mechanism is described in more detail in the
substitute
functions of module
misc of the
User Reference
Manual.
The substitution mechanism uses the eval function in Glish. As of
15-Jan-1999 eval only looks at global variables. This means that in a
function one needs to create a global variable (with a unique name) if
the variable is to be used in a LEL command. The global variable should
be deleted at the end of the function (with symbol_delete). The
name can be made unique by using the function name as a suffix.
In Glish applying a region to an image can also be done using the
subim function of an Image tool.
It forms an image from the given region in the input image.
This new image can be used in a LEL expression.
E.g.
img := image('inimage'); subimg := img.subimage(region=someregion); # Virtual Image tool (a reference) img2 := imagecalc(pixels='min($subimg, $clipvalue)');has the same result as the earlier example. Both subimg and im2 are virtual images (not written to disk).
C++ interface
This consists of 2 parts.
- 1.
- The function command in
Images/ImageExprParse.h
can be used to execute a LEL command. The result is a
LatticeExprNode
object. E.g.
LatticeExprNode seltab1 = ImageExprParse::command ("imagein1 + imagein2");
This example does the same as the Glish one shown above. - 2.
- The other interface is a true C++ interface having the
advantage that C++ variables can be used. Class
LatticeExprNode
contains functions to form an expression. The same operators
and functions as in the command interface are available.
E.g.
Float clipValue = 10; PagedImage<Float> image("imagein"); LatticeExpr<Float> expr(min(image,clipValue));
forms an expression to clip the image. Note that the expression is written as a normal C++ expression. The overloaded operators and functions in class LatticeExprNode ensure that the expression is formed in the correct way.
Note that a LatticeExprNode object is usually automatically converted to a templated LatticeExpr object, which makes it possible to use it as a normal Lattice.
So far the expression is only formed, but not evaluated. Evaluation is only done when the expression is used in an operation, e.g. as the source of the copy operation shown below.PagedImage<Float> imout("imageout"); imout.copyData (expr);