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 anlysis and plotting. These types are handled by Sleipnir.jl
.
Sleipnir.Results
— Typemutable 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 thicknessH
over 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 ofdate1
anddate2
).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.θ::Union{Nothing, ComponentArray{F}}
: Machine learning model parameters.loss::Union{Nothing, Vector{F}}
Vector with evolution of loss function.
Sleipnir.Results
— MethodResults(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),
θ::Union{Nothing,ComponentArray{F}} = nothing,
loss::Union{Nothing,Vector{F}} = nothing
) 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 ofdate1
anddate2
). 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
: AResults
object 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
— Functionplot_glacier(results::Results, plot_type::String, variables::Vector{Symbol}; kwargs...) -> Figure
Generate 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
Figure
object containing the desired visualization.
Notes
- Ensure the
variables
andkwargs
match 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
— Functionplot_glacier_vid(
plot_type::String,
H::Vector{Matrix{Float64}},
glacier::Glacier2D,
simuparams::SimulationParameters,
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.
H
: A vector of matrices containing the ice thickness over time. This should be replaced by a Results instance in the future once Results no longer depends on an iceflow model.glacier
: A glacier instance.simuparams
: The simulation parameters.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)".