Results and plotting
Results
Every Simulation type has an associated Results object(s), one for each one of the glaciers in the simulation. This object, as its name indicates, stores all the results of the simulation, which can be used for data analysis and plotting. These types are handled by Sleipnir.jl.
Sleipnir.Results — Type
mutable struct Results{F <: AbstractFloat, I <: Integer}A mutable struct to store the results of simulations.
Fields
rgi_id::String: Identifier for the RGI (Randolph Glacier Inventory).H::Vector{Matrix{F}}: Vector of matrices representing glacier ice thicknessHover time.H_glathida::Matrix{F}: Optional matrix for Glathida ice thicknesses.H_ref::Vector{Matrix{F}}: Reference data for ice thickness.S::Matrix{F}: Glacier surface altimetry.B::Matrix{F}: Glacier bedrock.V::Matrix{F}: Glacier ice surface velocities.Vx::Matrix{F}: x-component of the glacier ice surface velocityV.Vy::Matrix{F}: y-component of the glacier ice surface velocityV.V_ref::Matrix{F}: Reference data for glacier ice surface velocitiesV.Vx_ref::Matrix{F}: Reference data for the x-component of the glacier ice surface velocityVx.Vy_ref::Matrix{F}: Reference data for the y-component of the glacier ice surface velocityVy.date_Vref::Vector{F}: Date of velocity observation (mean ofdate1anddate2).date1_Vref::Vector{F}: First date of velocity acquisition.date2_Vref::Vector{F}: Second date of velocity acquisition.Δx::F: Grid spacing in the x-direction.Δy::F: Grid spacing in the y-direction.lon::F: Longitude of the glacier grid center.lat::F: Latitude of the glacier grid center.nx::I: Number of grid points in the x-direction.ny::I: Number of grid points in the y-direction.tspan::Vector{F}: Time span of the simulation.
Sleipnir.Results — Method
Results(glacier::G, ifm::IF;
rgi_id::String = glacier.rgi_id,
H::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
H_glathida::Matrix{F} = glacier.H_glathida,
H_ref::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
S::Matrix{F} = zeros(Sleipnir.Float, size(ifm.S)),
B::Matrix{F} = zeros(Sleipnir.Float, size(glacier.B)),
V::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
Vx::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
Vy::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
V_ref::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
Vx_ref::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
Vy_ref::Vector{Matrix{F}} = Vector{Matrix{Sleipnir.Float}}([[;;]]),
date_Vref::Vector{F} = Vector{Sleipnir.Float}([]),
date1_Vref::Vector{F} = Vector{Sleipnir.Float}([]),
date2_Vref::Vector{F} = Vector{Sleipnir.Float}([]),
Δx::F = glacier.Δx,
Δy::F = glacier.Δy,
lon::F = glacier.cenlon,
lat::F = glacier.cenlat,
nx::I = glacier.nx,
ny::I = glacier.ny,
t::Vector{F} = Vector{Sleipnir.Float}([]),
tspan::Tuple{F, F} = (NaN, NaN),
) where {G <: AbstractGlacier, F <: AbstractFloat, IF <: AbstractModel, I <: Integer}Construct a Results object for a glacier simulation.
Arguments
glacier::G: The glacier object, subtype ofAbstractGlacier.ifm::IF: The model object, subtype ofAbstractModel.rgi_id::String: The RGI identifier for the glacier. Defaults toglacier.rgi_id.H::Vector{Matrix{F}}: Ice thickness matrices. Defaults to an empty vector.H_glathida::Matrix{F}: Ice thickness from GlaThiDa. Defaults toglacier.H_glathida.H_ref::Vector{Matrix{F}}: Reference ice thickness. Defaults to an empty vector.S::Matrix{F}: Surface elevation matrix. Defaults to a zero matrix of the same size asifm.S.B::Matrix{F}: Bed elevation matrix. Defaults to a zero matrix of the same size asglacier.B.V::Vector{Matrix{F}}: Velocity magnitude matrix. Defaults to an empty vector.Vx::Vector{Matrix{F}}: Velocity in the x-direction matrix. Defaults to an empty vector.Vy::Vector{Matrix{F}}: Velocity in the y-direction matrix. Defaults to an empty vector.V_ref::Vector{Matrix{F}}: Reference velocity magnitude matrix. Defaults to an empty vector.Vx_ref::Vector{Matrix{F}}: Reference velocity in the x-direction matrix. Defaults to an empty vector.Vy_ref::Vector{Matrix{F}}: Reference velocity in the y-direction matrix. Defaults to an empty vector.date_Vref::Vector{F}: Date of velocity observation (mean ofdate1anddate2). Defaults to an empty vector.date1_Vref::Vector{F}: First date of velocity acquisition. Defaults to an empty vector.date2_Vref::Vector{F}: Second date of velocity acquisition. Defaults to an empty vector.Δx::F: Grid spacing in the x-direction. Defaults toglacier.Δx.Δy::F: Grid spacing in the y-direction. Defaults toglacier.Δy.lon::F: Longitude of the glacier grid center. Defaults toglacier.cenlon.lat::F: Latitude of the glacier grid center. Defaults toglacier.cenlat.nx::I: Number of grid points in the x-direction. Defaults toglacier.nx.ny::I: Number of grid points in the y-direction. Defaults toglacier.ny.tspan::Tuple(F, F): Timespan of the simulation.θ::Union{Nothing, ComponentArray{F}}: Model parameters. Defaults tonothing.loss::Union{Nothing, Vector{F}}: Loss values. Defaults tonothing.
Returns
results::Results: AResultsobject containing the simulation results.
Plots
One of the main things one can do with a Results object, is plotting them. The main function to do so is the following one:
Sleipnir.plot_glacier — Function
plot_glacier(results::Results, plot_type::String, variables::Vector{Symbol}; kwargs...) -> FigureGenerate various types of plots for glacier data.
Arguments
results::Results: The results object containing the data to be plotted.plot_type::String: Type of plot to generate. Options are:- "heatmaps": Heatmaps for glacier variables like
:H,:H₀,:S,:B,:V,:Vx,:Vy,:V_ref. - "evolution difference": Temporal difference metrics (between start and end) for a variable, with optional metrics like "hist" (histogram) and "difference".
- "evolution statistics": Temporal statistical metrics for a variable, with optional metrics like "average", "median", "min", "max", and "std".
- "integrated volume": Temporal evolution of the integrated ice volume for a variable.
- "bias": Scatter plot to visualize the bias between two variables.
- "heatmaps": Heatmaps for glacier variables like
variables::Vector{Symbol}: Variables to be plotted, e.g.,:H.
Optional Keyword Arguments
tspan: A tuple representing the start and end time for the simulation.metrics: Metrics to visualize, e.g.,["average"]for statistics,["difference"]for difference.scale_text_size::Union{Nothing,Float64}: Optional argument to scale the text size for heatmaps.threshold::Vector{F}: Threshold values for filtering data in bias plots.figsize::Tuple{Int64, Int64}: Size of the figure.
Returns
- A
Figureobject containing the desired visualization.
Notes
- Ensure the
variablesandkwargsmatch the requirements of the specifiedplot_type. - The function routes requests to specific plotting functions based on
plot_type.
Another option is to generate a video of the evolution of the glacier's ice thickness during the simulation:
Sleipnir.plot_glacier_vid — Function
plot_glacier_vid(
plot_type::String,
results::Results,
glacier::Glacier2D,
tspan,
step,
pathVideo::String;
framerate::Int=24,
baseTitle::String=""
)Generate various types of videos for glacier data. For now only the evolution of the glacier ice thickness is supported. More types of visualizations will be added in the future.
Arguments
plot_type: Type of plot to generate. Options are:- "thickness": Heatmap of the glacier thickness.
results: A result object containing the simulation results including ice thickness over time.glacier: A glacier instance.tspan: The simulation time span.step: Time step to use to retrieve the results and generate the video.pathVideo: Path of the mp4 file to generate.
Optional Keyword Arguments
framerate: The framerate to use for the video generation.baseTitle: The prefix to use in the title of the frames. In each frame it is concatenated with the value of the year in the form " (t=XXXX)".
And finally, it is also possible to plot various gridded data on a glacier with the following function:
Sleipnir.plot_gridded_data — Function
plot_gridded_data(
gridded_data::Union{Vector{Matrix{F}}, Matrix{F}},
results::Results;
scale_text_size::Union{Nothing,Float64}=nothing,
timeIdx::Union{Nothing,Int64}=nothing,
figsize::Union{Nothing, Tuple{Int64, Int64}} = nothing,
plotContour::Bool=false,
colormap = :cool,
logPlot = false,
) where {F <: AbstractFloat}Plot a gridded matrix (or a time series of matrices) as a heatmap using metadata from results.
Arguments
gridded_data::Union{Vector{Matrix{F}}, Matrix{F}}: Single snapshot or time series (defaults to last timestep).results::Results: Supplies lon, lat, x, y, rgi_id, Δx and H (mask).scale_text_size,figsize,colormap: Optional plotting params.timeIdx::Union{Nothing,Int64}: Select timestep whengridded_datais a vector.plotContour::Bool: overlay glacier-mask contour from results.H.logPlot::Bool: Use log10 colorscale (positive non-NaN values determine range).
Behavior
- Masks out cells where
results.H[begin] .<= 0(set to NaN). - Adds colorbar, central lon/lat tick, and a Δx-based scale bar in km.
- If
plotContour, draws mask boundary lines. - Returns a
CairoMakie.Figure.
Errors
- Asserts gridded_data is non-empty and timeIdx (if provided) is in range.