Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add the endtime to basin.arrow results #1359

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions core/src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,27 @@ function basin_table(
node_id::Vector{Int32},
storage::Vector{Float64},
level::Vector{Float64},
precipitation::Vector{Union{Missing, Float64}},
evaporation::Vector{Union{Missing, Float64}},
drainage::Vector{Union{Missing, Float64}},
infiltration::Vector{Union{Missing, Float64}},
precipitation::Vector{Float64},
evaporation::Vector{Float64},
drainage::Vector{Float64},
infiltration::Vector{Float64},
}
(; saved) = model
(; vertical_flux) = saved

# The last timestep is not included; there is no period over which to compute flows.
data = get_storages_and_levels(model)
storage = vec(data.storage)
level = vec(data.level)
storage = vec(data.storage[:, begin:(end - 1)])
level = vec(data.level[:, begin:(end - 1)])

nbasin = length(data.node_id)
ntsteps = length(data.time)
ntsteps = length(data.time) - 1
nrows = nbasin * ntsteps

precipitation = Vector{Union{Missing, Float64}}(missing, nrows)
evaporation = Vector{Union{Missing, Float64}}(missing, nrows)
drainage = Vector{Union{Missing, Float64}}(missing, nrows)
infiltration = Vector{Union{Missing, Float64}}(missing, nrows)
precipitation = zeros(nrows)
evaporation = zeros(nrows)
drainage = zeros(nrows)
infiltration = zeros(nrows)

idx_row = 0

Expand All @@ -118,7 +119,7 @@ function basin_table(
end
end

time = repeat(data.time; inner = nbasin)
time = repeat(data.time[begin:(end - 1)]; inner = nbasin)
node_id = repeat(Int32.(data.node_id); outer = ntsteps)

return (;
Expand Down
13 changes: 2 additions & 11 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,7 @@
:drainage,
:infiltration,
),
(
DateTime,
Int32,
Float64,
Float64,
Union{Missing, Float64},
Union{Missing, Float64},
Union{Missing, Float64},
Union{Missing, Float64},
),
(DateTime, Int32, Float64, Float64, Float64, Float64, Float64, Float64),
)
@test Tables.schema(control) == Tables.Schema(
(:time, :control_node_id, :truth_state, :control_state),
Expand Down Expand Up @@ -108,7 +99,7 @@
@test nsaved > 10
# t0 has no flow, 2 flow edges
@test nrow(flow) == (nsaved - 1) * 2
@test nrow(basin) == nsaved
@test nrow(basin) == nsaved - 1
@test nrow(control) == 0
@test nrow(allocation) == 0
@test nrow(subgrid) == nsaved * length(p.subgrid.level)
Expand Down
14 changes: 3 additions & 11 deletions core/test/time_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ end
n_basin = length(basin.node_id)
basin_table = DataFrame(Ribasim.basin_table(model))

# No vertical flux data for last saveat
t_end = last(basin_table).time
data_end = filter(:time => t -> t == t_end, basin_table)
@test all(ismissing.(data_end.precipitation))
@test all(ismissing.(data_end.evaporation))
@test all(ismissing.(data_end.drainage))
@test all(ismissing.(data_end.infiltration))

time_table = DataFrame(basin.time)
t_end = time_table.time[end]
filter!(:time => t -> t !== t_end, time_table)

time_table[!, "basin_idx"] = [
Ribasim.id_index(basin.node_id, node_id)[2] for
node_id in Ribasim.NodeID.(:Basin, time_table.node_id)
Expand All @@ -66,9 +61,6 @@ end
end
end

filter!(:time => t -> t !== t_end, basin_table)
filter!(:time => t -> t !== t_end, time_table)

@test all(
isapprox(
basin_table.evaporation,
Expand Down
22 changes: 11 additions & 11 deletions docs/core/usage.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,20 @@ derivative | Float64 | - | -
The basin table contains:

- results of the storage and level of each basin, which are instantaneous values;
- results of the vertical fluxes on each basin, which are mean values over the `saveat` intervals. In the time column the start of the period is indicated. This means that for the final time in the table the mean vertical fluxes are not computed, and thus are `missing`.
- results of the vertical fluxes on each basin, which are mean values over the `saveat` intervals. In the time column the start of the period is indicated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also explicitly indicate here that the final state of the model is absent?


The initial condition is also written to the file.

column | type | unit
------------- | ------------------------ | ----
time | DateTime | -
node_id | Int32 | -
storage | Float64 | $m^3$
level | Float64 | $m$
precipitation | Union{Float64, Missing} | $m^3 s^{-1}$
evaporation | Union{Float64, Missing} | $m^3 s^{-1}$
drainage | Union{Float64, Missing} | $m^3 s^{-1}$
infiltration | Union{Float64, Missing} | $m^3 s^{-1}$
column | type | unit
------------- | ---------| ----
time | DateTime | -
node_id | Int32 | -
storage | Float64 | $m^3$
level | Float64 | $m$
precipitation | Float64 | $m^3 s^{-1}$
evaporation | Float64 | $m^3 s^{-1}$
drainage | Float64 | $m^3 s^{-1}$
infiltration | Float64 | $m^3 s^{-1}$


The table is sorted by time, and per time it is sorted by `node_id`.
Expand Down
Loading