From 2f5f9ee27161463187f7b63039b984da3c0e96eb Mon Sep 17 00:00:00 2001 From: Odd Date: Sat, 28 Dec 2024 00:58:14 +0100 Subject: [PATCH] Adapted plotting to changes in CairoMakie --- Project.toml | 1 + docs/Project.toml | 1 + examples/flat_areas.jl | 11 ++++---- examples/synthetic.jl | 63 +++++++++++++++++++++--------------------- examples/urban.jl | 39 ++++++++++---------------- src/IOandplot.jl | 20 +++++++------- 6 files changed, 62 insertions(+), 73 deletions(-) diff --git a/Project.toml b/Project.toml index c372548..6798f70 100644 --- a/Project.toml +++ b/Project.toml @@ -36,6 +36,7 @@ Makie = "0.21" OffsetArrays = "1.13" Roots = "2.1.2" julia = "1.9" + [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/docs/Project.toml b/docs/Project.toml index 0bff533..bccc9ed 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -11,6 +11,7 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" SurfaceWaterIntegratedModeling = "71e2a337-b4d4-4738-9f2b-3c37e1d3d462" [compat] +CairoMakie = "0.12.18" ArchGDAL = "0.10.2" ColorSchemes = "3.24" GeometryBasics = "0.4.11" diff --git a/examples/flat_areas.jl b/examples/flat_areas.jl index 631fd92..6d82765 100644 --- a/examples/flat_areas.jl +++ b/examples/flat_areas.jl @@ -30,8 +30,7 @@ tex = fill(cmap[:green], size(grid)) sf, fig, sc = plotgrid(grid, texture = tex, colormap=ColorSchemes.:Paired_12, colorrange=(1,12)) -fig -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # ## Identifying flat areas and running spill analysis # @@ -45,7 +44,7 @@ isflat = identify_flat_areas(grid, rel_tol, max_cluster_size) tex[isflat] .= cmap[:blue] drape_surface(sf, tex) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # We can see that the ocean part was correctly identified as flat, but so were @@ -57,7 +56,7 @@ isflat = identify_flat_areas(grid, rel_tol, max_cluster_size) tex[isflat] .= cmap[:blue] tex[.!isflat] .= cmap[:green] drape_surface(sf, tex) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # With this value for the threshold, only the ocean remains identified as flat. # @@ -97,7 +96,7 @@ tex[tex.==0] .= cmap[:green]-1; tex[isflat] .= cmap[:blue]; drape_surface(sf, tex) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # ## Adding more sinks # @@ -124,7 +123,7 @@ tex[tex.==0] .= cmap[:green]-1 tex[isflat] .= cmap[:blue] drape_surface(sf, tex) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # # [^1]: # The data used in this example was originally obtained from diff --git a/examples/synthetic.jl b/examples/synthetic.jl index e0541e3..dcfffe0 100644 --- a/examples/synthetic.jl +++ b/examples/synthetic.jl @@ -44,12 +44,11 @@ view2 = (GLMakie.Vec(90, 494, 8.6), GLMakie.Vec(100, 114, -4.5), 0.68); sf, fig, sc = plotgrid(grid, texture=fill(cmap[:bright], size(grid)), colormap=ColorSchemes.:Paired_12, colorrange=(1, 12), wireframe=true) -fig -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # Grid seen from above. Trap 1 and 2 from Fig. 1 can be seen on the upper left # side, wheras trap 3 is seen downstream on the lower right side. -set_camerapos(fig, sc, view2...) +set_camerapos(sc, view2...) # Grid seen from the side. Here we see how trap 1 and 2 (right) constitute # subtraps, or pockets, within a larger trap 4. As they gradually fill with @@ -95,7 +94,7 @@ tex[tstruct.footprints[2]] .= cmap[:green] tex[tstruct.footprints[3]] .= cmap[:blue] drape_surface(sf, tex); -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # Trap 1 and 2 are shown in red and green respectively, trap 3 in blue and trap # 4 in orange. @@ -124,7 +123,7 @@ tex[tstruct.footprints[2]] .= cmap[:green] tex[tstruct.footprints[3]] .= cmap[:blue] drape_surface(sf, tex); -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # The spill region of trap 4 is the union of the blue and green regions on this # plot. The beige-colored part of the surface does not spill to any trap; water @@ -140,7 +139,7 @@ set_camerapos(fig, sc, view1...) # We can visualize the spillfield by draping it directly on the surface: drape_surface(sf, tstruct.spillfield .*2) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # The eight different colors on this plot indicate the eight different local # flow directions. The bright blue color, which makes up most of the grid's @@ -167,7 +166,7 @@ for sp in tstruct.spillpoints tex[sp.downstream_region_cell] = cmap[:lilac] end drape_surface(sf, tex); -set_camerapos(fig, sc, +set_camerapos(sc, GLMakie.Vec(49.3, 156.7, 90.7), # set observer position GLMakie.Vec(86.8, 100.7, -3.3), # set observer target point 0.95) # zoom level @@ -183,7 +182,7 @@ tex = show_region_selection(tstruct, selection=[3, 4], region_color=cmap[:green]-1, trap_color=cmap[:green], river_color=cmap[:red]) drape_surface(sf, tex); -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # Here, we can see how trap 4 spills into trap 3, and trap 3 spills out of the # domain. @@ -282,8 +281,8 @@ tex = runoff_at(seq, 5) filled_trapcells = vcat(tstruct.footprints[:]...) ## footprint of all cells tex[filled_trapcells] .= extrema(tex)[2] # maximum value sf_flow, fig_flow, sc_flow = plotgrid(grid, texture=tex, colormap=:Blues); -fig_flow -set_camerapos(fig_flow, sc_flow, view1...) + +set_camerapos(sc_flow, view1...) # The flow is strongly concentrated along the streams exiting from each trap, # drowning out any other detail. To make more details visible, we can use @@ -291,8 +290,8 @@ set_camerapos(fig_flow, sc_flow, view1...) tex = log10.(runoff_at(seq, 5)) tex[filled_trapcells] .= extrema(tex)[2] # maximum value sf_flow_log, fig_flow_log, sc_flow_log = plotgrid(grid, texture=tex, colormap=:Blues) -fig_flow_log -set_camerapos(fig_flow_log, sc_flow_log, view1...) + +set_camerapos(sc_flow_log, view1...) # Although the `SpillEvent`s in `seq` describe the points in time where one or # more trap statuses change, we may also be interested in the amount of water @@ -331,16 +330,16 @@ tex, = interpolate_timeseries(tstruct, seq, tpoints, river_color=cmap[:red]) drape_surface(sf, tex[1]) -fig -set_camerapos(fig, sc, view1...) + +set_camerapos(sc, view1...) # At time 0.1 drape_surface(sf, tex[2]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.3 drape_surface(sf, tex[3]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.42 # ## Infiltration @@ -360,8 +359,8 @@ infil[1:110, 1:end] .= 2.0; sf_infil, fig_infil, sc_infil = plotgrid(grid, texture=infil, colormap=ColorSchemes.:rainbow, colorrange=(0, 2)) -fig_infil -set_camerapos(fig_infil, sc_infil, view1...) + +set_camerapos(sc_infil, view1...) # # In this figure, the purple part of the surface is impermeable, and the red @@ -388,20 +387,20 @@ tex, = interpolate_timeseries(tstruct, seq2, tpoints2, trap_color=cmap[:orange], river_color=cmap[:red]) drape_surface(sf, tex[1]) -fig -set_camerapos(fig, sc, view1...) + +set_camerapos(sc, view1...) # At time 0.1 drape_surface(sf, tex[2]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.3 drape_surface(sf, tex[3]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.42 drape_surface(sf, tex[4]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.60 # # Here, we can see that trap 3 does not start to fill up before @@ -420,8 +419,8 @@ dry_terrain = Float64.(runoff .< 0.0) dry_terrain[filled_trapcells] .= false ## submerged terrain should be considered wet ## regardless of inflow and infiltration rates drape_surface(sf_infil, dry_terrain) -fig_infil -set_camerapos(fig_infil, sc_infil, view1...) + +set_camerapos(sc_infil, view1...) # From this figure, where dry terrain is shown in green, the following # observations can be noted: @@ -435,8 +434,8 @@ tex_flow = log10.(max.(runoff, eps())) tex_flow[runoff .< 0.0] .= minimum(tex_flow[:]) tex_flow[filled_trapcells] .= maximum(tex_flow[:]) drape_surface(sf_flow_log, tex_flow) -fig_flow_log -set_camerapos(fig_flow_log, sc_flow_log, view1...) + +set_camerapos(sc_flow_log, view1...) # One interesting thing to note from this plot is how overland flow builds up # across the impermeable part of the surface, and then gradually attenuates as @@ -459,20 +458,20 @@ tex, = interpolate_timeseries(tstruct, seq3, tpoints3, filled_color=cmap[:blue], trap_color=cmap[:orange], river_color=cmap[:red]) -fig + drape_surface(sf, tex[1]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.3. This is identical to the previous case above. drape_surface(sf, tex[2]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.6. This is also identical to the previous case above. drape_surface(sf, tex[3]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 0.8. This is when rain stops. drape_surface(sf, tex[4]) -set_camerapos(fig, sc, view1...) +set_camerapos(sc, view1...) # At time 2.1. We note that the water level in trap 4 on the impermeable part of # the terrain remains unchanged, whereas the water level in trap 3, on the # permeable part of the domain, has dropped significantly. diff --git a/examples/urban.jl b/examples/urban.jl index 19ca3a3..9cf88d8 100644 --- a/examples/urban.jl +++ b/examples/urban.jl @@ -68,12 +68,10 @@ view1 = (GLMakie.Vec(1223, 587, 1056), GLMakie.Vec(391, 327, 13.8), 0.66); view2 = (GLMakie.Vec(1223, 587, 1056), GLMakie.Vec(391, 327, 13.8), 0.30); # Here is a snapshot for the terrain model: -figmap -set_camerapos(figmap, scmap, view1...) +set_camerapos(scmap, view1...) # And a snapshot of the surface model: -figpho -set_camerapos(figpho, scpho, view1...) +set_camerapos(scpho, view1...) # Here is a visualization of the different masks loaded: fig = GLMakie.Figure() @@ -171,11 +169,10 @@ overlay_sinks[river_mask .> Images.Gray{Images.N0f8}(0.0)] .= blue_color; # seen in the close-up view below. sf_nosink, fig_nosinks, sc_nosinks = plotgrid(grid_dtm, texture=overlay_nosinks) -fig_nosinks -set_camerapos(fig_nosinks, sc_nosinks, view1...) +set_camerapos(sc_nosinks, view1...) # Close-up view: -set_camerapos(fig_nosinks, sc_nosinks, view2...) +set_camerapos(sc_nosinks, view2...) # #### With sinks: # @@ -185,11 +182,10 @@ set_camerapos(fig_nosinks, sc_nosinks, view2...) # water. sf_sinks, fig_sinks, sc_sinks = plotgrid(grid_dtm, texture=overlay_sinks); -fig_sinks -set_camerapos(fig_sinks, sc_sinks, view1...) +set_camerapos(sc_sinks, view1...) # Close-up view: -set_camerapos(fig_sinks, sc_sinks, view2...) +set_camerapos(sc_sinks, view2...) # ## Visualize flow intensity # @@ -222,12 +218,11 @@ runoff, = watercourses(tstruct_sinks, filled_traps, sf_flow, fig_flow, sc_flow = plotgrid(grid_dtm, texture=runoff, colormap=:Blues) -fig_flow -set_camerapos(fig_flow, sc_flow, view1...) -# + +set_camerapos(sc_flow, view1...) ## Close-up view: -set_camerapos(fig_flow, sc_flow, view2...) +set_camerapos(sc_flow, view2...) # Only a few spots are colored non-white in the above plots. This is because # the flow across the terrain is highly concentrated in a few locations with @@ -237,13 +232,10 @@ set_camerapos(fig_flow, sc_flow, view2...) sf_flow_log, fig_flow_log, sc_flow_log = plotgrid(grid_dtm, texture=log10.(runoff), colormap=:Blues) -fig_flow_log -set_camerapos(fig_flow_log, sc_flow_log, view1...) - -# +set_camerapos(sc_flow_log, view1...) # Close-up view: -set_camerapos(fig_flow_log, sc_flow_log, view2...) +set_camerapos(sc_flow_log, view2...) # On these logarithmic plots, differences between strong and weak flows # are attenuated, and it is easier to see how the water flows. @@ -285,8 +277,7 @@ upstream_texture[pt_ix_upscaled] .= red_color ## Plot the grid sf_upstr_log, fig_upstr_log, sc_upstr_log = plotgrid(grid_dtm, texture=upstream_texture) -fig_upstr_log -set_camerapos(fig_upstr_log, sc_upstr_log, +set_camerapos(sc_upstr_log, GLMakie.Vec(-17, 202, 178), # observer position GLMakie.Vec(472, 113, -255), # observer target 0.8) @@ -407,13 +398,11 @@ end # Although the animation above can not be shown directly in the online # documentation, we can show the end states. To better see the differences, we # use closeup views: -f1 -set_camerapos(f1, sc1, view2...) +set_camerapos(sc1, view2...) # Terrain state at end of animated period, assuming no infiltration. # -f2 -set_camerapos(f2, sc2, view2...) +set_camerapos(sc2, view2...) # Terrain state at end of animated period, including the effect of infiltration. diff --git a/src/IOandplot.jl b/src/IOandplot.jl index 7025be6..705868b 100644 --- a/src/IOandplot.jl +++ b/src/IOandplot.jl @@ -164,11 +164,11 @@ end # ---------------------------------------------------------------------------- function _get_tex_transform(tex) - if _using_cairo() && eltype(tex) <: Real - x -> x - else - x -> reverse(transpose(x), dims=1) - end + # if _using_cairo() && eltype(tex) <: Real + # x -> x + # else + x -> reverse(transpose(x), dims=1) + #end #_using_glmakie() ? x -> reverse(transpose(x), dims=1) : x -> x end @@ -206,7 +206,7 @@ end # ---------------------------------------------------------------------------- """ - set_camerapos(figure, scene, cpos, ctarget, czoom) + set_camerapos(scene, cpos, ctarget, czoom) Set the camera position, target and zoom level for a given scene. @@ -214,7 +214,7 @@ This function is provided as a workaround to smooth over different idiosyncracies in camera handling for the Makie backends GLMakie and CairoMakie. """ -function set_camerapos(fig, scene, cpos, ctarget, czoom) +function set_camerapos(scene, cpos, ctarget, czoom) cam = Makie.cameracontrols(scene) upvec = Makie.Vec3f0(0.0, 0.0, 1.0) # if _using_glmakie() @@ -227,7 +227,7 @@ function set_camerapos(fig, scene, cpos, ctarget, czoom) Makie.update_cam!(scene, cpos, ctarget, upvec) #scene.center[] = false - if _using_cairo() - return fig - end + #if _using_cairo() + return scene + #end end