Skip to content

Commit

Permalink
MB utils added, MB mask moved to Huginn
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBolibar committed Sep 13, 2023
1 parent 55b3269 commit ae97c48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Reexport = "1"
PyCall = "1"
Revise = "3"
Sleipnir = "0.3.2"
Sleipnir = "0.3.3"
Infiltrator = "1"
JLD2 = "0.4"
julia = "1.9"
Expand Down
31 changes: 7 additions & 24 deletions src/models/mass_balance/mass_balance_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ function compute_MB(mb_model::TImodel1, climate_2D_period::Climate2Dstep)
return ((mb_model.acc_factor .* climate_2D_period.snow) .- (mb_model.DDF .* climate_2D_period.PDD))
end

function MB_timestep(model::Model, glacier::Glacier, params_solver::SolverParameters, t::F) where {F <: AbstractFloat}
function MB_timestep(model::Model, glacier::G, step::F, t::F) where {F <: AbstractFloat, G <: AbstractGlacier}
# First we get the dates of the current time and the previous step
period = partial_year(Day, t - params_solver.step):Day(1):partial_year(Day, t)
period = partial_year(Day, t - step):Day(1):partial_year(Day, t)
climate_step::PyObject = get_cumulative_climate(glacier.climate.sel(time=period))
# Convert climate dataset to 2D based on the glacier's DEM
climate_2D_step::PyObject = downscale_2D_climate(climate_step, glacier)
Expand All @@ -14,32 +14,15 @@ function MB_timestep(model::Model, glacier::Glacier, params_solver::SolverParame
end


function MB_timestep!(model::Model, glacier::Glacier, params_solver::SolverParameters, t::F) where {F <: AbstractFloat}
function MB_timestep!(model::Model, glacier::G, step::F, t::F) where {F <: AbstractFloat, G <: AbstractGlacier}
# First we get the dates of the current time and the previous step
period = partial_year(Day, t - params_solver.step):Day(1):partial_year(Day, t)
@timeit get_timer("ODINN") "Cumulative climate" begin
period = partial_year(Day, t - step):Day(1):partial_year(Day, t)

get_cumulative_climate!(glacier.climate, period)
end

# Convert climate dataset to 2D based on the glacier's DEM
@timeit get_timer("ODINN") "Downscale 2D climate" begin
downscale_2D_climate!(glacier)
end
@timeit get_timer("ODINN") "Compute MB" begin
model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step)
end
end

function apply_MB_mask!(H::Matrix{F}, glacier::Glacier, ifm::IceflowModel) where {F <: AbstractFloat}
# Appy MB only over ice, and avoid applying it to the borders in the accummulation area to avoid overflow
MB::Matrix{F}, MB_mask::BitMatrix, MB_total::Matrix{F} = ifm.MB, ifm.MB_mask, ifm.MB_total
MB_mask .= ((H .> 0.0) .&& (MB .< 0.0)) .|| ((H .> 0.0) .&& (glacier.dist_border .> 1.0) .&& (MB .>= 0.0))
H[MB_mask] .+= MB[MB_mask]
MB_total[MB_mask] .+= MB[MB_mask]
model.iceflow.MB .= compute_MB(model.mass_balance, glacier.climate.climate_2D_step)
end

# function apply_MB_mask!(H, MB, MB_total, dist_border::Matrix{Float64})
# # Appy MB only over ice, and avoid applying it to the borders in the accummulation area to avoid overflow
# MB_mask = ((H .> 0.0) .&& (MB .< 0.0)) .|| ((H .> 0.0) .&& (dist_border .> 1.0) .&& (MB .>= 0.0))
# H[MB_mask] .+= MB[MB_mask]
# MB_total[MB_mask] .+= MB[MB_mask]
# end

0 comments on commit ae97c48

Please sign in to comment.