Skip to content

Commit fa3cea5

Browse files
committed
Refactor field simulation
1 parent 22f3b6f commit fa3cea5

File tree

7 files changed

+348
-319
lines changed

7 files changed

+348
-319
lines changed

src/simulation.jl

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

5-
"""
6-
SimulationMethod
7-
8-
A method for simulating geostatistical processes.
9-
"""
10-
abstract type SimulationMethod end
11-
12-
"""
13-
LUSIM(; [options])
14-
15-
The LU simulation method introduced by Alabert 1987.
16-
17-
The full covariance matrix is built to include all locations
18-
of the data, and samples from the multivariate Gaussian are
19-
drawn via a lower-upper (LU) matrix factorization.
20-
21-
## Options
22-
23-
`factorization` - Factorization function from LinearAlgebra (default to `cholesky`)
24-
25-
## References
26-
27-
* Alabert 1987. [The practice of fast conditional simulations
28-
through the LU decomposition of the covariance matrix]
29-
(https://link.springer.com/article/10.1007/BF00897191)
30-
31-
* Oliver 2003. [Gaussian cosimulation: modeling of the cross-covariance]
32-
(https://link.springer.com/article/10.1023%2FB%3AMATG.0000002984.56637.ef)
33-
34-
### Notes
35-
36-
The method is only adequate for domains with relatively small
37-
number of elements (e.g. 100x100 grids) where it is feasible to
38-
factorize the full covariance.
39-
40-
For larger domains (e.g. 3D grids), other methods are preferred
41-
such as [`SEQSIM`](@ref) and [`FFTSIM`](@ref).
42-
"""
43-
@kwdef struct LUSIM{F} <: SimulationMethod
44-
factorization::F = cholesky
45-
end
46-
47-
"""
48-
SEQSIM(; [options])
49-
50-
The sequential simulation method introduced by Gomez-Hernandez 1993.
51-
52-
The method traverses all locations of the geospatial domain according to
53-
a path, approximates the conditional distribution within a neighborhood
54-
using a geostatistical model, and assigns a value to the center of the
55-
neighborhood by sampling from this distribution.
56-
57-
## Options
58-
59-
* `path` - Process path (default to `LinearPath()`)
60-
* `minneighbors` - Minimum number of neighbors (default to `1`)
61-
* `maxneighbors` - Maximum number of neighbors (default to `26`)
62-
* `neighborhood` - Search neighborhood (default to `:range`)
63-
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
64-
65-
For each location in the process `path`, a maximum number of
66-
neighbors `maxneighbors` is used to fit the conditional Gaussian
67-
distribution. The neighbors are searched according to a `neighborhood`.
68-
69-
The `neighborhood` can be a `MetricBall`, the symbol `:range` or `nothing`.
70-
The symbol `:range` is converted to `MetricBall(range(f))` where `f` is the
71-
geostatistical function of the Gaussian process. If `neighborhood` is `nothing`,
72-
the nearest neighbors are used without additional constraints.
73-
74-
## References
75-
76-
* Gomez-Hernandez & Journel 1993. [Joint Sequential Simulation of
77-
MultiGaussian Fields](https://link.springer.com/chapter/10.1007/978-94-011-1739-5_8)
78-
79-
### Notes
80-
81-
This method is very sensitive to the neighbor search options.
82-
Care must be taken to make sure that enough neighbors are used
83-
in the underlying geostatistical model.
84-
"""
85-
@kwdef struct SEQSIM{P,N,D} <: SimulationMethod
86-
path::P = LinearPath()
87-
minneighbors::Int = 1
88-
maxneighbors::Int = 26
89-
neighborhood::N = :range
90-
distance::D = Euclidean()
91-
end
92-
93-
"""
94-
FFTSIM(; [options])
95-
96-
The FFT simulation method introduced by Gutjahr 1997.
97-
98-
The covariance function is perturbed in the frequency domain
99-
after a fast Fourier transform. White noise is added to the
100-
phase of the spectrum, and a realization is produced by an
101-
inverse Fourier transform.
102-
103-
## Options
104-
105-
* `minneighbors` - Minimum number of neighbors (default to `1`)
106-
* `maxneighbors` - Maximum number of neighbors (default to `26`)
107-
* `neighborhood` - Search neighborhood (default to `nothing`)
108-
* `distance` - Distance used to find nearest neighbors (default to `Euclidean()`)
109-
110-
## References
111-
112-
* Gutjahr 1997. [General joint conditional simulations using a fast
113-
Fourier transform method](https://link.springer.com/article/10.1007/BF02769641)
114-
115-
* Gómez-Hernández, J. & Srivastava, R. 2021. [One Step at a Time: The Origins
116-
of Sequential Simulation and Beyond](https://link.springer.com/article/10.1007/s11004-021-09926-0)
117-
118-
### Notes
119-
120-
The method is limited to simulations on regular grids, and care must be
121-
taken to make sure that the correlation length is small enough compared to
122-
the grid size. As a general rule of thumb, avoid correlation lengths greater
123-
than 1/3 of the grid.
124-
125-
Visual artifacts can appear near the boundaries of the grid if the correlation
126-
length is large compared to the grid itself.
127-
"""
128-
@kwdef struct FFTSIM{N,D} <: SimulationMethod
129-
minneighbors::Int = 1
130-
maxneighbors::Int = 26
131-
neighborhood::N = nothing
132-
distance::D = Euclidean()
133-
end
134-
135-
# ----------------
136-
# IMPLEMENTATIONS
137-
# ----------------
138-
1395
include("simulation/point.jl")
1406
include("simulation/field.jl")

src/simulation/field.jl

+12-5
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ function dataschema(data)
151151
Tables.Schema(schema.names, map(nonmissingtype, schema.types))
152152
end
153153

154-
# ----------------
155-
# IMPLEMENTATIONS
156-
# ----------------
154+
# --------
155+
# METHODS
156+
# --------
157157

158-
include("field/gaussian.jl")
159-
include("field/lindgren.jl")
158+
include("field/methods.jl")
159+
include("field/generic.jl")
160160

161161
# ---------
162162
# DEFAULTS
@@ -202,3 +202,10 @@ function defaultsimulation(process::GaussianProcess, domain; data=nothing)
202202
SEQSIM()
203203
end
204204
end
205+
206+
# ----------------
207+
# IMPLEMENTATIONS
208+
# ----------------
209+
210+
include("field/gaussian.jl")
211+
include("field/lindgren.jl")

src/simulation/field/gaussian.jl

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
# ------------------------------------------------------------------
44

55
include("gaussian/lu.jl")
6-
include("gaussian/seq.jl")
76
include("gaussian/fft.jl")

src/simulation/field/gaussian/seq.jl

-135
This file was deleted.

0 commit comments

Comments
 (0)