diff --git a/src/Huginn.jl b/src/Huginn.jl index 3fb4b88..65d6499 100644 --- a/src/Huginn.jl +++ b/src/Huginn.jl @@ -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 @@ -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 \ No newline at end of file diff --git a/src/plotting/Plotting.jl b/src/plotting/Plotting.jl deleted file mode 100644 index d6e4e99..0000000 --- a/src/plotting/Plotting.jl +++ /dev/null @@ -1,4 +0,0 @@ - -using CairoMakie - -include("plotting_utils.jl") \ No newline at end of file diff --git a/src/plotting/plotting_utils.jl b/src/plotting/plotting_utils.jl index fca4895..427c7ff 100644 --- a/src/plotting/plotting_utils.jl +++ b/src/plotting/plotting_utils.jl @@ -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`. @@ -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) @@ -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" @@ -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 @@ -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") @@ -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 diff --git a/test/plotting.jl b/test/plotting.jl index 6c5d541..2b7bcc3 100644 --- a/test/plotting.jl +++ b/test/plotting.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 23803c8..c720da6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,7 @@ using JLD2 using Plots using Infiltrator using OrdinaryDiffEq - +using CairoMakie using Huginn include("utils_test.jl") @@ -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() \ No newline at end of file +@testset "Glacier Plotting" plot_analysis_flow_parameters_test() \ No newline at end of file