Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SP #8

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ Variography = "04a0146e-e6df-5636-8d7f-62fa9eb0b20c"

[weakdeps]
ImageQuilting = "e8712464-036d-575c-85ac-952ae31322ab"
StratiGraphics = "135379e1-83be-5ae7-9e8e-29dade3dc6c7"
TuringPatterns = "fde5428d-3bf0-5ade-b94a-d334303c4d77"

[extensions]
GeoStatsProcessesImageQuiltingExt = "ImageQuilting"
GeoStatsProcessesStratiGraphicsExt = "StratiGraphics"
GeoStatsProcessesTuringPatternsExt = "TuringPatterns"

[compat]
Expand All @@ -42,6 +44,7 @@ ImageQuilting = "0.22"
Meshes = "0.35"
ProgressMeter = "1.9"
Statistics = "1.9"
StratiGraphics = "0.7"
Tables = "1.11"
TuringPatterns = "0.6"
Variography = "0.19"
Expand Down
68 changes: 68 additions & 0 deletions ext/GeoStatsProcessesStratiGraphicsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

module GeoStatsProcessesStratiGraphicsExt

using Random
using Meshes

using StratiGraphics: LandState, Strata, simulate, voxelize

using GeoStatsProcesses: SP, RandSetup

import GeoStatsProcesses: randprep, randsingle

function randprep(::AbstractRNG, process::SP, setup::RandSetup)
# retrieve domain info
domain = setup.domain

@assert embeddim(domain) == 3 "solver implemented for 3D domain only"

pairs = map(setup.varnames) do var
# determine initial state
state = if isnothing(process.state)
nx, ny, _ = size(domain)
land = zeros(nx, ny)
LandState(land)
else
process.state
end

# save preprocessed input
var => state
end

Dict(pairs)
end

function randsingle(::AbstractRNG, process::SP, setup::RandSetup, prep)
# retrieve domain info
domain = setup.domain
_, __, nz = size(domain)

# retrieve process parameters
(; environment, stack, nepochs, fillbase, filltop) = process

pairs = map(setup.varnames) do var
# get parameters for the variable
state = prep[var]

# simulate the environment
record = simulate(environment, state, nepochs)

# build stratigraphy
strata = Strata(record, stack)

# return voxel model
model = voxelize(strata, nz; fillbase, filltop)

# flatten result
var => vec(model)
end

Dict(pairs)
end


end
3 changes: 2 additions & 1 deletion src/GeoStatsProcesses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ include("fft.jl")
include("lu.jl")
include("iq.jl")
include("tp.jl")
include("sp.jl")

export SPDEGP, SEQ, SGP, FFTGP, LUGP, IQ, TP
export SPDEGP, SEQ, SGP, FFTGP, LUGP, IQ, TP, SP

end
12 changes: 12 additions & 0 deletions src/sp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

@kwdef struct SP{E,S,ST,N,FB,FT} <: GeoStatsProcess
environment::E
state::S = nothing
stack::ST = :erosional
nepochs::N = 10
fillbase::FB = NaN
filltop::FT = NaN
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ImageQuilting = "e8712464-036d-575c-85ac-952ae31322ab"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StratiGraphics = "135379e1-83be-5ae7-9e8e-29dade3dc6c7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TuringPatterns = "fde5428d-3bf0-5ade-b94a-d334303c4d77"
Variography = "04a0146e-e6df-5636-8d7f-62fa9eb0b20c"
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Test

import ImageQuilting
import TuringPatterns
using StratiGraphics: SmoothingProcess, Environment, ExponentialDuration

@testset "GeoStatsProcesses.jl" begin
@testset "FFTGP" begin
Expand Down Expand Up @@ -143,5 +144,17 @@ import TuringPatterns
Random.seed!(2019)
sdomain = CartesianGrid(200, 200)
sims = rand(TP(), sdomain, [:z => Float64], 3)
@test length(sims) == 3
@test size(domain(sims[1])) == (200, 200)
end

@testset "SP" begin
rng = MersenneTwister(2019)
proc = SmoothingProcess()
env = Environment(rng, [proc, proc], [0.5 0.5; 0.5 0.5], ExponentialDuration(rng, 1.0))
sdomain = CartesianGrid(50, 50, 20)
sims = rand(SP(environment=env), sdomain, [:z => Float64], 3)
@test length(sims) == 3
@test size(domain(sims[1])) == (50, 50, 20)
end
end