X
3921

Obtaining Irregular Grid Intervals with IDL

 

This Help Article demonstrates how the XOUT and YOUT keywords, to the TRIGRID routine, can be used to obtain a grid with irregular intervals.

The following example begins by creating an irregularly-gridded dataset of a Gaussian surface. A grid is then formed from these points using the TRIANGULATE and TRIGRID routines. The inputs to the XOUT and YOUT keywords are determined at random to produce an irregular interval. Since the XOUT and YOUT vectors must be monotonically increasing or decreasing, they must be sorted before passing them to the TRIGRID routine. The lines of the resulting surface are spaced at the irregular intervals provided by the settings of the XOUT and YOUT keywords.

See also TRIANGULATE and TRIGRID in the IDL Help for more information on these routines.

Code Example:

PRO griddingIrregularIntervals

    ; Make 100 normal x, y points:
    x = RANDOMN(seed, 100)
    y = RANDOMN(seed, 100)
    PRINT, MIN(x), MAX(x)
    PRINT, MIN(y), MAX(y)

    ; Make a Gaussian surface:
    z = EXP(-(x^2 + y^2))

    ; Obtain triangulation:
    TRIANGULATE, x, y, triangles, boundary

    ; Create random x values. These values will be used to
    ; form the x locations of the resulting grid.
    gridX = RANDOMN(seed, 30)
    ; Sort x values. Sorted values are required for the XOUT
    ; keyword.
    sortX = UNIQ(gridX, SORT(gridX))
    gridX = gridX[sortX]
    ; Output sorted x values to be used with the XOUT
    ; keyword.
    PRINT, 'gridX:'
    PRINT, gridX

    ; Create random y values. These values will be used to
    ; form the y locations of the resulting grid.
    gridY = RANDOMN(seed, 30)
    ; Sort y values. Sorted values are required for the YOUT
    ; keyword.
    sortY = UNIQ(gridY, SORT(gridY))
    gridY = gridY[sortY]
    ; Output sorted y values to be used with the YOUT
    ; keyword.
    PRINT, 'gridY:'
    PRINT, gridY

    ; Derive grid of initial values. The location of the
    ; resulting grid points are the inputs to the XOUT and
    ; YOUT keywords.
    grid = TRIGRID(x, y, z, triangles, XOUT = gridX, $
     YOUT = gridY, EXTRAPOLATE = boundary)

    ; Display resulting grid. The grid lines are not
    ; at regular intervals because of the randomness of the
    ; inputs to the XOUT and YOUT keywords.
    SURFACE, grid, gridX, gridY, /XSTYLE, /YSTYLE

END
______________________________________________________________
Reviewed by BC on 09/05/2014