Grid Math

The Grids | Calculate | Math command creates a new grid file that transforms the Z values of a single grid file or combines Z values from multiple grid files. The output grid file is based on a mathematical function of the form f(A, B, C, D), where A, B, C, D represent input grid files.

A defined math function can be performed by node position on corresponding nodes with the same row and column coordinates from the input grid files. The result of the calculation is placed at the same coordinates in the output grid file. For example, the function log10(A) creates an output grid file with the logarithmic base 10 values for each of the grid nodes in Grid A.

A math function can also be performed on grid files that do not have the same number of rows and columns. Surfer matches the grid files' X and Y values and then performs calculations on those overlapping values. If needed, input grids are projected to the master grid's coordinate system and then resampled to the master grid's geometry.

By default, if a node contains the NoData value in any input grid, it is assigned the NoData value in the output grid. However, you can change the NoData Handling for each grid so that NoData nodes are assigned a value. The output grid file will then have a value when the input grid contains the NoData value.

Grid Math Dialog

Click the Grids | Calculate | Math command to open the Grid Math dialog.

grid math example

Specify grid files and define a math function in the Grid Math dialog.

Input Grid

The Input Grid column displays the selected grid files. The X and Y limits and grid size of these files define the output grid. Place the mouse over any grid file to reveal the full path and file name for the grid.

Variable

By default, Surfer defines each grid with a Variable name letter. The first grid is A, the second grid is B, and so on. To change the Variable name for a grid, click in the Variable name box next to the current Variable name. Delete the existing text and type a new name. The variable name is case insensitive, so G1B is the same as g1b. Variable names must start with an underscore (_) or letter and can only contain alphanumeric characters.

NoData Handling

The NoData Handling option specifies the value to use for any NoData nodes in the grid. If a NoData node is found in the grid, the NoData output option assigns the NoData value to the output grid file for the same node. If the NoData Handling is changed to Remap to, the NoData node in the input grid is changed to the value in the Remap Value column. To change the NoData Handling option, click on the current option and select the desired option from the list.

If Align grids using is set to XY coordinates and NoData Handling is set to NoData output, all nodes outside the overlapping area will be assigned NoData. To keep the original values of the master grid in areas where there is no data overlap, set NoData Handling to Remap to, and then set the Remap Value to a value that does not affect the math function (e.g., 0 for addition or subtraction).

Remap Value

When the NoData Handling is set to Remap to, the Remap Value box becomes available. Highlight the existing value and type in a new value to change the Remap to value. This sets every NoData node in the input grid to this new Remap Value. Each grid file can contain a different Remap Value.

Add Grids

Click the Add Grids button to open the Open Grid(s) dialog. To perform an operation on a single grid, select only one grid file. To perform an operation on multiple grids, select multiple grid files using the CTRL and SHIFT keys. You can select any number of grid files at once. When all grids are selected, click the Open button. The grid file names are displayed in the Input Grid list.

Remove Grid

To remove a grid from the Input Grid list, click once on the grid to select it. Click the Remove Grid button. The selected grid is removed from the list.

Grid Info

Click the Grid Info button to display the number of grid rows, number of grid columns, X, Y, Z minimums and maximums, and statistics for the selected grid. If the grid file is large, click OK in the message box that appears to create a detailed grid report or click Cancel to create a shorter, less detailed grid report.

Align Grids

If the input grid files have the same number of rows and columns, select the Node position value from the Align grids using list. The math function will be performed in equivalent grid nodes, regardless of the X and Y values. If the input grid files do not have the same number of rows and columns, select the XY coordinates value from the Align grids using list to match the input grid files on X and Y values.

If Align grids using is set to XY coordinates and all grids are referenced but in a different coordinate system, the resulting grid file uses the master grid's coordinate system. If an input grid files is not referenced but another grid file is referenced, Surfer displays a warning about mixing referenced and unreferenced grid files. Selecting Yes continues with the math function operation, but none of the other grids will be projected to the master grid's coordinate system. If the grids are in the same coordinate system, selecting Yes will perform the math as expected. However, if a grid is not referenced and not in the same coordinate system, select No at the warning to cancel the math function operation and return to the Grid Math dialog. Select different grid files with referenced or matching coordinate systems or use the Grids | Edit | Assign Coordinate System to change the coordinate system of one or more of the grid files.

Master Grid

From the Master grid (for geometry) list, select the master grid to use as the base geometry for the new grid produced by the math function.

Enter a Function of the Form f(A,B, ...)

In the Enter a function of the form f(A,B, ...) where A, B, ... are the variables in the list above box, enter a function which describes the output grid file. The Variable names are used in the equation. By default, variable names are A, B, C, D, etc. These refer to the input grid files. To perform a calculation on grid file A only, you can leave any reference to additional grid files out of the specified function.

Mathematical functions and operators can be used in the Enter a function of the form f(A,B...) where A, B... are the variables in the list above field. For example, to add the Z values from two grids A and B, type A + B . Or for example to create an output grid where the values are the greater value from two grids A and B, type IF(B>A,B,A).

To use a stored function, click the next to the current function. This will display the ten most recent functions used. The functions are stored in the registry, so the equations are stored between Surfer sessions. You can also start typing the function in the function box. If the function is in the function history, the entire function will auto-complete.

Output Grid

Type a file path and file name, including the file type extension, in the Output Grid field, or click the image\open2.png button and specify the path and file name for the grid file in the Save Grid As dialog.

Add New Map or Layer

Check the Add grid as layer to check box to automatically add the created grid to a new or existing map. Select [New Map] in the Add grid as layer to field to create a new map. Click the current selection and select an existing map to add a new layer to the map. Select the layer type by clicking the current selection in the New layer type field and selecting the desired layer type from the list.

Note: If you are saving the grid file in the DEM grid format, clear the Add grid as layer check box and add the map or layer with a Home | New Map or Home | Add to Map | Layer command.

To Use the Math Command

  1. Click the Grids | Calculate | Math command or the button.
  2. In the Grid Math dialog, click the Add Grids button. Select any number of grid files and click Open.
  3. In the Align grids using list, select what type of grid alignment to use.
  4. In the Output Grid section, click the image\open2.png button to specify a different path or file name for the grid file to be created.
  5. In the Enter a function of the form f(A,B, ...) where A, B, ... are the variables in the list above. box, enter a function that represents the output grid file, and where A and B refer to the input grid files.
  6. Click OK to create the new grid file.

Grid Math and .GSR2 Files

When the input .GRD file for a Grid | Math command has a defined .GSR2 file with coordinate system information, the information in the first input .GRD file is used for the output .GRD file. The Export Options dialog appears with the option to save the coordinate system information. It is recommended to check the GS Reference (Version 2) file if you intend to use the grid file in Surfer , as the GSR2 retains all of the information needed. The grid has the same coordinate system as the original file, but the .GSR2 is required to define the coordinate system.

See Also

Mathematical Functions

Grid Convert

Grid Extract

Grid Transform

Using Grid Math to Eliminate Negative Values

Generate an Isopach Map