Skip to content

Commit 43eecc3

Browse files
Update all examples
Use `pathof()` to point to example test data Add example of custom calibration approaches
1 parent 0788c36 commit 43eecc3

27 files changed

+435
-118
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ using CSV, DataFrames, YAML
9292
using StatsPlots
9393
using Streamfall
9494

95-
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
95+
data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
9696

9797
# Load data file which holds observed streamflow, precipitation and PET data
9898
obs_data = CSV.read(
99-
joinpath(example_data_dir, "cotter/climate/CAMELS-AUS_410730.csv"),
99+
joinpath(data_dir, "cotter/climate/CAMELS-AUS_410730.csv"),
100100
DataFrame;
101101
comment="#"
102102
)
@@ -225,12 +225,12 @@ using Streamfall
225225

226226
# Load a network from a file, providing a name for the network and the file path.
227227
# Creates a graph representation of the stream with associated metadata.
228-
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
229-
sn = load_network("Example Network", joinpath(example_data_dir, "campaspe/campaspe_network.yml"))
228+
data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
229+
sn = load_network("Example Network", joinpath(data_dir, "campaspe/campaspe_network.yml"))
230230

231231
# Load climate data, in this case from a CSV file with data for all nodes.
232232
# Indicate which columns are precipitation and evaporation data based on partial identifiers
233-
climate = Climate(joinpath(example_data_dir, "campaspe/climate/climate.csv"), "_rain", "_evap")
233+
climate = Climate(joinpath(data_dir, "campaspe/climate/climate.csv"), "_rain", "_evap")
234234

235235
# This runs an entire stream network
236236
@info "Running an example stream..."

docs/make.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
push!(LOAD_PATH,"../src/")
1+
push!(LOAD_PATH, "../src/")
22

33
# using Pkg
44

@@ -8,28 +8,29 @@ using Documenter, Streamfall
88

99

1010
makedocs(sitename="Streamfall Documentation",
11-
format = Documenter.HTML(
12-
prettyurls = get(ENV, "CI", nothing) == "true"
11+
format=Documenter.HTML(
12+
prettyurls=get(ENV, "CI", nothing) == "true"
1313
),
14-
pages = [
14+
pages=[
1515
"index.md",
1616
"primer.md",
1717
"expected_data_formats.md",
1818
"Examples" => [
1919
"examples/examples.md",
2020
"examples/node_creation.md",
2121
"examples/network_loading.md",
22+
"Model evaluation" => [
23+
"examples/evaluation/simple_showcase.md",
24+
"examples/evaluation/model_comparison.md",
25+
"examples/evaluation/simple_multisystem.md",
26+
],
2227
"Calibration" => [
2328
# "examples/calibration_setup.md",
24-
"examples/calibration.md",
25-
],
26-
"Model evaluation" => [
27-
"examples/simple_showcase.md",
28-
"examples/model_comparison.md",
29-
"examples/simple_multisystem.md",
29+
"examples/calibration/calibration.md",
30+
"examples/calibration/custom_calibration.md",
3031
],
3132
"Ensemble modeling" => [
32-
"examples/weighted_ensembles.md"
33+
"examples/ensembles/weighted_ensembles.md"
3334
]
3435
],
3536
"API" => [
@@ -51,8 +52,8 @@ makedocs(sitename="Streamfall Documentation",
5152
)
5253

5354
deploydocs(
54-
repo = "github.com/ConnectedSystems/Streamfall.jl.git",
55-
devbranch = "main",
55+
repo="github.com/ConnectedSystems/Streamfall.jl.git",
56+
devbranch="main",
5657
target="build",
5758
deps=nothing,
5859
make=nothing
101 KB
Loading
101 KB
Loading
94.8 KB
Loading

docs/src/examples/calibration.md renamed to docs/src/examples/calibration/calibration.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,41 @@ Data is prepped with the script `campaspe_data_prep.jl` in the `test/data/campas
99
directory.
1010
"""
1111

12-
using OrderedCollections
13-
using Glob
14-
1512
using Statistics
16-
using CSV, DataFrames, YAML
13+
using CSV, YAML, DataFrames
1714
using Streamfall
1815

1916
# Import visualization packages to compile extensions
20-
using Plots, GraphPlot
21-
17+
using StatsPlots, GraphPlot
2218

23-
sn = load_network("Example Network", "../test/data/campaspe/campaspe_network.yml")
19+
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
20+
sn = load_network(
21+
"Example Network",
22+
joinpath(example_data_dir, "campaspe/campaspe_network.yml")
23+
)
2424

2525
# The Campaspe catchment is represented as a network of eight nodes, including one dam.
2626
# All nodes use the IHACRES_CMD rainfall-runoff model.
2727
plot_network(sn)
2828

2929
# Load climate data - in this case from a CSV file with data for all nodes.
3030
# Indicate which columns are precipitation and evaporation data based on partial identifiers
31-
climate = Climate("../test/data/campaspe/climate/climate.csv", "_rain", "_evap")
31+
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data/campaspe")
32+
climate = Climate(joinpath(example_data_dir, "climate/climate.csv"), "_rain", "_evap")
3233

3334
# Historic flows and dam level data
3435
calib_data = CSV.read(
35-
"../test/data/campaspe/gauges/outflow_and_level.csv",
36+
joinpath(example_data_dir, "gauges/outflow_and_level.csv"),
3637
DataFrame;
3738
comment="#"
3839
)
3940

4041
# Historic extractions from the dam
41-
extraction_data = CSV.read("../test/data/campaspe/gauges/dam_extraction.csv", DataFrame; comment="#")
42+
extraction_data = CSV.read(
43+
joinpath(example_data_dir, "gauges/dam_extraction.csv"),
44+
DataFrame;
45+
comment="#"
46+
)
4247

4348
# We now have a dataset for calibration (`calib_data`) and a dataset indicating the
4449
# historic dam extractions (`extraction_data`).
@@ -79,8 +84,9 @@ calibrate!(
7984
MaxTime=60.0
8085
);
8186

82-
# Could calibrate a specific node, assuming all nodes upstream have already been calibrated
83-
# Set `calibrate_all=true` to calibrate all upstream nodes as well.
87+
# A specific node can also be calibrated, assuming all nodes upstream have already been
88+
# calibrated.
89+
# Otherwise, set `calibrate_all=true` to calibrate all upstream nodes as well.
8490
# To produce the results shown below, the node upstream from the dam was calibrated an
8591
# additional 2 hours.
8692
# calibrate!(
@@ -102,11 +108,11 @@ Streamfall.NSE(dam_obs[366:end], dam_sim[366:end])
102108
Streamfall.mKGE(dam_obs[366:end], dam_sim[366:end])
103109

104110
# Plot results
105-
f = quickplot(dam_obs, dam_sim, climate, "Modelled - 406000", false; burn_in=366)
106-
savefig(f, "example_dam_level.png")
111+
f = quickplot(dam_obs, dam_sim, climate; label="Modelled - 406000", log=false, burn_in=366)
112+
# savefig(f, "example_dam_level.png")
107113

108114
# Save calibrated network to a file
109-
save_network(sn, "example_network_calibrated.yml")
115+
# save_network(sn, "example_network_calibrated.yml")
110116

111117
# Illustrating that the re-loaded network reproduces the results as above
112118
sn2 = load_network("Calibrated Example", "example_network_calibrated.yml")

docs/src/examples/calibration_setup.md renamed to docs/src/examples/calibration/calibration_setup.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ The calibration examples all rely on the functions shown here.
44

55
List of metrics provided by Streamfall can be found in [Included metrics](@ref)
66

7+
The example here assumes the data has been installed or copied locally.
8+
Alternatively, download the `test/data` directory from the project repository and
9+
change the `DATA_PATH` variable below accordingly.
710

811
## Importing shared/common packages
912

@@ -12,19 +15,16 @@ List of metrics provided by Streamfall can be found in [Included metrics](@ref)
1215
using Statistics, DataFrames, CSV
1316
using Distributed, BlackBoxOptim
1417

15-
using ModelParameters
16-
using Graphs, MetaGraphs
17-
using YAML, Plots
18+
using YAML
19+
using StatsPlots, GraphPlot
1820
using Streamfall
1921
```
2022

21-
2223
## Load network specification
2324

24-
Note that the `DATA_PATH` is pointing to the `test/data/campaspe/` directory.
25-
2625
```julia
2726
# Load and generate stream network
27+
DATA_PATH = joinpath(dirname(dirname(pathof(Streamfall))), "test/data/campaspe/")
2828
network = YAML.load_file(joinpath(DATA_PATH, "campaspe_network.yml"))
2929
sn = create_network("Example Network", network)
3030
```
@@ -34,14 +34,15 @@ sn = create_network("Example Network", network)
3434
```julia
3535
# Load climate data
3636
date_format = "YYYY-mm-dd"
37-
climate_data = CSV.File(joinpath(data_path, "climate/climate_historic.csv"),
37+
climate_data = CSV.read(joinpath(DATA_PATH, "climate/climate_historic.csv"),
3838
comment="#",
39-
dateformat=date_format) |> DataFrame
39+
dateformat=date_format, DataFrame)
40+
41+
dam_level_fn = joinpath(DATA_PATH, "gauges/406000_historic_levels_for_fit.csv")
42+
hist_dam_levels = CSV.read(dam_level_fn, dateformat=date_format, DataFrame)
4043

41-
dam_level_fn = joinpath(data_path, "dam/historic_levels_for_fit.csv")
42-
dam_releases_fn = joinpath(data_path, "dam/historic_releases.csv")
43-
hist_dam_levels = CSV.File(dam_level_fn, dateformat=date_format) |> DataFrame
44-
hist_dam_releases = CSV.File(dam_releases_fn, dateformat=date_format) |> DataFrame
44+
dam_releases_fn = joinpath(DATA_PATH, "gauges/406000_historic_outflow.csv")
45+
hist_dam_releases = CSV.read(dam_releases_fn, dateformat=date_format, DataFrame)
4546

4647
# Subset to same range
4748
climate_data, hist_dam_levels, hist_dam_releases = Streamfall.align_time_frame(climate_data,

0 commit comments

Comments
 (0)