Clim 301 Lab1

Aug. 26 Lab: (due Sep. 2) Contouring

This lab is an introduction to contouring. The goal is to learn how to interpret a contour plot, and how to create one.

We first examine a sample contour plot.



We note that each contour line represents a line of equal value for a general function f(x,y). The lines are usually plotted at equal intervals, in this example an interval of 6.

In the lab, everyone examines the line connecting the two red markers on the plot. A ruler is used to draw a line connecting each mark. The ruler is then used to mark half-inch intervals along the line. A value of the function f(x,y) is determined at each of these marks, by examining the contour field, and subjectively interpolating between the contour lines as necessary.

A graph is then made of these values. Below is a computer rendering of the graph:



This graph will not be quite the same as the hand-drawn graph, since the computer is using more data points to plot the line.

We note that places where the curve has high slope are locations on the original contour plot where the contours are more tightly packed. We also note that a tangent slope at a point on the graph is a partial derivative of the function f(x,y) with respect to x.

The tangent line discussed above is the tangent line to the function f(x,y) in the direction where x is varying and y is fixed. We consider the maximum slope of a line drawn tangent to the function f(x,y) at a point, where we allow both x and y to vary as needed. This tangent will be a vector that is perpendicular to the contour lines at that point. In meteorology we call this the gradient.

When looking at a contour plot of some specific meteorological variable, the regions where the contour lines are closely spaced (ie, where there is a strong gradient) are usually of great interest to the forecaster.

The next portion of the lab covers how to create a contour plot, given a field of regularly-spaced points that sample the function f(x,y):

The contour plot is constructed one contour line at a time, where each line repreents a constant value of f(x,y) along the entire line. A contour plot normally consists of contour lines drawn at some equal integer interval.

Each contour line is constructed with adherence to the following rules:

  1. The values are higher on one side of the line, and lower on the other side of the line -- along the entire length of the line. As the lines are constructed, they should be checked to insure that the side of the line where the values are higher does not "flip" to the other side at some point.
  2. Contour lines may be closed (for example, circular). There may be any number of lines that pass between two of the adjacent point values.
  3. Contour lines never "fork" or split.
  4. Contour lines of different values never cross.
  5. There are three singularity points: minimum, maximum, and col. A col may require special handling. See below. Minimums and maximums are surrounded by at least one closed contour (even though that contour may be at a contour value that is not drawn.) Sometimes the minimum and maximum points are plotted, using some known and accepted notation.
  6. No line will break abruptly except at the limits of the data. (An exception to this is when a line is drawn using an intermediate value to examine some feature of interest more closely. This sort of contour line will always be drawn in a different color or line style to denote it is not a member of the set of normal contours.)
  7. Each contour line is labeled with its value.

The saddle point, or col point is a location where contour lines of the same value may get very close, or even meet. An example of this is shown below:


More on Contouring


Consider a set of points in x,y that sample f(x,y). When these points are regularly spaced in both x and y, they form a grid. Having a grid of points is very useful for working with the data using computers.

Here is an example (taken from the lab exercise) of a grid of points:

This is a sketch that allows us to discuss a computer algorithm for constructing contour lines within the grid.

We first have an outside loop that loops through each contour level. We then have a loop that examines each grid box one at a time. A grid box has a data value at each corner.

Consider the center grid box in the above sketch, drawn in black. There are four sides to the box. Two of the sides are horizontal, and two are vertical. Each side has two data values. For each side of the box, we compare these two data values with our contour line value, to see if the contour line passes through that side of the box.

For example, if we are drawing the 450 contour line, and examining the vertical side on the left (we are discussing the center box), we do the following logical test:

Is 469 greater than 450 and is 406 less than 450
----or----
is 469 less than 450 and is 406 greater than 450

If this logical test is true, then the contour line intersects our box side. We then use linear interpolation to determine just where this intersection is (this calculation is shown on the above sketch, below the grid).

If the contour line intersects one side of the box, it must intersect another side.

So we test each side in turn, to find the other intersection point. Once we have both points, we can draw a line that connects each point, and move on to the next box.

Note that a col point may have a contour line of the same value pass through all four sides! This allows for two possible ways of drawing the contour line segments. See the bottom of the above sketch for an example of this situation (this col example is a grid box not seen in the lab exercise). A "shortest path" test can be used to choose between the two possibilities.

In the sketch above, the other contour line segments that would be drawn for the 450 contour line are shown in purple, and the line segments that would be drawn for the other contour levels are shown in green.

Here is an example of a contour plot done using this technique, with the grid point values shown in green:

In practice, somewhat more complex algorithms are used, where the line is "followed" to obtain a sequence of ordered points along the line. This allows the line to be more easily labeled, and it allows for various smoothing operations to be done, such as a spline fit.

This is a smoothed version of the previous plot: