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

Update FieldProcess constructors #14

Merged
merged 9 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion ext/GeoStatsProcessesTuringPatternsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function randprep(::AbstractRNG, process::TuringProcess, ::DefaultRandMethod, se
topo = topology(domain)

# assert grid topology
@assert topo isa GridTopology "simulation only defined over grid topology"
@assert topo isa GridTopology "process only defined over grid topology"

# retrieve simulation size
sz = size(topo)
Expand Down
19 changes: 8 additions & 11 deletions src/field/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
# ------------------------------------------------------------------

"""
GaussianProcess([parameters])

Gaussian process with given variogram and mean.

## Parameters

* `variogram` - Theoretical variogram model (default to `GaussianVariogram()`)
* `mean` - Mean field value (default to `0.0`)
GaussianProcess(variogram=GaussianVariogram(), mean=0.0)

Gaussian process with given theoretical `variogram` and global `mean`.
"""
@kwdef struct GaussianProcess{V,T} <: FieldProcess
variogram::V = GaussianVariogram()
mean::T = 0.0
struct GaussianProcess{V,T} <: FieldProcess
variogram::V
mean::T
end

GaussianProcess(variogram) = GaussianProcess(variogram, 0.0)
GaussianProcess() = GaussianProcess(GaussianVariogram(), 0.0)

#---------
# METHODS
#---------
Expand Down
6 changes: 3 additions & 3 deletions src/field/gaussian/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# ------------------------------------------------------------------

"""
FFTMethod([paramaters])
FFTMethod(; [paramaters])

The FFT Gaussian simulation method introduced by Gutjahr 1997.
The FFT Gaussian process method introduced by Gutjahr 1997.
The covariance function is perturbed in the frequency domain
after a fast Fourier transform. White noise is added to the
phase of the spectrum, and a realization is produced by an
Expand All @@ -17,7 +17,7 @@ inverse Fourier transform.
* `neighborhood` - Search neighborhood (default to `nothing`)
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)

### References
## References

* Gutjahr 1997. [General joint conditional simulations using a fast
Fourier transform method](https://link.springer.com/article/10.1007/BF02769641)
Expand Down
8 changes: 4 additions & 4 deletions src/field/gaussian/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# ------------------------------------------------------------------

"""
LUMethod([paramaters])
LUMethod(; [paramaters])

The LU Gaussian simulation method introduced by Alabert 1987.
The LU Gaussian process method introduced by Alabert 1987.
The full covariance matrix is built to include all locations
of the simulation domain, and samples from the multivariate
of the process domain, and samples from the multivariate
Gaussian are drawn via LU factorization.

## Parameters
Expand All @@ -16,7 +16,7 @@ Gaussian are drawn via LU factorization.
* `correlation` - Correlation coefficient between two covariates (default to `0`)
* `init` - Data initialization method (default to `NearestInit()`)

### References
## References

* Alabert 1987. [The practice of fast conditional simulations
through the LU decomposition of the covariance matrix]
Expand Down
14 changes: 7 additions & 7 deletions src/field/gaussian/seq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
# ------------------------------------------------------------------

"""
SEQMethod([paramaters])
SEQMethod(; [paramaters])

The sequential simulation method introduced by Gomez-Hernandez 1993.
The sequential process method introduced by Gomez-Hernandez 1993.
It traverses all locations of the geospatial domain according to a path,
approximates the conditional Gaussian distribution within a neighborhood
using Kriging, and assigns a value to the center of the neighborhood by
sampling from this distribution.

## Parameters

* `path` - Simulation path (default to `LinearPath()`)
* `path` - Process path (default to `LinearPath()`)
* `minneighbors` - Minimum number of neighbors (default to `1`)
* `maxneighbors` - Maximum number of neighbors (default to `10`)
* `neighborhood` - Search neighborhood (default to `nothing`)
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
* `init` - Data initialization method (default to `NearestInit()`)

For each location in the simulation `path`, a maximum number of
For each location in the process `path`, a maximum number of
neighbors `maxneighbors` is used to fit the conditional Gaussian
distribution. The neighbors are searched according to a `neighborhood`.

### References
## References

* Gomez-Hernandez & Journel 1993. [Joint Sequential Simulation of
MultiGaussian Fields](https://link.springer.com/chapter/10.1007/978-94-011-1739-5_8)

### Notes

* This method is very sensitive to the simulation path and number of
* This method is very sensitive to the process path and number of
samples. Care must be taken to make sure that neighborhoods have
enough samples for the geostatistical model (e.g. Kriging).
"""
Expand All @@ -49,7 +49,7 @@ function randprep(::AbstractRNG, process::GaussianProcess, method::SEQMethod, se
(; path, minneighbors, maxneighbors, neighborhood, distance, init) = method
probmodel = GeoStatsModels.SimpleKriging(variogram, mean)
marginal = Normal(mean, √sill(variogram))
SequentialProcess(; probmodel, marginal, path, minneighbors, maxneighbors, neighborhood, distance, init)
SequentialProcess(probmodel, marginal; path, minneighbors, maxneighbors, neighborhood, distance, init)
end

function randsingle(rng::AbstractRNG, ::GaussianProcess, ::SEQMethod, setup::RandSetup, prep)
Expand Down
26 changes: 13 additions & 13 deletions src/field/lindgren.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
# ------------------------------------------------------------------

"""
LindgrenProcess([paramaters])
LindgrenProcess(range=1.0, sill=1.0)

The SPDE process introduced by Lindgren 2011. It relies on a
discretization of the Laplace-Beltrami operator on meshes and
is adequate for highly curved domains (e.g. surfaces).
Lindgren process with given `range` (correlation length)
and `sill` (total variance) as described in Lindgren 2011.

## Parameters
The process relies relies on a discretization of the Laplace-Beltrami
operator on meshes and is adequate for highly curved domains (e.g. surfaces).

* `range` - Range or correlation length (default to `1.0`)
* `sill` - Sill or total variance (default to `1.0`)

### References
## References

* Lindgren et al. 2011. [An explicit link between Gaussian fields and
Gaussian Markov random fields: the stochastic partial differential
equation approach](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2011.00777.x)
"""
@kwdef struct LindgrenProcess <: FieldProcess
range::Float64 = 1.0
sill::Float64 = 1.0
struct LindgrenProcess <: FieldProcess
range::Float64
sill::Float64
end

LindgrenProcess(range) = LindgrenProcess(range, 1.0)
LindgrenProcess() = LindgrenProcess(1.0, 1.0)

function randprep(::AbstractRNG, process::LindgrenProcess, ::DefaultRandMethod, setup::RandSetup)
isnothing(setup.geotable) || @error "conditional simulation is not implemented"
isnothing(setup.geotable) || @error "conditional process is not implemented"

# retrieve sill and range
𝓁 = process.range
Expand Down
45 changes: 26 additions & 19 deletions src/field/quilting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,45 @@
# ------------------------------------------------------------------

"""
QuiltingProcess([paramaters])
QuiltingProcess(trainimg, tilesize; [paramaters])

Image quilting process as described in Hoffimann et al. 2017.
Image quilting process with training image `trainimg` and tile size `tilesize`
as described in Hoffimann et al. 2017.

## Parameters

### Required

* `trainimg` - Training image from which to extract tiles
* `tilesize` - Tuple with tile size for each dimension

### Optional

* `overlap` - Overlap size (default to (1/6, 1/6, ..., 1/6))
* `path` - Simulation path (`:raster` (default), `:dilation`, or `:random`)
* `path` - Process path (`:raster` (default), `:dilation`, or `:random`)
* `inactive` - Vector of inactive voxels (i.e. `CartesianIndex`) in the grid
* `soft` - A pair `(data,dataTI)` of geospatial data objects (default to `nothing`)
* `tol` - Initial relaxation tolerance in (0,1] (default to `0.1`)
* `init` - Data initialization method (default to `NearestInit()`)

## References

* Hoffimann et al 2017. *Stochastic simulation by image quilting of process-based geological models.*
* Hoffimann et al 2015. *Geostatistical modeling of evolving landscapes by means of image quilting.*
* Hoffimann et al 2017. [Stochastic simulation by image quilting
of process-based geological models](https://www.sciencedirect.com/science/article/abs/pii/S0098300417301139)
* Hoffimann et al 2015. [Geostatistical modeling of evolving landscapes
by means of image quilting](https://www.researchgate.net/publication/295902985_Geostatistical_Modeling_of_Evolving_Landscapes_by_Means_of_Image_Quilting)
"""
@kwdef struct QuiltingProcess{TR,TS,O,P,IN,S,T,I} <: FieldProcess
struct QuiltingProcess{TR,TS,O,P,IN,S,T,I} <: FieldProcess
trainimg::TR
tilesize::TS
overlap::O = nothing
path::P = :raster
inactive::IN = nothing
soft::S = nothing
tol::T = 0.1
init::I = NearestInit()
overlap::O
path::P
inactive::IN
soft::S
tol::T
init::I
end

QuiltingProcess(
trainimg,
tilesize;
overlap=nothing,
path=:raster,
inactive=nothing,
soft=nothing,
tol=0.1,
init=NearestInit()
) = QuiltingProcess(trainimg, tilesize, overlap, path, inactive, soft, tol, init)
37 changes: 23 additions & 14 deletions src/field/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,48 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------


"""
SequentialProcess([paramaters])
SequentialProcess(probmodel, marginal; [paramaters])

A sequential simulation process.
A sequential process with given conditional distribution model `probmodel`
and `marginal` distribution.

For each location in the simulation `path`, a maximum number
For each location in the process `path`, a maximum number
of neighbors `maxneighbors` is used to fit a distribution.
The neighbors are searched according to a `neighborhood`,
and in case there are none, use a `marginal` distribution.

## Parameters

* `probmodel` - Conditional distribution model from GeoStatsModels.jl
* `marginal` - Marginal distribution from Distributions.jl
* `path` - Simulation path (default to `LinearPath()`)
* `path` - Process path (default to `LinearPath()`)
* `minneighbors` - Minimum number of neighbors (default to `1`)
* `maxneighbors` - Maximum number of neighbors (default to `10`)
* `neighborhood` - Search neighborhood (default to `nothing`)
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
* `init` - Data initialization method (default to `NearestInit()`)
"""
@kwdef struct SequentialProcess{M,MD,P,N,D,I} <: FieldProcess
struct SequentialProcess{M,MD,P,N,D,I} <: FieldProcess
probmodel::M
marginal::MD
path::P = LinearPath()
minneighbors::Int = 1
maxneighbors::Int = 10
neighborhood::N = nothing
distance::D = Euclidean()
init::I = NearestInit()
path::P
minneighbors::Int
maxneighbors::Int
neighborhood::N
distance::D
init::I
end

SequentialProcess(
probmodel,
marginal;
path=LinearPath(),
minneighbors=1,
maxneighbors=10,
neighborhood=nothing,
distance=Euclidean(),
init=NearestInit()
) = SequentialProcess(probmodel, marginal, path, minneighbors, maxneighbors, neighborhood, distance, init)

function randprep(::AbstractRNG, process::SequentialProcess, ::DefaultRandMethod, setup::RandSetup)
# retrieve domain info
domain = setup.domain
Expand Down
27 changes: 15 additions & 12 deletions src/field/strata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
# ------------------------------------------------------------------

"""
StrataProcess([paramaters])
StrataProcess(environment; [paramaters])

A process to simulate 3D stratigraphic models.
Strata process with given geological `environment`
as described in Hoffimann 2018.

## Parameters

* `environment` - Geological environment
* `state` - Initial geological state
* `stack` - Stacking scheme (:erosional or :depositional)
* `nepochs` - Number of epochs (default to 10)
* `fillbase` - Fill value for the bottom layer (default to `NaN`)
* `filltop` - Fill value for the top layer (default to `NaN`)

### References
## References

Hoffimann 2018. *Morphodynamic analysis and statistical
synthesis of geormorphic data.*
* Hoffimann 2018. [Morphodynamic analysis and statistical synthesis of
geormorphic data](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2019JF005245)
"""
@kwdef struct StrataProcess{E,S,ST,N,FB,FT} <: FieldProcess
struct StrataProcess{E,S,ST,N,FB,FT} <: FieldProcess
environment::E
state::S = nothing
stack::ST = :erosional
nepochs::N = 10
fillbase::FB = NaN
filltop::FT = NaN
state::S
stack::ST
nepochs::N
fillbase::FB
filltop::FT
end

StrataProcess(environment; state=nothing, stack=:erosional, nepochs=10, fillbase=NaN, filltop=NaN) =
StrataProcess(environment, state, stack, nepochs, fillbase, filltop)
18 changes: 10 additions & 8 deletions src/field/turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------

"""
TuringProcess([paramaters])
TuringProcess(; [paramaters])

Turing process as described in Turing 1952.

Expand All @@ -14,13 +14,15 @@ Turing process as described in Turing 1952.
* `edge` - edge condition (default to `nothing`)
* `iter` - number of iterations (default to `100`)

### References
## References

Turing 1952. *The chemical basis of morphogenesis.*
* Turing 1952. [The chemical basis of morphogenesis](https://royalsocietypublishing.org/doi/10.1098/rstb.1952.0012)
"""
@kwdef struct TuringProcess{P,B,E,I} <: FieldProcess
params::P = nothing
blur::B = nothing
edge::E = nothing
iter::I = 100
struct TuringProcess{P,B,E,I} <: FieldProcess
params::P
blur::B
edge::E
iter::I
end

TuringProcess(; params=nothing, blur=nothing, edge=nothing, iter=100) = TuringProcess(params, blur, edge, iter)
Loading
Loading