Skip to content

Commit

Permalink
Fixed test for plotting utility
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekag7 committed Dec 6, 2023
1 parent 3e54ebc commit 1112b88
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/Huginn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Tullio
using Infiltrator
using Plots, PlotThemes
Plots.theme(:wong2) # sets overall theme for Plots
using Makie
using CairoMakie
#using CairoMakie , GeoMakie
import Pkg
using Distributed
Expand Down Expand Up @@ -68,6 +68,6 @@ include("models/iceflow/IceflowModel.jl")
include("simulations/predictions/Prediction.jl")

# Everything related to plotting
include("plotting/Plotting.jl")
include("plotting/plotting_utils.jl")

end # module
4 changes: 0 additions & 4 deletions src/plotting/Plotting.jl

This file was deleted.

63 changes: 34 additions & 29 deletions src/plotting/plotting_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export plot_analysis_flow_parameters
########################################################

"""
vary_diff_plot(tspan, A_values, n_values, rgi_ids)
plot_analysis_flow_parameters(tspan, A_values, n_values, rgi_ids)
Generate and plot the difference in ice thickness for a specified glacier over a time span `tspan`, for varying parameters `A_values` and `n_values`.
Expand All @@ -24,18 +24,19 @@ Generate and plot the difference in ice thickness for a specified glacier over a
"""

function plot_analysis_flow_parameters(
tspan,
A_values,
n_values,
rgi_ids,
ice_thickness_source="Farinotti19",
workers=1,
use_iceflow=true,
use_MB=true,
use_multiprocessing=true,
reltol=1e-8,
iceflow_model=SIA2Dmodel,
mass_balance_model=TImodel1
tspan,
A_values,
n_values,
rgi_ids,
ice_thickness_source="Farinotti19",
workers=1,
use_iceflow=true,
use_MB=true,
use_multiprocessing=true,
reltol=1e-8,
iceflow_model=SIA2Dmodel,
mass_balance_model=TImodel1,

)
# Calculate the size of the grid
rows = length(n_values)
Expand All @@ -58,7 +59,8 @@ function plot_analysis_flow_parameters(
]
h_diff = [result[i,j].H[end]-result[i,j].H[1] for i in 1:rows, j in 1:cols]

Δx = result[1,1].Δx

Δx = hasproperty(result[1,1], :Δx) ? result[1,1].Δx : 0

#Extract longitude and latitude
lon = hasproperty(result[1,1], :lon) ? result[1,1].lon : "none"
Expand All @@ -75,7 +77,7 @@ function plot_analysis_flow_parameters(
max_abs_value = max(abs(minimum(reduce(vcat, [vec(matrix) for matrix in h_diff]))), abs(maximum(reduce(vcat, [vec(matrix) for matrix in h_diff]))))

# Initialize the figure
fig = Makie.Figure(resolution = (800, 600),layout=GridLayout(rows, cols))
fig = Makie.Figure(size = (800, 600),layout=GridLayout(rows, cols))

# Iterate over each combination of A and n values
for i in 1:rows
Expand Down Expand Up @@ -111,18 +113,19 @@ function plot_analysis_flow_parameters(
end

function generate_result(
tspan,
A,
n,
rgi_ids,
ice_thickness_source="Farinotti19",
workers=1,
use_iceflow=true,
use_MB=true,
use_multiprocessing=true,
reltol=1e-8,
iceflow_model=SIA2Dmodel, # Default function for iceflow
mass_balance_model=TImodel1 # Default function for mass balance
tspan,
A,
n,
rgi_ids,
ice_thickness_source="Farinotti19",
workers=1,
use_iceflow=true,
use_MB=true,
use_multiprocessing=true,
reltol=1e-8,
iceflow_model=SIA2Dmodel,
mass_balance_model=TImodel1,

)
# Set up the working directory
working_dir = joinpath(dirname(Base.current_project()), "data")
Expand Down Expand Up @@ -156,14 +159,16 @@ function generate_result(
)

# Initialize glaciers and run prediction
glaciers = Sleipnir.initialize_glaciers(rgi_ids, params)
glaciers = initialize_glaciers(rgi_ids, params)
prediction = Prediction(model, glaciers, params)
run!(prediction)

# Extract the first result and calculate h_diff

# Extract the first result
result = prediction.results[1]



return result
end

Expand Down
24 changes: 9 additions & 15 deletions test/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
function plotting_test()
# Add all individual plotting test functions
plot_analysis_flow_parameters_test()
end

function plot_analysis_flow_parameters_test()
# Test for valid input
tspan = (2000.0, 2015.0)
tspan = (2000.0, 2005.0)
A_values = [8.5e-20]
n_values = [3.0]
rgi_ids = ["RGI60-11.01450"]


# Test for error with too many rows/cols
A_values_large = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
n_values_large = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
@test_throws ErrorException plot_analysis_flow_parameters(tspan, A_values_large, n_values, rgi_ids)
@test_throws ErrorException plot_analysis_flow_parameters(tspan, A_values, n_values_large, rgi_ids)
try
plot_analysis_flow_parameters(tspan, A_values, n_values, rgi_ids)
@test true # Test passes if no error is thrown
catch e
println("Error occurred: ", e)
@test false # Test fails if any error is caught

end

# Test for error with too many rgi_ids
rgi_ids_large = ["RGI60-11.01450", "RGI60-11.03638"]
@test_throws ErrorException plot_analysis_flow_parameters(tspan, A_values, n_values, rgi_ids_large)
end

4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using JLD2
using Plots
using Infiltrator
using OrdinaryDiffEq

using CairoMakie
using Huginn

include("utils_test.jl")
Expand Down Expand Up @@ -36,4 +36,4 @@ ENV["GKSwstype"]="nul"

@testset "Conservation of Mass - Flat Bed" unit_mass_flatbed_test(; rtol=1.0e-7)

@testset "Glacier Analysis" plotting_test()
@testset "Glacier Plotting" plot_analysis_flow_parameters_test()

0 comments on commit 1112b88

Please sign in to comment.