Implementation of coastal flood and mangrove migration models based on Bezerra et al. (2013), built on top of DisSModel.
brmangue-dissmodel implements spatially explicit models of coastal ecosystem processes using the DisSModel framework. Two coupled processes are modelled:
- Flood Dynamics β sea-level rise propagation and terrain elevation adjustments.
- Mangrove Migration β ecosystem response to rising sea levels, soil transitions, and sediment accretion.
The original BR-MANGUE cellular automata model (Bezerra et al., 2013) is provided on two spatial substrates:
- Raster (
brmangue.models.raster) β NumPy/RasterBackend, vectorized and fast. This is the canonical implementation, validated against TerraME golden outputs. - Vector (
brmangue.models.vector) β GeoDataFrame/libpysal, cell-by-cell over real polygon geometry. Numerically equivalent to the raster implementation (verified by the benchmark executor).
# Raster simulation (NumPy-based, fast)
python examples/main_raster.py run \
--input examples/data/input/synthetic_grid_60x60_tiff.zip \
--output examples/data/output/saida.tiff \
--param interactive=true \
--param end_time=20
# Vector simulation (GeoDataFrame-based)
python examples/main_vector.py run \
--input examples/data/input/synthetic_grid_60x60_shp.zip \
--output examples/data/output/saida.gpkg \
--param end_time=20
# Load calibrated parameters from TOML (works for both substrates)
python examples/main_raster.py run \
--input examples/data/input/synthetic_grid_60x60_tiff.zip \
--toml examples/model.toml
# Vector vs Raster equivalence benchmark
python examples/main_benchmark.py run \
--input examples/data/input/synthetic_grid_60x60_shp.zip \
--param end_time=10 \
--param taxa_elevacao=0.011 \
--param tolerance=0.05
# Validate executor data contract without running
python examples/main_raster.py validate \
--input examples/data/input/synthetic_grid_60x60_tiff.zip
# Prepare raster from vector
python examples/prepare_raster.py data/input.shp --output data/input.tif
# Run Validation against TerraME golden CSVs
python src/brmangue/executors/validation_executor.py run \
--input examples/data/input/elevacao_pol.zip \
--param golden_dir=tests/fixtures/golden \
--param end_time=19 \
--param taxa_elevacao=0.05 \
--param altura_mare=6.0 \
--param checkpoints=[1,5,10,15,20]# Submit job
curl -X POST http://localhost:8000/submit_job \
-H "X-API-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model_name": "brmangue_raster",
"input_dataset": "s3://dissmodel-inputs/ilha_maranhao_epsg31983.tif",
"parameters": {"end_time": 88, "taxa_elevacao": 0.011}
}'Sea-level rise propagates across the landscape using a push-based neighbourhood algorithm faithful to the original TerraME implementation (Bezerra et al., 2013).
Ecosystem transitions driven by tidal influence and flooding thresholds, including soil migration and optional sediment accretion (Alongi, 2008).
Both processes exist in raster and vector form with identical equations, thresholds, parameter names, and update ordering.
The project follows the DisSModel ModelExecutor pattern β each executor separates
science from infrastructure.
| name | Substrate | Input β Output | Description |
|---|---|---|---|
brmangue_raster |
RasterBackend / NumPy | Shapefile / GeoTIFF β GeoTIFF | Production simulation (canonical, validated against TerraME) |
brmangue_vector |
GeoDataFrame / libpysal | Shapefile / ZIP β GeoPackage | Cell-by-cell vector simulation over real polygon geometry |
brmangue_benchmark |
raster + vector | Shapefile / ZIP β scatter.png + report.md | Runs both substrates on the same input and reports match %/MAE/RMSE per band |
validation |
RasterBackend | Shapefile / ZIP β scatter.png + report.md | Compares raster output against TerraME golden CSVs at configurable checkpoints |
# Vector simulation over real geometry (GeoDataFrame / libpysal)
python examples/main_vector.py run \
--input examples/data/input/synthetic_grid_60x60_shp.zip \
--output examples/data/output/saida.gpkg \
--param end_time=88 \
--param taxa_elevacao=0.5 \
--param altura_mare=6.0
# With column remapping (source uses non-canonical names)
python examples/main_vector.py run \
--input examples/data/input/synthetic_grid_60x60_shp.zip \
--column-map uso=land_use alt=elevation solo=soil# Runs both Vector and Raster models on the same input; reports match per band
python examples/main_benchmark.py run \
--input examples/data/input/synthetic_grid_60x60_shp.zip \
--param end_time=10 \
--param taxa_elevacao=0.011 \
--param altura_mare=6.0 \
--param tolerance=0.05
# Output artifacts written to outputs/experiments/<id>/benchmark/
# scatter.png β per-band Vector vs Raster scatter plots
# report.md β runtime (ms/step) and accuracy table# From source
git clone https://github.com/DisSModel/brmangue-dissmodel.git
cd brmangue-dissmodel
pip install -e .brmangue-dissmodel/
βββ src/
β βββ brmangue/
β βββ __init__.py
β βββ common/
β β βββ constants.py # TIFF_BANDS, CRS, USO_COLORS, ...
β β βββ utils.py # default_output_uri helper
β βββ executors/ # ModelExecutor implementations
β β βββ __init__.py # imports executors β auto-registration
β β βββ raster_executor.py # Production simulation (raster, canonical)
β β βββ vector_executor.py # Vector simulation over real geometry
β β βββ benchmark_executor.py # Vector vs raster equivalence check
β β βββ validation_executor.py # Validation against TerraME golden CSVs
β βββ models/
β βββ raster/ # NumPy-based models (canonical)
β β βββ flood_model.py
β β βββ mangrove_model.py
β βββ vector/ # GeoDataFrame-based models
β βββ flood_model.py
β βββ mangrove_model.py
βββ tests/
β βββ fixtures/golden/ # TerraME reference CSVs (step_01..step_20)
β βββ test_transition_rules.py
β βββ test_model_invariants.py
βββ examples/
β βββ main_raster.py # BrmangueRasterExecutor via CLI
β βββ main_vector.py # BrmangueVectorExecutor via CLI
β βββ main_benchmark.py # BrmangueBenchmarkExecutor via CLI
β βββ prepare_raster.py # Vector to GeoTIFF converter
β βββ model.toml # Simulation parameters
β βββ data/
βββ pyproject.toml
Two test modules cover model correctness without external data:
tests/test_transition_rules.pyβ analytical tests on 3Γ3 synthetic grids with hand-calculated expected values (flood propagation, mangrove soil/use migration, altitude blocking).tests/test_model_invariants.pyβ structural invariants on a 5Γ5 real grid (flooded cells monotonically non-decreasing,SOLO_MANGUE_MIGRADOnever reverts, masked cells never change, etc.).
pytest tests/ -vValidationExecutor (src/brmangue/executors/validation_executor.py,
name="validation") runs the raster model and compares its output step-by-step
against reference CSVs generated by the original TerraME/Lua model
(Bezerra et al., 2013), located in tests/fixtures/golden/step_NN.csv
(currently step_01 β¦ step_20).
Metrics reported per band (uso, solo, alt) at each checkpoint:
match %, MAE, RMSE, max_err.
The golden CSVs are indexed on state, not on number of executions:
step_01.csv is the initial state, before the model has run once (verified:
zero cells differ from the input shapefile). Simulation step N therefore maps
to step_{N+1}.csv, applied via GOLDEN_STEP_OFFSET in the executor.
With 20 golden files, the highest comparable simulation step is 19.
| Step | uso |
solo |
alt (1 mm tol) |
alt MAE |
|---|---|---|---|---|
| 1 | 100.0% | 100.0% | 99.8% | 0.00001 |
| 5 | 100.0% | 100.0% | 99.0% | 0.00017 |
| 10 | 100.0% | 100.0% | 98.2% | 0.00036 |
| 19 | 100.0% | 100.0% | 97.3% | 0.00068 |
The categorical bands (uso, solo) agree with TerraME exactly, cell for
cell, at every checkpoint β MAE is 0 and max error is 0. Only alt diverges,
by accumulated floating-point differences in the flux diffusion; the maximum
absolute error after 19 steps is 0.24 m against elevations of 1β58 m.
At taxa_elevacao=0.05 the flood component never triggers a land-use
transition: the lowest cell adjacent to a source sits at 1.0 m and the sea only
reaches 1.0 m at step 20, by which point flux diffusion has raised it further.
The golden CSVs confirm TerraME does exactly the same (zero newly flooded cells
across all 20 steps), so the Python model is faithful β but this reference
scenario leaves the flood component unexercised, and the agreement above
reflects the mangrove migration component.
The original laboratory script (lab1.lua) uses TAXA_ELEVACAO_MAR = 0.5 with
FINAL_TIME = 11, under which flooding does occur (2,470 cells by step 11).
tests/test_model_invariants.py::test_flood_model_floods_with_laboratory_parameters
pins this so the coverage gap cannot reappear silently.
# See Quick Start above for the full CLI invocation:
python src/brmangue/executors/validation_executor.py run \
--input examples/data/input/elevacao_pol.zip \
--param golden_dir=tests/fixtures/golden \
--param end_time=19 \
--param 'checkpoints=[1,5,10,19]'Bezerra, D. da S., Amaral, S., & Kampel, M. (2013). Impactos da ElevaΓ§Γ£o do NΓvel MΓ©dio do Mar sobre o Ecossistema Manguezal: A ContribuiΓ§Γ£o do Sensoriamento Remoto e Modelos Computacionais. CiΓͺncia e Natura, 35(2), 152β162. https://doi.org/10.5902/2179460X12569
Developed by the LambdaGeo research group.