AI
Sargassum AI: detecting and forecasting sargassum with neural networks
Satellites, ocean currents and neural networks to see where sargassum is in the Mexican Caribbean and forecast where it will be in 7 days. With all the math, an honest test on the record 2025 season and a 3D simulator.
Every summer the Mexican Caribbean receives tons of sargassum: a brown macroalga that floats in rafts, washes onto beaches, rots and releases gases. 2025 was the year with the most sargassum on record. Cleanup starts offshore, with barriers and boats, and that requires knowing where it is today and where it will land in the coming days.
Using only open data, I built a complete pipeline that does both. A U-Net neural network detects sargassum in satellite imagery. A ConvLSTM network combines seven days of sargassum with currents and wind to forecast where sargassum will be one week later. Both are tested against reference methods, on a season they never saw.
The simulator
Open the simulator full screen · also on GitHub Pages.
How to use it
- Play the season. The bar at the bottom runs from March to August 2025, day by day, at 1, 3 or 7 days per second.
- Pick a mode. In Verify, the colored area is what the network forecast 7 days earlier for the date shown, and golden dots are what the satellite observed that day, so the forecast can be judged at a glance. In Forecast +7 d, the area is what the network expects one week ahead.
- Read the traffic light. For Cancún–Isla Mujeres, Puerto Morelos–Playa del Carmen–Cozumel, Tulum–Sian Ka’an and Costa Maya–Mahahual, the panel shows the forecast probability of landfall and what was actually observed.
- Switch the camera: Caribbean, Quintana Roo or Coast.
What you are seeing
- Golden dots are sargassum detected by satellite. Each dot appears if a random number is below its cell’s coverage that day, so dot density is coverage.
- The yellow-to-red area is the presence probability computed by the network. The light line marks its decision threshold.
- Moving white streaks are that day’s surface currents.
The full pipeline
- Download. AFAI satellite index, currents, wind and labeled imagery: seven seasons, March to September, 2019 to 2025.
- Cleaning. Remove land, the coastal strip, features that never move and outlier days.
- Detection. U-Net on 10 m Sentinel-2 imagery.
- Forecast. 7-day ConvLSTM.
- Test. Against persistence and against particle-tracking physics, on the 2025 season.
- Visualization. A Three.js 3D simulator and a cinematic Blender scene.
1. The signal: what sargassum looks like from space
Water absorbs almost all near-infrared light, while floating vegetation reflects it. The AFAI (Alternative Floating Algae Index) uses that contrast. It measures how far reflectance at the red edge (748 nm) rises above the straight line joining red (667 nm) and near-infrared (869 nm).
The NOAA/USF 7-day product comes on a 0.015° grid (~1.6 km). I group 4×4 pixel blocks into ~6.7 km cells. The coverage of cell on day is the fraction of valid pixels above the threshold:
What is not sargassum
The first map showed the first problem. With the threshold alone, every coastline looks covered: Yucatán, Cuba, Belize, Honduras. That is shallow sandy bottom and turbid water, which also reflect at the red edge. I built a mask from the data itself:
- Land: pixels with no data on any date.
- Coastal strip: land dilated by 3 pixels (~5 km).
- Static features: pixels above the threshold on more than half the days of all seven seasons. Sargassum moves; the seafloor does not.
The mask removes 38 % of the above-threshold pixels offshore.
Fraction of days with AFAI above the threshold, March to August 2025. Left: plain threshold. Right: with the coastal and static-feature mask.
Pulses that are not sargassum
The daily series brought the second problem. Coverage rises and falls in one-to-two-week pulses synchronized across the whole Caribbean; in August 2025 it went from 2 % to 10 % and back. A change that large and that simultaneous points partly to observing conditions (sun glint, clouds, the 7-day composite) and not only to real sargassum. I flagged a day as an outlier when its mean coverage drifted too far from the 15-day rolling median :
Daily offshore coverage by season. Mean: 1.01 % (2019), 0.62 %, 1.13 %, 1.99 %, 0.82 %, 0.46 % and 2.80 % in 2025, the highest of the series.
2. Detection: a U-Net that separates sargassum from everything else
AFAI shows where something reflects like vegetation, but not what it is. For that I trained a U-Net on MARIDA, a public set of 1,381 Sentinel-2 crops (256×256 pixels at 10 m, 11 bands) labeled per pixel into 15 classes. I merged dense and sparse sargassum into the positive class. The other thirteen classes are negatives, and they are exactly the confusing ones: foam, ships, wakes, waves, turbid water and shallow water.
A U-Net is an encoder that compresses the image and a decoder that rebuilds it, with direct links between the two so fine detail is not lost. I used a pretrained ResNet34 encoder with its first layer adapted to 11 bands.
Sargassum is rare: about 5 thousand pixels against hundreds of thousands of water. With the standard loss, the network learns to always say “water”. So I combined weighted cross-entropy with Dice loss, which measures overlap. Both are computed only over the labeled pixels :
with , ×5 oversampling of crops containing sargassum, and rotations and flips as augmentation.
| Metric (test set) | Value |
|---|---|
| F1 | 0.900 |
| IoU | 0.818 |
| Precision | 0.819 |
| Recall | 0.999 |
The network finds virtually all the sargassum, and about 18 % of what it flags is something else. One caveat: MARIDA labels the pixels that are easy to annotate, so on a full scene I expect a lower number.
3. Forecast: a network with a memory of the sea
To forecast day , the network reads the last seven days. Each day is a 6-channel image:
- : sargassum coverage.
- : the fraction of valid data.
- : surface current in m/s, from Copernicus Marine.
- : 10 m wind from ERA5.
It also receives the mean forcing of the coming week, .
A ConvLSTM is a recurrent network in which every matrix product is replaced by a convolution, so its memory is a map:
First version: squared error is misleading
The first network predicted coverage by minimizing mean squared error. It cut that error by 39 % against persistence and looked like a success. When I plotted it, I saw the trick: the network had learned to paint a smooth, faint field over the whole likely area. That lowers the MSE, but the map does not locate the patches.
First version, August 21, 2025. The right panel is the network: good MSE, blurry map.
Second version: presence probability
I changed the question: instead of how much sargassum, will there be sargassum in this cell? The target is and the output a probability . I trained with focal loss plus Dice. Focal loss multiplies each error by , which is nearly zero for easy cases (empty open sea) and concentrates learning on the edges of the mats:
The split is by time: training on 2019–2023 (941 cases), tuning on 2024 (161) and testing on 2025 (149). The network never saw 2025.
Second version, typical day (June 10, 2025). The network marks probability zones instead of a blurry field.
4. Better than what? The reference methods
A forecast is only worth something if it beats the obvious. I compared against two references:
Persistence: in 7 days, sargassum will be where it is today, . It is hard to beat, because sargassum moves slowly.
Physics: I release particles in every cell with sargassum and move them with the current plus a fraction of the wind (windage), in 6-hour steps:
I calibrated on 2024 between 0 and 3 %. The best value was .
5. Results
To measure accuracy I use IoU: the area where the forecast and reality overlap, divided by the area covered by either.
| 7-day forecast, 2025 season | IoU |
|---|---|
| Physics (particle tracking) | 0.117 |
| Persistence | 0.173 |
| ConvLSTM v2 | 0.199 |
| 2025 month | Days the network wins | Mean IoU advantage |
|---|---|---|
| March | 15 of 18 | +0.065 |
| April | 30 of 30 | +0.063 |
| May | 15 of 31 | −0.010 |
| June | 6 of 30 | −0.035 |
| July | 3 of 9 | +0.006 |
| August | 27 of 31 | +0.068 |
What the numbers say
- The network beats both references. It outperforms persistence on 96 of 149 days (64 %) and has the better mean IoU. The gain is real but modest (+15 %) and uneven: in April and August it almost always wins, in June it almost always loses.
- Physics loses to persistence, even when calibrated. At full current speed a particle travels hundreds of kilometers in a week, while much of the satellite signal barely moves. That confirms part of the signal does not behave like drifting sargassum.
- Per-beach alerts cannot be evaluated yet. In 2025 there was sargassum off the coast in 96 % of cases; an always-on alert would score F1 ≈ 0.98, the same as the network. Intensity levels are needed, not just presence.
6. The scene: landfall in Blender
Besides the data simulator, I built a cinematic Blender 5 scene to see the phenomenon at human scale. The sea uses an ocean modifier with foam and turquoise water with volumetric absorption. The sargassum rafts are made with Geometry Nodes: they float on the waves, drift toward the shore, grow in wind-driven rows and pile up dry on the sand. The scene is a reproducible script included in the repository.
”Landfall”, a procedural Blender 5 scene with Geometry Nodes, rendered in Cycles. Top: the start; bottom: a few days later.
Code and data
The whole project is open: download, cleaning, training, evaluation and simulator, with the methodology and results documented. It is at github.com/GersainBarron/sargazo-ia.
Independent proposal built on open data; not an official product of any institution.