From 34c21a21b277a8d14b2fff7c303b74114bd506a8 Mon Sep 17 00:00:00 2001 From: Milan Date: Tue, 7 Nov 2023 13:55:43 -0500 Subject: [PATCH] plot(::LowerTriangularMatrix) --- .../LowerTriangularMatrices.jl | 4 +++ src/LowerTriangularMatrices/plot.jl | 29 +++++++++++++++++++ src/RingGrids/RingGrids.jl | 2 +- src/SpeedyWeather.jl | 1 + src/output/plot.jl | 3 ++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/LowerTriangularMatrices/plot.jl create mode 100644 src/output/plot.jl diff --git a/src/LowerTriangularMatrices/LowerTriangularMatrices.jl b/src/LowerTriangularMatrices/LowerTriangularMatrices.jl index 136c15fd9..cc844d859 100644 --- a/src/LowerTriangularMatrices/LowerTriangularMatrices.jl +++ b/src/LowerTriangularMatrices/LowerTriangularMatrices.jl @@ -2,8 +2,12 @@ module LowerTriangularMatrices using DocStringExtensions import Adapt +import UnicodePlots export LowerTriangularMatrix, eachharmonic +# export plot include("lower_triangular_matrix.jl") +include("plot.jl") + end \ No newline at end of file diff --git a/src/LowerTriangularMatrices/plot.jl b/src/LowerTriangularMatrices/plot.jl new file mode 100644 index 000000000..3806dff5a --- /dev/null +++ b/src/LowerTriangularMatrices/plot.jl @@ -0,0 +1,29 @@ +function plot(L::LowerTriangularMatrix{T}; mode::Function=abs) where T + + l,m = size(L) + title ="$l×$m LowerTriangularMatrix{$T}" + + Lplot = similar(L,real(T)) + for lm in eachharmonic(L) + Lplot[lm] = mode(L[lm]) + end + + # use at most 33x32 points in height x width, but fewer for smaller matrices + height = min(l,33) + width = min(m,32) + + plot_kwargs = pairs(( xlabel="m", + xoffset=-1, + ylabel="ℓ", + yoffset=-1, + title=title, + colormap=:inferno, + compact=true, + colorbar=true, + zlabel=string(mode), + array=true, + width=width, + height=height)) + + return UnicodePlots.heatmap(Lplot;plot_kwargs...) +end \ No newline at end of file diff --git a/src/RingGrids/RingGrids.jl b/src/RingGrids/RingGrids.jl index 4e45f8a35..da062d20c 100644 --- a/src/RingGrids/RingGrids.jl +++ b/src/RingGrids/RingGrids.jl @@ -66,7 +66,7 @@ export interpolate, update_locator, update_locator! -export plot +# export plot include("utility_functions.jl") diff --git a/src/SpeedyWeather.jl b/src/SpeedyWeather.jl index 0692ae031..82f12b9c3 100644 --- a/src/SpeedyWeather.jl +++ b/src/SpeedyWeather.jl @@ -199,6 +199,7 @@ include("dynamics/models.jl") # OUTPUT include("output/output.jl") # defines Output include("output/feedback.jl") # defines Feedback +include("output/plot.jl") # INTERFACE include("run_speedy.jl") diff --git a/src/output/plot.jl b/src/output/plot.jl new file mode 100644 index 000000000..d0132f426 --- /dev/null +++ b/src/output/plot.jl @@ -0,0 +1,3 @@ +# to avoid ambiguity with exporting plot +plot(L::LowerTriangularMatrix{T}; kwargs...) where T = LowerTriangularMatrices.plot(L;kwargs...) +plot(G::AbstractGrid{T}; kwargs...) where T = RingGrids.plot(G;kwargs...) \ No newline at end of file