Skip to content

Commit

Permalink
Merge pull request #10 from firasalchalabi/animations
Browse files Browse the repository at this point in the history
Animations, Tests, README, Author
  • Loading branch information
AtilaSaraiva authored Mar 15, 2024
2 parents 659d4fb + ba05cfb commit 837a638
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 22 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
julia = "1"

[extras]
SeisProcessing = "3ac90d68-5a11-50c7-932e-af3f40d97fdc"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[targets]
test = ["Test"]
test = ["Test", "SeisProcessing", "Random"]
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,76 @@
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://seismicjulia.github.io/SeisMakie.jl/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://seismicjulia.github.io/SeisMakie.jl/dev/)
[![Build Status](https://github.com/SeismicJulia/SeisMakie.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/SeismicJulia/SeisMakie.jl/actions/workflows/CI.yml?query=branch%3Amain)

SeisMakie.jl is a package intended for plotting seismic data. Some examples are wiggle, image, overlay and frequency-wavenumber plots.

## Examples

### Wiggle Plot

```julia
using CairoMakie, SeisProcessing

# Seismic data consisting of linear events
d = SeisLinearEvents()
f, ax = SeisPlotTX(d, style="wiggle")
save("./images/wiggle.png", f)
f
```

<img src="./images/wiggle.png" width="600">


### Image Plot

```julia
using CairoMakie, SeisProcessing

# Seismic data consisting of linear events
d = SeisLinearEvents()
f, ax = SeisPlotTX(d, style="image")
save("./images/image.png", f)
f
```

<img src="./images/image.png" width="600">


### Overlay Plot

```julia
using CairoMakie, SeisProcessing

# Seismic data consisting of linear events
d = SeisLinearEvents()
f = Figure()
_, ax = SeisPlotTX(d, fig=f, style="overlay") # If you would like to plot on an existing figure
save("./images/overlay.png", f)
f
```

<img src="./images/overlay.png" width="600">


### Frequency-Wavenumber Plot

```julia
using CairoMakie, SeisProcessing

# Seismic data consisting of linear events
d = SeisLinearEvents()
f, ax = SeisPlotFK(d)
save("./images/fk.png", f)
f
```

<img src="./images/fk.png" width="600">
</br>
</br>

---------------------------

</br>
For more information about the different functions, view the docs. For more examples,
check out the Pluto notebook under examples/.

Binary file added images/fk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/overlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/wiggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/Recipes/SeisAmplitudeRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ julia> f, ax, amp = seisamplitude(d)
julia> d = SeisLinearEvents(); f = Figure(); ax = Axis(f)
julia> amp = seisamplitude!(ax, d)
```
Author: Firas Al Chalabi (2024)
Credits: Aaron Stanton (2015)
- Most of the code in this file is taken from SeisPlot.jl written by Aaron Stanton.
"""
@recipe(SeisAmplitude, d) do scene
Attributes(
Expand Down
9 changes: 6 additions & 3 deletions src/Recipes/SeisFKRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
seisfk(d; <keyword arguments>)
seisfk!(ax, d; <keyword arguments>)
Plot time-space, frequency-wavenumber or amplitude-frequency 2D seismic data `d`
with color, wiggles or overlay.
Plot frequency-wavenumber 2D seismic data `d`.
# Arguments
- `d::Matrix{<:AbstractFloat}`: 2D data to plot.
Expand All @@ -20,7 +19,7 @@ with color, wiggles or overlay.
- `dx=1`: increment of x-axis.
- `dy=1`: increment of y-axis.
- `cmap=:PuOr`: colormap for `"color"` or `"overlay"` style.
- `cmap=:PuOr`: colormap
Return the figure and axis corresponding to d.
Expand All @@ -33,6 +32,10 @@ julia> f, ax, fk = seisfk(d)
julia> d = SeisLinearEvents(); f = Figure(); ax = Axis(f)
julia> fk = seisfk!(ax, d)
```
Author: Firas Al Chalabi (2024)
Credits: Aaron Stanton (2015)
- Most of the code in this file is taken from SeisPlot.jl written by Aaron Stanton.
"""
@recipe(SeisFK, d) do scene
Attributes(
Expand Down
61 changes: 50 additions & 11 deletions src/Recipes/SeisImageRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ julia> f, ax, img = seisimage(d)
julia> d = SeisLinearEvents(); f = Figure(); ax = Axis(f)
julia> img = seisimage!(ax, d)
```
Author: Firas Al Chalabi (2024)
Credits: Aaron Stanton (2015)
- Most of the code in this file is taken from SeisPlot.jl written by Aaron Stanton.
"""
@recipe(SeisImage, d) do scene
Attributes(
Expand All @@ -46,22 +50,57 @@ end

function Makie.plot!(img::SeisImage{<:Tuple{AbstractMatrix{<:Real}}})

if (isnothing(img.vmin[]) || isnothing(img.vmax))
if (img.pclip[]<=100)
a = -quantile(abs.(img.d[][:]), (img.pclip[]/100))
transposed_d = Observable{Any}()

x = Observable{Any}()
y = Observable{Any}()

colorrange = Observable{Any}()


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,2)*dy)

if (isnothing(vmin) || isnothing(vmax))
if (img.pclip[]<=100)
a = -quantile(abs.(d[:]), (pclip/100))
else
a = -quantile(abs.(d[:]), 1)*pclip/100
end
b = -a
else
a = -quantile(abs.(img.d[][:]), 1)*img.pclip[]/100
a = vmin
b = vmax
end
b = -a
else
a = img.vmin[]
b = img.vmax[]

colorrange[] = (a, b)

end

x = (img.ox[], img.ox[]+size(img.d[],2)*img.dx[])
y = (img.oy[], img.oy[]+size(img.d[],1)*img.dy[])
Makie.Observables.onany(update_plot, img.d, img.ox, img.oy, img.dx, img.dy, img.pclip, img.vmin, img.vmax)

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, img.d[]', colorrange=(a, b), colormap=img.cmap[])
image!(img, x, y, transposed_d, colorrange=colorrange, colormap=img.cmap)

img
end
4 changes: 4 additions & 0 deletions src/Recipes/SeisWiggleRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ julia> f, ax, wp = seiswiggle(d)
julia> d = SeisLinearEvents(); f = Figure(); ax = Axis(f)
julia> wp = seiswiggle!(ax, d)
```
Author: Firas Al Chalabi (2024)
Credits: Aaron Stanton (2015)
- The code in this file was inspired by some of Aaron Stanton's in SeisPlot.jl.
"""
@recipe(SeisWiggle, d) do scene
Attributes(
Expand Down
2 changes: 2 additions & 0 deletions src/SeisDifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Return the figure and 3 axes corresponding to d1, d2, d1-d2.
julia> d1 = SeisLinearEvents(); d2 = SeisLinearEvents();
julia> f, ax1, ax2, ax_diff = SeisDifference(d1, d2);
```
Author: Firas Al Chalabi (2024)
"""
function SeisDifference(d1, d2;
fig=nothing, ox=0, dx=1, oy=0, dy=1, gx=nothing,
Expand Down
2 changes: 2 additions & 0 deletions src/SeisPlotAmplitude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Plot amplitude-frequency 2D seismic data `d`
julia> d = SeisLinearEvents();
julia> f, ax = SeisPlotAmplitude(d,100,0.004);
```
Author: Firas Al Chalabi (2024)
"""
function SeisPlotAmplitude(d::Array{<:Real, 2}; fig=nothing, ax=nothing, fmax=100, dy=0.004,
normalize=false, color=:black, label="")
Expand Down
7 changes: 4 additions & 3 deletions src/SeisPlotFK.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
SeisPlotFK(d; <keyword arguments>)
Plot time-space, frequency-wavenumber or amplitude-frequency 2D seismic data `d`
with color, wiggles or overlay.
Plot frequency-wavenumber 2D seismic data `d`.
# Arguments
- `d::Matrix{<:AbstractFloat}`: 2D data to plot.
Expand All @@ -19,7 +18,7 @@ with color, wiggles or overlay.
- `dx=1`: increment of x-axis.
- `dy=1`: increment of y-axis.
- `cmap=:PuOr`: colormap for `"color"` or `"overlay"` style.
- `cmap=:PuOr`: colormap
Return the figure and axis corresponding to d.
Expand All @@ -28,6 +27,8 @@ Return the figure and axis corresponding to d.
julia> d = SeisLinearEvents();
julia> f, ax = SeisPlotFK(d);
```
Author: Firas Al Chalabi (2024)
"""
function SeisPlotFK(d; fig=nothing, dx=1, dy=1, fmax=100,
pclip=99.9, vmin=nothing, vmax=nothing, cmap=:PuOr)
Expand Down
2 changes: 2 additions & 0 deletions src/SeisPlotTX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Return the figure and axis corresponding to d.
julia> d = SeisLinearEvents();
julia> f, ax = SeisPlotTX(d);
```
Author: Firas Al Chalabi (2024)
"""
function SeisPlotTX(d;
fig=nothing, gx=nothing, ox=0, dx=1, oy=0, dy=1, xcur=1.2, wiggle_trace_increment=1,
Expand Down
4 changes: 1 addition & 3 deletions src/Util.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Creates an Axis object to be used by SeisColor, SeisOverlay, SeisWiggle.
"""
# Creates an Axis object to be used by SeisColor, SeisOverlay, SeisWiggle.
function __create_axis(fig)
return Axis(fig, yreversed=true, xautolimitmargin=(0,0), yautolimitmargin=(0,0))
end
75 changes: 74 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
using SeisMakie
using SeisProcessing
using Random
using Test

@testset "SeisMakie.jl" begin
# Write your tests here

d = SeisLinearEvents()

dx = 10
dy = 0.004

@testset "SeisWiggleRecipe" begin
gx = [ dx*(i-1) for i=1:size(d,2) ]
# create a random permutation vector to sample gx and d
p = (randsubseq(gx, 0.85) dx) .+ 1
gx = gx[p]

f, ax, wp = seiswiggle(d[:, p], gx=gx, dy=dy, xcur=2, wiggle_trace_increment=4)

@test true
end

@testset "SeisImageRecipe" begin

f, ax, img = seisimage(d, dx=dx, dy=dy, pclip=97, cmap=:viridis)

@test true

end

@testset "SeisOverlayRecipe" begin

f, ax, ov = seisoverlay(d, dx=dx, dy=dy, xcur=2, wiggle_trace_increment=4, pclip=97, cmap=:viridis)

@test true

end

@testset "SeisFKRecipe" begin

f, ax, fk = seisfk(d, dx=dx, dy=dy, pclip=97, fmax=90)

@test true
end

@testset "SeisAmplitudeRecipe" begin

f, ax, amp = seisamplitude(d, dy=dy, fmax=90)

@test true
end

@testset "SeisPlotTX" begin
gx = [ dx*(i-1) for i=1:size(d,2) ]
# create a random permutation vector to sample gx and d
p = (randsubseq(gx, 0.85) dx) .+ 1
gx = gx[p]
f, ax = SeisPlotTX(d[:, p], gx=gx, dy=dy, xcur=2, wiggle_trace_increment=4, style="wiggle")
@test true
f, ax = SeisPlotTX(d, dx=dx, dy=dy, pclip=97, cmap=:viridis, style="image")
@test true
f, ax = SeisPlotTX(d, dx=dx, dy=dy, xcur=2, wiggle_trace_increment=4, pclip=97, cmap=:viridis, style="overlay")
@test true
end

@testset "SeisPlotFK" begin
f, ax = SeisPlotFK(d, dx=dx, dy=dy, pclip=97, fmax=90)

@test true
end

@testset "SeisAmplitude" begin
f, ax = SeisPlotAmplitude(d, dy=dy, fmax=90)

@test true
end

end

0 comments on commit 837a638

Please sign in to comment.