Exercise 0-B. The Variogram and What Its Parameters Do
Part 0. Fundamentals and Their Failure Modes
| At a glance | |
|---|---|
| Textbook sections | the interpolation fundamentals behind sections 10.3, 10.4, 11.12 and 15.7 |
| Fundamentals covered | inverse distance weighting, the empirical variogram, model fitting, ordinary kriging, kriging variance, leave one out cross validation |
| Technical demand | Tier 1 and Tier 2 required. Python with numpy, scipy, pandas and matplotlib |
| Effort | three hours including the write up |
| Prerequisites | none, though Exercise 0-A introduces the weights idea this exercise extends |
Overview
Interpolation turns a scatter of measured points into a continuous surface, and every pixel in that surface is a claim about a place nobody measured. Inverse distance weighting makes that claim from distance alone and asks the analyst for one parameter. Ordinary kriging makes it from a fitted model of how the phenomenon varies with separation, and asks the analyst for five or six. The extra parameters are the reason kriging is better and the reason it fails more interestingly, because each one encodes a belief about the phenomenon that the software will accept without argument.
The exercise interpolates mean annual air temperature across the Arizona Meteorological Network, a set of stations spread across a state with pronounced relief. Students fit an empirical variogram, watch what the lag distance and bin count do to its shape, fit a model, and then move the nugget, the sill and the range one at a time while cross validated error reports the consequence. Anisotropy enters last, because temperature in Arizona varies with elevation and elevation is not isotropic, so a model that assumes the same behavior in every direction is making a claim the terrain contradicts. Each of those parameters is presented by commercial software as a field with a default already in it.
Every parameter change produces a map and an error figure, and the student reports both. A surface that looks smoother is not therefore better, and separating the two is the skill the exercise builds.
Step by step
- Run against the frozen station year and see the points. Tier 1. Change to the toolkit folder inside GeoAI_Exercises and type python exercise_0b.py to run the exercise against the frozen station year in snapshots. Running python pull_azmet.py replaces the frozen snapshot with a fresh download and changes the checksum, so run it only when your instructor asks. Record the station count, the elevation range and the checksum on your provenance card. The network map below shows the stations as plain points, and you should look at it before any surface exists, because the sampling design constrains everything that follows and the gaps in the network are where the interpolation will be least trustworthy.

- Build the empirical variogram. Tier 1. The program computes semivariance for every station pair, bins those pairs by separation distance, and plots the binned means against distance. Record the number of pairs, the lag distance the program chose, and the bin count. Then read the shape of the cloud and answer in writing whether semivariance rises with distance, where it stops rising, and what the value at very short separations appears to be.

- Move the lag. Tier 2. Block 3 refits the variogram at each lag distance listed in
LAG_SWEEPat the top of exercise_0b.py and skips any lag that leaves fewer than three bins. Record the bin count, fitted range, sill and cross validated error at each lag it fits, and name any lag it skipped. Then add a lag of your own choosing toLAG_SWEEP, rerun, and record the result. Lag choice is a smoothing decision on the variogram itself, so too few wide bins hide structure and too many narrow bins produce a cloud too noisy to fit, and finding the middle is a judgment the software will not make.
Figure, three panels. The same empirical variogram binned at three lag distances, showing structure hidden by wide bins and noise created by narrow ones.
- Move the nugget and the range. Tier 2. The program fits a spherical model and reports the nugget, the sill and the range. Block 4 then refits with one parameter held at an alternative value at a time, being the nugget at zero, the nugget at 99.9 percent of the sill, the range halved and the range doubled, and reports the leave one out cross validated root mean square error under each. Record all four errors, then change one of the alternative values in the
overrideslist in exercise_0b.py, rerun, and record the result. State in writing what the nugget represents physically, and why a nugget that equals the sill produces a surface that is indistinguishable from the global mean.
- Test for direction. Tier 2. The program attempts directional variograms in the four bearings listed in
DIRECTIONSand reports any bearing with too few pairs to fit. Record the fitted range and sill for each bearing it fits, name the bearing it could not fit, then state whether the network shows anisotropy and in which orientation. Arizona's relief runs in a recognizable direction and temperature follows elevation, so an anisotropy finding here has a physical explanation the student should name.
Figure. Directional variograms for the bearings the program could fit, drawn on one axis, with the fitted range annotated per bearing.
- Drop stations and watch it degrade. Tier 2. The program refits the variogram using random subsets of the network at several sample sizes, reporting cross validated error at each. Record the error at every sample size and identify the point below which the variogram can no longer be fitted with confidence. State how many stations you would require before you would publish a kriged surface of this variable, and defend the number.
- Compare against inverse distance weighting. Tier 1. The program produces both surfaces from identical points and reports cross validated error for each. Record both errors and both maps. Then answer the question the comparison raises: kriging also produces a variance surface and inverse distance weighting produces nothing of the kind, so state what that variance surface tells a decision maker that the prediction surface alone cannot.

- Read the code. Tier 1. Annotate the function
fit_variogramin kriging.py, stating what it consumes, what it produces, and what would change if the model form were switched from spherical to exponential. Then explain why the fitting is performed on binned means and never on the raw pair cloud.
- Complete the handoff. Tier 1. Open the decisions file the program writes and answer every question in it. The list includes the model form, the lag, the search neighborhood and the color treatment of the variance surface, none of which the program justified.
Key takeaways
A kriged surface is a model output and the parameters are the model. Nugget, sill, range and anisotropy each encode a belief about how the phenomenon behaves in space, and a surface produced from defaults encodes the software author's beliefs in place of the analyst's. Cross validated error is the only honest referee among competing parameter sets, because smoothness is a property of the picture and accuracy is a property of the prediction. A smoother surface invites preference on first inspection, which is why the exercise reports both quantities side by side at every parameter change.
Sample size governs what can be fitted at all. A variogram estimated from too few pairs produces a range and a sill with wide uncertainty, and a surface built on that fit carries uncertainty the map never displays. The exercise puts a number on where that boundary sits for this network. That number belongs in any report built on an interpolated surface, and it almost never appears in one.
The kriging variance surface is the deliverable most practitioners discard. It states where the surface is guessing, it is available at no additional cost, and a decision made from the prediction surface alone throws away the one product that would have flagged the weak areas.
Questions
- Explain what a pure nugget model means physically and what it implies about the sampling design that produced it.
- Your directional variograms disagree. State two competing explanations, one about the phenomenon and one about the sampling, and name the evidence that would separate them.
- A colleague reports that kriging produced a smoother map than inverse distance weighting and concludes it is more accurate. Using your Step 7 numbers, answer the colleague.
- Section 15.7 asks that uncertainty be made visible. Describe the map you would publish for a decision maker who needs the temperature surface, and state where the variance surface appears in it.