-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculate_exposed_GDP.py
50 lines (38 loc) · 1.42 KB
/
calculate_exposed_GDP.py
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
"""
Author: Jerom Aerts
Contact: [email protected]
Description:
Calculate exposed GDP of flood hazard map after data homogenization
This script requires the following two components in order to work:
- Gridded GDP layer, see create_haversine_grid.py
- Binary flood hazard map, see data_homogenization.py
"""
import os
import numpy as np
import rasterio
def exposed_GDP(floodmap, GDP_layer):
# Load floodmap and haversine grid
src_A = rasterio.open(floodmap)
profile = src_A.meta.copy()
src_B = rasterio.open(GDP_layer)
# Create empty array for filling
inundated_area = np.zeros([1,73800])
# Loop through arrays
i = 0
for ji, window in src_A.block_windows(1):
i += 1
affine = rasterio.windows.transform(window, src_A.transform)
height, width = rasterio.windows.shape(window)
bbox = rasterio.windows.bounds(window, src_A.transform)
profile.update({
'height': height,
'width': width,
'affine': affine})
array_A = src_A.read(1, window=window)
array_B = src_B.read(1, window=window)
# Multiply binary array with haversine array to retrieve exposed GDP
array_combined = array_A * array_B
array_combined = np.sum(array_combined)
exposed_GDP = np.append(exposed_GDP, array_combined)
exposed_GDP = np.sum(exposed_GDP,0)
return exposed_GDP