Skip to content

Commit

Permalink
remove absolute paths from get_rgi_paths to make the tests platform a…
Browse files Browse the repository at this point in the history
…gnostic
  • Loading branch information
albangossard committed Jan 20, 2025
1 parent b9a8cdd commit 1516094
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/glaciers/climate/climate2D_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Initializes the `Climate` data structure for a given `Glacier``
function initialize_glacier_climate!(glacier::AbstractGlacier, params::Parameters)

dummy_period = partial_year(Day, params.simulation.tspan[1]):Day(1):partial_year(Day, params.simulation.tspan[1] + params.simulation.step)
raw_climate = RasterStack(joinpath(params.simulation.rgi_paths[glacier.rgi_id], "raw_climate_$(params.simulation.tspan).nc"))
raw_climate = RasterStack(joinpath(prepro_dir, params.simulation.rgi_paths[glacier.rgi_id], "raw_climate_$(params.simulation.tspan).nc"))
climate_step = get_cumulative_climate(raw_climate[At(dummy_period)])
climate_2D_step = downscale_2D_climate(climate_step, glacier)
longterm_temps = get_longterm_temps(glacier.rgi_id, params, raw_climate)
Expand All @@ -33,7 +33,7 @@ function initialize_glacier_climate!(glacier::AbstractGlacier, params::Parameter
end

function generate_raw_climate_files(rgi_id::String, simparams::SimulationParameters) where {F <: AbstractFloat}
rgi_path = simparams.rgi_paths[rgi_id]
rgi_path = joinpath(prepro_dir, simparams.rgi_paths[rgi_id])
if !ispath(joinpath(rgi_path, "raw_climate_$(simparams.tspan).nc"))
println("Getting raw climate data for: ", rgi_id)
# Get raw climate data for gdir
Expand Down Expand Up @@ -198,7 +198,7 @@ partial_year(float) = partial_year(Day, float)


function get_longterm_temps(rgi_id::String, params::Parameters)
rgi_path = params.simulation.rgi_paths[rgi_id]
rgi_path = joinpath(prepro_dir, params.simulation.rgi_paths[rgi_id])
glacier_gd = RasterStack(joinpath(rgi_path, "gridded_data.nc"))
climate = RasterStack(joinpath(rgi_path, "raw_climate_$(params.simulation.tspan).nc"))
apply_t_grad!(climate, glacier_gd.topo)
Expand All @@ -207,7 +207,7 @@ function get_longterm_temps(rgi_id::String, params::Parameters)
end

function get_longterm_temps(rgi_id::String, params::Parameters, climate::RasterStack)
glacier_gd = RasterStack(joinpath(params.simulation.rgi_paths[rgi_id], "gridded_data.nc"))
glacier_gd = RasterStack(joinpath(prepro_dir, params.simulation.rgi_paths[rgi_id], "gridded_data.nc"))
apply_t_grad!(climate, glacier_gd.topo)
longterm_temps = mean.(groupby(climate.temp, Ti=>year)).data
return longterm_temps
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 @@ -103,7 +103,7 @@ function initialize_glacier_data(rgi_id::String, params::Parameters; smoothing=f
# Load glacier gridded data
F = params.simulation.float_type
I = params.simulation.int_type
rgi_path = params.simulation.rgi_paths[rgi_id]
rgi_path = joinpath(prepro_dir, params.simulation.rgi_paths[rgi_id])
glacier_gd = RasterStack(joinpath(rgi_path, "gridded_data.nc"))
glacier_grid = JSON.parsefile(joinpath(rgi_path, "glacier_grid.json"))
# println("Using $ice_thickness_source for initial state")
Expand All @@ -115,7 +115,7 @@ function initialize_glacier_data(rgi_id::String, params::Parameters; smoothing=f
H₀ = F.(ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.consensus_ice_thickness.data, 0.0))
end
fillNaN!(H₀) # Fill NaNs with 0s to have real boundary conditions
if smoothing
if smoothing
println("Smoothing is being applied to initial condition.")
smooth!(H₀) # Smooth initial ice thickness to help the solver
end
Expand Down Expand Up @@ -193,7 +193,7 @@ function get_glathida!(glaciers::Vector{Glacier2D}, params::Parameters; force=fa
end

function get_glathida_glacier(glacier::Glacier2D, params::Parameters, force)
rgi_path = params.simulation.rgi_paths[rgi_id]
rgi_path = joinpath(prepro_dir, params.simulation.rgi_paths[rgi_id])
gtd_path = joinpath(rgi_path, "glathida.h5")
if isfile(gtd_path) && !force
gtd_grid = h5read(gtd_path, "gtd_grid")
Expand All @@ -209,7 +209,7 @@ function get_glathida_glacier(glacier::Glacier2D, params::Parameters, force)
gtd_grid .= ifelse.(count > 0, gtd_grid ./ count, 0.0)

# Save file
h5open(joinpath(params.simulation.rgi_paths[glacier.rgi_id], "glathida.h5"), "w") do file
h5open(joinpath(prepro_dir, params.simulation.rgi_paths[glacier.rgi_id], "glathida.h5"), "w") do file
write(file, "gtd_grid", gtd_grid)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/setup/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end

function get_rgi_paths()
rgi_paths = JSON.parsefile(joinpath(prepro_dir, "rgi_paths.json"))
rgi_paths = Dict(k => joinpath(prepro_dir, string(v)) for (k,v) in pairs(rgi_paths)) # Convert Dict{String, Any} to Dict{String, String}
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

Expand Down
Binary file modified test/data/params/params_specified.jld2
Binary file not shown.
Binary file modified test/data/params/simulation_params_specified.jld2
Binary file not shown.
3 changes: 0 additions & 3 deletions test/params_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
function params_constructor_specified(; save_refs::Bool = false)

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,
g = 9.81,
Expand All @@ -28,8 +27,6 @@ function params_constructor_specified(; save_refs::Bool = false)
working_dir = "",
rgi_paths = rgi_paths)

# TODO: check that the tests pass if script is launched from a different computer with different values inside rgi_paths

params = Parameters(physical=physical_params,
simulation=simulation_params)

Expand Down

0 comments on commit 1516094

Please sign in to comment.