Skip to main content

Discrete Spatial Modeling framework for raster and vector simulations

Project description

DisSModel

Discrete Spatial Modeling framework for Python

License: MIT Python 3.10+ PyPI version status

DisSModel is a modular, open-source Python framework for spatially explicit dynamic modeling. Developed by the LambdaGeo group at the Federal University of Maranhão (UFMA), it provides a unified environment for building Cellular Automata (CA) and System Dynamics (SysDyn) models on top of the Python geospatial ecosystem.

DisSModel is designed as a modern, Pythonic alternative to the TerraME framework, replacing the TerraLib/Lua stack with GeoPandas, PySAL, and Salabim.


Features

  • Cellular Automata — spatial grid models with configurable neighborhood strategies (Queen, Rook, KNN)
  • System Dynamics — compartmental models with automatic live plotting via @track_plot
  • Flexible grid generation — from dimensions, bounds, or an existing GeoDataFrame
  • Fill strategies — random sampling, zonal statistics, minimum distance, and pattern-based initialization
  • Three execution modes — CLI scripts, Jupyter notebooks, and Streamlit web apps
  • Reactive UIdisplay_inputs reads annotated model attributes and generates sidebar widgets automatically
  • Built on standard tools — GeoPandas, libpysal, Salabim, Matplotlib, Streamlit

Installation

pip install dissmodel

Requires Python 3.10+.


Quickstart

System Dynamics — SIR Model

from dissmodel.core import Environment
from dissmodel.models.sysdyn import SIR
from dissmodel.visualization import Chart

env = Environment()
SIR(susceptible=9998, infected=2, recovered=0, duration=2, contacts=6, probability=0.25)
Chart(show_legend=True)
env.run(30)

Cellular Automaton — Forest Fire

from dissmodel.core import Environment
from dissmodel.geo import vector_grid
from dissmodel.models.ca import FireModel
from dissmodel.models.ca.fire_model import FireState

gdf = vector_grid(dimension=(30, 30), resolution=1, attrs={"state": FireState.FOREST})
env = Environment(end_time=20)
fire = FireModel(gdf=gdf)
fire.initialize()
env.run()

Streamlit App

streamlit run examples/streamlit/ca_all.py

Instantiation order

The Environment must always be created before any model. Models connect to the active environment automatically on creation.

Environment  →  Model  →  Visualization
     ↑             ↑            ↑
  first         second        third

Architecture

DisSModel is organized into four modules:

alt text

Module Description
dissmodel.core Simulation clock and execution lifecycle (Environment, Model)
dissmodel.geo Spatial data structures — grid generation, fill strategies, neighborhood
dissmodel.models Ready-to-use CA and SysDyn reference implementations
dissmodel.visualization Observer-based visualization — Chart, Map, display_inputs, @track_plot

Included Models

Cellular Automata (dissmodel.models.ca)

Model Description
GameOfLife Conway's Game of Life with classic built-in patterns
FireModel Forest fire spread with Rook neighborhood
FireModelProb Probabilistic fire with spontaneous combustion and regrowth
Snow Snowfall and accumulation from top row
Growth Stochastic radial growth from a center seed
Propagation Active state transmission with KNN neighborhood
Anneal Binary system relaxation via majority-vote rule

System Dynamics (dissmodel.models.sysdyn)

Model Description
SIR Susceptible–Infected–Recovered epidemiological model
PredatorPrey Lotka–Volterra ecological dynamics
PopulationGrowth Exponential growth with variable rate
Lorenz Deterministic chaos — Lorenz attractor
Coffee Newton's Law of Cooling

Execution Modes

All models can be run in three modes:

CLI

python examples/cli/sysdyn_sir.py
python examples/cli/ca_game_of_life.py

Streamlit

streamlit run examples/streamlit/sysdyn_all.py   # all SysDyn models
streamlit run examples/streamlit/ca_all.py        # all CA models

Running examples/streamlit/ca_all.py ...

alt text

Jupyter Notebook

See examples/notebooks/ for interactive notebooks with step-by-step explanations.


Reactive Streamlit Interface

display_inputs reads annotated model attributes and generates sidebar widgets automatically — no extra configuration needed:

env = Environment(start_time=0, end_time=steps)
gdf = vector_grid(dimension=(grid_size, grid_size), resolution=1, attrs={"state": 0})
model = FireModel(gdf=gdf)
display_inputs(model, st.sidebar)  # generates sliders from type annotations
model.initialize()                 # uses parameters set by display_inputs

Grid and Neighborhood

from dissmodel.geo import vector_grid, fill, FillStrategy

# Create a 20x20 grid
gdf = vector_grid(dimension=(20, 20), resolution=1.0, attrs={"state": 0})

# Fill with random values
fill(FillStrategy.RANDOM_SAMPLE, gdf=gdf, attr="state", data={0: 0.7, 1: 0.3}, seed=42)

Supported neighborhood strategies: Queen, Rook, KNN (via libpysal).


Development

git clone https://github.com/LambdaGeo/dissmodel
cd dissmodel
pip install -e .
pip install -r requirements.txt  # dev dependencies
pytest tests/

Version 0.2.0

Major improvements:

  • New raster backend architecture
  • Examples for raster and vector simulations
  • Improved modular structure

Documentation

Full documentation available at: https://lambdageo.github.io/dissmodel/


Citation

If you use DisSModel in your research, please cite:

Costa, S. & Santos Junior, N. (2025). DisSModel: A Discrete Spatial Modeling
Framework for Python. LambdaGeo, Federal University of Maranhão (UFMA).
https://github.com/LambdaGeo/dissmodel

License

MIT © LambdaGeo — UFMA

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dissmodel-0.2.1.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dissmodel-0.2.1-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file dissmodel-0.2.1.tar.gz.

File metadata

  • Download URL: dissmodel-0.2.1.tar.gz
  • Upload date:
  • Size: 43.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dissmodel-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4c136899634fba4d2b119190c53732ebc2355c0cbcd63bf027b7608f202c704c
MD5 725ca42562cfb3b3816270ff4f60f3b2
BLAKE2b-256 d6b39571faf39bde93a434fc07be051db99ec0e75f8f7674eaf01d7ea10629d5

See more details on using hashes here.

File details

Details for the file dissmodel-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dissmodel-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 60.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dissmodel-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23eeacdb889b6c8f099d636ed8107c0892fd2094d22f2276be091bd9ce0fbc72
MD5 7c5c7797b433496251002966968dc05e
BLAKE2b-256 dacb611a22b6891b298320e3c4e54b895c9387189db9ee6c1817b391eb362c19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page