|
3 | 3 | This example showcases a comparison of models using multi-processing. |
4 | 4 |
|
5 | 5 | ```julia |
6 | | -using Distributed, Plots, StatsPlots |
| 6 | +using Distributed |
| 7 | +using Plots |
7 | 8 |
|
8 | 9 | N = 4 |
9 | 10 | if nworkers() < N |
10 | 11 | addprocs(N, exeflags="--project=$(Base.active_project())") |
11 | 12 | end |
12 | 13 |
|
13 | 14 | @everywhere begin |
14 | | - using DataFrames, CSV |
15 | | - using Streamfall, BlackBoxOptim |
| 15 | + using CSV, DataFrames |
| 16 | + using Streamfall |
16 | 17 |
|
17 | 18 | HERE = @__DIR__ |
18 | 19 | DATA_PATH = joinpath(HERE, "../test/data/cotter/") |
19 | 20 |
|
20 | 21 | # Load observations |
21 | | - date_format = "YYYY-mm-dd" |
22 | | - obs_data = CSV.File(joinpath(DATA_PATH, "climate/CAMELS-AUS_410730.csv"), |
23 | | - comment="#", |
24 | | - dateformat=date_format) |> DataFrame |
25 | | - |
26 | | - hist_streamflow = obs_data[:, ["Date", "410730_Q"]] |
| 22 | + date_format = |
| 23 | + obs_data = CSV.read( |
| 24 | + joinpath(DATA_PATH, "climate/CAMELS-AUS_410730.csv"), |
| 25 | + DataFrame; |
| 26 | + comment="#", |
| 27 | + dateformat="YYYY-mm-dd" |
| 28 | + ) |
| 29 | + |
| 30 | + hist_streamflow = extract_flow(obs_data, "410730") |
| 31 | + # hist_streamflow = obs_data[:, ["Date", "410730_Q"]] |
27 | 32 | climate_data = obs_data[:, ["Date", "410730_P", "410730_PET"]] |
28 | 33 | climate = Climate(climate_data, "_P", "_PET") |
29 | 34 |
|
|
39 | 44 | hymod_node = create_node(SimpleHyModNode, "410730", 129.2) |
40 | 45 | gr4j_node = create_node(GR4JNode, "410730", 129.2) |
41 | 46 | symhyd_node = create_node(SYMHYDNode, "410730", 129.2) |
42 | | -ihacres_node = create_node(BilinearNode, "410730", 129.2) |
| 47 | +ihacres_node = create_node(IHACRESBilinearNode, "410730", 129.2) |
43 | 48 |
|
44 | 49 |
|
45 | 50 | # Calibrate each node separately using multiprocessing |
46 | | -node_names = ["HyMod", "GR4J", "SYMHYD", "IHACRES"] |
| 51 | +node_types = ["HyMod", "GR4J", "SYMHYD", "IHACRES"] |
47 | 52 | node_list = [hymod_node, gr4j_node, symhyd_node, ihacres_node] |
48 | 53 | result = pmap(opt_func, node_list) |
49 | 54 |
|
50 | | - |
51 | 55 | # Create comparison plot |
52 | | -Qo = hist_streamflow[:, "410730_Q"] |
| 56 | +Qo = hist_streamflow[:, "410730"] |
53 | 57 | Qo_burn = Qo[burn_in:end] |
54 | 58 | res_plots = [] |
55 | 59 |
|
56 | | -for ((res, opt), node, n_name) in zip(result, node_list, node_names) |
| 60 | +for ((res, opt), node, n_name) in zip(result, node_list, node_types) |
57 | 61 | update_params!(node, best_candidate(res)...) |
58 | 62 | reset!(node) |
59 | 63 | run_node!(node, climate) |
60 | 64 |
|
61 | 65 | node_burn = node.outflow[burn_in:end] |
62 | 66 |
|
63 | | - res_plot = quickplot(Qo, node, climate, n_name; burn_in=366) |
| 67 | + # Plot log scale |
| 68 | + res_plot = quickplot(Qo, node, climate, n_name, true; burn_in=366) |
64 | 69 | push!(res_plots, res_plot) |
65 | 70 | end |
66 | 71 |
|
67 | | - |
68 | 72 | combined_plot = plot( |
69 | 73 | [rplt for rplt in res_plots]..., |
70 | 74 | layout=(length(node_list),1), |
|
0 commit comments