Mauritius Strategic Tool for the Analysis of Risk: mu-star Technical Documentation
This document describes the methodology, data and implementation for the
development of the Mauritius Strategic Tool for the Analysis of Risk (mu-star).
The focus of this document is to:
- Provide a detailed overview of the methodology and the component models;
- Record the modelling assumptions made in the analysis;
- Describe the datasets collected and finalised in implementing the methodology;
This is a technical document which is meant to explain the theory and concepts behind the spatial risk analysis and component models being developed in Mauritius.
The main target audience of this report includes climate risk and infrastructure
modellers and technical experts who would be interested in understanding the
detailed working of mu-star, including researchers and model developers who
intend to work on and develop the codebase.
Document control
| Issue | Status | Authors | Reviewed by | Issue Date |
|---|---|---|---|---|
| - | Working document | Tom Russell, … | - | - |
Developer’s README
This chapter covers installation and setup of the codes to run and reproduce the analysis. It assumes familiarity with the git version control system, the use of the command-line (or “terminal” or “shell”) to run various tools, and the Python programming language.
The repository nismod/mu-star contains
project-specific codes and configuration to run climate-related risk and
resilience analysis of infrastructure networks in Mauritius.
Outline
The overall technical architecture of the project follows this outline:
- data and results are held separately from code, shared under appropriate licence agreements
nismod/mu-starholds the modelling and analysis code- implements the reproducible modelling and analysis pipeline or “workflow”
- depends on data collection and preprocessing
- technologies:
- programming language of choice is Python, suggest using micromamba to manage environment
- workflow tool of choice is snakemake
- the workflow rules in
./workflowdefine the processing steps to run the full analysis, from source data inputs- nested within the workflow, each infrastructure system (energy, transport, water) has a model that calculates metrics of disruption
- models are developed as separate packages within
./src/<model_name>, exposing a standard interface that can then be called from the workflow rules- inputs are:
- data describing the system (assets, usage)
- a list of assets to consider “disrupted” or non-functional
- outputs are metrics of disruption to supply, for example:
- customers (or demand zones) with loss of service
- costs of supply or re-routing in disrupted state
- levels of service
- inputs are:
nismod/irv-standaloneholds the web application code- implements the results visualisation platform or “viewer”
- depends on data (results) generated by the workflow
- technologies:
- development setup uses docker and docker-compose
- backend is in Python and FastAPI, Django, with vector and raster tileservers
- frontend in TypeScript and React, with maplibre-gl-js and d3 among other dependencies
- database is Postgres with PostGIS
flowchart TB
User["Application user<br/>Web browser"]
Admin["Administrator<br/>Web browser"]
subgraph IRV["Web app: nismod/irv-standalone"]
UI["User interface<br/>React / TypeScript"]
AdminUI["Admin user interface<br/>Django Admin"]
subgraph VM["Server"]
Proxy["Web server / reverse proxy"]
Django["Django application<br/>Web API, authentication and metadata"]
end
Proxy <-->|"Requests"| Django
UI -->|"API requests"| Proxy
AdminUI -->|"Admin requests"| Proxy
Database[("Application data and metadata<br/>PostgreSQL / PostGIS database<br/>Raster and vector tiles")]
end
subgraph MU["Workflow: nismod/mu-star"]
Snakemake["Modelling and analysis workflow<br/>Snakemake"]
Models["Damage, disruption, risk and adaptation analysis<br/>Python models"]
Snakemake -->|"Orchestrate"| Models
end
subgraph SharedStore["Shared file store"]
InputData[("Prepared input data")]
Results[("Analytical outputs and<br/>visualisation-ready results")]
end
User -->|"HTTPS"| UI
UI -->|"Display maps, charts<br/>and analytical results"| User
Admin -->|"HTTPS"| AdminUI
AdminUI -->|"Manage users,<br/>data and metadata"| Admin
Django <-->|"Queries"| Database
InputData -->|"Read"| Models
Models -->|"Write"| Results
Results -->|"Load data and results"| Database
Setup and installation
Clone or download this repository from GitHub:
git clone git@github.com:nismod/mu-star.git
Next, install required dependencies. We recommend using
micromamba
to install these into a conda environment.
Create a conda environment once (per machine/user):
micromamba create --file environment.yaml
Activate it any time you pick up work on this repository:
micromamba activate mu-star
Install nbstripout to ensure that no outputs are committed with any jupyter
notebooks:
nbstripout --install
Usage
The principal goal of this repository is to analyse risks to infrastructure systems, in terms of direct damages, indirect losses, and the costs and benefits of adaptation options.
These results will be visualised in an online viewer, under development at irv-standalone.
The analysis is comprised of Python scripts wrapped in
snakemake rules. Snakemake is a workflow
management system that can be used to break up complex modelling chains and
improve the reproducibility of analyses. To invoke a rule, call snakemake
followed by the file you want to produce.
Some functionality is contained within a helper Python module, located in
src/mu_star.
Environment
To make snakemake, the helper Python module and other software dependencies available, activate the environment we previously created.
micromamba activate mu-star
Configuration
Analysis options can be configured using the config/config.yaml file. See it
for inline documentation.
Invocation
We use snakemake to drive any analysis. It’s best explained with an example.
To invoke the rule (and all necessary predecessor rules) to compute direct
damage (rehabiliation) costs to the road network due to fluvial flooding, we’d
run the following:
snakemake --dry-run --cores 1 data/out/damage/layer-road/rp/peril-flood/subperil-fluvial/ensemble-0/damage.zarr
Parts of the requested file path are parameterisable, e.g. layer-road,
peril-flood, subperil-fluvial. By varying these ‘wildcards’ different
outputs can be produced.
Note that the --dry-run flag asks snakemake to report on what work (if any)
is necessary. As jobs can be long running, this is useful to check beforehand.
To actually run the rules, remove the dry run flag.
The --cores flag indicates how many processors snakemake will use to execute
the rules. If rules do not depend on one another and enough processors are
available, they may execute simultaneously.
Available rules
See .smk files in workflow/ for available rules and their required input and
output files.
While this workflow is in development, some of the rules are placeholders.
The energy workflow builds three network products: base-mauritius from the
provided CEB transmission data, and two inferred coverage estimates for
Mauritius and Rodrigues, inferred-osm-mauritius-rodrigues (OpenStreetMap
power features) and inferred-provided-mauritius-rodrigues (provided
substations, generators and the CEB backbone). Settings live in
config/energy/energy.yaml; file paths there are relative to the data root
(data/ unless data_root is set in config/config.yaml).
Before the first build, place the provided CEB data under
data/incoming/energy/provided/ and fetch the OpenStreetMap and night-light
inputs once. Each fetch needs internet and its allow_download flag switched
on in config/energy/energy.yaml (energy.osm.allow_download and
energy.nightlight.source.allow_download); switch them off again afterwards so
later runs stay offline:
snakemake -c1 fetch_energy_osm
snakemake -c1 fetch_energy_nightlights
Then build all three products:
snakemake -c1 build_energy_networks
To build a single product, ask for its output file, for example:
snakemake -c1 data/processed/energy/networks/base-mauritius/base-mauritius.nc
The code entry point is energy.build.build_network. Inferred voltages and
capacities are placeholders, and energy has no disruption analysis yet. See
docs/src/infrastructure-energy.md for the method, inputs, outputs and current
limitations.
Testing
Test the helper library and other included packages by activating the environment and running the following from this directory:
python -m pytest -n 2 src/
Run auto-formatting and check for common minor problems using ruff:
ruff format
ruff check
Developer notebooks
For visual debugging while developing a model, the notebooks/ directory holds
local, dev-only notebooks that read the pipeline’s standard outputs and render
them. They are namespaced per system and are not part of any workflow rule;
production visualisation is the separate viewer at
https://github.com/nismod/irv-standalone. The energy notebooks live in
notebooks/energy/: 00-data-review looks at the inputs, and
01-build-network runs the build (from a cell or the terminal) and inspects a
product. Notebook outputs are stripped on commit via nbstripout; enable this
once per clone so committed notebooks stay diff-clean:
pre-commit install
nbstripout --install
See notebooks/README.md for the per-system layout and conventions.
Documentation
Documentation is written in the ./docs/src directory using
markdown and built
using mdbook.
Read the latest documentation at: https://nismod.github.io/mu-star/
Contributing
New to the project? Start with CONTRIBUTING.md. It covers
setup and a first session, how we work with branches and pull requests, where
your work goes and how to write issues. In short: open draft pull requests
early, keep changes fairly small, and ask for review often.
Citation
All contributors should be listed in ./CITATION.cff.
Once released, a Zenodo DOI will be available.
Cite this software as follows:
Russell, T., & Thomas, F. Mauritius STAR [Computer software]. https://github.com/nismod/mu-star
@software{Russell_Mauritius_STAR,
author = {Russell, Tom and Thomas, Fred},
license = {MIT},
title = {{Mauritius STAR}},
url = {https://github.com/nismod/mu-star}
}
Acknowledgements
Funded by the Foreign and Commonwealth Development Office (FCDO) of the United Kingdom.
Risk analysis
Hazards
Context
Economic activity and trade
In order to understand the finer geographical scale at which the economy is organised, we introduce modelling methods allowing to disaggregate reported national statistics for economic output onto a fine spatial indexed grid. The methodology fits into the inverse problem theory and in this context observed data is taken and a model that produces this data under some constraint and sometimes limited prior knowledge about a pheomenon is developped. In the following sections, the model, input data and output schema will be described.
Data
The input data come from various sources including academic, open source, crowd sourced, and official accounts. The full list has been put together into a catalogue available upon request. The econometric model uses OvertureMaps as it’s primary source of points of interest (POIs), for which the exact coordinates and a categorical classification are known, the
Sectorial coverage
Coverage of selected entries of our data catalogue:
Methods
Process
The method involves three main steps:
- Data Collection and Preprocessing: data are downloaded, transformed into consistent file formats, and allocated to spatial units, providing proxies, priors and constraints for the modelling.
- Downscaling: a Bayesian hierarchical model integrates geospatial variables (e.g., population density, infrastructure distribution, night-time light emissions, and land use classifications) and coarse-resolution constraints on spatial, sectoral economic activity.
- Validation: datasets representing aggregations of spatial, sectoral activity, some with limited geographical coverage, are used to validate our downscaled economic distributions.
There are multiple sources for global data covering different sectors of economic activity and physical features, available at different resolutions, covering different time periods, and provided in different formats and coordinate systems.
Inputs are taken from: multi-regional input-output tables for national, sectoral production(Lenzen et al., 2017), non-residential built-up area (European Commission. Joint Research Centre., 2023), and points of interest and land use from Overture Maps1 and OpenStreetMap(OpenStreetMap contributors, 2017).
Validation data sets include: combined national/sub-national sectoral value added from the World Development Indicators(World Bank, 2024), the CIA World Factbook2, (Wenz et al., 2023) and the US Bureau of Economic Analysis3 county level economic activity.
Data is projected onto the H3 grid4. Raster data cell centroids are projected onto H3 at a resolution higher than the raster cell size, then a Voronoi tessellation fills any gaps in the H3 grid. Points are allocated directly to their H3 cell. Polygons are allocated to all contained H3 cells. The resolution for projection of vector features is chosen to cover the equivalent of a small building block, meters.
The multi-faceted nature of the problem, which takes into account prior knowledge on the spatial locations, general law of distribution of economic output, as well as expert knowledge on certain sectors naturally fits into a Bayesian framework. A Bayesian hierarchical model (BHM) (Song et al., 2014) allows modelling complex phenomena relying both on prior information, which can be obtained by the modeller from a mix of expert sources, but also integrate a stochastic approach to parameter exploration. The model step is realised by running a Markov Chain Monte Carlo (MCMC) process, leading to a posterior distribution. The output of this process incorporates our prior beliefs and adjusts them based on likelihoods given observed data.
The core of the model can be summarised as follows:
Where is the matrix of econometric weights for which the mean() and standard deviation() are fixed using available information on the input proxy data and the constraints, is a matrix of proxy variables index representing rescaled and normalised input proxy data, is a matrix containing per sector per location output samples, is the uncertainty, taken as a fixed fraction of the lognormal mean. This sampling is performed under the following constraints:
where is a unit of the geographical constraint, is a unit of the sectoral constraint, and is the corresponding region and sector aggregated value at the resolution of the constraint.
Spatial Representation and Indexing
Pycnophylactic Condition
- From a strict conditioning(Tobler, 1979), to a flexible one allowing for an uncertainty on the reported macro level data, and less penalising for the model.
The macro level data, expressed as a sum of micro level observations combined :
allowing for a standard deviation of of the observed value. In this formulation, the observed reported is interpreted as the expected value of a normal distribution.
The constraint is implemented through the use of aggregation operators, and , that perform the necessary spatial and sectorial aggregation to obtain a constraint resolution level value of the output. This value can then be checked against the constraint.
The successive application of these aggregation operators to an output tensor () provides a tensor containing modelled outputs aggregated to the same spatial and sectoral resolution as the constrain. At this level of resolution, the likelihood function can be applied and comparison can be made with the available data.
Visually, the model is represented as follows :
Utilities Access and Network Interdependence
Using a graph voronoi network partitioning[erwigGraphVoronoiDiagram2000], the interconnection between an economic sector and the different utilities is investigated further. This method provides a deeper understanding(Molnár et al., 2023) into the spatial layout of different networked infrastructure systems and the cluster structure emerging from the facilities location and the nearest accessible region around them. This in turn provides key insights into which infrastructures support the largest economic output across the studied region.
-
https://overturemaps.org/ ↩
-
https://www.cia.gov/the-world-factbook/ ↩
-
https://www.bea.gov/ ↩
-
https://h3geo.org/ ↩
Population
Infrastructure systems models
Water
Energy
The energy analysis builds network models of Mauritius’s electricity system. Nobody has surveyed the distribution grid (the lines that carry power from substations to streets and homes), so the analysis estimates where it runs. It produces three network products:
- base-mauritius: the transmission network of the national utility, the Central Electricity Board (CEB), built directly from its substations, 66 kV routes and generation sites. This is the closest thing to the real grid.
- inferred-osm-mauritius-rodrigues: an estimate of the distribution grid that starts from the substations, plants and generators mapped in OpenStreetMap and joins them across the road network.
- inferred-provided-mauritius-rodrigues: the same estimate, starting from CEB’s own substations and generators and keeping the CEB transmission backbone.
The two inferred products share the method below. They differ only in where their power assets come from.
How the inferred estimate works
- Find lit-up areas. Somewhere consistently bright at night is almost certainly electrified. We take twelve monthly VIIRS night-light images (VIIRS is a satellite sensor) for 2024 and take the median of each pixel across the year, which smooths out cloudy months. A filter then picks out pixels brighter than their surroundings, and those above a brightness threshold become targets: places the grid has to reach. Only pixels inside the island outlines count. (The filter and threshold are adapted from GridFinder by Chris Arderne, MIT licence.)
- Take the roads. Distribution lines tend to follow roads, so the drivable road network from OpenStreetMap gives the candidate routes. A two-way street is stored once.
- Keep the roads that matter. We keep every road within 1 km of a target or a known power asset and drop the rest. When that strands a lit cluster, because the unlit road connecting it was dropped, we restore the shortest real-road path back to the main network.
- Connect the power assets. Each substation, plant or generator is joined to the nearest point on the nearest kept road, and the road is split there, as long as that point is within 1 km. In the provided variant an asset also connects to the nearest CEB backbone line, and a junction that carries both voltage levels becomes a transformer.
- Keep parallel roads. Two roads running between the same junctions stay as two separate lines.
Both 1 km distances are settings in config/energy/energy.yaml.
The result is a coverage estimate: where the network plausibly runs, not a
survey of the real lines. Its voltages (11 kV for distribution, 66 kV for the
CEB backbone) and line capacities are placeholders. They are published in the
model_v_nom_kv and model_s_nom_mva columns, while v_nom_kv and
s_nom_mva stay empty until real values exist.
Inputs
- Provided CEB data: a power demand workbook and shapefiles of substations,
transmission routes and generation sites, shared under licence and placed by
hand under
<data>/incoming/energy/provided/. Generator capacities are CEB annual report figures held insrc/energy/resources/generator_capacity_reference.csv. A generation site with no reference capacity is kept ingenerators.csvfor review but left out of the PyPSA network. - OpenStreetMap: the drivable road network, mapped power features and the
outline of each island, fetched once into
<data>/incoming/energy/osm/<region>/. - VIIRS night lights: twelve monthly tiles for 2024, fetched once into
<data>/incoming/energy/nightlights/viirs-2024-monthly/from an ArcGIS image service (NighttimeLightsMDNB ImageServer) that serves the Earth Observation Group’s VIIRS DNB monthly cloud-free average-radiance composites. One caveat from the provider: a zero radiance can mean “no cloud-free observations that month” rather than darkness. The median over twelve months reduces this problem but does not remove it.
<data> is the data root: data/ in this repository unless data_root is set
in config/config.yaml. Nothing is downloaded unless you switch it on in
config/energy/energy.yaml; the README gives the fetch commands.
Outputs
Each product is written under <data>/processed/energy/networks/<product>/:
<product>.nc: the network as a PyPSA model (an open-source toolkit for power system modelling), with<product>_metadata.jsonrecording the inputs, settings and checksums of the build.geoparquet/: the nodes and edges as GeoParquet layers (a GIS file format) for mapping, with a manifest tying them to the network.inferred_distribution/(inferred products only): the road graph as plain CSV node and edge tables.
Human-readable tables go to <data>/out/energy/<product>/: generators.csv,
lines.csv and validation.json. The validation report holds advisory checks:
total line length against CEB’s published figures (479 km of 66 kV transmission
for the base network; 10,492 km of transmission plus distribution circuits for
the inferred networks), and modelled generation against CEB’s reported
installed capacity. Every warning is also logged when the build runs, so a
problem is never silent.
Known limits:
- Rodrigues has no provided CEB data, so the provided variant gives it a stand-in root (a placeholder substation) on its road network.
- The distribution proxy follows roads, so lines that cross open country are not represented.
- Voltages and capacities are placeholders, and no power flow is calculated.
Disruption analysis (deferred)
Each infrastructure model is meant to answer “given a set of disrupted assets, what is the loss of supply?” The simulation that would answer this for energy is not built yet.