Writing your own operators in IDL

This is a short tutorial on writing elementary operators (aka "genes") for genie in IDL. It is assumed that the reader knows the basic ideas behind how genie works, and what operators generally do. It is also assumed that the reader has a minimal proficiency in writing IDL, but a minimal proficiency is really all that is needed, unless you want to do something complicated.

In general, operators read a small number of input planes (often one or two), perform some operations with them, based on an set of parameters (typically, zero to a few), and produce output planes (usually just one). A "plane" is a two-dimensional array of floating point numbers, and corresponds to either a "data plane" (a single spectral channel in the original multispectral image or auxilliary image such as a DEM) or to a "scratch plane" which is equivalent to a data plane when used as input, and which are used to store the output of operators (original data planes are not modified by operators).

To begin, let's look at a simple operator: ADDP (for "add planes")

      PRO ga_addp, in1, in2, out
      out = in1 + in2
      END
    

The first two arguments are the two input planes, and the third argument is the output plane. As long as the input planes are non-negative, the output plane will be non-negative, as required.

For example, here is another operator: ADDS ("add a scalar")

      PRO ga_adds, in, out, scalar
      COMMON GenieParms, dataScale
      out = (in + dataScale*scalar) > 0
      END
    

(Note the `x > 0' operator in IDL is equivalent to the minimum of x and 0; that is, it returns x as long as x is positive, but returns 0 whenever x is negative.)

A simple example of how to use these helper functions is provided by the DILATE operator:

PRO ga_dilate, in, out, w, s

    mse = gs_mselt(w,s)            ;morphological structure element

    ;; scale input
    tmp = gs_discretize(in)

    tmp = gs_padimage(tmp,w)
    tmp = dilate(tmp,mse,/gray,/ulong)
    tmp = gs_padimage(tmp,w,/unpad)

    ;; rescale output
    out = gs_discretize(tmp,/undo)

END

Once you've written an operator in IDL, you need to place it somewhere GENIE can access the file, and you need to provide an 'eop' entry for it so that GENIE knows it is available and understands how to use it.

The standard location for IDL operators in individual 'pro' files is INSTALL_PATH/share/genie/pro. Here, for instance, INSTALL_PATH=/opt/isis on the the standard Solaris installations. For developers, INSTALL_PATH is ISIS_DEV/genie/CONFIG_GUESS. (If you are a developer, you should know what your ISIS_DEV path is, and CONFIG_GUESS is a string like 'sparc-sun-solaris2.6' which describes the platform on which you are running.)

The standard location for the 'eop' files of the GENIE distribution is INSTALL_PATH/share/genie.

If you are writing your own operators, you will find the files in these directories useful as examples of what do to. Although you can place your new or modified 'eop' files and 'pro' files in these directories, we actually recommend placing then elsewhere. GENIE can be directed to use them by setting the --eopSearchPath and --idlSearchPath options in your options ('.opt') file to include the new directories where you have placed your new .pro and .eop files. If you have written a new 'myfile.eop' then you should add "myfile" to the list of --eopFiles.

For example, here are three eop entries, from the three operators shown above.

ADDP rp=2 idl=ga_addp libgenie=ge_add_planes;

ADDS idl=ga_adds libgenie=ge_add_scalar_to_plane
    parm={initval=[-1:1],del=.2};

DILATE idl=ga_dilate
    parm={type=i,initval=[1:3],del=1,bound=[1:5]}
    parm={type=s,initval=1,del=0,bound=[0:8]};

The 'ADDP' is a simple eop entry. There are two read planes (rp=2), one write plane (wp=1 is default), and the idl program is ga_addp, which is implemented in the file ga_addp.pro. There is also a libgenie entry for this operator, but it is ignored for GENIE running with IDL.

The 'ADDS' operator includes a single parameter, which is of the default floating point type. It is specified to start in the range from -1 to 1, and mutations are gaussian steps with standard deviation 0.2.

The 'DILATE' operator has a single read plane (rp=1 is default), a single write plane (wp=1 is default), and two parameters. The first is an integer specifying the radius of the structuring element. Note that the bound prevents the radius from being zero or negative. The second type is symbolic and corresponds to the shape of the structuring element. For many operators gs_mselt() provides some nine different shapes (see gs_melt.pro for the authoritative list), and all of those are allowed (bound=[0:8]), but the initial value will be 1, which corresponds to a circular element, and since del=0, there will be no mutations. That is, a run that uses this eop file will only use circular structure elements.

More information on eop files is in the documentation in the appendix on EOP files.

Note: the operators shown so far have a fixed number of inputs, outputs, and parameters. It is possible to write operators for which these numbers are variable. These are quite a bit more complicated, and the reader is referred to the operators in the MultiSpec.eop file, and the associated IDL .pro files, for examples.