Skip to content

Commit b191cb6

Browse files
committed
Refactor source files
1 parent 40eea2c commit b191cb6

File tree

7 files changed

+132
-146
lines changed

7 files changed

+132
-146
lines changed

src/simulation/field.jl

+11-9
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,17 @@ end
155155
# METHODS
156156
# --------
157157

158-
include("field/methods.jl")
159-
include("field/generic.jl")
158+
"""
159+
FieldSimulationMethod
160+
161+
A method for simulating field processes.
162+
"""
163+
abstract type FieldSimulationMethod end
164+
165+
include("field/lusim.jl")
166+
include("field/seqsim.jl")
167+
include("field/fftsim.jl")
168+
include("field/defsim.jl")
160169

161170
# ---------
162171
# DEFAULTS
@@ -211,10 +220,3 @@ function defaultsimulation(process::GaussianProcess, domain; data=nothing)
211220
end
212221

213222
defaultsimulation(::IndicatorProcess, domain; data=nothing) = SEQSIM()
214-
215-
# ----------------
216-
# IMPLEMENTATIONS
217-
# ----------------
218-
219-
include("field/gaussian.jl")
220-
include("field/lindgren.jl")
File renamed without changes.

src/simulation/field/gaussian/fft.jl src/simulation/field/fftsim.jl

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22
# Licensed under the MIT License. See LICENSE in the project root.
33
# ------------------------------------------------------------------
44

5+
"""
6+
FFTSIM(; [options])
7+
8+
The FFT simulation method introduced by Gutjahr 1997.
9+
10+
The covariance function is perturbed in the frequency domain
11+
after a fast Fourier transform. White noise is added to the
12+
phase of the spectrum, and a realization is produced by an
13+
inverse Fourier transform.
14+
15+
Data conditioning is currently performed with Kriging, which
16+
accepts the following neighbor search options.
17+
18+
## Options
19+
20+
* `minneighbors` - Minimum number of neighbors (default to `1`)
21+
* `maxneighbors` - Maximum number of neighbors (default to `26`)
22+
* `neighborhood` - Search neighborhood (default to `nothing`)
23+
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
24+
25+
## References
26+
27+
* Gutjahr 1997. [General joint conditional simulations using a fast
28+
Fourier transform method](https://link.springer.com/article/10.1007/BF02769641)
29+
30+
### Notes
31+
32+
The method is limited to simulations on regular grids, and care must be
33+
taken to make sure that the correlation length is small enough compared to
34+
the grid size. As a general rule of thumb, avoid correlation lengths greater
35+
than 1/3 of the grid.
36+
37+
Visual artifacts can appear near the boundaries of the grid if the correlation
38+
length is large compared to the grid itself.
39+
"""
40+
@kwdef struct FFTSIM{N,D} <: FieldSimulationMethod
41+
minneighbors::Int = 1
42+
maxneighbors::Int = 26
43+
neighborhood::N = nothing
44+
distance::D = Euclidean()
45+
end
46+
547
function preprocess(::AbstractRNG, process::GaussianProcess, method::FFTSIM, init, domain, data)
648
# function and mean
749
f = process.func

src/simulation/field/gaussian.jl

-6
This file was deleted.

src/simulation/field/gaussian/lu.jl src/simulation/field/lusim.jl

+33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22
# Licensed under the MIT License. See LICENSE in the project root.
33
# ------------------------------------------------------------------
44

5+
"""
6+
LUSIM()
7+
8+
The LU simulation method introduced by Alabert 1987 and Davis 1987.
9+
10+
The full covariance matrix is built to include all locations
11+
of the data, and samples from the multivariate Gaussian are
12+
drawn via a lower-upper (LU) matrix factorization.
13+
14+
## References
15+
16+
* Alabert 1987. [The practice of fast conditional simulations
17+
through the LU decomposition of the covariance matrix]
18+
(https://link.springer.com/article/10.1007/BF00897191)
19+
20+
* Davis 1987. [Production of conditional simulations via the LU
21+
triangular decomposition of the covariance matrix]
22+
(https://link.springer.com/article/10.1007/BF00898189)
23+
24+
* Oliver 2003. [Gaussian cosimulation: modeling of the cross-covariance]
25+
(https://link.springer.com/article/10.1023%2FB%3AMATG.0000002984.56637.ef)
26+
27+
### Notes
28+
29+
The method is only adequate for domains with relatively small
30+
number of elements (e.g. 100x100 grids) where it is feasible to
31+
factorize the full covariance.
32+
33+
For larger domains (e.g. 3D grids), other methods are preferred
34+
such as [`SEQSIM`](@ref) and [`FFTSIM`](@ref).
35+
"""
36+
struct LUSIM <: FieldSimulationMethod end
37+
538
function preprocess(::AbstractRNG, process::GaussianProcess, method::LUSIM, init, domain, data)
639
# process parameters
740
f = process.func

src/simulation/field/methods.jl

-131
This file was deleted.

src/simulation/field/generic.jl src/simulation/field/seqsim.jl

+46
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22
# Licensed under the MIT License. See LICENSE in the project root.
33
# ------------------------------------------------------------------
44

5+
"""
6+
SEQSIM(; [options])
7+
8+
The sequential simulation method introduced by Gomez-Hernandez 1993.
9+
10+
The method traverses all locations of the geospatial domain according to
11+
a path, approximates the conditional distribution within a neighborhood
12+
using a geostatistical model, and assigns a value to the center of the
13+
neighborhood by sampling from this distribution.
14+
15+
## Options
16+
17+
* `path` - Process path (default to `LinearPath()`)
18+
* `minneighbors` - Minimum number of neighbors (default to `1`)
19+
* `maxneighbors` - Maximum number of neighbors (default to `26`)
20+
* `neighborhood` - Search neighborhood (default to `:range`)
21+
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
22+
23+
For each location in the process `path`, a maximum number of
24+
neighbors `maxneighbors` is used to fit the conditional Gaussian
25+
distribution. The neighbors are searched according to a `neighborhood`.
26+
27+
The `neighborhood` can be a `MetricBall`, the symbol `:range` or `nothing`.
28+
The symbol `:range` is converted to `MetricBall(range(f))` where `f` is the
29+
geostatistical function of the Gaussian process. If `neighborhood` is `nothing`,
30+
the nearest neighbors are used without additional constraints.
31+
32+
## References
33+
34+
* Gomez-Hernandez & Journel 1993. [Joint Sequential Simulation of
35+
MultiGaussian Fields](https://link.springer.com/chapter/10.1007/978-94-011-1739-5_8)
36+
37+
### Notes
38+
39+
This method is very sensitive to neighbor search options and
40+
simulation path. Care must be taken to make sure that enough
41+
neighbors are used in the underlying geostatistical model.
42+
"""
43+
@kwdef struct SEQSIM{P,N,D} <: FieldSimulationMethod
44+
path::P = LinearPath()
45+
minneighbors::Int = 1
46+
maxneighbors::Int = 26
47+
neighborhood::N = :range
48+
distance::D = Euclidean()
49+
end
50+
551
function preprocess(::AbstractRNG, process, method::SEQSIM, init, domain, data)
652
# geostatistical function
753
func = process.func

0 commit comments

Comments
 (0)