Skip to content

Commit

Permalink
minor changes from pair program session
Browse files Browse the repository at this point in the history
  • Loading branch information
kmdeck committed Nov 5, 2024
1 parent 31505d7 commit 44c86b1
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/Routing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,50 @@ end
# Specific hillslope-channel models loaded here:
include("MizurouteV1.jl")

# only for one routing lv
# For each routing level, do this
# Questions: how to make this for a single step, and how to broadcast over basins
function update_state_from_hillslope!(
river_state::RS,
hillslope_model::HM,
env::E,
) where {RS <: RiverState, HM <: AbstractHillslopeModel, E <: Environment}
static_env::SE,
dyn_env::DE
) where {RS <: RiverState, HM <: AbstractHillslopeModel, SE <: StaticEnvironment, DE <: DynamicEnvironmen}
# Constants
day_to_s = 86400
km²_to_m² = 1000000

routing_lv_basins = env.static_env.routing_lv_basins
start_date = env.dyn_env.start_date
end_date = env.dyn_env.end_date
dates = collect(start_date:Day(1):end_date)
attributes_df = env.static_env.attributes_df #may need to load into static_env during compute state
timeseries_dir = env.dyn_env.timeseries_dir
routing_lv_basins = static_env.routing_lv_basins
start_date = dyn_env.start_date
end_date = dyn_env.end_date
dates = collect(start_date:Day(1):end_date) # allocates, may not be used?
attributes_df = static_env.attributes_df #may need to load into static_env during compute state
timeseries_dir = dyn_env.timeseries_dir

a, θ = hillslope_model.shape, hillslope_model.timeseries
max_time = 60 #60 used in mauricio's
distribution = [a * exp(-t / θ) for t in 0:(max_time - 1)]
max_time = 60 #60 used in mauricio's # -> how much history to use in the convolutional integral
distribution = [a * exp(-t / θ) for t in 0:(max_time - 1)] # allocates

for basin_id in routing_lv_basins
timeseries_df =
CSV.read(joinpath(timeseries_dir, "basin_$basin_id.csv"), DataFrame)
CSV.read(joinpath(timeseries_dir, "basin_$basin_id.csv"), DataFrame) # allocates
filtered_df =
filter(row -> start_date <= row[:date] <= end_date, timeseries_df)
basin_area =
attributes_df[attributes_df.HYBAS_ID .== basin_id, :area][1]
runoff =
(filtered_df[:, :sro_sum] .+ filtered_df[:, :ssro_sum]) .*
basin_area ./ day_to_s .* km²_to_m²

streamflow = DSP.conv(runoff, distribution)
basin_area ./ day_to_s .* km²_to_m² # allocates

river_state.hillslope[:, basin_id] = streamflow #update river_state_inplace
river_state.hillslope[:, basin_id] .= DSP.conv(runoff, distribution) #update river_state_inplace
end

end

update_state_from_hillslope!(
river_state::RS,
hillslope_model::HM,
env::E,
) where {RS <: RiverState, HM <: AbstractHillslopeModel, E <: Environment} = update_state_from_hillslope!(river_state, hillslope_model, env.static_env, env.dyn_env)


function update_state_from_channel!() end

0 comments on commit 44c86b1

Please sign in to comment.