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.ResultsType
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 thickness H 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 velocity V.
  • Vy::Matrix{F}: y-component of the glacier ice surface velocity V.
  • V_ref::Matrix{F}: Reference data for glacier ice surface velocities V.
  • Vx_ref::Matrix{F}: Reference data for the x-component of the glacier ice surface velocity Vx.
  • Vy_ref::Matrix{F}: Reference data for the y-component of the glacier ice surface velocity Vy.
  • date_Vref::Vector{F}: Date of velocity observation (mean of date1 and date2).
  • 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.
source
Sleipnir.ResultsMethod
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 of AbstractGlacier.
  • ifm::IF: The model object, subtype of AbstractModel.
  • rgi_id::String: The RGI identifier for the glacier. Defaults to glacier.rgi_id.
  • H::Vector{Matrix{F}}: Ice thickness matrices. Defaults to an empty vector.
  • H_glathida::Matrix{F}: Ice thickness from GlaThiDa. Defaults to glacier.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 as ifm.S.
  • B::Matrix{F}: Bed elevation matrix. Defaults to a zero matrix of the same size as glacier.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 of date1 and date2). 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 to glacier.Δx.
  • Δy::F: Grid spacing in the y-direction. Defaults to glacier.Δy.
  • lon::F: Longitude of the glacier grid center. Defaults to glacier.cenlon.
  • lat::F: Latitude of the glacier grid center. Defaults to glacier.cenlat.
  • nx::I: Number of grid points in the x-direction. Defaults to glacier.nx.
  • ny::I: Number of grid points in the y-direction. Defaults to glacier.ny.
  • tspan::Tuple(F, F): Timespan of the simulation.
  • θ::Union{Nothing, ComponentArray{F}}: Model parameters. Defaults to nothing.
  • loss::Union{Nothing, Vector{F}}: Loss values. Defaults to nothing.

Returns

  • results::Results: A Results object containing the simulation results.
source

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_glacierFunction
plot_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.
  • 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 and kwargs match the requirements of the specified plot_type.
  • The function routes requests to specific plotting functions based on plot_type.
source

Another option is to generate a video of the evolution of the glacier's ice thickness during the simulation:

Sleipnir.plot_glacier_vidFunction
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)".
source

And finally, it is also possible to plot various gridded data on a glacier with the following function:

Sleipnir.plot_gridded_dataFunction
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 when gridded_data is 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.
source