From 15160948529d15335522f5ab6bbf7f8a78b835ab Mon Sep 17 00:00:00 2001 From: Alban Gossard Date: Mon, 20 Jan 2025 17:25:28 +0100 Subject: [PATCH] remove absolute paths from get_rgi_paths to make the tests platform agnostic --- src/glaciers/climate/climate2D_utils.jl | 8 ++++---- src/glaciers/glacier/glacier2D_utils.jl | 8 ++++---- src/setup/config.jl | 2 +- test/data/params/params_specified.jld2 | Bin 10457 -> 10457 bytes .../params/simulation_params_specified.jld2 | Bin 8812 -> 8812 bytes test/params_construction.jl | 3 --- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/glaciers/climate/climate2D_utils.jl b/src/glaciers/climate/climate2D_utils.jl index 4ba143d..4579a3c 100644 --- a/src/glaciers/climate/climate2D_utils.jl +++ b/src/glaciers/climate/climate2D_utils.jl @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/src/glaciers/glacier/glacier2D_utils.jl b/src/glaciers/glacier/glacier2D_utils.jl index 78b6591..e43c937 100644 --- a/src/glaciers/glacier/glacier2D_utils.jl +++ b/src/glaciers/glacier/glacier2D_utils.jl @@ -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") @@ -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 @@ -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") @@ -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 diff --git a/src/setup/config.jl b/src/setup/config.jl index 4f22afb..55c58cc 100644 --- a/src/setup/config.jl +++ b/src/setup/config.jl @@ -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 diff --git a/test/data/params/params_specified.jld2 b/test/data/params/params_specified.jld2 index 224eb287b3d2e581b4207477c47cfdce53c394ca..b2fe94acc05f10326f21070f12372a5f8b72cb57 100644 GIT binary patch delta 551 zcmcZ^cr$QA6PuWUg{3(IgDe9h0|@AYNd|_=7VHL$a+6=O%L~Y3NO2f2DolRKAupha zA;oFHs5JQ{r@VkNh7^|pqsrt=Zg~M!bg3QO28?QxGuh+?)G?&k3>Y;gX9As}i6I4a zq1NO~pfj{Fq<}8enVbo9hAxH_(1m)FGr8mi^f9D>E;N|@5-4SeE@i=OF!=?y29pBE zW<{RuY#S5u88_b$Y7}79pB$yE%<{KZY0KnBWosaJFOci0-n<>iHD^@-h3I4j6=jys z^ICX7LV`-rKt2HtXywTd)x=ri7Bb%g>resfcm~w5_}q#IU?DZIkf*9L%a*KFdSD?9 zu+SQy&~i)b31A^Dun@nRGRx#25g{NUK^>3~5W}p}1zYvD;to4Vdh!J|7NC2t0(I;v ZS;Pc3!~krFg*woxBR95fj#sZ@1OVFEYhVBX delta 899 zcmcZ^cr$QA6PuZ_nXv@}gDe9h0|@woNd^Y}jQreG{luK4#5{dHe-}?bKYcJ6Ur>}< zP?WDfxq`!hQEqZ3o4kQMsaj{S889kLUdbVEph&9L8$er?CZ7b_s!XcZA3$4GCUbJi z8>o`1)q>N2QEjp&yS#xqsahl04Hz{hX98{2BvtDSpsiYyJAt-pld5$G&{mzvCxN!= zlB)Fw&{n<4nq2Y*`lM=&;4)w|nEVpxU_(;1N^lrV?%>j3I>5I1AlEUr%{PP^1sMG& zM=2|_eA&I>(d0&DYan+okbCFQ@0CEVIjaIFwN6%0QD#Xv#`6&*B&Y;Uz$c)ISb6e8 zHF1_)t?F#B4i&JDXFwhOo8R673#oyHJXMuhRxtnH0T$8#3#|bPh4JhH*=)|L1s390 zQ)Y=%zIXv7B&Y)t0%Dj|x?rpLjn6CtNl(6@#sYNjRiKW?F)aLGLkz%%Sg0$rXzgM) K-W;!9#Rve9mg8su diff --git a/test/data/params/simulation_params_specified.jld2 b/test/data/params/simulation_params_specified.jld2 index 75676970ff2a57f5df4c9e0aa5d1f3ca58a7e837..0850e679ba3d8f4895ea29b1d0bf780bff59be60 100644 GIT binary patch delta 562 zcmZXQJx>Bb5QcBf9Un(bR%1Xujy+gFgo4Ee2$q--8zR3ziH(&e#^O5p0X9r;Wugs< z27iN6Xkl!wwx*!d>ztct!)~&h?DNcI-pr!6=sixXq-u9shLJLu5uOIUh5`MEV%rcz z1W#)!s#pessNh*m#T3gy5EIs)f6VIL4c~hs`|EqAG^B7?BXKaOAe&!ZBF`t{iE8JL#_wS($Ld;3KL}Mq@%bLfyPHx0co=p**2mMAQB0 zJ0X`46ViM>_#A|2qZlH*|I;N+_eXax)KQ|2SL`^sZVw4n2-RF^3jeT-sEhe-@SDh- eNvfz(#nP3D!P|6i(C-b`j0gBAIJ0h{$$kM9*k)G% delta 910 zcmb7?ze@s99Ki3%>3M}kEv9+i>6w{<_d>AD^(b4E8X6i31wrVChtS|uZ7nT*BWkEM zp+yji_CTk?DVc`*(nG{ zxw2m}3VX%Efsx3YYq^}k&K;{-vZ@sWP9;jFpypJmk5{cbDe=RTq|#|#^#iK`=wVgi zRoyO1g5YzjROMB(Zb~#ryHpzDRm)fnLk+7suUf}y1g^0hKj8igKKXL(h(Oi2vV zvP$Q8)iSDa_{Im%^Qtk4!j&9zG^A!nevq2o$@GZFp2haxJbK|o@rrksn*ywBi(n}t z$-|+diz|uocN;nV_Vhv*QRVIVh@k*OnV>EXmbYIS3Nmzy2zGCd8PXUcD*kIMes80R zu#Is4*L7A`Jk|v>BFt!^p}zDV8HzF#*K|?p`yGff_`Wmz9JGouyAfwMJ~e%G>+5GV RpEWleLLE9GrI`sWkY6qV-gE!} diff --git a/test/params_construction.jl b/test/params_construction.jl index b8efac6..22498bc 100644 --- a/test/params_construction.jl +++ b/test/params_construction.jl @@ -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, @@ -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)