Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link example models to readthedocs #101

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/examples/geo_schelling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GeoSchelling Model (Polygons)

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/ZnBk_eSw0_M"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/geo_schelling/README.md
---
start-line: 3
---
```
15 changes: 15 additions & 0 deletions docs/examples/geo_schelling_points.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GeoSchelling Model (Points & Polygons)

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/iLMU6jfmir8"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/geo_schelling_points/README.md
---
start-line: 3
---
```
15 changes: 15 additions & 0 deletions docs/examples/geo_sir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GeoSIR Epidemics Model

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/oZShtptaIg4"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/geo_sir/README.md
---
start-line: 3
---
```
31 changes: 31 additions & 0 deletions docs/examples/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Examples

**Vector Data**

- [GeoSchelling Model (Polygons)](geo_schelling.md)
- [GeoSchelling Model (Points & Polygons)](geo_schelling_points.md)
- [GeoSIR Epidemics Model](geo_sir.md)

**Raster Data**

- [Rainfall Model](rainfall.md)
- [Urban Growth Model](urban_growth.md)

**Raster and Vector Data Overlay**

- [Population Model](population.md)

```{toctree}
---
maxdepth: 2
hidden: true
caption: Examples
---
Overview <self>
geo_schelling
geo_schelling_points
geo_sir
rainfall
urban_growth
population
```
15 changes: 15 additions & 0 deletions docs/examples/population.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Population Model

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/0k8tsYPVwQs"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/population/README.md
---
start-line: 3
---
```
15 changes: 15 additions & 0 deletions docs/examples/rainfall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Rainfall Model

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/T2FQwFnPDR8"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/rainfall/README.md
---
start-line: 3
---
```
15 changes: 15 additions & 0 deletions docs/examples/urban_growth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Urban Growth Model

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/UNtTJL5N83g"
frameborder="0"
allowfullscreen>
</iframe>

```{include} ../../examples/urban_growth/README.md
---
start-line: 3
---
```
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Don't forget to check out the [Contributors guide](https://github.com/projectmes
maxdepth: 2
hidden: true
---
tutorials/intro_tutorial
Introduction <self>
Tutorial <tutorials/intro_tutorial>
examples/overview
API Documentation <apis/api_main>
```

Expand Down
16 changes: 16 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Examples

## Vector Data

- [GeoSchelling Model (Polygons)](https://github.com/projectmesa/mesa-geo/tree/main/examples/geo_schelling)
- [GeoSchelling Model (Points & Polygons)](https://github.com/projectmesa/mesa-geo/tree/main/examples/geo_schelling_points)
- [GeoSIR Epidemics Model](https://github.com/projectmesa/mesa-geo/tree/main/examples/geo_sir)

## Raster Data

- [Rainfall Model](https://github.com/projectmesa/mesa-geo/tree/main/examples/rainfall)
- [Urban Growth Model](https://github.com/projectmesa/mesa-geo/tree/main/examples/urban_growth)

## Raster and Vector Data Overlay

- [Population Model](https://github.com/projectmesa/mesa-geo/tree/main/examples/population)
14 changes: 11 additions & 3 deletions examples/geo_schelling/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# GeoSchelling Segregation Model
# GeoSchelling Model (Polygons)

![](../../docs/images/examples/geo_schelling.gif)

## Summary

This is a geoversion of a simplified Schelling example. For the original implementation details please see the Mesa Schelling examples.
Instead of a regular grid it uses European NUTS-2 regions as location for majority and minority opinions.
For a region to be happy it only needs to have more similar neighbors than unsimilar ones.

### GeoSpace

Instead of an abstract grid space, we represent the space using NUTS-2 regions to create the GeoSpace in the model.

### GeoAgent

NUTS-2 regions are the GeoAgents. The neighbors of a polygon are considered those polygons that touch its border (i.e., edge neighbours). During the running of the model, a polygon queries the colors of the surrounding polygon and if the ratio falls below a certain threshold (e.g., 40% of the same color), the agent moves to an uncolored polygon.

## How to Run

Expand Down
12 changes: 7 additions & 5 deletions examples/geo_schelling_points/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# GeoSchelling Segregation Model with Point Agents
# GeoSchelling Model (Points & Polygons)

![](../../docs/images/examples/geo_schelling_points.gif)

## Summary

This is a geoversion of a simplified Schelling example.

**GeoSpace**
### GeoSpace

The NUTS-2 regions are considered as a shared definition of neighborhood among all agents, instead of a locally defined neighborhood such as Moore or von Neumann.
The NUTS-2 regions are considered as a shared definition of neighborhood among all people agents, instead of a locally defined neighborhood such as Moore or von Neumann.

**GeoAgent**
### GeoAgent

Each agent resides in a randomly assigned region, and checks the color ratio of its region against a pre-defined "happiness" threshold at every step. If the ratio falls below the threshold, the agent is found to be "unhappy", and randomly moves to another region. In this example, agents are represented as points, with locations randomly chosen within their regions.
There are two types of GeoAgents: people and regions. Each person resides in a randomly assigned region, and checks the color ratio of its region against a pre-defined "happiness" threshold at every time step. If the ratio falls below a certain threshold (e.g., 40%), the agent is found to be "unhappy", and randomly moves to another region. People are represented as points, with locations randomly chosen within their regions. The color of a region depends on the color of the majority population it contains (i.e., point in polygon calculations).

## How to run

Expand Down
2 changes: 2 additions & 0 deletions examples/geo_sir/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# GeoSIR Epidemics Model

[![](https://img.youtube.com/vi/oZShtptaIg4/0.jpg)](https://www.youtube.com/watch?v=oZShtptaIg4)

## Summary

This is a geoversion of a simple agent-based pandemic SIR model, as an example to show the capabilities of mesa-geo.
Expand Down
25 changes: 25 additions & 0 deletions examples/population/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Population Model

[![](https://img.youtube.com/vi/0k8tsYPVwQs/0.jpg)](https://www.youtube.com/watch?v=0k8tsYPVwQs)

## Summary

This is an implementation of the [Uganda Example](https://github.com/abmgis/abmgis/tree/master/Chapter05-GIS/Models/UgandaExample) in Python, using [Mesa](https://github.com/projectmesa/mesa) and [Mesa-Geo](https://github.com/projectmesa/mesa-geo).

### GeoSpace

The GeoSpace consists of both a raster and a vector layer. The raster layer contains population data for each cell, and it is this data that is used for model initialisation, in the sense creating the agents. The vector layer shown in blue color represents a lake in Uganda. It overlays with the raster layer to mask out the cells that agents cannot move into.

### GeoAgent

The GeoAgents are people, created based on the population data. As this is a simple example model, the agents only move randomly to neighboring cells at each time step. To make the simulation more realistic and visually appealing, the agents in the same cell have a randomized position within the cell, so that they don’t stand on top of each other at exactly the same coordinate.

## How to run

To run the model interactively, run `mesa runserver` in this directory. e.g.

```bash
mesa runserver
```

Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press `Start`.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def step(self):
self.set_random_world_coord()


class Uganda(mesa.Model):
class Population(mesa.Model):
def __init__(
self,
population_gzip_file="data/popu.asc.gz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mesa_geo.visualization.ModularVisualization import ModularServer
from mesa_geo.visualization.modules import MapModule

from .model import Uganda
from .model import Population
from .space import UgandaCell


Expand Down Expand Up @@ -38,4 +38,6 @@ def agent_portrayal(agent):
geospace_element = MapModule(agent_portrayal)
num_agents_element = NumAgentsElement()

server = ModularServer(Uganda, [geospace_element, num_agents_element], "Uganda Model")
server = ModularServer(
Population, [geospace_element, num_agents_element], "Population Model"
)
3 changes: 3 additions & 0 deletions examples/population/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from population.server import server

server.launch()
17 changes: 14 additions & 3 deletions examples/rainfall/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
Rainfall Model
==============
# Rainfall Model

An implementation of the [Rainfall Model](https://github.com/abmgis/abmgis/tree/master/Chapter06-IntegratingABMandGIS/Models/Rainfall) in Python, using [Mesa](https://github.com/projectmesa/mesa) and [mesa-geo](https://github.com/projectmesa/mesa-geo).
[![](https://img.youtube.com/vi/T2FQwFnPDR8/0.jpg)](https://www.youtube.com/watch?v=T2FQwFnPDR8)

## Summary

This is an implementation of the [Rainfall Model](https://github.com/abmgis/abmgis/tree/master/Chapter06-IntegratingABMandGIS/Models/Rainfall) in Python, using [Mesa](https://github.com/projectmesa/mesa) and [Mesa-Geo](https://github.com/projectmesa/mesa-geo). Inspired by the NetLogo [Grand Canyon model](http://ccl.northwestern.edu/netlogo/models/GrandCanyon), this is an example of how a digital elevation model (DEM) can be used to create an artificial world.

### GeoSpace

The GeoSpace contains a raster layer representing elevations. It is this elevation value that impacts how the raindrops move over the terrain. Apart from `elevation`, each cell of the raster layer also has a `water_level` attribute that is used to track the amount of water it contains.

### GeoAgent

In this example, the raindrops are the GeoAgents. At each time step, raindrops are randomly created across the landscape to simulate rainfall. The raindrops flow from cells of higher elevation to lower elevation based on their eight surrounding cells (i.e., Moore neighbourhood). The raindrop also has its own height, which allows them to accumulate, gain height and flow if they are trapped at places such as potholes, pools, or depressions. When they reach the boundary of the GeoSpace, they are removed from the model as outflow.

## How to run

Expand Down
14 changes: 0 additions & 14 deletions examples/uganda/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/uganda/run.py

This file was deleted.

9 changes: 6 additions & 3 deletions examples/urban_growth/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
UrbanGrowth Model
==============
# Urban Growth Model

An implementation of the [UrbanGrowth Model](https://github.com/abmgis/abmgis/tree/master/Chapter06-IntegratingABMandGIS/Models/UrbanGrowth) in Python, using [Mesa](https://github.com/projectmesa/mesa) and [mesa-geo](https://github.com/projectmesa/mesa-geo).
[![](https://img.youtube.com/vi/UNtTJL5N83g/0.jpg)](https://www.youtube.com/watch?v=UNtTJL5N83g)

## Summary

This is an implementation of the [UrbanGrowth Model](https://github.com/abmgis/abmgis/tree/master/Chapter06-IntegratingABMandGIS/Models/UrbanGrowth) in Python, using [Mesa](https://github.com/projectmesa/mesa) and [Mesa-Geo](https://github.com/projectmesa/mesa-geo).

## How to run

Expand Down
8 changes: 4 additions & 4 deletions examples/urban_growth/urban_growth/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

def cell_portrayal(cell: UrbanCell) -> Tuple[float, float, float, float]:
if cell.urban:
if cell.new_urbanized:
return 255, 0, 0, 1
else:
if cell.old_urbanized:
return 0, 0, 255, 1
else:
return 255, 0, 0, 1
else:
return 0, 0, 0, 0

Expand Down Expand Up @@ -58,6 +58,6 @@ def render(self, model):
server = ModularServer(
UrbanGrowth,
[map_module, urbanized_text, urbanized_chart],
"UrbanGrowth Model",
"Urban Growth Model",
model_params,
)
3 changes: 3 additions & 0 deletions examples/urban_growth/urban_growth/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class UrbanCell(Cell):
road_pixel: UrbanCell | None

new_urbanized: bool | None
old_urbanized: bool | None

def __init__(
self,
Expand All @@ -43,6 +44,7 @@ def __init__(
self.road_found = None
self.road_pixel = None
self.new_urbanized = None
self.old_urbanized = None

def step(self):
self._new_spreading_center_growth()
Expand Down Expand Up @@ -102,6 +104,7 @@ def load_datasets(

for cell in self.raster_layer:
cell.urban = True if cell.urban == 2 else False
cell.old_urbanized = cell.urban

def check_road(self):
for cell in self.raster_layer:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = Mesa-Geo
url= https://github.com/projectmesa/mesa-geo
project_urls =
# Docs: RTD = "https://mesa-geo.readthedocs.io/en/latest/"
Docs: RTD = https://mesa-geo.readthedocs.io/en/main
CI: GitHub = https://github.com/projectmesa/mesa-geo/actions
GitHub: issues = https://github.com/projectmesa/mesa-geo/issues
GitHub: repo = https://github.com/projectmesa/mesa-geo
Expand Down