Skip to content

Commit

Permalink
bugfix in docstring; allows plotting of CartData structure directly
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskaus committed Jan 6, 2025
1 parent 69604f6 commit 4275414
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions ext/PlotsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,55 @@ export plot_topo, plot_cross_section, plot_phasediagram, plot_cross_section_simu
println("Adding Plots.jl plotting extensions for LaMEM")

"""
plot_cross_section(model::Union{Model,CartData}, args...; field::Symbol=:phase,
plot_cross_section(model::Model, args...; field::Symbol=:phase,
timestep::Union{Nothing, Int64}=nothing,
dim=1, x=nothing, y=nothing, z=nothing, aspect_ratio::Union{Real, Symbol}=:equal)
This plots a cross-section through the LaMEM `model`, of the field `field`. If that is a vector or tensor field, specify `dim` to indicate which of the fields you want to see.
If the keyword `timestep` is specified, it will load a timestep
"""
function plot_cross_section(model::Union{Model,CartData}, args...; field::Symbol=:phase,
timestep::Union{Nothing, Int64}=nothing, dim=1,
function plot_cross_section(model::Model, args...; field::Symbol=:phase,
timestep::Union{Nothing, Int64}=0, dim=1,
x=nothing, y=nothing, z=nothing,
aspect_ratio::Union{Real, Symbol}=:equal)

# load a particular timestep
data_cart, time_val = read_LaMEM_timestep(model,timestep)

if isnothing(x) && isnothing(y) && isnothing(z)
x = mean(extrema(model.Grid.Grid.X))
end

title_str = ""
if !isnothing(timestep)
# load a particular timestep
data_cart, time = read_LaMEM_timestep(model,timestep)
model = data_cart
title_str=title_str*" time=$(time_val[1])"
end

hm = plot_cross_section(data_cart, args...; field=field, dim=dim,x=x, y=y, z=z, title_str=title_str, aspect_ratio=aspect_ratio)

return hm
end

"""
plot_cross_section(data::CartData, args...; field::Symbol=:phase,
title_str="",
dim=1, x=nothing, y=nothing, z=nothing, aspect_ratio::Union{Real, Symbol}=:equal)
This plots a cross-section through a `CartData` dataset `data` of the field `field`, typically read in from a LaMEM simulation.
If that is a vector or tensor field, specify `dim` to indicate which of the fields you want to see.
"""
function plot_cross_section(data::CartData, args...; field::Symbol=:phase,
dim=1,
x=nothing, y=nothing, z=nothing,
title_str="",
aspect_ratio::Union{Real, Symbol}=:equal)


if isnothing(x) && isnothing(y) && isnothing(z)
x = mean(extrema(model.Grid.Grid.X))
x = mean(extrema(data.x.val))
end

data_tuple, axes_str = cross_section(model, field; x=x, y=y, z=z)
data_tuple, axes_str = cross_section(data, field; x=x, y=y, z=z)

if isa(data_tuple.data, Array)
data_field = data_tuple.data
Expand All @@ -41,12 +67,8 @@ function plot_cross_section(model::Union{Model,CartData}, args...; field::Symbol
data_field = data_tuple.data[dim]
cb_str = String(field)*"[$dim]"
end

title_str = axes_str.title_str
if !isnothing(timestep)
title_str=title_str*"; time=$(time[1])"
end

title_str *= " "*axes_str.title_str

hm = Plots.heatmap(data_tuple.x, data_tuple.z, data_field',
aspect_ratio=aspect_ratio,
xlabel=axes_str.x_str,
Expand All @@ -58,14 +80,13 @@ function plot_cross_section(model::Union{Model,CartData}, args...; field::Symbol
return hm
end


"""
plot_cross_section_simulation(model::Union{Model,CartData}, args...; field::Symbol=:phase,
plot_cross_section_simulation(model::Model, args...; field::Symbol=:phase,
dim=1, x=nothing, y=nothing, z=nothing, aspect_ratio::Union{Real, Symbol}=:equal)
As `plot_cross_section`, but for the entire simulation instead of a single timestep.
"""
function plot_cross_section_simulation(model::Union{Model,CartData}, args...; field::Symbol=:phase,
function plot_cross_section_simulation(model::Model, args...; field::Symbol=:phase,
dim=1, x=nothing, y=nothing, z=nothing, aspect_ratio::Union{Real, Symbol}=:equal)

Timesteps,_,_ = read_LaMEM_simulation(model);
Expand Down

0 comments on commit 4275414

Please sign in to comment.