Skip to content

Commit

Permalink
create get_rgi_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
albangossard committed Jan 17, 2025
1 parent 53f3636 commit 0f3df9f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/glaciers/climate/climate2D_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ function apply_t_cumul_grad!(climate_2D_step::Climate2Dstep, S::Matrix{F}) where
end

"""
apply_t_grad!(climate, g_dem)
apply_t_grad!(climate::RasterStack, dem::Raster)
Applies temperature gradients to the glacier 2D climate data based on a DEM.
Applies temperature gradients to the glacier 2D climate data based on a DEM.
"""
function apply_t_grad!(climate::RasterStack, dem::Raster)
# We apply the gradients to the temperature
climate.temp.data .= climate.temp.data .+ climate.gradient.data .* (mean(dem.data[:]) .- climate.ref_hgt)
end

"""
downscale_2D_climate(climate, g_dem)
downscale_2D_climate(glacier::Glacier2D)
Projects climate data to the glacier matrix by simply copying the closest gridpoint to all matrix gridpoints.
Generates a new xarray Dataset which is returned.
Generates a new RasterStack which is returned.
"""
function downscale_2D_climate!(glacier::Glacier2D)
# Update 2D climate structure
Expand All @@ -132,7 +132,7 @@ function downscale_2D_climate!(glacier::Glacier2D)
climate.climate_2D_step.avg_gradient .= climate.climate_step.avg_gradient.data

# 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 xarray structure
apply_t_cumul_grad!(climate.climate_2D_step, reshape(glacier.S, size(glacier.S))) # Reproject current S with the RasterStack structure
end

function downscale_2D_climate(climate_step::Dict, glacier::Glacier2D)
Expand Down
7 changes: 7 additions & 0 deletions src/setup/config.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export get_rgi_paths

function __init__()

Expand Down Expand Up @@ -51,5 +52,11 @@ function filter_existing_paths(paths::Vector{String})
return existing_paths
end

function get_rgi_paths()
rgi_paths = JSON.parsefile(joinpath(prepro_dir, "rgi_paths.json"))
rgi_paths = Dict(k => string(v) for (k,v) in pairs(rgi_paths)) # Convert Dict{String, Any} to Dict{String, String}
return rgi_paths
end


include("helper_utilities.jl")
3 changes: 1 addition & 2 deletions test/glaciers_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

function glaciers2D_constructor(; save_refs::Bool = false)

rgi_paths = JSON.parsefile(joinpath(Sleipnir.prepro_dir, "rgi_paths.json"))
rgi_paths = Dict(k => string(v) for (k,v) in pairs(rgi_paths)) # Convert Dict{String, Any} to Dict{String, String}
rgi_paths = get_rgi_paths()
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450"]

params = Parameters(simulation=SimulationParameters(velocities=false,
Expand Down
2 changes: 1 addition & 1 deletion test/params_construction.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function params_constructor_specified(; save_refs::Bool = false)

rgi_paths = JSON.parsefile(joinpath(Sleipnir.prepro_dir, "rgi_paths.json"))
rgi_paths = get_rgi_paths()
rgi_paths = Dict(k => string(v) for (k,v) in pairs(rgi_paths)) # Convert Dict{String, Any} to Dict{String, String}

physical_params = PhysicalParameters= 900.0,
Expand Down

0 comments on commit 0f3df9f

Please sign in to comment.