diff --git a/examples/routing/gamma_IRF.jl b/examples/routing/gamma_IRF.jl index ce535e3..e9fcebf 100644 --- a/examples/routing/gamma_IRF.jl +++ b/examples/routing/gamma_IRF.jl @@ -2,16 +2,10 @@ using ClimaRivers using JSON, Dates # build hillslope model -shape = 1.5 -timescale = 1.0 -t_max_hs = 60.0 -hillslope = MizurouteHillslopeV1{Float64}(shape, timescale, t_max_hs) +hillslope = MizurouteHillslopeV1{Float64}() # build channel model -wave_velocity = 1.5 * 86400 -diffusivity = 8000 * 86400 -t_max_ch = 120.0 -channel = MizurouteChannelV1{Float64}(wave_velocity, diffusivity, t_max_ch) +channel = MizurouteChannelV1{Float64}() # build model river_model = HillslopeChannelRiverModel(hillslope, channel) @@ -19,18 +13,19 @@ river_model = HillslopeChannelRiverModel(hillslope, channel) # build static environment routing_lv_basins_dir = "/groups/esm/achiang/ClimaRivers.jl/data/routing/routing_lvs/routing_lvs_lv05" attributes_dir = "/groups/esm/achiang/ClimaRivers.jl/data/routing/attributes/attributes_lv05" -static_env = StaticEnvironment(routing_lv_basins_dir, attributes_dir) +graph_dict = JSON.parsefile( + "/groups/esm/achiang/ClimaRivers.jl/data/routing/graphs/graph_lv05.json", +) +static_env = StaticEnvironment(routing_lv_basins_dir, attributes_dir, graph_dict) # build dynamic environment -timeseries_dir = "/groups/esm/achiang/ClimaRivers.jl/data/routing/timeseries/timeseries_lv05" +forcing_timeseries_dir = "/groups/esm/achiang/ClimaRivers.jl/data/routing/timeseries/timeseries_lv05" output_dir = "/groups/esm/achiang/ClimaRivers.jl/data/routing/simulations/simulations_lv05/gamma_IRF" -dynamic_env = DynamicEnvironment(timeseries_dir, output_dir) +dynamic_env = DynamicEnvironment(forcing_timeseries_dir, output_dir) # build environment -graph_dict = JSON.parsefile( - "/groups/esm/achiang/ClimaRivers.jl/data/routing/graphs/graph_lv05.json", -) -env = Environment(static_env, dynamic_env, graph_dict) + +env = Environment(static_env, dynamic_env) ## evolutionary model, evolving a state over time model_types = ["instant"] diff --git a/examples/routing/mini_gamma_IRF.jl b/examples/routing/mini_gamma_IRF.jl index 37565c9..2ced7c0 100644 --- a/examples/routing/mini_gamma_IRF.jl +++ b/examples/routing/mini_gamma_IRF.jl @@ -2,41 +2,36 @@ using ClimaRivers using JSON, Dates # build hillslope model -shape = 1.5 -timescale = 1.0 -t_max_hs = 60.0 -hillslope = MizurouteHillslopeV1{Float64}(shape, timescale, t_max_hs) +hillslope = MizurouteHillslopeV1{Float64}() # build channel model -wave_velocity = 1.5 * 86400 -diffusivity = 8000 * 86400 -t_max_ch = 120.0 -channel = MizurouteChannelV1{Float64}(wave_velocity, diffusivity, t_max_ch) +channel = MizurouteChannelV1{Float64}() # build model river_model = HillslopeChannelRiverModel(hillslope, channel) -# build static environment +# build environment data_file_path = joinpath(@__DIR__,"..","..","mini_data","routing") + +# build static environment @info "reading data files from $(data_file_path)" +graph_dict = JSON.parsefile( + joinpath(data_file_path, "graphs","graph_lv05.json"), +) routing_lv_basins_dir = joinpath(data_file_path, "routing_lvs","routing_lvs_lv05") attributes_dir = joinpath(data_file_path, "attributes","attributes_lv05") -static_env = StaticEnvironment(routing_lv_basins_dir, attributes_dir) +static_env = StaticEnvironment(routing_lv_basins_dir, attributes_dir, graph_dict) # build dynamic environment -timeseries_dir = joinpath(data_file_path, "timeseries","timeseries_lv05") +forcing_timeseries_dir = joinpath(data_file_path, "timeseries","timeseries_lv05") output_dir = joinpath(data_file_path, "simulations","simulations_lv05","gamma_IRF") @info "creating output" if !isdir(output_dir) mkpath(output_dir) end -dynamic_env = DynamicEnvironment(timeseries_dir, output_dir) +dynamic_env = DynamicEnvironment(forcing_timeseries_dir, output_dir) -# build environment -graph_dict = JSON.parsefile( - joinpath(data_file_path, "graphs","graph_lv05.json"), -) -env = Environment(static_env, dynamic_env, graph_dict) +env = Environment(static_env, dynamic_env) ## evolutionary model, evolving a state over time model_types = ["instant"] @@ -44,7 +39,6 @@ model_type = model_types[1] start_date = Date("1996-01-01", "yyyy-mm-dd") end_date = Date("2014-12-31", "yyyy-mm-dd") -dates = collect(start_date:Day(1):end_date) # streamflow = zeros(dates,basins) hillslope_data = zeros(10, 10) # Replace with actual data once implemented diff --git a/src/Environments.jl b/src/Environments.jl index 29d6a88..66debcf 100644 --- a/src/Environments.jl +++ b/src/Environments.jl @@ -1,24 +1,27 @@ # Contains the structs that define the static and dynamic environment that configures/forces the river model. export StaticEnvironment, DynamicEnvironment, Environment +# Static Data Objects struct StaticEnvironment - # static data objects + "Directory containing list of all basins" routing_lv_basins_dir::String + "Directory containing attribute csv" attributes_dir::String + "Basin mapping dictionary" + graph_dict::Dict end +# Dynamic Data Objects struct DynamicEnvironment - # timeseries objects - # date/time - index map - timeseries_dir::String + "Directory containing forcing timeseries csv" + forcing_timeseries_dir::String + "Directory to store simulation results" output_dir::String end struct Environment{SE <: StaticEnvironment, DE <: DynamicEnvironment} + "Static data objects" static_env::SE - dyn_env::DE - graph_dict::Dict + "Dynamic data objects" + dynamic_env::DE end - -# get_static(env, :name) -# get_dynamic(env, :name, time=date/time) diff --git a/src/MizurouteV1.jl b/src/MizurouteV1.jl index 5888e5b..43f02f5 100644 --- a/src/MizurouteV1.jl +++ b/src/MizurouteV1.jl @@ -7,7 +7,7 @@ struct MizurouteHillslopeV1{FT <: AbstractFloat} <: AbstractHillslopeModel shape::FT "Timescale factor, θ [day]" timescale::FT - "Max time" + "Max time (days)" t_max::FT end # MizurouteHillslopeV1(x,y) @@ -26,13 +26,13 @@ struct MizurouteChannelV1{FT <: AbstractFloat} <: AbstractChannelModel wave_velocity::FT "Diffusivity, D [m²/day] (adjusted)" diffusivity::FT - "Max time" + "Max time (days)" t_max::FT end function MizurouteChannelV1{FT}() where {FT <: AbstractFloat} wave_velocity = FT(1.5 * 86400) - diffusivity = FT(8000 * 86400) + diffusivity = FT(800 * 86400) t_max = FT(120.0) return MizurouteChannelV1(wave_velocity, diffusivity, t_max) end diff --git a/src/Routing.jl b/src/Routing.jl index cc909c8..857b2b0 100644 --- a/src/Routing.jl +++ b/src/Routing.jl @@ -58,8 +58,8 @@ function update_state_from_hillslope!( day_to_s = 86400 km²_to_m² = 1000000 - timeseries_dir = env.dyn_env.timeseries_dir - output_dir = env.dyn_env.output_dir + forcing_timeseries_dir = env.dynamic_env.forcing_timeseries_dir + output_dir = env.dynamic_env.output_dir dates = collect(start_date:Day(1):end_date) routing_lv_basins_dir = env.static_env.routing_lv_basins_dir @@ -82,7 +82,7 @@ function update_state_from_hillslope!( # make new txt file for basin_id in all_basin_ids # routing_lv_basins timeseries_df = - CSV.read(joinpath(timeseries_dir, "basin_$basin_id.csv"), DataFrame) + CSV.read(joinpath(forcing_timeseries_dir, "basin_$basin_id.csv"), DataFrame) filtered_df = filter(row -> start_date <= row[:date] <= end_date, timeseries_df) basin_area = @@ -139,9 +139,10 @@ function update_state_from_channel!( km_to_m = 1e3 - output_dir = env.dyn_env.output_dir - timeseries_dir = env.dyn_env.timeseries_dir + output_dir = env.dynamic_env.output_dir + forcing_timeseries_dir = env.dynamic_env.forcing_timeseries_dir + graph_dict = env.static_env.graph_dict routing_lv_basins_dir = env.static_env.routing_lv_basins_dir attributes_df = CSV.read( joinpath(env.static_env.attributes_dir, "attributes.csv"), @@ -168,7 +169,7 @@ function update_state_from_channel!( # Iterate over upstreams upstream_basin_list = - get_upstream_basins(string(basin_id), env.graph_dict) + get_upstream_basins(string(basin_id), graph_dict) for up_basin in upstream_basin_list # Read DataFrame with inputs from upstream up_timeseries_df = CSV.read(