Immigration of Flood Display With Python and Eyesign Data: Fear Guide

They have often destroyed and destroyed all over the world, with the effects of climate change in recent decades. In this case, flooding and role playes in the risk of risk and disaster risk response, and it is always focused on advanced research and educational studies.
In this article, we will build a basic flood access model using the Python and model for digital lift (Dem). We will use the flooding process to imitate how the growing water level affects the environment and shakes the access process. It is a look for the geospatial data test and the risk of flooding, or without the back of the hydraulic mode.
What will you learn about
1. What is the digital lift model (Dem)
A Digital Nomination Model (Dem) Is the number representation of the world, where each cell (or pixel) is a general grid (known as the Raster data) contains the value of the heor. Unlike digital photographs that keep the color information, DEMS shop data, generally without top items such as vegetation, buildings and other human structures.
DEMs is widely used in fields such as map, hydrology, environmental monitoring and science. They work as the foundation data for any app that requires detailed understanding of the area and elevation.
Many sources provide free and reliable dem data, including USGS Mapation Map, NASA EARHDATAno Shuttle Radar Topography Mission (SRTM).
In this article, we will use the dem by USGS National Geospatial Program programwhich is freely available and liberated from the community domain.
Note: Details provided by USGs has a 3-arc area's decision (approximately 30 feet of liquor).
The interested place (Aii) in this study is located in the northeastern Brazil. The DE file includes 1 ° × 1 ×, from 6 °, 39 ° W, 3 degrniing, and using the WGS84 CorDinary System (as shown below.
2. How to upload and view the data for proposal for Python
Now we will use the Python to set an active location to visualize and evaluate some original information about Dem data. First, let's take the required libraries.
# import libraries
import rasterio
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
rasterio: Reading and writing geospatial Raster data like DEMs.
matplotlib.pyplot: Create regular and active visual images.
numpy: It treats numerical activities and data based on array.
FuncAnimation: Poor pictures photos by renewing a frame with a frame.
Next, let's use rasterio Library to open and see the Eye of the Dem LOOI.
# Helper function to load DEM Files
def load_dem(path):
with rasterio.open(path) as src:
dem = src.read(1)
transform = src.transform
nodata = src.nodata
if nodata is not None:
# Mask no-data values
dem = np.ma.masked_equal(dem, nodata)
return dem, transform
The above function reads the highest data and explores whether the file includes the amounts “data values”. NO-Data prices are used to represent areas without a voluntary elevation data (eg cover without or damaged pixels). If NO-Data-Data is, work takes the pixels np.nanmaking it easier to manage or neglect in analysis later and seeing.
To see dem data
dem = load_dem("s06_w039_1arc_v3.tif")
plt.imshow(dem, cmap='terrain')
plt.title("Digital Elevation Model")
plt.colorbar(label="Elevation (m)")
plt.show()

- Local links are used in seeing
As we can see, the Axes are in Pixel in connection (columns and lines). A better understanding of flooding, it is important to know local coordinates (Latitude and length) associated with each pixel of the image.
To achieve that, we will use the DEM connection system data. As before, DEM uses us using WGS84 Coordinate System (EPSG: 4326).
We may adapt to the assistant uploading DEM files:
def load_dem(path):
with rasterio.open(path) as src:
dem = src.read(1)
transform = src.transform
nodata = src.nodata
if nodata is not None:
# Mask nodata values
dem = np.ma.masked_equal(dem, nodata)
return dem, transform
The work returns the change Data from Dem, which is EFFF with Pixel Maps Position (Line, column) in local coordination (Latitude and length).
To represent local coordinates with structural axes, you will need to check the extent parameter from imshow() work.
dem, transform = load_dem("s06_w039_1arc_v3.tif")
# Compute extent from transform
extent = [
transform[2], # xmin (longitude)
transform[2] + transform[0] * dem.shape[1], # xmax
transform[5] + transform[4] * dem.shape[0], # ymin (latitude)
transform[5] # ymax
]
# Plot with using geographic coordinates
fig, ax = plt.subplots()
img = ax.imshow(dem, cmap='terrain', extent=extent, origin='upper')
ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
plt.colorbar(img, label='Elevation (m)')
plt.title('DEM Visualization')
plt.show()
This page extent The parameter will be used to describe the bounds of the demographic area using rasers based values transform an item in the fees. Puts a minimum of small and thick (xmin, xmax) length (ymin, ymax) To prolong the links that hold the links in position of pixel indices.
Finally, we have the following consequences:

3. How can you imitate the circumstances of teachers about the highlands of the height
Now, we will show the easiest but helpful way to see the flood conditions and implementing the incale. It contains to describe the rate of the height and creating binary mask that identifies all the high places under this Standard.
In this example, we imitate the floods in all the highlands below 40 feet.
flood_threshold = 40 # meters
flood_mask = (dem <= flood_threshold).astype(int)
plt.imshow(flood_mask, extent=extent, cmap='Blues')
plt.title(f"Flooded Area (Threshold: {flood_threshold}m)")
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.show()

With just a few of the code lines, we can imagine the impact of different conditions of flooding conditions in the interest (AII). However, because this is the figurative, it does not indicate how the Flood continues later. Dealing That, We Will Use Matplotlib's FuncAnimation creating a strong view.
4. How to make flooding height about Python
Now we will imitate the flood condition through increasing the water quality and producing a new mask in each step. We will abolish this mask in the Terrain picture and have animate.
# flood_levels defines how high the flood rises per frame
flood_levels = np.arange(15, 100, 5)
# Set up figure and axes
fig, ax = plt.subplots()
img = ax.imshow(dem, cmap='terrain', extent=extent, origin='upper')
flood_overlay = ax.imshow(np.zeros_like(dem), cmap='Blues', alpha=0.4, extent=extent, origin='upper')
title = ax.set_title("")
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
# Animation function
def update(frame):
level = flood_levels[frame]
mask = np.where(dem <= level, 1, np.nan)
flood_overlay.set_data(mask)
title.set_text(f"Flood Level: {level} m")
return flood_overlay, title
# Create animation
ani = FuncAnimation(fig, update, frames=len(flood_levels), interval=300, blit=True)
plt.tight_layout()
plt.show()
# save the output as a gif
ani.save("flood_simulation.gif", writer='pillow', fps=5)

If you are interested in building photos with Python, this step-by-step lesson is a good start place.
The conclusion and steps that follow
In this article, we have created basic work travel to make flooding vulnerabilities in Python using higher rate data from dem file. Of course, this model does not use the most developed strategies on the subject, is still eye contact, communication, this method of lifting the Threshold provides a potential and accessible entry.
Advanced imitation strategies include:
- Floods spread from the Flood
- The flow of flow and accumulation
- Time for a time-based flow
However, this craftsman may have the largest educational benefits of teachers, learners, and the analysts test geospatial data in disaster response courses and environmental model.
The full code is available here.
I am very encouraging to students to check the code using their elevation data, adapt to their context, and evaluate the development methods or path.
Progress
[1] US Geological survey. National map. The US Internal Ministry. Restored on May 17, 2025, from
[2] US Geological survey. What is the digital lift model (Dem)? The US Internal Ministry. Restored on May 17, 2025, from
[3] Gillies, s. Georfering – Docs in Randuario (stable). Randuo. Returned on May 27, 2025, from
[4] Gillies, Sean. AFFININT TransForms – Randurio (recent). Reached on May 27, 2025.
Data Source: The dem data used in this project is provided by the US Geological Survey (USGS) by national map and is in the public interest.


