-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticFlooding.m
81 lines (58 loc) · 2.03 KB
/
StaticFlooding.m
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
function SF = StaticFlooding(lon, lat, z, wl, wb)
% Flooding method: bathtub approach taking into account hydrological
% connections
% --------
% Inputs:
% lon: longitude grid (columns)
% lat: latitude grid (rows)
% z: elevation (bathy-topography)
% lon, lat, and z may have the same size [M,N]
% wl: flood water level used to inundate (matrix format)
% wb: one point (lon, lat) indicating some place in the main water body
% (sea or river)
% --------
% Outputs:
% FloodDepthVec: coordinates [lon, lat] of flooded grid points and
% flood depth (meters)
% FloodDepth: grid of flood depth [M,N] with data only on the
% flooded grids
% FloodDepthAndSea: flood depth [M,N] including the main water body
dem_xyz= [lon(:), lat(:), z(:)];
% the topography is reduced by the inundating water level
zF= z - wl;
% Converting it into a binary black and white image of 1 and 0
zBW = zF;
zBW(zBW> 0) = nan; % land
zBW(zBW<= 0) = ones; % water
zBW(isnan(zBW)) = zeros; % land
%% Polygons and holes
Lc = bwboundaries_SFM(zBW);
%% Find the polygon with the sea boundary
% main water body
[~,sea_bound]= calc_distance(wb,dem_xyz);
Lwb1 = Lc{1}(sea_bound);
Lwb2 = Lc{2}(sea_bound);
% polygons
Lp = zeros(size(z));
Lp(Lc{1}== Lwb1)= ones;
% holes
holes = zeros(size(z));
holes(Lc{2}== Lwb2)= 1;
L = Lp + holes;
%% Inundating the main water body + connected areas
fpos = find(L== 2);
FloodDepthAndSea = nan(size(z));
FloodDepthAndSea(fpos) = zF(fpos);
%% Only new land indundated under wl
% grid format
FloodDepth = nan(size(z));
FloodDepth(fpos) = FloodDepthAndSea(fpos); % depth of flooded areas
FloodDepth(z<=0) = nan; % remove the main water body from the matrix
% output
SF.FloodDepth = FloodDepth;
SF.FloodDepthAndSea = FloodDepthAndSea;
SF.wb = wb;
% SF.lon = lon;
% SF.lat = lat;
% SF.z = z;
% SF.wb = wb;