Skip to content

Commit

Permalink
Merge pull request #8 from AtilaSaraiva/somesmallfixes
Browse files Browse the repository at this point in the history
several small formating and functionality corrections
  • Loading branch information
AtilaSaraiva authored Mar 7, 2024
2 parents b1e690f + 7d032ae commit 35aea9c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/Recipes/SeisAmplitudeRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ julia> amp = seisamplitude!(ax, d)
"""
@recipe(SeisAmplitude, d) do scene
Attributes(
fmax=100,
fmax=100,
dy=0.004,

normalize=false,
Expand All @@ -39,7 +39,7 @@ julia> amp = seisamplitude!(ax, d)
end

function Makie.plot!(amp::SeisAmplitude{<:Tuple{AbstractMatrix{<:Real}}})

nx = size(amp.d[], 2)
df = 1/amp.dy[]/size(amp.d[], 1)
FMAX = df*size(amp.d[], 1)/2
Expand Down
16 changes: 8 additions & 8 deletions src/Recipes/SeisFKRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ julia> fk = seisfk!(ax, d)
"""
@recipe(SeisFK, d) do scene
Attributes(
dx=1,
dy=1,
dx=1,
dy=1,
fmax=100,

pclip=99.9,
vmin=nothing,
vmax=nothing,
pclip=99.9,
vmin=nothing,
vmax=nothing,

cmap=:PuOr
)
end
Expand All @@ -62,7 +62,7 @@ function Makie.plot!(fk::SeisFK{<:Tuple{AbstractMatrix{<:Real}}})
nf = convert(Int32, floor((size(fk.d[], 1)/2)*fk.fmax[]/FMAX))
D = abs.(fftshift(fft(fk.d[])))
D = D[round(Int,end/2):round(Int,end/2)+nf, :]

if (isnothing(fk.vmin[]) || isnothing(fk.vmax[]))
a = 0.
if (fk.pclip[] <= 100)
Expand All @@ -76,5 +76,5 @@ function Makie.plot!(fk::SeisFK{<:Tuple{AbstractMatrix{<:Real}}})
end

image!(fk, (kmin, kmax), (0.0, fk.fmax[]), D', colorrange=(a, b), colormap=fk.cmap[])

end
14 changes: 7 additions & 7 deletions src/Recipes/SeisImageRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ julia> img = seisimage!(ax, d)
@recipe(SeisImage, d) do scene
Attributes(
ox = 0,
dx = 1,
dx = 1,
oy = 0,
dy = 1,

Expand All @@ -45,23 +45,23 @@ julia> img = seisimage!(ax, d)
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))
else
a = -quantile(abs.(img.d[][:]), 1)*img.pclip[]/100
end
b = -a
b = -a
else
a = img.vmin[]
b = img.vmax[]
end
x = (img.ox[]-img.dx[], img.ox[]+size(img.d[],2)*img.dx[])

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[])

img
end
end
30 changes: 19 additions & 11 deletions src/Recipes/SeisOverlayRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ julia> ov = seisoverlay!(ax, d)
Attributes(
trace_color = :black,
trace_width = 0.7,

ox = 0,
dx = 1,

oy = 0,
dy = 1,

xcur = 1,
wiggle_trace_increment = 1,

pclip = 98,
vmin = nothing,
vmax = nothing,
x = (1, 500),

x = (1, 500),
y = (1, 100),

cmap = :seismic
Expand All @@ -61,11 +61,19 @@ end

function Makie.plot!(overlay::SeisOverlay{<:Tuple{AbstractMatrix{<:Real}}})

seisimage!(overlay, overlay.d[], ox=overlay.ox[], dx=overlay.dx[], oy=overlay.oy[], dy=overlay.dy[], colormap=overlay.cmap[],
vmin=overlay.vmin[], vmax=overlay.vmax[], pclip=overlay.pclip[])
seiswiggle!(overlay, overlay.d[], ox=overlay.ox[], dx=overlay.dx[], oy=overlay.oy[], dy=overlay.dy[],
xcur=overlay.xcur[], wiggle_trace_increment=overlay.wiggle_trace_increment[], trace_color=overlay.trace_color[],
trace_width=overlay.trace_width[], fillbands=false)
seisimage!(overlay, overlay.d[], ox=overlay.ox[], dx=overlay.dx[], oy=overlay.oy[],
dy=overlay.dy[],
colormap=overlay.cmap[],
vmin=overlay.vmin[],
vmax=overlay.vmax[],
pclip=overlay.pclip[])
seiswiggle!(overlay, overlay.d[], ox=overlay.ox[], dx=overlay.dx[], oy=overlay.oy[],
dy=overlay.dy[],
xcur=overlay.xcur[],
wiggle_trace_increment=overlay.wiggle_trace_increment[],
trace_color=overlay.trace_color[],
trace_width=overlay.trace_width[],
fillbands=false)

overlay
end
Expand All @@ -75,4 +83,4 @@ function Makie.extract_colormap(pl::Plot{seisoverlay, Tuple{Matrix{Float64}}})
# - typeof(pl.plots[1]) = Plot{SeisMakie.seisimage, Tuple{Matrix{<:Real}}}
# - typeof(pl.plots[1].plots[1]) = Image{Tuple{ClosedInterval{Float32}, ClosedInterval{Float32}, Matrix{Float32}}}
return Makie.extract_colormap(pl.plots[1].plots[1])
end
end
16 changes: 8 additions & 8 deletions src/Recipes/SeisWiggleRecipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ julia> wp = seiswiggle!(ax, d)
end

function Makie.plot!(wp::SeisWiggle{<:Tuple{AbstractMatrix{<:Real}}})

d = wp.d
gx = wp.gx

Expand All @@ -62,23 +62,23 @@ function Makie.plot!(wp::SeisWiggle{<:Tuple{AbstractMatrix{<:Real}}})

oy = wp.oy[]
dy = wp.dy[]

xcur = wp.xcur[]
wiggle_trace_increment = wp.wiggle_trace_increment[]

if isnothing(gx[])
gx[] = [ox+(i-1)*dx for i in 1:size(d[], 2)]
gx[] = [ox+(i-1)*dx for i in 1:size(d[], 2)]
end

traces = Observable(Vector{Point2f}[])
positive_traces = Observable(Vector{Point2f}[])
zero_lines = Observable(Vector{Point2f}[])

function update_plot(d, gx)
function update_plot(d, gx)
empty!(traces[])
empty!(positive_traces[])
empty!(zero_lines[])

dgx = minimum([gx[i]-gx[i-1] for i in 2:length(gx)])
max_perturb = maximum(abs, d)
times = oy:dy:(dy*(size(d, 1)-1)+oy)
Expand All @@ -90,7 +90,7 @@ function Makie.plot!(wp::SeisWiggle{<:Tuple{AbstractMatrix{<:Real}}})
while gx[i] >= st+wiggle_trace_increment*dgx
st += wiggle_trace_increment*dgx
end

if gx[i] >= st && gx[i] < st+wiggle_trace_increment*dgx
trace = Point2.(gx[i] .+ (scale .* d[:, i]), times)
pos_trace = Point2.(gx[i] .+ max.(scale .* d[:, i], 0), times)
Expand All @@ -101,7 +101,7 @@ function Makie.plot!(wp::SeisWiggle{<:Tuple{AbstractMatrix{<:Real}}})
st += wiggle_trace_increment*dgx
end
end
end
end

Makie.Observables.onany(update_plot, d, gx)

Expand Down
15 changes: 9 additions & 6 deletions src/SeisDifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Return the figure and 3 axes corresponding to d1, d2, d1-d2.
# Example
```julia
julia> d1 = SeisLinearEvents(); d2 = SeisLinearEvents();
julia> d1 = SeisLinearEvents(); d2 = SeisLinearEvents();
julia> f, ax1, ax2, ax_diff = SeisDifference(d1, d2);
```
"""
function SeisDifference(d1, d2;
fig=nothing, ox=0, dx=1, oy=0, dy=1, gx=nothing,
pclip=98, vmin=nothing, vmax=nothing, wiggle_line_color=:black,
pclip=98, vmin=nothing, vmax=nothing, wiggle_line_color=:black,
wiggle_fill_color=:black, trace_width=0.7, cmap=:viridis, style="overlay", horizontal=true)

if isnothing(fig)
Expand All @@ -68,9 +68,12 @@ function SeisDifference(d1, d2;

for (i, ax) in enumerate(axes)
xlims!(ax, low=ox-dx, high=ox+size(d1,2)*dx)
push!(plots, plotfunc(ax, data[i], ox=ox, dx=dx, oy=oy, dy=dy, gx=gx, pclip=pclip, vmin=vmin, vmax=vmax,
wiggle_line_color=wiggle_line_color, wiggle_fill_color=wiggle_fill_color,
trace_width=trace_width, cmap=cmap))
push!(plots, plotfunc(ax, data[i], ox=ox, dx=dx, oy=oy, dy=dy, gx=gx, pclip=pclip,
vmin=vmin, vmax=vmax,
wiggle_line_color=wiggle_line_color,
wiggle_fill_color=wiggle_fill_color,
trace_width=trace_width,
cmap=cmap))
end

if !(style == "wiggles" || style == "wiggle")
Expand All @@ -82,4 +85,4 @@ function SeisDifference(d1, d2;
end

return fig, axes[1], axes[2], axes[3]
end
end
6 changes: 2 additions & 4 deletions src/SeisMakie.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

module SeisMakie

# Write your package code here.
using Makie
using Statistics
using FFTW
Expand All @@ -19,14 +17,14 @@ module SeisMakie
include("SeisPlotAmplitude.jl")

include("Util.jl")

export seisamplitude
export seisamplitude!
export seisfk
export seisfk!
export seisimage
export seisimage!
export seisoverlay
export seisoverlay
export seisoverlay!
export seiswiggle
export seiswiggle!
Expand Down
6 changes: 3 additions & 3 deletions src/SeisPlotAmplitude.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Plot amplitude-frequency 2D seismic data `d`
# Example
```julia
julia> d = SeisLinearEvents();
julia> d = SeisLinearEvents();
julia> f, ax = SeisPlotAmplitude(d,100,0.004);
```
"""
function SeisPlotAmplitude(d::Array{<:Real, 2}; fig=nothing, ax=nothing, fmax=100, dy=0.004,
normalize=false, color=:black, label="")

if isnothing(fig)
if isnothing(fig)
fig = Figure()
end

Expand All @@ -42,4 +42,4 @@ function SeisPlotAmplitude(d::Array{<:Real, 2}; fig=nothing, ax=nothing, fmax=10
seisamplitude!(ax, d, fmax=fmax, dy=dy, normalize=normalize, color=color, label=label)

return fig, ax
end
end
31 changes: 18 additions & 13 deletions src/SeisPlotTX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,43 @@ Return the figure and axis corresponding to d.
# Example
```julia
julia> d = SeisLinearEvents();
julia> d = SeisLinearEvents();
julia> f, ax = SeisPlotTX(d);
```
"""
function SeisPlotTX(d;
function SeisPlotTX(d;
fig=nothing, gx=nothing, ox=0, dx=1, oy=0, dy=1, xcur=1.2, wiggle_trace_increment=1,
pclip=98, vmin=nothing, vmax=nothing,
wiggle_line_color=:black, wiggle_fill_color=:black,trace_width=0.7,
pclip=98, vmin=nothing, vmax=nothing,
wiggle_line_color=:black, wiggle_fill_color=:black,trace_width=0.7,
cmap=:seismic, style="image")

if isnothing(fig)
fig = Figure()
end

ax = __create_axis(fig[1,1])

if style == "overlay"
overlay = seisoverlay!(ax, d; ox=ox, dx=dx, oy=oy, dy=dy, pclip=pclip, vmin=vmin, vmax=vmax, xcur=xcur,
wiggle_trace_increment=wiggle_trace_increment, wiggle_line_color=wiggle_line_color,
wiggle_fill_color=wiggle_fill_color, trace_width=trace_width, cmap=cmap)

overlay = seisoverlay!(ax, d;
ox=ox, dx=dx, oy=oy, dy=dy, pclip=pclip, vmin=vmin, vmax=vmax, xcur=xcur,
wiggle_trace_increment=wiggle_trace_increment,
wiggle_line_color=wiggle_line_color,
wiggle_fill_color=wiggle_fill_color,
trace_width=trace_width, cmap=cmap)

Colorbar(fig[1, 2], overlay)
elseif style == "wiggles" || style == "wiggle"
if !isnothing(gx)
ox = gx[1]
dx = wiggle_trace_increment*minimum([gx[i]-gx[i-1] for i = 2:length(gx)])
end

seiswiggle!(ax, d; gx=gx, ox=ox, dx=dx, oy=oy, dy=dy, xcur=xcur, wiggle_trace_increment=wiggle_trace_increment,
wiggle_line_color=wiggle_line_color, wiggle_fill_color=wiggle_fill_color,
trace_width=trace_width)
else
seiswiggle!(ax, d; gx=gx, ox=ox, dx=dx, oy=oy, dy=dy, xcur=xcur,
wiggle_trace_increment=wiggle_trace_increment,
wiggle_line_color=wiggle_line_color,
wiggle_fill_color=wiggle_fill_color,
trace_width=trace_width)
else
img = seisimage!(ax, d; ox=ox, dx=dx, oy=oy, dy=dy, pclip=pclip, vmin=vmin, vmax=vmax, cmap=cmap)
Colorbar(fig[1,2], img)
end
Expand Down

0 comments on commit 35aea9c

Please sign in to comment.