Skip to content

Commit

Permalink
fix bugs with the climate_2D_step structure
Browse files Browse the repository at this point in the history
  • Loading branch information
albangossard committed Jan 21, 2025
1 parent 1516094 commit a88dc71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "Sleipnir"
uuid = "e39a38ff-72a2-4fea-8891-9f0a36e6c5fa"
uuid = "f5e6c550-199f-11ee-3608-394420200519"
authors = ["Jordi Bolibar <[email protected]>", "Facundo Sapienza <[email protected]>"]
version = "0.6.1"

Expand Down
18 changes: 10 additions & 8 deletions src/glaciers/climate/climate2D_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ function get_cumulative_climate!(climate, period, gradient_bounds=[-0.009, -0.00

climate.avg_gradients = mean(climate.climate_raw_step.gradient)
climate.climate_raw_step.temp.data .= max.(climate.climate_raw_step.temp, 0.0) # get PDDs
climate.climate_raw_step.gradient.data = clamp.(climate.climate_raw_step.gradient.data, gradient_bounds[1], gradient_bounds[2]) # Clip gradients within plausible values
climate.climate_step = sum(climate.climate_raw_step)
climate.climate_raw_step.gradient.data .= clamp.(climate.climate_raw_step.gradient.data, gradient_bounds[1], gradient_bounds[2]) # Clip gradients within plausible values
climate.climate_step["prcp"] = sum(climate.climate_raw_step.prcp)
climate.climate_step["temp"] = sum(climate.climate_raw_step.temp)
climate.climate_step["gradient"] = sum(climate.climate_raw_step.gradient)
climate.climate_step["avg_temp"] = climate.avg_temps
climate.climate_step["avg_gradient"] = climate.avg_gradients
climate.climate_step["ref_hgt"] = metadata(climate.climate_raw_step)["ref_hgt"]
Expand Down Expand Up @@ -127,13 +129,13 @@ Generates a new RasterStack which is returned.
function downscale_2D_climate!(glacier::Glacier2D)
# Update 2D climate structure
climate = glacier.climate
climate.climate_2D_step.temp .= climate.climate_step.avg_temp.data
climate.climate_2D_step.PDD .= climate.climate_step.temp.data
climate.climate_2D_step.snow .= climate.climate_step.prcp.data
climate.climate_2D_step.rain .= climate.climate_step.prcp.data
climate.climate_2D_step.temp .= climate.climate_step["avg_temp"]
climate.climate_2D_step.PDD .= climate.climate_step["temp"]
climate.climate_2D_step.snow .= climate.climate_step["prcp"]
climate.climate_2D_step.rain .= climate.climate_step["prcp"]
# Update gradients
climate.climate_2D_step.gradient .= climate.climate_step.gradient.data
climate.climate_2D_step.avg_gradient .= climate.climate_step.avg_gradient.data
climate.climate_2D_step.gradient = climate.climate_step["gradient"]
climate.climate_2D_step.avg_gradient = climate.climate_step["avg_gradient"]

# Apply temperature gradients and compute snow/rain fraction for the selected period
apply_t_cumul_grad!(climate.climate_2D_step, reshape(glacier.S, size(glacier.S))) # Reproject current S with the RasterStack structure
Expand Down
8 changes: 4 additions & 4 deletions src/glaciers/glacier/glacier2D_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ function initialize_glacier_data(rgi_id::String, params::Parameters; smoothing=f
S_coords = Dict{String,Vector{Float64}}("x"=> dims(glacier_gd, 1).val, "y"=> dims(glacier_gd, 2).val)
S::Matrix{Float64} = glacier_gd.topo.data
#smooth!(S)

if params.simulation.velocities
V = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_v.data, 0.0)
Vx = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_vx.data, 0.0)
Vy = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_vy.data, 0.0)
V::Matrix{Float64} = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_v.data, 0.0)
Vx::Matrix{Float64} = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_vx.data, 0.0)
Vy::Matrix{Float64} = ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_vy.data, 0.0)
fillNaN!(V)
fillNaN!(Vx)
fillNaN!(Vy)
Expand Down

0 comments on commit a88dc71

Please sign in to comment.