File size: 7,549 Bytes
84155e1
391cd51
5cebdd4
84155e1
5cebdd4
84155e1
3ca9806
84155e1
 
 
 
a6ec964
 
3ca9806
a6ec964
3ca9806
 
a6ec964
3ca9806
a6ec964
3ca9806
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ec964
3ca9806
a6ec964
3ca9806
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ec964
3ca9806
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ec964
3ca9806
 
 
 
 
a6ec964
3ca9806
 
 
 
 
a6ec964
3ca9806
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
---
title: eVCA
emoji: 📍
colorFrom: red
colorTo: red
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
license: mit
short_description: Download and process hazard layers for Red Cross VCAs.
---

## eVCA Hazard and Exposure Analysis App

Digital Enhanced Vulnerability and Capacity Assessment
510 Netherlands Red Cross

This application automates spatial analysis of hazard exposure across countries and administrative regions. It retrieves hazard rasters, downloads exposure data, and runs modular analysis functions that combine both to answer operational and strategic questions in disaster risk management, emergency response, and advocacy.

The app is built entirely around modular extension. Developers can add new hazards, new exposure layers, and new analysis functions without modifying the core application logic.

---

# 1. Purpose

The app supports eVCA workflows by

* Generating hazard rasters for selected countries and return periods
* Fetching exposure datasets (HOTOSM, HDX CODs)
* Running any available analysis modules that compare hazards with exposure
* Presenting outputs in a structured and repeatable format

Typical use cases include

* National-level flood exposure prioritisation
* Identification of exposed critical infrastructure
* Road and building exposure summaries
* High resolution, locally relevant assessments of settlements and access routes

---

# 2. Architecture Overview

```
analysis/
   drm_planning.py          # Analysis functions and metadata
data/
   ckan.py                  # HDX population and admin downloads
   hotosm.py                # HOTOSM exposure downloads
   options.py               # Country and return period selections
hazards/
   flood.py                 # Hazard raster generation logic (per hazard)
app.py                      # Gradio interface
config.py                   # Hazard registry
requirements.txt
```

The structure separates responsibilities

* `hazards/` holds hazard raster generation modules
* `data/` fetches all exposure layers
* `analysis/` contains analysis functions runnable on any hazard and exposure inputs
* `app.py` dynamically discovers hazards and analyses
* `config.py` registers hazard metadata and layer dependencies

---

# 3. How the System Discovers Hazards and Analyses

## Hazards

Any file inside `hazards/` with a function named

```
generate_<hazardname>_raster(iso: str, rp: int, gis_name: str=None)
```

is automatically discovered.
Example: `flood.py` exposes `generate_flood_raster`, which the interface loads at runtime.

## Analyses

Any module inside `analysis/` that defines a dictionary named `ANALYSIS_METADATA` is registered automatically.
Its fields are

```
{
    "name": "...",
    "function": <callable>,
    "required_files": ["raster_path", ...],
    "enabled": True or False
}
```

All enabled analyses run after raster and exposure acquisition.

---

# 4. Adding a New Hazard Type

To add a new hazard

1. Create a file in `hazards/`
   Example

   ```
   hazards/landslide.py
   ```

2. Implement a generator function

   ```
   def generate_landslide_raster(iso: str, rp: int, gis_name: str=None):
       return output_path, message
   ```

   The function must

   * Accept `iso` and `rp`
   * Clip or build a raster of the hazard over the selected geometry
   * Return `(path_to_local_tif, status_message)`
   * Write only local files, no in-memory objects

3. Do not edit `app.py`. The app imports hazards dynamically.

4. Register hazard metadata in `config.py`

   ```
   hazard_registry["Landslide"] = HazardSource(
       name="Landslide",
       rp_options=[10, 25, 50, 100],
       generate_fn=generate_landslide_raster,
       data_layers=["populated_places", "roads", "buildings"]
   )
   ```

Once added, the hazard appears automatically in the dropdown interface.

---

# 5. Adding a New Exposure Layer

Exposure layers are stored under `data/`. A new exposure layer requires

* A download function
* A stable filename or return object
* Declaration inside the hazard’s `data_layers` list if required for analysis

Steps

1. Add a download function in `data/`
   Example

   ```
   data/electricity.py
   def download_electricity_grid(iso: str):
        return local_zip_path
   ```

2. Modify the hazard’s `data_layers` entry in `config.py` if the hazard depends on it.

3. In `app.py`, the wrapper automatically receives the file path if the downloader is added to the list of downloads.

You do not need to modify core logic. Analyses decide if they need the layer by reading `required_files`.

---

# 6. Adding a New Analysis Function

Analyses answer questions such as

* Which populated places intersect the hazard
* Which buildings or roads are exposed
* Which administrative areas have highest exposure intensity
* High or low exposure combined with vulnerability metrics

## Steps to add an analysis

1. Create a new file inside `analysis/`, for example

   ```
   analysis/roads_exposure.py
   ```

2. Implement a function with signature

   ```
   def analyze_something(raster_path: str, roads_path: str, ...):
       return message_string or tuple_of_message_strings
   ```

   The function must

   * Accept file paths only
   * Return human readable strings for UI display
   * Handle missing files internally with clear messages

3. Add metadata

   ```
   ANALYSIS_METADATA = {
       "name": "Road Flood Exposure",
       "function": analyze_something,
       "required_files": ["raster_path", "roads_path"],
       "enabled": True
   }
   ```

4. The app loads this automatically using `run_analyses`.

No integration changes are necessary elsewhere.

---

# 7. Example: Exposed Populated Places Analysis

`drm_planning.py` contains an example analysis that

* Loads populated places from HOTOSM
* Converts hazard rasters into polygons
* Computes intersections using GeoPandas
* Produces

  * Top 10 exposed settlements by population
  * Counts by settlement type

This module demonstrates the required structure and metadata pattern for all new analyses.

---

# 8. Example Analysis Questions That Can Be Implemented

Developers can modularly implement analyses that answer

* National settlement exposure by return period
* Provincial infrastructure exposure
* Road segments intersecting 25 to 100 year flood zones
* Disproportionate exposure for vulnerable settlements
* Local evacuation centre siting
* Isolation risk for communities after access routes are flooded
* Exposure intersection with poverty or displacement data
* Comparisons of exposure across 10, 100, and 500 year scenarios

Each question type can be implemented as a distinct analysis module.

---

# 9. Development Workflow

1. Clone the repository
2. Create a new hazard module, exposure downloader, or analysis script
3. Add metadata where required
4. Test locally with

   ```
   python app.py
   ```
5. Push to GitHub, and the app updates automatically on HuggingFace Spaces if configured

---

# 10. Running Locally

Clone repository

```
git clone https://huggingface.co/spaces/your-username/evca
```

Install dependencies in the folder where the repository was cloned

```
pip install -r requirements.txt
```

Launch locally

```
python app.py
```

The Gradio interface will open in your browser.

---

# 11. Contributing Guidelines

* Follow the modular structure
* Avoid modifying `app.py` unless updating UI behaviour
* Ensure new hazard generators return physical `.tif` files
* Ensure analyses return readable Markdown
* Handle missing data gracefully
* Keep functions pure and file based