Skip to content

Commit 98765cf

Browse files
committed
starttime from forcing.nc and fews_run
Change `starttime` from forcing.nc: first timestep in forcing.nc minus 1 model timestep, so the first forcing timestep is included in the Wflow run. For a `fews_run` the `starttime` is equal to the first forcing timestep (first forcing timestep is excluded).
1 parent 85b144a commit 98765cf

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

docs/src/user_guide/additional_options.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ specified in the main section of the TOML configuration file:
267267
fews_run = true # optional, default value is false
268268
```
269269

270-
This ensures that a different format for the log file is used such that each log message
271-
takes up only one line. That meets the [General Adapter
270+
This ensures that Wflow offsets the time handling, to meet the expectations of Delft-FEWS.
271+
272+
It also uses a different format for the log file such that each log message takes up only
273+
one line. That meets the [General Adapter
272274
logFile](https://publicwiki.deltares.nl/display/FEWSDOC/05+General+Adapter+Module#id-05GeneralAdapterModule-logFile)
273275
expectations, which then can get parsed with these Delft-FEWS log parsing settings:
274276

src/Wflow.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Clock(config, reader)
5858
# and add them to the config
5959
starttime = get(config, "starttime", nothing)
6060
if starttime === nothing
61-
starttime = first(nctimes)
61+
starttime = first(nctimes) - Δt
6262
config.starttime = starttime
6363
end
6464
endtime = get(config, "endtime", nothing)
@@ -68,6 +68,10 @@ function Clock(config, reader)
6868
end
6969

7070
calendar = get(config, "calendar", "standard")::String
71+
fews_run = get(config, "fews_run", false)::Bool
72+
if fews_run
73+
config.starttime = starttime + Δt
74+
end
7175
starttime = cftime(config.starttime, calendar)
7276

7377
Clock(starttime, 0, Δt)

test/io.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ end
7171
pop!(Dict(config), "timestepsecs")
7272
clock = Wflow.Clock(config, reader)
7373

74-
@test clock.time == DateTimeProlepticGregorian(2000, 1, 2)
74+
@test clock.time == DateTimeProlepticGregorian(2000, 1, 1)
7575
@test clock.iteration == 0
7676
@test clock.Δt == Second(Day(1))
7777
# test that the missing keys have been added to the config
78-
@test config.starttime == DateTime(2000, 1, 2)
78+
@test config.starttime == DateTime(2000, 1, 1)
7979
@test config.endtime == DateTime(2001, 1, 1)
8080
@test config.timestepsecs == 86400
8181

test/run.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ config.output.path =
4646
model = Wflow.initialize_sbm_model(config)
4747
Wflow.run(model)
4848

49+
50+
# second half of January, warm start, fews_run set to true, and starttime set one day earlier
51+
# to match endtime of part 1
52+
config.starttime = DateTime("2000-01-14T00:00:00")
53+
config.endtime = DateTime("2000-02-01T00:00:00")
54+
config.model.reinit = false # warm start
55+
config.fews_run = true
56+
config.state.path_input =
57+
joinpath(dirname(tomlpath), "data/state-test/outstates-moselle-january-1of2.nc")
58+
config.state.path_output = joinpath(
59+
dirname(tomlpath),
60+
"data/state-test/outstates-moselle-january-2of2-fews_run.nc",
61+
)
62+
config.output.path =
63+
joinpath(dirname(tomlpath), "data/state-test/output-moselle-january-2of2-fews_run.nc")
64+
model = Wflow.initialize_sbm_model(config)
65+
Wflow.run(model)
66+
4967
# verify that there are minimal differences in the end state of the two runs
5068
endstate_one_run_path =
5169
joinpath(dirname(tomlpath), "data/state-test/outstates-moselle-january.nc")
@@ -64,3 +82,22 @@ varnames = setdiff(keys(endstate_restart), keys(endstate_restart.dim))
6482
@test maxdiff < 1e-9
6583
end
6684
end
85+
86+
# the fews_run restart should match the other restart exactly
87+
endstate_fewsrun_path = joinpath(
88+
dirname(tomlpath),
89+
"data/state-test/outstates-moselle-january-2of2-fews_run.nc",
90+
)
91+
endstate_restart_path =
92+
joinpath(dirname(tomlpath), "data/state-test/outstates-moselle-january-2of2.nc")
93+
endstate_fewsrun = NCDataset(endstate_fewsrun_path)
94+
endstate_restart = NCDataset(endstate_restart_path)
95+
96+
varnames = setdiff(keys(endstate_restart), keys(endstate_restart.dim))
97+
@testset "fews_run" begin
98+
for varname in varnames
99+
a = endstate_fewsrun[varname][:]
100+
b = endstate_restart[varname][:]
101+
@test all(skipmissing(a) .== skipmissing(b))
102+
end
103+
end

0 commit comments

Comments
 (0)