Skip to content

Commit

Permalink
Makie plotting in examples and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro3 committed Jul 16, 2024
1 parent 6577e6c commit 3dc21d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ The main function of this package is `waterflows`, please refer to its
doc-string. Here a simple example using it:

```julia
using WhereTheWaterFlows, PyPlot
```
using WhereTheWaterFlows, GLMakie
const WWF = WhereTheWaterFlows

"Synthtic DEM with a few maxs and mins"
Expand All @@ -39,29 +40,23 @@ x,y,dem = peaks2(200)
area, slen, dir, nout, nin, sinks, pits, c, bnds = waterflows(dem)

# log-upslope area as well as pits (sinks)
WWF.plt.plotarea(x, y, area, pits)

# log-upslope area over contours of the dem
WWF.plt.plotarea_dem(x, y, dem, area, pits)
plt_area(x, y, area, pits)

# catchments
figure()
WWF.plt.heatmap(x,y,c)
plt_catchments(x,y,c)

# A single catchment of some point. Choose one with large catchment:
i, j = 50, findmax(area[50,:])[2]
cc = catchment(dir, CartesianIndex(i,j))
WWF.plt.heatmap(x,y,cc)
plot(x[i], y[j], "<r", ms=10)
heatmap(x,y,cc)
scatter!(x[i], y[j], markersize=50)

# stream length
figure()
WWF.plt.heatmap(x,y,slen)
heatmap(x,y,slen)

demf = fill_dem(dem, pits, dir)
demf = fill_dem(dem, sinks, dir)
# "lake-depth"
figure()
WWF.plt.heatmap(x,y,demf.-dem)
heatmap(x, y, demf.-dem)
```
In the `example/` folder there are two more complicated examples. One
Expand Down
12 changes: 6 additions & 6 deletions examples/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if !@isdefined plotyes
plotyes = true
end
if plotyes
@eval using PyPlot
@eval using GLMakie
end
using WhereTheWaterFlows
if !(@isdefined WWF)
Expand All @@ -22,15 +22,15 @@ dx = 0.01
xs = -1.5:dx:1
ys = -0.5:dx:3.0
dem = ele.(xs, ys', randfac=0.1, withpit=true);
plotyes && WWF.plt.heatmap(xs, ys, dem)
plotyes && heatmap(xs, ys, dem)

area, slen, dir, nout, nin, sinks, pits, c, bnds = WWF.waterflows(dem, drain_pits=true);

@assert size(dem)==(length(xs), length(ys))
plotyes && WWF.plt.plotit(xs, ys, dem)
plotyes && WWF.plt.plotarea(xs, ys, area, pits)
plotyes && plt_it(xs, ys, dem)
plotyes && plt_area(xs, ys, area, sinks)

plotyes && WWF.plt.heatmap(xs, ys, c)
plotyes && plt_catchments(xs, ys, c)

demf = WWF.fill_dem(dem, sinks, dir) #, small=1e-6)
plotyes && WWF.plt.heatmap(xs, ys, demf.-dem)
plotyes && heatmap(xs, ys, demf.-dem)
12 changes: 5 additions & 7 deletions examples/subglacial-routing-feedback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ phi_filled = WWF.fill_dem(phi, sinks, dir) #, small=1e-6)
lake_depth = phi_filled .- phi
# Plot it
if plotyes
WWF.plt.plotit(x, y, phi)
WWF.plt.plotarea(x, y, area[1], pits)
WWF.plt.plotarea(x, y, area[2], pits)
plt_it(x, y, phi)
plt_area(x, y, area[1], pits)
plt_area(x, y, area[2], pits)

PyPlot.figure()
WWF.plt.heatmap(x, y, c)
plt_catchments(x, y, c)

PyPlot.figure()
WWF.plt.heatmap(x, y, lake_depth)
heatmap(x, y, lake_depth)
end
8 changes: 4 additions & 4 deletions examples/subglacial-routing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ phi = bed + flotation_fraction * rho_i/rho_w * (surface - bed)
area, slen, dir, nout, nin, sinks, pits, c, bnds = WWF.waterflows(phi, drain_pits=true)

# Plot it
plotyes && WWF.plt.plotit(x, y, phi)
plotyes && WWF.plt.plotarea(x, y, area, sinks)
plotyes && plt_it(x, y, phi)
plotyes && plt_area(x, y, area, sinks)

plotyes && WWF.plt.heatmap(x, y, c)
plotyes && plt_catchments(x, y, c)

phi_filled = WWF.fill_dem(phi, sinks, dir) #, small=1e-6)
plotyes && WWF.plt.heatmap(x, y, phi_filled .- phi)
plotyes && heatmap(x, y, phi_filled .- phi)
8 changes: 4 additions & 4 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Plot `dir` as flow field
end
function Makie.plot!(plot::Plt_Dir)
(;dir, x, y, sinks) = plot
vecfield = lift(dir-> dir2vec.(dir, true), dir)
vecfield = lift(dir-> WWF.dir2vec.(dir, true), dir)
vecfieldx = lift(vecfield -> [v[1] for v in vecfield], vecfield)
vecfieldy = lift(vecfield -> [v[2] for v in vecfield], vecfield)
arrows!(plot, x, y, vecfieldx, vecfieldy, lengthscale=0.005, align=:center)
Expand Down Expand Up @@ -66,7 +66,7 @@ function Makie.plot!(plot::Plt_Area)
if threshold[]<Inf
pl[][area[].<threshold[]] .= NaN
end
plt_sinks!(x,y,sinks)
plt_sinks!(plot, x, y, sinks)
heatmap!(plot, x, y, pl)
end

Expand All @@ -81,7 +81,7 @@ end
function Makie.plot!(plot::Plt_Sinks)
pp = lift((x,y,sinks) -> sinks2vecs(x, y, sinks), plot.x, plot.y, plot.sinks)
px, py = lift(x->x, pp[])
scatter!(plot, px, py, color=:red)
scatter!(plot, px, py, color=:red, markersize=25)
end

"""
Expand Down Expand Up @@ -165,7 +165,7 @@ plt_it(x, y, dem) = plt_it(x, y, waterflows(dem), dem)
function plt_it(x, y, waterflows_output::Tuple, dem)
area, slen, dir, nout, nin, sinks, sink_pits = waterflows_output

f = GLMakie.Figure()
f = Makie.Figure()
ax1 = Axis(f[1, 1]; aspect=1, title="")
contour!(x, y, dem)
ax2 = Axis(f[2, 1]; aspect=1, title="")
Expand Down

0 comments on commit 3dc21d9

Please sign in to comment.