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. The defined function is performed on corresponding nodes with the same row and column coordinates from the input grid files, and 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.


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.


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.



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.


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.


All selected grids must contain the same number of grid rows and columns, and should extend over the same X and Y ranges.


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.


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 ten 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.

  2. In the Grid Math dialog, click the Add Grids button. Select any number of grid files and click Open.  All grids must contain the same number of grid rows and columns, and the same X and Y ranges.

  3. 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.

  4. 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.

  5. 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 the Grid Math Command to Generate an Isopach Map

Using Grid Math to Eliminate Negative Values