TUgridFill2D TCL UTILITIES USER MANUAL TUgridFill2D
SYNOPSIS
Fill gaps in a 2D grid
PACKAGE
TCLUTILS
NAME
TUgridFill2D
USAGE
TUgridFill2D  Grid gInfo gNorm fInfo
INPUT DEFINITIONS
Grid - A 2D data grid generated through a call to TUdataGrid.
gInfo - The grid information array.
gNorm - The grid normalization array associated with Grid. This was returned in the call to TUdataGrid.
fInfo - The fill information array. This sets several parameters used in the fill algorithm. The array element defintions are:
0 - The minimum number of known values per quadrant. Must be 1 or larger. The area surrounding a location being fit is surrounded by 4 quadrants. A good fit should come from a minimum of 1 point in each quadrant to include information from all directions. Note: The procedure may ajust the input value if it turns out that it produces less than the number of points requred to produce a fit.
1 - The maximum search radius used to locate filled data grids cells to use in the least squares interpolation. The variable is specified in units of grid cells. A large number will include the entire grid. The search stops when the minimum number of points criteria in each quadrant has been reached.
2 - This is the minimum number of quadrants which need values for an interpolation to be attempted. This should be set to 4. The procedure will change this for emtpy cells on the grid edges for which it is impossible to find points in all 4 quadrants.
3 - This allows for constraints to be placed on the interpolated cell value. Set this value to 0 to turn off all checks. Set it to 1 if the interpolated value can't be larger than the nearest known value Set this to 2 if the interpolation is not allowed to be larger than any value which went into interpolation. The value should be set to 0 unless you see some insatbility in the filling process.
4 - This defines the left-hand X edge of the grid for the procedure. It is an offset in grid cells from column 0 of the grid. A value of 0 keeps the left-hand edge at the grid edge. It is useful for eliminating empty columns of cells from the fill procedure. Resetting the edge allows the routine to better fit the cells close to the actual data edge in the grid.
5 - This defines the right-hand X edge of the grid for the procedure. It is an offset in grid cells from the last column of the grid. A value of 0 keeps the right-hand edge at the right grid edge. It is useful for eliminating empty columns of cells from the fill procedure. Resetting the edge allows the routine to better fit the cells close to the actual data edge in the grid.
6 - This defines the lower Y edge of the grid for the procedure. It is an offset in grid cells from the first row of the grid. A value of 0 keeps the lower edge at the bottom grid edge. It is useful for eliminating empty rows of cells from the fill procedure. Resetting the edge allows the routine to better fit the cells close to the actual data edge in the grid.
7 - This defines the upper Y edge of the grid for the procedure. It is an offset in grid cells from the upper row of the grid. A value of 0 keeps the upper edge at the upper grid edge. It is useful for eliminating empty rows of cells from the fill procedure. Resetting the edge allows the routine to better fit the cells close to the actual data edge in the grid.
8 - Sets the weighting to use in for each value the interpolation. The weighting is defined as:
W = (MinR/DataR)fInFo(8)
where MinR is the distance of the closest cell to the interpolation point and DataR is the distance of the cell being added to the interpolation.
9 - Is the order of the 2D least squares fit used in the interpolation.
RETURN DEFINITION
NONE
DESCRIPTION
TUgridFill2D takes a 2D Grid of values created using the procedure TUdataGrid and fills any empty cells that it finds in the grid. Empty cells are filled using a 2D least squares algorithm with data from the closest filled cells as input.
The interpolation proceeds along the following path. When an empty cell is located it is considered to be an the origin of a rectangular coordinate system. The closest filled cells to the empty cell are then located. The search extends to a distance sInfo(1) from the empty cell. These cells are organized both by distance and by the quadrant they lie in with respect to empty cell. (If a cell sits at (row,column) position (A,B) then the qudrants are defined as: R>=A, C>=B; R<=A, C>=B; R<=A, C<=B; and R>=A, C<=B.) For an interpolation to give good results it is advantageous for there to be data present from each of the four quadrants. The user can specify through sInfo(2) the number of quadrants which must have data in them in order for a fit to be made. Generally this is 4 but there are situations where it may be desireable to reduce this number. The procedure will reduce this number for cells on and outside the edge of the grid as defined in sInfo(4-7). Values included in the interpolation are weighted by a power of the ratio of their distance to the empty cell to the distance of the closed filled cell. The power is given in sInfo(8). A value of 0 turns off the weighting. Positive value give larger weight to closer values while neagive values would give larger weight to the more distant values. The order of the least squares fit used is given in sInfo(9).
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
EXAMPLE 1:Filling gaps in a 2D grid. Note how the grid edges are moved in on the top and right sides. The upper plot shows that there are no data points out to these edges. Moving the edges in allows the fill to partially work in this area since the procedure will only demand 2 quadrants to be filled and not 4 which would never be achieved.
# PERFORM a 2D fill to a sparsely filled 2D grid

# SET up a data set of four Gaussians centered at (-3,-3) and one at (-3, 3)
#   (3,-3) and (3, 3).  Each will have a different intensity

set nP 0
for { set X -6.0 } { $X <= 6.0 } { set X [expr $X + .5] } {
   for { set Y -6.0 } { $Y <= 6.0 } { set Y [expr $Y + .5] } {
       set Xx($nP) $X
       set Yy($nP) $Y
       set R [expr ($X - 3.0) * ($X - 3.0) + ($Y - 3.0) * ($Y - 3.0)]
       set A [expr exp(-$R / 6.0)]
       set R [expr ($X - 3.0) * ($X - 3.0) + ($Y + 3.0) * ($Y + 3.0)]
       set B [expr 3.0 * exp(-$R / 6.0)]
       set R [expr ($X + 3.0) * ($X + 3.0) + ($Y - 3.0) * ($Y - 3.0)]
       set C [expr 4.0 * exp(-$R / 6.0)]
       set R [expr ($X + 3.0) * ($X + 3.0) + ($Y + 3.0) * ($Y + 3.0)]
       set D [expr 2.0 * exp(-$R / 6.0)]
       set Vv($nP) [expr $A + $B + $C + $D] 
       incr nP
   }
}

# SET up the grid information array.  There are more cells in the grid than
#   data points which will generate empty cells to fill

set gInfo(0) -6.0
set gInfo(1) 6.0
set gInfo(2) -6.0
set gInfo(3) 6.0
set gInfo(4) 100
set gInfo(5) 100
set gInfo(6) POINT
set gInfo(7) POINT
set gInfo(8) COLUMN
set gInfo(9) IGNORE
set gInfo(10) NEW:ADD:END
set gInfo(11) -1
set gInfo(12) -5
set gInfo(13) -1.0e30
set gInfo(14)  1.0e30
set gInfo(15)  NO
set gInfo(16)  NO

# GRID the data

TUdataGrid $nP 1 Xx Xx 1 Yy Yy Vv Grid Norm gInfo

# SET up the plot basics.  There is an upper an lower plot

GraphicsOn TK ETones SWAP

GenWindow 1 0.0 0.0 0.0 1.0 1.0 0.0  0. 0. 0. 1. 1. 0. XY
set WinInfo(8,corFmt) 1
RelWindow 8 1 100.0 425.0 0. 450. 775. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 8 8 $gInfo(4) $gInfo(5)
set WinInfo(9,corFmt) 1
RelWindow 9 1 100.0 65.0 0. 450. 415. 0. -6. 0. 0. 6. 2. 0.
DefinePlot 9 9 $gInfo(4) $gInfo(5)

# SET up the color map to run from 0 to 4.0

PLTcolorMap 0.0 4.0 LINEAR 0 cA

# PLOT the sparsely filled grid in the upper plot

Plot3D 8 Xb Yb Dummy Dummy Grid AUTO Dummy cA

# Set up the fill information array

set sInfo(0) 1;      # At least one value per quadrant
set sInfo(1) 10;     # Look out to a radius of 10 cells
set sInfo(2) 4;      # Need 1 value in each quadrant
set sInfo(3) 0;      # No check on interpolated value
set sInfo(4) 0;      # Left grid edge left alone
set sInfo(5) 4;      # Right grid edge 4 cells in from edge
set sInfo(6) 0;      # Bottom grid edge left alone
set sInfo(7) 4;      # Top grid edge 4 cells down from edge
set sInfo(8) 1.0;    # Weighting factor 1.0
set sInfo(9) 1;      # First order fit

# Fill the grid

TUgridFill2D Grid gInfo Norm sInfo

# PLOT filled grid in lower plot

Plot3D 9 Xb Yb Dummy Dummy Grid AUTO Dummy cA

# THROW up the axis.  Only annotate lower plot

PlotOutlines 8 [list "" 1.0 "" 1.0] [list NONE NONE BOTH BOTH]
PlotOutlines 9 [list "X" 1.0 "Y" 1.0] [list BOT BOT BOTH BOTH]
update
      
Sept 21, 2006