Skip to content

Commit

Permalink
some cleaning and remove Sleipnir dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
albangossard committed Jan 20, 2025
1 parent 9c448cd commit b629b77
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 42 deletions.
4 changes: 0 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Sleipnir = "e39a38ff-72a2-4fea-8891-9f0a36e6c5fa"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Tullio = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc"

Expand All @@ -36,10 +34,8 @@ OrdinaryDiffEq = "6"
PlotThemes = "3"
Plots = "1"
ProgressMeter = "1"
PyCall = "1"
Reexport = "1"
Revise = "3"
Sleipnir = "0.6.1"
Tullio = "0.3"
julia = "1.7"

Expand Down
23 changes: 0 additions & 23 deletions src/Huginn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using CairoMakie
import Pkg
using Distributed
using ProgressMeter
using PyCall

### ODINN.jl dependencies ###
using Reexport
Expand All @@ -30,28 +29,6 @@ cd(@__DIR__)
const global root_dir::String = dirname(Base.current_project())
const global root_plots::String = joinpath(root_dir, "plots")

# ##############################################
# ############ PYTHON LIBRARIES ##############
# ##############################################

# We either retrieve the reexported Python libraries from Sleipnir or we start from scratch
const netCDF4::PyObject = isdefined(Sleipnir, :netCDF4) ? Sleipnir.netCDF4 : PyNULL()
const cfg::PyObject = isdefined(Sleipnir, :cfg) ? Sleipnir.cfg : PyNULL()
const utils::PyObject = isdefined(Sleipnir, :utils) ? Sleipnir.utils : PyNULL()
const workflow::PyObject = isdefined(Sleipnir, :workflow) ? Sleipnir.workflow : PyNULL()
const tasks::PyObject = isdefined(Sleipnir, :tasks) ? Sleipnir.tasks : PyNULL()
const global_tasks::PyObject = isdefined(Sleipnir, :global_tasks) ? Sleipnir.global_tasks : PyNULL()
const graphics::PyObject = isdefined(Sleipnir, :graphics) ? Sleipnir.graphics : PyNULL()
const bedtopo::PyObject = isdefined(Sleipnir, :bedtopo) ? Sleipnir.bedtopo : PyNULL()
const millan22::PyObject = isdefined(Sleipnir, :millan22) ? Sleipnir.millan22 : PyNULL()
const MBsandbox::PyObject = isdefined(Sleipnir, :MBsandbox) ? Sleipnir.MBsandbox : PyNULL()
const salem::PyObject = isdefined(Sleipnir, :salem) ? Sleipnir.salem : PyNULL()

# Essential Python libraries
const xr::PyObject = isdefined(Sleipnir, :xr) ? Sleipnir.xr : PyNULL()
const rioxarray::PyObject = isdefined(Sleipnir, :rioxarray) ? Sleipnir.rioxarray : PyNULL()
const pd::PyObject = isdefined(Sleipnir, :pd) ? Sleipnir.pd : PyNULL()

# ##############################################
# ############ HUGINN LIBRARIES ##############
# ##############################################
Expand Down
4 changes: 1 addition & 3 deletions src/parameters/SolverParameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ function Parameters(;
)

# Build the parameters based on all the subtypes of parameters
parameters = Sleipnir.Parameters(physical, simulation, OGGM,
parameters = Sleipnir.Parameters(physical, simulation,
nothing, solver, nothing, nothing)

if parameters.simulation.multiprocessing
enable_multiprocessing(parameters)
end

oggm_config(OGGM.working_dir; oggm_processes=OGGM.workers)

return parameters
end
Expand Down
4 changes: 2 additions & 2 deletions src/simulations/predictions/prediction_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function batch_iceflow_PDE!(glacier_idx::I, simulation::Prediction) where {I <:
params = simulation.parameters
glacier = simulation.glaciers[glacier_idx]

glacier_id = isnothing(glacier.gdir) ? "unnamed" : glacier.rgi_id
glacier_id = isnothing(glacier.rgi_id) ? "unnamed" : glacier.rgi_id
println("Processing glacier: ", glacier_id)

# Initialize glacier ice flow model
Expand Down Expand Up @@ -130,7 +130,7 @@ function batch_iceflow_PDE(glacier_idx::I, simulation::Prediction) where {I <: I
params = simulation.parameters
glacier = simulation.glaciers[glacier_idx]

glacier_id = isnothing(glacier.gdir) ? "unnamed" : glacier.rgi_id
glacier_id = isnothing(glacier.rgi_id) ? "unnamed" : glacier.rgi_id
println("Processing glacier: ", glacier_id)

# Initialize glacier ice flow model (don't needed for out-of-place? maybe a simplified version?)
Expand Down
14 changes: 7 additions & 7 deletions test/PDE_UDE_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function pde_solve_test(; rtol::F, atol::F, save_refs::Bool=false, MB::Bool=fals

rgi_paths = get_rgi_paths()

params = Parameters(simulation = SimulationParameters(use_MB=MB,
params = Huginn.Parameters(simulation = SimulationParameters(use_MB=MB,
velocities=false,
tspan=(2010.0, 2015.0),
working_dir = Huginn.root_dir,
Expand All @@ -19,21 +19,21 @@ function pde_solve_test(; rtol::F, atol::F, save_refs::Bool=false, MB::Bool=fals
## Retrieving gdirs and climate for the following glaciers
## Fast version includes less glacier to reduce the amount of downloaded files and computation time on GitHub CI
if fast
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450", "RGI60-08.00213", "RGI60-04.04351", "RGI60-01.02170"]
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450"] #, "RGI60-08.00213", "RGI60-04.04351", "RGI60-01.02170"]
else
rgi_ids = ["RGI60-11.03638", "RGI60-11.01450", "RGI60-08.00213", "RGI60-04.04351", "RGI60-01.02170",
"RGI60-02.05098", "RGI60-01.01104", "RGI60-01.09162", "RGI60-01.00570", "RGI60-04.07051",
"RGI60-07.00274", "RGI60-07.01323", "RGI60-01.17316"]
end

if MB
model = Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
model = Huginn.Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
else
model = Model(iceflow = SIA2Dmodel(params), mass_balance = nothing)
model = Huginn.Model(iceflow = SIA2Dmodel(params), mass_balance = nothing)
end

# We retrieve some glaciers for the simulation
glaciers = initialize_glaciers(rgi_ids, params)
glaciers::Vector{Sleipnir.AbstractGlacier} = initialize_glaciers(rgi_ids, params)

# We create an ODINN prediction
prediction = Prediction(model, glaciers, params)
Expand Down Expand Up @@ -97,15 +97,15 @@ function TI_run_test!(save_refs::Bool = false; rtol::F, atol::F) where {F <: Abs

rgi_paths = get_rgi_paths()

params = Parameters(simulation = SimulationParameters(use_MB=true,
params = Huginn.Parameters(simulation = SimulationParameters(use_MB=true,
velocities=false,
tspan=(2010.0, 2015.0),
working_dir = Huginn.root_dir,
test_mode = true,
rgi_paths = rgi_paths),
solver = SolverParameters(reltol=1e-8)
)
model = Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
model = Huginn.Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
rgi_ids = ["RGI60-11.03638"]

glacier = initialize_glaciers(rgi_ids, params)[1]
Expand Down
6 changes: 3 additions & 3 deletions test/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function plot_analysis_flow_parameters_test()

rgi_paths = get_rgi_paths()

params = Parameters(simulation = SimulationParameters(use_MB=true,
params::Sleipnir.Parameters = Huginn.Parameters(simulation = SimulationParameters(use_MB=true,
tspan=(2010.0, 2015.0),
working_dir = working_dir,
test_mode = true,
Expand All @@ -16,9 +16,9 @@ function plot_analysis_flow_parameters_test()
rgi_paths=rgi_paths),
solver = SolverParameters(reltol=1e-8)
)
model = Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
model::Sleipnir.Model = Huginn.Model(iceflow = SIA2Dmodel(params), mass_balance = TImodel1(params))
rgi_ids = ["RGI60-11.01450"]
glaciers = initialize_glaciers(rgi_ids, params)
glaciers::Vector{Sleipnir.AbstractGlacier} = initialize_glaciers(rgi_ids, params)

# Test for valid input
prediction = Prediction(model, glaciers, params)
Expand Down

0 comments on commit b629b77

Please sign in to comment.