Skip to content

Commit

Permalink
Set timestamps at the beginning of the period
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Feb 26, 2024
1 parent 24a7609 commit b20c814
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion core/src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ function flow_table(
nflow = length(unique_edge_ids_flow)
ntsteps = length(t)

time = repeat(datetime_since.(t, config.starttime); inner = nflow)
# the timestamp should represent the start of the period, not the end
t_starts = circshift(t, 1)
t_starts[1] = 0.0
time = repeat(datetime_since.(t_starts, config.starttime); inner = nflow)
edge_id = repeat(unique_edge_ids_flow; outer = ntsteps)
from_node_type = repeat(from_node_type; outer = ntsteps)
from_node_id = repeat(from_node_id; outer = ntsteps)
Expand Down
4 changes: 2 additions & 2 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
end

@testset "Results values" begin
@test flow.time[1] > DateTime(2020)
@test flow.time[1] == DateTime(2020)
@test coalesce.(flow.edge_id[1:4], -1) == [-1, -1, 9, 11]
@test flow.from_node_id[1:4] == [6, typemax(Int), 0, 6]
@test flow.to_node_id[1:4] == [6, typemax(Int), typemax(Int), 0]
Expand Down Expand Up @@ -200,7 +200,7 @@ end
table = Ribasim.flow_table(model)

# flows are recorded at the end of each period, and are undefined at the start
@test unique(table.time) == Ribasim.datetimes(model)[2:end]
@test unique(table.time) == Ribasim.datetimes(model)[1:(end - 1)]

# inflow = outflow over FractionalFlow
t = table.time[1]
Expand Down

0 comments on commit b20c814

Please sign in to comment.