Skip to content

Commit

Permalink
remove PyCall dependencies in the 1D files
Browse files Browse the repository at this point in the history
  • Loading branch information
albangossard committed Jan 16, 2025
1 parent 56fed6b commit bca2c11
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 47 deletions.
10 changes: 5 additions & 5 deletions src/glaciers/climate/Climate1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
end

@kwdef mutable struct Climate1D{F <: AbstractFloat}
raw_climate::Py # Raw climate dataset for the whole simulation
raw_climate::RasterStack # Raw climate dataset for the whole simulation
# Buffers to avoid memory allocations
climate_raw_step::Ref{Py} # Raw climate trimmed for the current step
climate_step::Ref{Py} # Climate data for the current step
climate_raw_step::Ref{RasterStack} # Raw climate trimmed for the current step
climate_step::Ref{RasterStack} # Climate data for the current step
climate_2D_step::Climate2Dstep # 2D climate data for the current step to feed to the MB model
longterm_temps::Vector{F} # Longterm temperatures for the ice rheology
avg_temps::Ref{Py} # Intermediate buffer for computing average temperatures
avg_gradients::Ref{Py} # Intermediate buffer for computing average gradients
avg_temps::Ref{RasterStack} # Intermediate buffer for computing average temperatures
avg_gradients::Ref{RasterStack} # Intermediate buffer for computing average gradients
end
2 changes: 1 addition & 1 deletion src/glaciers/glacier/Glacier.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

include("Glacier2D.jl")

# include("Glacier1D.jl") # TODO: uncomment this line
include("Glacier1D.jl")
22 changes: 12 additions & 10 deletions src/glaciers/glacier/Glacier1D.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

export Glacier1D, Climate1D, AbstractGlacier

abstract type AbstractGlacier end
abstract type AbstractGlacier end

include("../climate/Climate1D.jl")

mutable struct Glacier1D{F <: AbstractFloat, I <: Integer} <: AbstractGlacier
rgi_id::Union{String, Nothing}
gdir::Union{Py, Nothing}
climate::Union{Climate1D, Nothing}
H₀::Union{Vector{F}, Nothing}
S::Union{Vector{F}, Nothing}
Expand All @@ -20,7 +19,7 @@ mutable struct Glacier1D{F <: AbstractFloat, I <: Integer} <: AbstractGlacier
λ::Union{Vector{F}, Nothing}
slope::Union{Vector{F}, Nothing}
dist_border::Union{Vector{F}, Nothing}
S_coords::Union{Py, Nothing}
S_coords::Union{Dict{String, Integer}, Nothing}
Δx::Union{F, Nothing}
Δy::Union{F, Nothing}
nx::Union{I, Nothing}
Expand All @@ -30,26 +29,29 @@ end
"""
function Glacier1D(;
rgi_id::Union{String, Nothing} = nothing,
gdir::Union{Py, Nothing} = nothing,
climate::Union{Climate1D, Nothing} = nothing,
H₀::Union{Vector{F}, Nothing} = nothing,
S::Union{Vector{F}, Nothing} = nothing,
B::Union{Vector{F}, Nothing} = nothing,
V::Union{Vector{F}, Nothing}= nothing,
A::Union{F, Nothing} = nothing,
C::Union{F, Nothing} = nothing,
n::Union{F, Nothing} = nothing,
w₀::Union{Vector{F}, Nothing} = nothing,
λ::Union{Vector{F}, Nothing} = nothing,
slope::Union{Vector{F}, Nothing} = nothing,
dist_border::Union{Vector{F}, Nothing} = nothing,
S_coords::Union{Py, Nothing} = nothing,
S_coords::Union{Dict{String, Integer}, Nothing} = nothing,
Δx::Union{F, Nothing} = nothing,
Δy::Union{F, Nothing} = nothing,
nx::Union{I, Nothing} = nothing,
ny::Union{I, Nothing} = nothing
) where {F <: AbstractFloat, I <: Integer}
) where {F <: AbstractFloat, I <: Integer}
Constructor for empty 2D Glacier object.
"""
function Glacier1D(;
rgi_id::Union{String, Nothing} = nothing,
gdir::Union{Py, Nothing} = nothing,
climate::Union{Climate1D, Nothing} = nothing,
H₀::Union{Vector{F}, Nothing} = nothing,
S::Union{Vector{F}, Nothing} = nothing,
Expand All @@ -62,12 +64,12 @@ function Glacier1D(;
λ::Union{Vector{F}, Nothing} = nothing,
slope::Union{Vector{F}, Nothing} = nothing,
dist_border::Union{Vector{F}, Nothing} = nothing,
S_coords::Union{Py, Nothing} = nothing,
S_coords::Union{Dict{String, Integer}, Nothing} = nothing,
Δx::Union{F, Nothing} = nothing,
Δy::Union{F, Nothing} = nothing,
nx::Union{I, Nothing} = nothing,
ny::Union{I, Nothing} = nothing
) where {F <: AbstractFloat, I <: Integer}
) where {F <: AbstractFloat, I <: Integer}

# Define default float and integer type for constructor
ft = Float64
Expand All @@ -79,7 +81,7 @@ end
################### UTILS #####################
###############################################

Base.:(==)(a::Glacier1D, b::Glacier1D) = a.rgi_id == b.rgi_id && a.gdir == b.gdir && a.climate == b.climate &&
Base.:(==)(a::Glacier1D, b::Glacier1D) = a.rgi_id == b.rgi_id && a.gdir == b.gdir && a.climate == b.climate &&
a.H₀ == b.H₀ && a.S == b.S && a.B == b.B && a.V == b.V &&
a.A == b.A && a.C == b.C && a.n == b.n && a.w₀ == b.w₀ && a.λ == b.λ &&
a.slope == b.slope && a.dist_border == b.dist_border && a.rgi_id == b.rgi_id &&
Expand Down
6 changes: 0 additions & 6 deletions src/glaciers/glacier/glacier2D_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ function initialize_glacier_data(rgi_id::String, params::Parameters; smoothing=f
smooth!(H₀) # Smooth initial ice thickness to help the solver
end

# # Create path for simulation results
# gdir_path = dirname(pyconvert(String, gdir.get_filepath("dem")))
# if !isdir(gdir_path)
# mkdir(gdir_path)
# end

try
# We filter glacier borders in high elevations to avoid overflow problems
dist_border = glacier_gd.dis_from_border.data
Expand Down
18 changes: 0 additions & 18 deletions src/setup/helper_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,3 @@ function safe_approx(a, b)
return a b
end
end

# # Function for Python objects
# function safe_getproperty(obj::Py, prop_name::Symbol)
# if PyCall.hasproperty(obj, prop_name)
# return PyCall.getproperty(obj, prop_name)
# else
# return 0.0
# end
# end

# # Function for Julia objects
# function safe_getproperty(obj, prop_name::Symbol)
# if hasproperty(obj, prop_name)
# return getproperty(obj, prop_name)
# else
# return 0.0
# end
# end
7 changes: 0 additions & 7 deletions test/glaciers_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ function glaciers2D_constructor(; save_refs::Bool = false)

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

# Empty all PyCall stuff to avoid issues
# TODO: remove the lines below
for glacier in glaciers
glacier.climate = nothing
glacier.S_coords = nothing
end

if save_refs
jldsave(joinpath(Sleipnir.root_dir, "test/data/glaciers/glaciers2D.jld2"); glaciers)
end
Expand Down

0 comments on commit bca2c11

Please sign in to comment.