From 91de7974c594c1d486d03eefb1292b568977eae2 Mon Sep 17 00:00:00 2001 From: Firas Date: Fri, 31 May 2024 16:14:20 -0600 Subject: [PATCH] Added makeAnimtion function and edited seisimageplot to check if the two ends of colorrange are identical --- src/Recipes/SeisImageRecipe.jl | 24 ++++++------------------ src/SeisMakie.jl | 4 ++++ src/makeAnimation.jl | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/makeAnimation.jl diff --git a/src/Recipes/SeisImageRecipe.jl b/src/Recipes/SeisImageRecipe.jl index 5ce8f18..e83d9ed 100644 --- a/src/Recipes/SeisImageRecipe.jl +++ b/src/Recipes/SeisImageRecipe.jl @@ -61,6 +61,7 @@ function Makie.plot!(img::SeisImagePlot{<:Tuple{AbstractMatrix{<:Real}}}) function update_plot(d, ox, oy, dx, dy, pclip, vmin, vmax) transposed_d[] = d' + x[] = (ox, ox + size(d,2)*dx) y[] = (oy, oy + size(d,1)*dy) @@ -84,23 +85,10 @@ function Makie.plot!(img::SeisImagePlot{<:Tuple{AbstractMatrix{<:Real}}}) update_plot(img.d[], img.ox[], img.oy[], img.dx[], img.dy[], img.pclip[], img.vmin[], img.vmax[]) - - # if (isnothing(img.vmin[]) || isnothing(img.vmax[])) - # if (img.pclip[]<=100) - # a = -quantile(abs.(img.d[][:]), (img.pclip[]/100)) - # else - # a = -quantile(abs.(img.d[][:]), 1)*img.pclip[]/100 - # end - # b = -a - # else - # a = img.vmin[] - # b = img.vmax[] - # end - - # x = (img.ox[], img.ox[]+size(img.d[],2)*img.dx[]) - # y = (img.oy[], img.oy[]+size(img.d[],1)*img.dy[]) - - image!(img, x, y, transposed_d, colorrange=colorrange, colormap=img.cmap) - + if (colorrange[][1] != colorrange[][2]) + image!(img, x, y, transposed_d, colorrange=colorrange, colormap=img.cmap) + else + image!(img, x, y, transposed_d, colormap=img.cmap) + end img end diff --git a/src/SeisMakie.jl b/src/SeisMakie.jl index e458ede..4dc5c7e 100644 --- a/src/SeisMakie.jl +++ b/src/SeisMakie.jl @@ -16,6 +16,8 @@ module SeisMakie include("seisPlotTX.jl") include("seisPlotAmplitude.jl") + include("makeAnimation.jl") + include("Util.jl") export seisamplitudeplot @@ -34,4 +36,6 @@ module SeisMakie export seisPlotFK export seisPlotAmplitude + export makeAnimation + end diff --git a/src/makeAnimation.jl b/src/makeAnimation.jl new file mode 100644 index 0000000..0b396c7 --- /dev/null +++ b/src/makeAnimation.jl @@ -0,0 +1,29 @@ +function makeAnimation( + filename::String, + A::AbstractArray{<:Real}; + pclip = 98, + ox = 0, + dx = 1, + oy = 0, + dy = 1, + framerate::Integer=30 +) + + # Creating an observable that triggers a change in the figure after a change in its value + obs = Observable(A[:, :, 1]) + + iterations = 1:size(A,3) + + fig = Figure() + ax = Axis(fig[1,1], yreversed=true, xautolimitmargin=(0,0), yautolimitmargin=(0,0)) + + # Creating a plot based on observable obs. If obs[] changes the plot automatically changes + seisimageplot!(ax, obs, pclip=pclip, ox=ox, dx=dx, oy=0, dy=1) + + record(fig, filename, iterations; framerate=30) do it + # modifying the Observable variable to change the plot + obs[] = A[:, :, it] + end + + return nothing +end \ No newline at end of file