Skip to content

Commit 6232aba

Browse files
committed
allow specifying rainfall on the grid; also returns the area of each grid cell in m2
1 parent 6283405 commit 6232aba

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/WaterFlow.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ end
3737

3838
"""
3939
Topo_water, sinks, pits, bnds = waterflows(Topo::GeoData;
40-
flowdir_fn=WhereTheWaterFlows.d8dir_feature, feedback_fn=nothing, drain_pits=true, bnd_as_sink=true)
40+
flowdir_fn=WhereTheWaterFlows.d8dir_feature, feedback_fn=nothing, drain_pits=true, bnd_as_sink=true,
41+
rainfall = nothing)
4142
42-
Takes a GMG GeoData object of a topographic map and routes water through the grid. We add a number of
43+
Takes a GMG GeoData object of a topographic map and routes water through the grid. Optionally,
44+
you can specify `rainfall` in which case we accumulate the rain as specified in this 2D array instead of the cellarea.
45+
This allows you to, for example, sum, up water if you have variable rainfall in the area.
46+
The other options are as in the `waterflows` function of the package `WhereTheWaterFlows`.
4347
4448
Example
4549
===
@@ -60,9 +64,15 @@ GeoData
6064
```
6165
6266
"""
63-
function waterflows(Topo::GeoData, flowdir_fn= WhereTheWaterFlows.d8dir_feature; feedback_fn=nothing, drain_pits=true, bnd_as_sink=true)
67+
function waterflows(Topo::GeoData, flowdir_fn= WhereTheWaterFlows.d8dir_feature; feedback_fn=nothing, drain_pits=true, bnd_as_sink=true, rainfall=nothing)
6468

6569
cellarea = cell_area(Topo)
70+
cellarea_m2 = cellarea
71+
if !isnothing(rainfall)
72+
@assert typeof(rainfall) == Array{Float64,2}
73+
cellarea = rainfall
74+
end
75+
6676
dem = Topo.depth.val[:,:,1]
6777

6878
area = zeros(Float64,size(Topo.depth.val))
@@ -75,6 +85,6 @@ function waterflows(Topo::GeoData, flowdir_fn= WhereTheWaterFlows.d8dir_feature;
7585
area[:,:,1], slen[:,:,1], dir[:,:,1], nout[:,:,1], nin[:,:,1], sinks, pits, c[:,:,1], bnds = waterflows(dem, cellarea, flowdir_fn;
7686
feedback_fn=feedback_fn, drain_pits=drain_pits, bnd_as_sink=bnd_as_sink)
7787

78-
Topo_water = addfield(Topo,(;area, slen, dir, nout, nin, c ))
88+
Topo_water = addfield(Topo,(;area, slen, dir, nout, nin, c, cellarea_m2 ))
7989
return Topo_water, sinks, pits, bnds
8090
end

test/test_WaterFlow.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ Topo_water, sinks, pits, bnds = waterflows(Topo)
1212
@test sum(Topo_water.fields.nin) == 459361
1313
@test sum(Topo_water.fields.dir) == 2412566
1414

15+
# With rain in m3/s per cell
16+
rainfall = ones(size(Topo.lon.val[:,:,1]))*1e-3 # 2D array with rainfall per cell area
17+
Topo_water1, sinks, pits, bnds = waterflows(Topo, rainfall=rainfall)
18+
19+
@test maximum(Topo_water1.fields.area) 169.79800000000208
1520

0 commit comments

Comments
 (0)