Skip to content

Commit

Permalink
Rename variables nc and inds
Browse files Browse the repository at this point in the history
  • Loading branch information
vers-w committed Nov 26, 2024
1 parent 986c9b1 commit 16e5259
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 216 deletions.
90 changes: 45 additions & 45 deletions src/demand/water_demand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ get_demand_gross(model::NonIrrigationDemand) = model.demand.demand_gross
get_demand_gross(model::NoNonIrrigationDemand) = 0.0

"Initialize non-irrigation water demand model for a water use `sector`"
function NonIrrigationDemand(nc, config, inds, dt, sector)
function NonIrrigationDemand(dataset, config, indices, dt, sector)
demand_gross =
ncread(
nc,
dataset,
config,
"vertical.demand.$(sector).demand_gross";
sel = inds,
sel = indices,
defaults = 0.0,
type = Float,
) .* (dt / basetimestep)
demand_net =
ncread(
nc,
dataset,
config,
"vertical.demand.$(sector).demand_net";
sel = inds,
sel = indices,
defaults = 0.0,
type = Float,
) .* (dt / basetimestep)
n = length(inds)
n = length(indices)
returnflow_f = return_flow_fraction.(demand_gross, demand_net)

demand = PrescibedDemand{Float}(; demand_gross, demand_net)
Expand Down Expand Up @@ -83,39 +83,39 @@ end
end

"Initialize non-paddy irrigation model"
function NonPaddy(nc, config, inds, dt)
function NonPaddy(dataset, config, indices, dt)
efficiency = ncread(
nc,
dataset,
config,
"vertical.demand.nonpaddy.parameters.irrigation_efficiency";
sel = inds,
sel = indices,
defaults = 1.0,
type = Float,
)
areas = ncread(
nc,
dataset,
config,
"vertical.demand.nonpaddy.parameters.irrigation_areas";
sel = inds,
sel = indices,
defaults = 1,
optional = false,
type = Int,
)
irrigation_trigger = ncread(
nc,
dataset,
config,
"vertical.demand.nonpaddy.parameters.irrigation_trigger";
sel = inds,
sel = indices,
defaults = 1,
optional = false,
type = Bool,
)
max_irri_rate =
ncread(
nc,
dataset,
config,
"vertical.demand.nonpaddy.parameters.maximum_irrigation_rate";
sel = inds,
sel = indices,
defaults = 25.0,
type = Float,
) .* (dt / basetimestep)
Expand All @@ -126,7 +126,7 @@ function NonPaddy(nc, config, inds, dt)
irrigation_areas = areas,
irrigation_trigger,
)
vars = NonPaddyVariables{Float}(; demand_gross = fill(mv, length(inds)))
vars = NonPaddyVariables{Float}(; demand_gross = fill(mv, length(indices)))

nonpaddy = NonPaddy{Float}(; variables = vars, parameters = params)

Expand Down Expand Up @@ -229,65 +229,65 @@ end
end

"Initialize paddy irrigation model"
function Paddy(nc, config, inds, dt)
function Paddy(dataset, config, indices, dt)
h_min = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.h_min";
sel = inds,
sel = indices,
defaults = 20.0,
type = Float,
)
h_opt = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.h_opt";
sel = inds,
sel = indices,
defaults = 50.0,
type = Float,
)
h_max = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.h_max";
sel = inds,
sel = indices,
defaults = 80.0,
type = Float,
)
efficiency = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.irrigation_efficiency";
sel = inds,
sel = indices,
defaults = 1.0,
type = Float,
)
areas = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.irrigation_areas";
sel = inds,
sel = indices,
optional = false,
type = Bool,
)
irrigation_trigger = ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.irrigation_trigger";
sel = inds,
sel = indices,
optional = false,
type = Bool,
)
max_irri_rate =
ncread(
nc,
dataset,
config,
"vertical.demand.paddy.parameters.maximum_irrigation_rate";
sel = inds,
sel = indices,
defaults = 25.0,
type = Float,
) .* (dt / basetimestep)
n = length(inds)
n = length(indices)
params = PaddyParameters{Float}(;
irrigation_efficiency = efficiency,
maximum_irrigation_rate = max_irri_rate,
Expand Down Expand Up @@ -437,34 +437,34 @@ end
end

"Initialize water demand model"
function Demand(nc, config, inds, dt)
function Demand(dataset, config, indices, dt)
domestic = if get(config.model.water_demand, "domestic", false)
NonIrrigationDemand(nc, config, inds, dt, "domestic")
NonIrrigationDemand(dataset, config, indices, dt, "domestic")
else
NoNonIrrigationDemand()
end
industry = if get(config.model.water_demand, "industry", false)
NonIrrigationDemand(nc, config, inds, dt, "industry")
NonIrrigationDemand(dataset, config, indices, dt, "industry")
else
NoNonIrrigationDemand()
end
livestock = if get(config.model.water_demand, "livestock", false)
NonIrrigationDemand(nc, config, inds, dt, "livestock")
NonIrrigationDemand(dataset, config, indices, dt, "livestock")
else
NoNonIrrigationDemand()
end
paddy = if get(config.model.water_demand, "paddy", false)
Paddy(nc, config, inds, dt)
Paddy(dataset, config, indices, dt)
else
NoIrrigationPaddy{Float}()
end
nonpaddy = if get(config.model.water_demand, "nonpaddy", false)
NonPaddy(nc, config, inds, dt)
NonPaddy(dataset, config, indices, dt)
else
NoIrrigationNonPaddy{Float}()
end

n = length(inds)
n = length(indices)
vars = DemandVariables(Float, n)
demand = Demand(; domestic, industry, livestock, paddy, nonpaddy, variables = vars)
return demand
Expand Down Expand Up @@ -544,25 +544,25 @@ end
end

"Initialize water allocation for the land domain"
function AllocationLand(nc, config, inds)
function AllocationLand(dataset, config, indices)
frac_sw_used = ncread(
nc,
dataset,
config,
"vertical.allocation.parameters.frac_sw_used";
sel = inds,
sel = indices,
defaults = 1,
type = Float,
)
areas = ncread(
nc,
dataset,
config,
"vertical.allocation.parameters.areas";
sel = inds,
sel = indices,
defaults = 1,
type = Int,
)

n = length(inds)
n = length(indices)

params = AllocationLandParameters(; areas = areas, frac_sw_used = frac_sw_used)
vars = AllocationLandVariables(Float, n)
Expand Down
6 changes: 3 additions & 3 deletions src/flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -885,18 +885,18 @@ end
error::Vector{T} | "m3" # error volume
end

function ShallowWaterRiverVariables(nc, config, inds, n_edges, inds_pit)
function ShallowWaterRiverVariables(dataset, config, indices, n_edges, inds_pit)
floodplain_1d = get(config.model, "floodplain_1d", false)::Bool
riverdepth_bc = ncread(
nc,
dataset,
config,
"lateral.river.riverdepth_bc";
sel = inds_pit,
defaults = 0.0,
type = Float,
)

n = length(inds)
n = length(indices)
# set river depth h to zero (including reservoir and lake locations)
h = zeros(n)
q_av = zeros(n_edges)
Expand Down
30 changes: 15 additions & 15 deletions src/glacier/glacier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ abstract type AbstractGlacierModel{T} end
end

"Initialize glacier model variables"
function GlacierVariables(nc, config, inds)
function GlacierVariables(dataset, config, indices)
glacier_store = ncread(
nc,
dataset,
config,
"vertical.glacier.variables.glacier_store";
sel = inds,
sel = indices,
defaults = 5500.0,
type = Float,
fill = 0.0,
Expand Down Expand Up @@ -54,41 +54,41 @@ end
struct NoGlacierModel{T} <: AbstractGlacierModel{T} end

"Initialize glacier HBV model parameters"
function GlacierHbvParameters(nc, config, inds, dt)
function GlacierHbvParameters(dataset, config, indices, dt)
g_tt = ncread(
nc,
dataset,
config,
"vertical.glacier.parameters.g_tt";
sel = inds,
sel = indices,
defaults = 0.0,
type = Float,
fill = 0.0,
)
g_cfmax =
ncread(
nc,
dataset,
config,
"vertical.glacier.parameters.g_cfmax";
sel = inds,
sel = indices,
defaults = 3.0,
type = Float,
fill = 0.0,
) .* (dt / basetimestep)
g_sifrac =
ncread(
nc,
dataset,
config,
"vertical.glacier.parameters.g_sifrac";
sel = inds,
sel = indices,
defaults = 0.001,
type = Float,
fill = 0.0,
) .* (dt / basetimestep)
glacier_frac = ncread(
nc,
dataset,
config,
"vertical.glacier.parameters.glacier_frac";
sel = inds,
sel = indices,
defaults = 0.0,
type = Float,
fill = 0.0,
Expand All @@ -105,9 +105,9 @@ function GlacierHbvParameters(nc, config, inds, dt)
end

"Initialize glacier HBV model"
function GlacierHbvModel(nc, config, inds, dt, bc)
params = GlacierHbvParameters(nc, config, inds, dt)
vars = GlacierVariables(nc, config, inds)
function GlacierHbvModel(dataset, config, indices, dt, bc)
params = GlacierHbvParameters(dataset, config, indices, dt)
vars = GlacierVariables(dataset, config, indices)
model =
GlacierHbvModel(; boundary_conditions = bc, parameters = params, variables = vars)
return model
Expand Down
Loading

0 comments on commit 16e5259

Please sign in to comment.