-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Makie
extension to Ribasim core (#1675)
Fixes #1672. I've added some basic functionality to plot storages and levels with Makie: ![basin_data](https://github.com/user-attachments/assets/c86a9ea5-4d81-4df9-84a5-2b2c2f087901) ![flow](https://github.com/user-attachments/assets/dcbd9d08-deab-450c-847c-e37fff39c536) (For conservative nodes I only plot the inflow) I'm first going to work on #1674 and then visualize that. --------- Co-authored-by: Martijn Visser <[email protected]>
- Loading branch information
1 parent
3bf29a6
commit 89e1f99
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module RibasimMakieExt | ||
using DataFrames: DataFrame | ||
using Makie: Figure, Axis, lines!, axislegend | ||
using Ribasim: Ribasim, Model | ||
|
||
function Ribasim.plot_basin_data!(model::Model, ax::Axis, column::Symbol) | ||
basin_data = DataFrame(Ribasim.basin_table(model)) | ||
for node_id in unique(basin_data.node_id) | ||
group = filter(:node_id => ==(node_id), basin_data) | ||
lines!(ax, group.time, getproperty(group, column); label = "Basin #$node_id") | ||
end | ||
|
||
axislegend(ax) | ||
return nothing | ||
end | ||
|
||
function Ribasim.plot_basin_data(model::Model) | ||
f = Figure() | ||
ax1 = Axis(f[1, 1]; ylabel = "level [m]") | ||
ax2 = Axis(f[2, 1]; xlabel = "time", ylabel = "storage [m³]") | ||
Ribasim.plot_basin_data!(model, ax1, :level) | ||
Ribasim.plot_basin_data!(model, ax2, :storage) | ||
f | ||
end | ||
|
||
function Ribasim.plot_flow!( | ||
model::Model, | ||
ax::Axis, | ||
edge_id::Int32; | ||
skip_conservative_out = false, | ||
) | ||
flow_data = DataFrame(Ribasim.flow_table(model)) | ||
flow_data = filter(:edge_id => ==(edge_id), flow_data) | ||
first_row = first(flow_data) | ||
# Skip outflows of conservative nodes because these are the same as the inflows | ||
if skip_conservative_out && | ||
Ribasim.NodeType.T(first_row.from_node_type) in Ribasim.conservative_nodetypes | ||
return nothing | ||
end | ||
label = "$(first_row.from_node_type) #$(first_row.from_node_id) → $(first_row.to_node_type) #$(first_row.to_node_id)" | ||
lines!(ax, flow_data.time, flow_data.flow_rate; label) | ||
return nothing | ||
end | ||
|
||
function Ribasim.plot_flow(model::Model) | ||
f = Figure() | ||
ax = Axis(f[1, 1]; xlabel = "time", ylabel = "flow rate [m³s⁻¹]") | ||
edge_ids = unique(Ribasim.flow_table(model).edge_id) | ||
for edge_id in edge_ids | ||
Ribasim.plot_flow!(model, ax, edge_id; skip_conservative_out = true) | ||
end | ||
axislegend(ax) | ||
f | ||
end | ||
|
||
end # module RibasimMakieExt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters