**Purpose**

The purpose of this web page is to describe two computerized contouring methods that are compatible with the FloPy module that develops MODFLOW input files. The contouring methods are (1) gridded averaging, and (2) Matplotlib linear interpolation on a triangular grid (matlotlib.tri.LinearTriInterpolator). This page is technical and assumes the reader is familiar with Python and MODFLOW.

**Gridded averaging contouring method**

The gridded averaging contouring method has not been described previously. The method uses a set of Python programs that I developed. The programs produce an array of values for cells on a gridded map. Known values (constants) are assigned to grid cells according to their locations, and values are calculated for the remaining cells. The calculated values are the average of the values in the immediately adjacent cells. If the grid used in a MODFLOW model is also used for the contouring, then a Python NumPy array is produced that can be used directly as input to FloPy. One of the programs produces a grid plot of the constant and calculated values and another produces a contour map.

The plotting and contouring method involves the following steps:

- Develop a map showing the locations of the constant values.
- Overlay the map with a grid that may be the same as a MODFLOW model grid.
- Enter the grid locations of the constants and their values into fdcontour_in.py. The fdcontour_in.py script is shown in Attachment 1. The locations are entered in an array that is analogous to the IBOUND array of MODFLOW.
- Run final_plot.py with Python3. This run produces the grid plot as a png file. The final_plot.py script is shown in Attachment 2. This step may be skipped if a plot is not wanted.
- Run array_contour.py with Python3. This run produces a Numpy array and a contour map of the constant and calculated values as a png file. The array_contour.py script is shown in Attachment 3.

The scripts final_plot.py and array_contour.py each import variables from fdcontour.py. The fdcontour.py script is shown in Attachment 4. The fdcontour.py program calculates the values in the cells that do not contain constants as the average value of the immediately adjacent cells. This is accomplished by solving the set of equations for average cell value simultaneously using successive overrelaxation (SOR).

Figure 1 shows the NumPy array produced for a simple artificial example of the method. In this example the array shape is 5X5. A constant value of 10 is assigned to the center cell, and constant values of 5 are assigned to corner cells and cells in the middle of each side of the grid. Figure 2 shows the plot of the array, and Figure 3 shows a contour map of the array. Inspection of Figure 1 shows that computed values in interior cells are indeed the average of the four surrounding cells. Computed values of cells along the sides of the grid are the average of the three adjacent cells. It is not necessary to put constants in the corner cells. When corner cells are computed values, they are the average of the two adjacent cells. Figure 2 is a plot of the values in Figure 1. Figure 3 is a contour map of the array in Figure 1 produced by the contour function of Matplotlib.

Figure 1. NumPy array.

Figure 2. Grid plot of symmetrical array.

Figure 3. Contour map of symmetrical array produced by gridded averaging.

Figure 4 shows a Matplotlab contour map of the array produced by moving the 10 constant from the center cell to the cell located left of the center, so that the constant locations are not symmetrical.

Figure 4. Contour map of asymmetrical array produced by gridded averaging.

**Linear interpolation on triangular grid contouring method**

I performed linear interpolation on a triangular grid with Matplotlib using tri.Triangulation and tri.LinearTriInterpolator. The Python script is shown in Attachment 5. I applied this interpolation method to the same constants as in the symmetrical example above. It produced an array similar to that produced by the averaging method. Figure 5 shows the contour map produced from the array. Figure 5 is analogous to Figure 3.

Figure 5. Contour map of symmetrical array produced by Matplotlib triangular linear interpolation.

Figure 6 shows the result when the triangular grid method was applied to the asymmetrical data. Figure 6 is analogous to Figure 4.

Figure 6. Contour map of asymmetrical array produced by Matplotlib triangular linear interpolation.

**Attachment 1 - fdcontour_in.py**

**Attachment 2 - final_plot.py**

**Attachment 3 - array_contour.py**

**Attachment 4 - fdcontour.py**

**Attachment 5 - pycontour.py**

**Addendum**

If you have questions or comments, especially about errors and omissions, send an email to ddunn@dunnhydrogeo.com. If you need a consulting geologist to perform a contour mapping task, send an email to the above address. Capabilities include remote work.

Posted January 17, 2019