HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /A raster calculation: slope and flooding
Earth and Environmental ScienceHardHigh School (11–12)Remote Sensing, GIS and Earth Data

A raster calculation: slope and flooding

Here is a small height raster of a coast, with cells of 30 m30\ \text{m}30 m and the sea along the west edge. You will find the slope of a cell, flood the coast from the sea, and turn the count into an area.

The idea. With central differences, zx=(zE−zW)/(2s)z_x = (z_E - z_W)/(2s)zx​=(zE​−zW​)/(2s) and zy=(zN−zS)/(2s)z_y = (z_N - z_S)/(2s)zy​=(zN​−zS​)/(2s), and tan⁡θ=zx2+zy2\tan\theta = \sqrt{z_x^2 + z_y^2}tanθ=zx2​+zy2​​. A sea at level hhh floods a cell if the cell is at or below hhh. The cell must also be joined to the sea by neighbours that share an edge and are at or below hhh.

Your tasks.

  1. In slope_deg, return the slope in degrees at a cell that is not on the edge of the raster.
  2. In flooded, return the number of cells that a sea of level level reaches from the west column.
  3. In area_ha, return the area in hectares of a number of cells.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, raise the level to 2.5. Does the flooded count equal the count of low cells?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← Degrees, distances and zonesA carbon dioxide record: trend and cycle →
More onRemote Sensing, GIS and Earth Data

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Vector layers and raster layersGIS: Coordinates, Projections and Map Layers

More labs on this topic

  1. Anomalies, a running mean and a trendHard
  2. A carbon dioxide record: trend and cycleHard
  3. Degrees, distances and zonesHard
  4. How often does the satellite pass?Hard
From digital numbers to a map of greenHard
All labs on this topic →