← All Base Form Math projects
BM-14NOT STARTEDBASE FORM · CALCULUSMATHPYTHON

Terrain explorer

Load a real elevation map, draw contour lines and slope arrows, and find every peak and pass.

EST.5 h
REWARD+100 XP
AFTERoriginal

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
gradient field; peak list
GOAL · match within 1e-6; same peaks
numpy.gradient · scipy.ndimage.maximum_filter—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

An elevation map, or DEM (digital elevation model), is a grid of heights, often one every 30 m. It is a function z(x,y)z(x, y) of two variables. This project is about the slope of such a function, and you'll compute it for a real piece of land.

On a hillside the slope depends on which way you face. The partial derivative ∂z/∂x\partial z / \partial x is the slope walking east, and ∂z/∂y\partial z / \partial y the slope walking north. Together they form the gradient:

∇z=(∂z∂x, ∂z∂y)\nabla z = \left(\frac{\partial z}{\partial x},\ \frac{\partial z}{\partial y}\right)

The gradient points straight uphill, and its length is the steepness in that direction. The slope in any other direction uu (a unit vector) is the dot product ∇z⋅u\nabla z \cdot u, called the directional derivative. Along a contour line the height doesn't change, so that dot product is zero. That's why the gradient always crosses contours at right angles.

Where the gradient is zero the ground is flat. That happens at peaks, at pits, and at passes, where a path between two peaks reaches its lowest point. Telling them apart from the heights around them is the last part of the build.

VISUALFig. 1
peak: higher than all8 neighbours pass (saddle): up twoways, down two ways gradient: pointsstraight uphill, atright angles to thecontour lines contour: equal height
Two hills joined by a pass. Gradient arrows point uphill and cross every contour at a right angle. Why it's here: It shows the three things you will compute on a real map: arrows, peaks and the pass between them.
HINT · OBJECTIVE 2
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 6
Stuck? Hints stay hidden until you ask.

DATA · a public DEM tile

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. Your gradient field matches `numpy.gradient` within 1e-6 at every cell, and your peak list equals the one from `scipy.ndimage.maximum_filter`. Record the max gradient difference with `python tools/mlarena.py record BM-14 "<max diff>"`.
  2. The README has a map of a real tile with contours, slope arrows, peaks and passes.
  3. One hiking route has a slope profile computed with the directional derivative.

Side quests

Rank peaks by prominence: how far you must descend from a peak before you can climb to a higher one.
Drop a raindrop: follow −∇z downhill from a start cell and draw its path to a pit or the map edge. This is gradient descent, the next project.

Terms in plain words

Partial derivative
The slope in one direction while the other coordinate is held still. ∂z/∂x is the slope walking east.
Gradient
The vector of partial derivatives (∂z/∂x, ∂z/∂y). It points straight uphill, and its length is how steep that is.
Directional derivative
The slope along any unit direction u. It equals the dot product ∇z · u.
Contour line
A line of equal height. The gradient always crosses it at a right angle.
Saddle point (pass)
A flat point that is neither a peak nor a pit: uphill in two directions, downhill in the other two.