rapsoj commited on
Commit
3ca9806
·
verified ·
1 Parent(s): 95c0ebf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +268 -25
README.md CHANGED
@@ -4,48 +4,291 @@ emoji: 📍
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.35.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  short_description: Download and process hazard layers for Red Cross VCAs.
12
  ---
13
 
14
- # eVCA Hazard and Exposure Data Downloader 🌍
15
 
16
- This Gradio app enables users to download GloFAS flood hazard rasters and relevant exposure data for vulnerability and capacity assessments (VCAs).
 
17
 
18
- ## 🚀 Features
19
 
20
- - Select a country and return period
21
- - Fetch hazard rasters and exposure data
22
- - CKAN and HOTOSM integrations
23
- - Modular hazard support
24
 
25
- ## 🧪 How to Use
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- 1. Select a country from the dropdown
28
- 2. Choose a return period and hazard (e.g. Flood)
29
- 3. Select subdivision if prompted
30
- 4. Click **Generate Raster**
31
- 5. Download your files below
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- ## 📁 Output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- - `.tif` raster files (hazards)
36
- - `.geojson` files (exposure layers)
37
- - Bundled `.zip` for downloads
38
 
39
- ## 🧩 Modular Design
40
 
41
- - `hazards/`: Hazard-specific logic (flood, wildfire, etc.)
42
- - `data/`: HOTOSM and CKAN fetchers
43
- - `app.py`: UI and orchestration logic
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- ## 🛠 Run Locally
46
 
47
- ```bash
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  git clone https://huggingface.co/spaces/your-username/evca
49
- cd evca
 
 
 
 
50
  pip install -r requirements.txt
 
 
 
 
 
51
  python app.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  short_description: Download and process hazard layers for Red Cross VCAs.
12
  ---
13
 
14
+ ## eVCA Hazard and Exposure Analysis App
15
 
16
+ Digital Enhanced Vulnerability and Capacity Assessment
17
+ 510 Netherlands Red Cross
18
 
19
+ 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.
20
 
21
+ 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.
 
 
 
22
 
23
+ ---
24
+
25
+ # 1. Purpose
26
+
27
+ The app supports eVCA workflows by
28
+
29
+ * Generating hazard rasters for selected countries and return periods
30
+ * Fetching exposure datasets (HOTOSM, HDX CODs)
31
+ * Running any available analysis modules that compare hazards with exposure
32
+ * Presenting outputs in a structured and repeatable format
33
+
34
+ Typical use cases include
35
+
36
+ * National-level flood exposure prioritisation
37
+ * Identification of exposed critical infrastructure
38
+ * Road and building exposure summaries
39
+ * High resolution, locally relevant assessments of settlements and access routes
40
 
41
+ ---
42
+
43
+ # 2. Architecture Overview
44
+
45
+ ```
46
+ analysis/
47
+ drm_planning.py # Analysis functions and metadata
48
+ data/
49
+ ckan.py # HDX population and admin downloads
50
+ hotosm.py # HOTOSM exposure downloads
51
+ options.py # Country and return period selections
52
+ hazards/
53
+ flood.py # Hazard raster generation logic (per hazard)
54
+ app.py # Gradio interface
55
+ config.py # Hazard registry
56
+ requirements.txt
57
+ ```
58
 
59
+ The structure separates responsibilities
60
+
61
+ * `hazards/` holds hazard raster generation modules
62
+ * `data/` fetches all exposure layers
63
+ * `analysis/` contains analysis functions runnable on any hazard and exposure inputs
64
+ * `app.py` dynamically discovers hazards and analyses
65
+ * `config.py` registers hazard metadata and layer dependencies
66
+
67
+ ---
68
+
69
+ # 3. How the System Discovers Hazards and Analyses
70
+
71
+ ## Hazards
72
+
73
+ Any file inside `hazards/` with a function named
74
+
75
+ ```
76
+ generate_<hazardname>_raster(iso: str, rp: int, gis_name: str=None)
77
+ ```
78
+
79
+ is automatically discovered.
80
+ Example: `flood.py` exposes `generate_flood_raster`, which the interface loads at runtime.
81
+
82
+ ## Analyses
83
+
84
+ Any module inside `analysis/` that defines a dictionary named `ANALYSIS_METADATA` is registered automatically.
85
+ Its fields are
86
+
87
+ ```
88
+ {
89
+ "name": "...",
90
+ "function": <callable>,
91
+ "required_files": ["raster_path", ...],
92
+ "enabled": True or False
93
+ }
94
+ ```
95
+
96
+ All enabled analyses run after raster and exposure acquisition.
97
+
98
+ ---
99
 
100
+ # 4. Adding a New Hazard Type
 
 
101
 
102
+ To add a new hazard
103
 
104
+ 1. Create a file in `hazards/`
105
+ Example
106
+
107
+ ```
108
+ hazards/landslide.py
109
+ ```
110
+
111
+ 2. Implement a generator function
112
+
113
+ ```
114
+ def generate_landslide_raster(iso: str, rp: int, gis_name: str=None):
115
+ return output_path, message
116
+ ```
117
+
118
+ The function must
119
+
120
+ * Accept `iso` and `rp`
121
+ * Clip or build a raster of the hazard over the selected geometry
122
+ * Return `(path_to_local_tif, status_message)`
123
+ * Write only local files, no in-memory objects
124
+
125
+ 3. Do not edit `app.py`. The app imports hazards dynamically.
126
+
127
+ 4. Register hazard metadata in `config.py`
128
+
129
+ ```
130
+ hazard_registry["Landslide"] = HazardSource(
131
+ name="Landslide",
132
+ rp_options=[10, 25, 50, 100],
133
+ generate_fn=generate_landslide_raster,
134
+ data_layers=["populated_places", "roads", "buildings"]
135
+ )
136
+ ```
137
+
138
+ Once added, the hazard appears automatically in the dropdown interface.
139
+
140
+ ---
141
+
142
+ # 5. Adding a New Exposure Layer
143
+
144
+ Exposure layers are stored under `data/`. A new exposure layer requires
145
+
146
+ * A download function
147
+ * A stable filename or return object
148
+ * Declaration inside the hazard’s `data_layers` list if required for analysis
149
+
150
+ Steps
151
+
152
+ 1. Add a download function in `data/`
153
+ Example
154
+
155
+ ```
156
+ data/electricity.py
157
+ def download_electricity_grid(iso: str):
158
+ return local_zip_path
159
+ ```
160
+
161
+ 2. Modify the hazard’s `data_layers` entry in `config.py` if the hazard depends on it.
162
+
163
+ 3. In `app.py`, the wrapper automatically receives the file path if the downloader is added to the list of downloads.
164
+
165
+ You do not need to modify core logic. Analyses decide if they need the layer by reading `required_files`.
166
+
167
+ ---
168
 
169
+ # 6. Adding a New Analysis Function
170
 
171
+ Analyses answer questions such as
172
+
173
+ * Which populated places intersect the hazard
174
+ * Which buildings or roads are exposed
175
+ * Which administrative areas have highest exposure intensity
176
+ * High or low exposure combined with vulnerability metrics
177
+
178
+ ## Steps to add an analysis
179
+
180
+ 1. Create a new file inside `analysis/`, for example
181
+
182
+ ```
183
+ analysis/roads_exposure.py
184
+ ```
185
+
186
+ 2. Implement a function with signature
187
+
188
+ ```
189
+ def analyze_something(raster_path: str, roads_path: str, ...):
190
+ return message_string or tuple_of_message_strings
191
+ ```
192
+
193
+ The function must
194
+
195
+ * Accept file paths only
196
+ * Return human readable strings for UI display
197
+ * Handle missing files internally with clear messages
198
+
199
+ 3. Add metadata
200
+
201
+ ```
202
+ ANALYSIS_METADATA = {
203
+ "name": "Road Flood Exposure",
204
+ "function": analyze_something,
205
+ "required_files": ["raster_path", "roads_path"],
206
+ "enabled": True
207
+ }
208
+ ```
209
+
210
+ 4. The app loads this automatically using `run_analyses`.
211
+
212
+ No integration changes are necessary elsewhere.
213
+
214
+ ---
215
+
216
+ # 7. Example: Exposed Populated Places Analysis
217
+
218
+ `drm_planning.py` contains an example analysis that
219
+
220
+ * Loads populated places from HOTOSM
221
+ * Converts hazard rasters into polygons
222
+ * Computes intersections using GeoPandas
223
+ * Produces
224
+
225
+ * Top 10 exposed settlements by population
226
+ * Counts by settlement type
227
+
228
+ This module demonstrates the required structure and metadata pattern for all new analyses.
229
+
230
+ ---
231
+
232
+ # 8. Example Analysis Questions That Can Be Implemented
233
+
234
+ Developers can modularly implement analyses that answer
235
+
236
+ * National settlement exposure by return period
237
+ * Provincial infrastructure exposure
238
+ * Road segments intersecting 25 to 100 year flood zones
239
+ * Disproportionate exposure for vulnerable settlements
240
+ * Local evacuation centre siting
241
+ * Isolation risk for communities after access routes are flooded
242
+ * Exposure intersection with poverty or displacement data
243
+ * Comparisons of exposure across 10, 100, and 500 year scenarios
244
+
245
+ Each question type can be implemented as a distinct analysis module.
246
+
247
+ ---
248
+
249
+ # 9. Development Workflow
250
+
251
+ 1. Clone the repository
252
+ 2. Create a new hazard module, exposure downloader, or analysis script
253
+ 3. Add metadata where required
254
+ 4. Test locally with
255
+
256
+ ```
257
+ python app.py
258
+ ```
259
+ 5. Push to GitHub, and the app updates automatically on HuggingFace Spaces if configured
260
+
261
+ ---
262
+
263
+ # 10. Running Locally
264
+
265
+ Clone repository
266
+
267
+ ```
268
  git clone https://huggingface.co/spaces/your-username/evca
269
+ ```
270
+
271
+ Install dependencies in the folder where the repository was cloned
272
+
273
+ ```
274
  pip install -r requirements.txt
275
+ ```
276
+
277
+ Launch locally
278
+
279
+ ```
280
  python app.py
281
+ ```
282
+
283
+ The Gradio interface will open in your browser.
284
+
285
+ ---
286
+
287
+ # 11. Contributing Guidelines
288
+
289
+ * Follow the modular structure
290
+ * Avoid modifying `app.py` unless updating UI behaviour
291
+ * Ensure new hazard generators return physical `.tif` files
292
+ * Ensure analyses return readable Markdown
293
+ * Handle missing data gracefully
294
+ * Keep functions pure and file based