Skip to content

Commit 3f1e338

Browse files
authored
Fix the glathida processing part (#66)
* fix the glathida processing part * bump version
1 parent 155166b commit 3f1e338

9 files changed

+26
-18
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Sleipnir"
22
uuid = "f5e6c550-199f-11ee-3608-394420200519"
33
authors = ["Jordi Bolibar <[email protected]>", "Facundo Sapienza <[email protected]>"]
4-
version = "0.7.0"
4+
version = "0.7.1"
55

66
[deps]
77
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

src/glaciers/glacier/glacier2D_utils.jl

+6-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function initialize_glaciers(rgi_ids::Vector{String}, params::Parameters; test=f
3636
pmap((rgi_id) -> generate_raw_climate_files(rgi_id, params.simulation), rgi_ids)
3737
end
3838

39-
glaciers = pmap((rgi_id) -> initialize_glacier(rgi_id, params; smoothing=false, test=test), rgi_ids)
39+
glaciers::Vector{Glacier2D} = pmap((rgi_id) -> initialize_glacier(rgi_id, params; smoothing=false, test=test), rgi_ids)
4040

4141
if params.simulation.use_glathida_data == true
4242

@@ -86,11 +86,6 @@ function initialize_glacier(rgi_id::String, parameters::Parameters; smoothing=fa
8686
# Initialize glacier climate
8787
initialize_glacier_climate!(glacier, parameters)
8888

89-
if test
90-
glacier.rgi_id = nothing # not sure of that line
91-
glacier.S_coords = nothing
92-
end
93-
9489
return glacier
9590
end
9691

@@ -193,23 +188,23 @@ function get_glathida!(glaciers::Vector{Glacier2D}, params::Parameters; force=fa
193188
end
194189

195190
function get_glathida_glacier(glacier::Glacier2D, params::Parameters, force)
196-
rgi_path = joinpath(prepro_dir, params.simulation.rgi_paths[rgi_id])
191+
rgi_path = joinpath(prepro_dir, params.simulation.rgi_paths[glacier.rgi_id])
197192
gtd_path = joinpath(rgi_path, "glathida.h5")
198193
if isfile(gtd_path) && !force
199194
gtd_grid = h5read(gtd_path, "gtd_grid")
200195
else
201-
glathida = CSV.File(joinpath(rgi_path, "glathida.csv"))
196+
glathida = CSV.File(joinpath(rgi_path, "glathida_data.csv"))
202197
gtd_grid = zeros(size(glacier.H₀))
203198
count = zeros(size(glacier.H₀))
204-
for (thick, i, j) in zip(glathida["elevation"], glathida["i_grid"], glathida["j_grid"])
199+
for (thick, i, j) in zip(glathida["thickness"], glathida["i_grid"], glathida["j_grid"])
205200
count[i,j] += 1
206201
gtd_grid[i,j] += thick
207202
end
208203

209-
gtd_grid .= ifelse.(count > 0, gtd_grid ./ count, 0.0)
204+
gtd_grid .= ifelse.(count .> 0, gtd_grid ./ count, 0.0)
210205

211206
# Save file
212-
h5open(joinpath(prepro_dir, params.simulation.rgi_paths[glacier.rgi_id], "glathida.h5"), "w") do file
207+
h5open(joinpath(rgi_path, "glathida.h5"), "w") do file
213208
write(file, "gtd_grid", gtd_grid)
214209
end
215210
end
2.14 MB
Binary file not shown.
-1.04 KB
Binary file not shown.
-1.04 KB
Binary file not shown.

test/glaciers_construction.jl

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11

22

3-
function glaciers2D_constructor(; save_refs::Bool = false)
3+
function glaciers2D_constructor(; save_refs::Bool = false, use_glathida_data::Bool = false)
44

55
rgi_paths = get_rgi_paths()
6-
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450"]
6+
if use_glathida_data
7+
rgi_ids = ["RGI60-07.00042", "RGI60-07.00065"] # Use glaciers that have glathida data
8+
file_suffix = "w_glathida"
9+
else
10+
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450"]
11+
file_suffix = "wo_glathida"
12+
end
13+
# Filter out glaciers that are not used to avoid having references that depend on all the glaciers processed in Gungnir
14+
rgi_paths = Dict(k => rgi_paths[k] for k in rgi_ids)
715

816
params = Parameters(simulation=SimulationParameters(velocities=false,
9-
use_glathida_data=false,
17+
use_glathida_data=use_glathida_data,
1018
working_dir=Sleipnir.root_dir,
1119
test_mode=true,
1220
rgi_paths=rgi_paths))
1321

1422
glaciers = initialize_glaciers(rgi_ids, params; test=true)
1523

1624
if save_refs
17-
jldsave(joinpath(Sleipnir.root_dir, "test/data/glaciers/glaciers2D.jld2"); glaciers)
25+
jldsave(joinpath(Sleipnir.root_dir, string("test/data/glaciers/glaciers2D_", file_suffix, ".jld2")); glaciers)
1826
end
1927

20-
glaciers_ref = load(joinpath(Sleipnir.root_dir,"test/data/glaciers/glaciers2D.jld2"))["glaciers"]
28+
glaciers_ref = load(joinpath(Sleipnir.root_dir, string("test/data/glaciers/glaciers2D_", file_suffix, ".jld2")))["glaciers"]
2129

2230
@test all(glaciers == glaciers_ref)
2331

test/params_construction.jl

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11

22
function params_constructor_specified(; save_refs::Bool = false)
33

4+
rgi_id = "RGI60-11.03638"
45
rgi_paths = get_rgi_paths()
6+
# Filter out glaciers that are not used to avoid having references that depend on all the glaciers processed in Gungnir
7+
rgi_paths = Dict(rgi_id => rgi_paths[rgi_id])
58

69
physical_params = PhysicalParameters= 900.0,
710
g = 9.81,

test/runtests.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ ENV["GKSwstype"]="nul"
2121

2222
@testset "Parameters constructors by default" params_constructor_default()
2323

24-
@testset "Glaciers 2D constructors" glaciers2D_constructor()
24+
@testset "Glaciers 2D constructors w/o glathida data" glaciers2D_constructor(use_glathida_data=false)
25+
26+
@testset "Glaciers 2D constructors w/ glathida data" glaciers2D_constructor(use_glathida_data=true)
2527

2628
#@testset "Glaciers 2D plots" glaciers2D_plots()

0 commit comments

Comments
 (0)