Reference
Sample Planning
Generating Points
Monty.Sampling.randin
— Functionrandin(
rng::Random.AbstractRNG,
geom::Meshes.Geometry{2, 𝒯},
N::Int64
) -> Vector{T} where T<:(Meshes.Point{2})
Generates a vector of N
random points inside a two-dimensional geometry
Monty.Sampling.randin!
— Functionrandin!(
rng::Random.AbstractRNG,
points::AbstractArray{Meshes.Point{2, 𝒯}, 1},
geom::Meshes.Geometry{2, 𝒯}
)
Fills a vector with random points inside a two-dimensional geometry
Monty.Sampling.gridpointoverlay
— Functiongridpointoverlay(geom, dims::Tuple{Integer, Integer}) -> Any
Creates a CartesianGrid
of size dims
, intersects the grid with geom
, and returns the centroids of intersected grid cells. Any cells with no intersection are removed.
gridpointoverlay(
rng::Random.AbstractRNG,
geom,
dims::Tuple{Integer, Integer}
) -> Any
Creates a CartesianGrid
of size dims
, intersects the grid with geom
, and returns points sampled randomly from the intersected grid cells. Any cells with no intersection are removed.
Monty.Jitters.jittergrid
— Functionjittergrid(
rng::Random.AbstractRNG,
grid::Meshes.CartesianGrid{2, 𝒯},
centering::Real
) -> Vector
Generates a vector of points where each point is assigned to a random location in each cell of a CartesianGrid
. The centering
parameter controls how closely the points tend to be to each cell's centroid. For uniform randomness (no centering) use centering=1.0
. Higher values induce stronger centering.
Sample Plans
Monty.Sampling.SamplePlan
— TypeA SamplePlan
represents the intended locations and times for all samples in a simulated deployment, in addition to whether target samples are control samples (no feedstock spreading). Generally, it's easiest to construct a sample plan using either the pairedsampleplan
or randomsampleplan
functions. The fields of a SamplePlan
are ReadOnlyArray
types that cannot be modified.
The fields are
location::ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}
round::ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}
time::ReadOnlyArrays.ReadOnlyArray{𝒯, 1, Vector{𝒯}} where 𝒯
control::ReadOnlyArrays.ReadOnlyVector{Bool, Vector{Bool}}
points::ReadOnlyArrays.ReadOnlyArray{Meshes.Point{2, 𝒯}, 1, Array{Meshes.Point{2, 𝒯}, 1}} where 𝒯
Monty.nsample
— Functionnsample(plan::SamplePlan) -> Int64
Returns the number of sample locations in a SamplePlan
. This is the number of planned samples after compositing the cores for each planned location. The number of cores for each sample is given by ncore(plan)
. The total number of cores is ncore(plan) * nsample(plan)
.
nsample(samp::CoreSet) -> Int64
Returns the number of cores per sample
Meshes.boundingbox
— Functionboundingbox(plan::SamplePlan) -> Meshes.Box
Returns the bounding box of the samples in a plan
Monty.Sampling.pairedsampleplan
— Functionpairedsampleplan(
points::Array{Meshes.Point{2, 𝒯}, 1},
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a SamplePlan
where sample locations are repeated for each round of sampling (location-paired). No control points are created. The timing of each sampling round is given by the times
vector.
pairedsampleplan(
points::Array{Meshes.Point{2, 𝒯}, 1},
control,
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a location-paired smaple plan using a vector of existing points
. Points inside the control
geometry will be assigned to the control group. The timing of each sampling round is given by the times
vector.
pairedsampleplan(
treatments::Array{Meshes.Point{2, 𝒯}, 1},
controls::Array{Meshes.Point{2, 𝒯}, 1},
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a location-paired sample plan using existing vectors of treatment
and control
points. The timing of each sampling round is given by the times
vector.
pairedsampleplan(
rng::Random.AbstractRNG,
field::Meshes.Geometry{2, 𝒯},
N::Integer,
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a location-paired sample plan using N
points selected random from inside a field
geometry. The locations are repeated for each sampling round specified in the times
vector.
pairedsampleplan(
rng::Random.AbstractRNG,
treatment::Meshes.Geometry{2, 𝒯},
ntreatment::Integer,
control::Meshes.Geometry{2, 𝒯},
ncontrol::Integer,
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a SamplePlan
where sample locations are repeated for each round of sampling (location-paired). ntreatment
treatment locations are drawn randomly from inside the treatment
geometry and ncontrol
control locations are drawn randomly from inside the control
geometry. The timing of each sampling round is given by the times
vector.
Monty.Sampling.randomsampleplan
— Functionrandomsampleplan(
rng::Random.AbstractRNG,
treatment::Meshes.Geometry{2, 𝒯},
ntreatment::AbstractVector{<:Integer},
control::Meshes.Geometry{2, 𝒯},
ncontrol::AbstractVector{<:Integer},
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a random SamplePlan
, where sample locations are not repeated across different rounds of sampling. For each round of sampling, treament points are drawn randomly from the treatment
geometry. The number of treatment points in each round is determined by the vector of integers ntreatment
. The same true for control points, using the control
geometry and ncontrol
sample sizes for each round. The timing of each sampling round is given by the times
vector.
randomsampleplan(
rng::Random.AbstractRNG,
treatment::Meshes.Geometry{2, 𝒯},
ntreatment::Integer,
control::Meshes.Geometry{2, 𝒯},
ncontrol::Integer,
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a random SamplePlan
, where sample locations are not repeated across different rounds of sampling. For each round of sampling, ntreatment
treament points are drawn randomly from the treatment
geometry and ncontrol
points are drawn randomly from inside the control
geometry. The timing of each sampling round is given by the times
vector.
randomsampleplan(
rng::Random.AbstractRNG,
field::Meshes.Geometry{2, 𝒯},
N::AbstractVector{<:Integer},
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a random sample plan with points selected randomly from inside the field
geometry for each round. The number of points in each round is given by a vector of integers N
and the timing of each round by the times
vector.
randomsampleplan(
rng::Random.AbstractRNG,
field::Meshes.Geometry{2, 𝒯},
N::Integer,
times::AbstractArray{𝒯, 1}
) -> SamplePlan
Creates a random SamplePlan
, where sample locations are not repeated across different rounds of sampling. For each round of sampling, N
treament points are drawn randomly from the field
geometry. The timing of each sampling round is given by the times
vector.
Location Jitter
Monty has three "jitter" types meant to be used as callable objects or "functors." This means that a jitter object is created with some parameters, then used like a function and applied to sample/core locations. Each jitter type can be called on a Point
and it will return a jittered Point
.
Monty.Jitters.jitterpoint
— Functionjitterpoint(
rng::Random.AbstractRNG,
point::Meshes.Point{𝒩, 𝒯},
σ
) -> Meshes.Point
Applies random, isotropic normally distributed jitter to a point in two-dimensional space, where σ
is the absolute standard deviation of the jitter.
Monty.Jitters.jitterpoints!
— Functionjitterpoints!(
rng::Random.AbstractRNG,
points::AbstractArray{Meshes.Point{2, 𝒯}, 1},
σ
)
Applies random, isotropic normally distributed jitter to a vector of points, where σ
is the absolute standard deviation of the jitter.
jitterpoints!(
rng::Random.AbstractRNG,
jittered::AbstractArray{Meshes.Point{2, 𝒯}, 1},
original::AbstractArray{Meshes.Point{2, 𝒯}, 1},
σ
)
Applies random, isotropic normally distributed jitter to a vector of points in place, filling the jittered
vector with points from original
after jittering them, where σ
is the absolute standard deviation of the jitter.
Monty.Jitters.NoJitter
— TypeAn empty type representing no jitter at all
NoJitter()
Monty.Jitters.Jitter
— TypeThe Jitter
type applies random isotropic noise to a Point
.
Jitter(d::UnivariateDistribution; seed=Union{Nothing,Integer}=nothing)
The first constructor above accepts a pre-specified distribution, which represents the noise applied in each dimension.
Jitter(σ; seed::Union{Nothing,Integer}=nothing)
The second constructor assumes a normal distribution for the noise, and receives the standard deviation of that distribution. In both cases a seed
can be given, which is used to draw random values.
Monty.Jitters.GridCentroidJitter
— TypeRandom variation of points within the dimensions of grid cells. The
Core Stencils
Like the jitter types above, core stencil types are all used as callable objects or "functors." This means that a stencil is created with some parameters, then used like a function to generate core locations. Generally, stencils don't have to be used directly in Monty. They are passed to executeplan!
, which handles the function calling. To use one directly, however, just requires passing a location and core number to the object
stencil(point::Point, n::Integer)
which returns the core location as another Point
.
Monty.Stencils.SingleCoreStencil
— TypeAn empty type representing a single core. The SingleCoreStencil constructor has no arguments
SingleCoreStencil()
Monty.Stencils.RandomStencil
— TypeA core stencil representing randomly drawn core locations
RandomStencil(N::Integer, args...; kwargs...)
Creates a RandomStencil
with N
cores, where the args
and kwargs
are passed through to the Jitter
constructor
Monty.Stencils.CircleStencil
— TypeA core stencil representing a circle of cores
A CircleStencil is defined by the number of cores and the radius of the circle
CircleStencil(N::Integer, r)
Monty.Stencils.HubSpokeStencil
— TypeA core stencil representing a circle of cores with one point in the center of the circle.
HubSpokeStencil(N::Integer, r)
The constructor takes the number of cores and a radius for the circle
Monty.Stencils.LineStencil
— TypeA core stencil representing a line of cores.
LineStencil(N::Integer, δ::𝒯, θ::𝒯) where {𝒯}
The constructor takes the number of cores, the distance between each core in the line (δ
), and the angle of the line (θ
)
Plan Execution
Monty.Sampling.CoreSet
— TypeA CoreSet
represents the realization of a SamplePlan
and is closely related. The sample plan represents the ideal sampling locations. A core set expands on the sample plan by
- representing planned and unplanned jitter in the target sample locations (for example, simple GPS inaccuracy)
- defining some number of cores for each sample, which are composited during the simulation process.
Dividing the sample plan and core set allows for more efficient simulation of many realizations from the same hypothetical sample plan. A core set can be defined without any location jitter and without compositing (a single core).
A CoreSet
can be created and filled by the executeplan
and executeplan!
functions, respectively.
Monty.Sampling.executeplan
— Functionexecuteplan(
plan::SamplePlan{𝒯};
stencil,
kwargs...
) -> CoreSet
Executes as sample plan and returns a CoreSet
Monty.Sampling.executeplan!
— Functionexecuteplan!(
samp::Array{Meshes.Point{2, 𝒯}, 2},
plan::SamplePlan{𝒯};
stencil,
plannedjitter,
samplerjitter,
corejitter
)
Executes a sample plan, filling an existing CoreSet
with the results.
Mixing Model
Monty.MixingModel.feedstockfraction
— Functionfeedstockfraction(
Γ::Distributions.UnivariateDistribution,
d
) -> Any
Computes the fraction of applied original feedstock contained in a sample, given the mixing profile Γ
, which must be a univariate distribution, and the sample depth d
. This function simply wraps a cdf
evaluation (cumulative probability density) and includes checks for physical consistency.
Monty.MixingModel.feedstockmass
— Functionfeedstockmass(Q, γ, ℒ) -> Any
Computes the mass of feedstock contained in a sample, given the application rate Q
, the sampled fraction γ
, and the feedstock mass loss fraction ℒ
. Evaluates
\[Q \gamma (1 - \mathscr{L})\]
Monty.MixingModel.feedstockelementmass
— Functionfeedstockelementmass(Q, γ, 𝓁, cf) -> Any
Computes the mass of an individual element or analyte in a sample, given the application rate Q
, the sampled feedstock fraction γ
, the analyte loss fraction 𝓁
, and the feedstock mass loss fraction ℒ
. Evaluates
\[Q \gamma (1 - \mathscr{l}) \mathscr{L}\]
Monty.MixingModel.feedstockthickness
— Functionfeedstockthickness(Q, γ, ρf, ℒ) -> Any
Computes the thickness of the feedstock in a sample, given the application rate Q
, the sampled feedstock fraction γ
, and the feedstock bulk density in the sample ρs
. Evaluates
\[Q \gamma / \rho_f\]
Monty.MixingModel.soilmass
— Functionsoilmass(ρs, d) -> Any
Computes the soil mass in a sample, given the soil bulk density ρs
and the soil/sample depth d
. Note that in analytical model, d
represents an apparent soil depth after accounting for the thickness of feedstock material. This function simply performs physical checks and evaluates
\[\rho_s d\]
Monty.MixingModel.soilelementmass
— Functionsoilelementmass(ρs, d, cs) -> Any
Computes the mass of an element/analyte in soil, given the soil bulk density ρs
, the soil/sample depth d
, and the concentration of the element in the soil cs
. Evaluates
\[\rho_s d c_s\]
Monty.MixingModel.samplemass
— Functionsamplemass(M, a) -> Any
Computes the mass of a sample given the sampled soil's mass per unit area M
and sampled cross-sectional area a
. Evaluates
M a
Monty.MixingModel.Sample
— TypeThe Sample
type represents a mass of soil/material with some number of analyte concentrations. When defined, all samples represent an individual soil core, which can be combined by addition (the +
operator) into composite samples.
The Sample
type has three fields:
Field | Description |
---|---|
concentrations | a NamedTuple containing exact sample concentrations |
mass | the exact mass of the sample |
cores | the number of individual cores combined into the composite sample |
A Sample
represents the true, exact properties of a piece of soil and is immutable. Once defined, it can't be modifed. When compositing samples (adding them together), the composite concentrations are computed exactly by mass weighted average. Samples are created from soil and deployment parameters using the mixing
function. To simulate measurement noise/uncertainty, a sample is passed to the measure
function, which applies gaussian noise defined in terms of relative standard deviations.
Monty.nanalyte
— Functionnanalyte(_::Sample{𝒩}) -> Any
Returns the number of analytes in a Sample
Monty.analytes
— Functionanalytes(_::Sample{𝒩, 𝒦}) -> Any
Returns the names/symbols of the analytes in a Sample
Monty.MixingModel.mixing
— Functionmixing(
γ::Number,
d::Number,
a::Number,
Q::Number,
ρf::Number,
cf::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
ρs::Number,
cs::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
𝓁::NamedTuple{𝒦, Tuple{Vararg{𝒰, 𝒩}}},
ℒ::Number
) -> Sample
Evaluates the mixing and leaching model for a single piece of soil, returning a Sample
.
mixing(
γ::Number,
d,
a,
Q,
ρf,
cf::Number,
ρs,
cs::Number,
𝓁::Number,
ℒ
) -> Sample{1, (:analyte,)}
Evaluates the mixing and leaching model for a single piece of soil, returning a Sample
.
Weathering & Leaching Models
Leaching models define the fraction of a feedstock's element lost at any point in time. Each leaching model is a scalar function of time. They always return values that are
- fractional, meaning $\in [0,1]$
- exactly 1 for negative time
- exactly zero at time zero
- monotonically increasing after time zero (no reverse leaching)
Monty.LeachingModels.NoLeaching
— TypeLeaching model with zero leaching at any time
Monty.LeachingModels.ExponentialLeaching
— TypeLeaching model with exponential loss over time. The internal fields are
λ::Any
C::Any
σ::Any
rng::Random.Xoshiro
The constructor is
function ExponentialLeaching(;
λ::𝒯=1.0,
C::𝒯=1.0,
σ::𝒯=0.0,
seed::Union{Nothing,Integer}=nothing,
)
Keyword Arguments
- The
λ
parameter is the exponential decay/loss rate C
is a floor, above which the leache fraction will never cross.- The
σ
parameter adds noise to the model, but should be used with caution because the noise is not symmetrical and can change the average leached fraction at a given point in time. - If there is noise, the internal
rng
can be initialized using theseed
keyword argument.
Monty.LeachingModels.MultiExponentialLeaching
— TypeLeaching model with an average of exponential losses over time. The internal fields are
λ::Tuple{Vararg{𝒯, 𝒩}} where {𝒯, 𝒩}
C::Any
σ::Any
rng::Random.Xoshiro
The constructor is
function MultiExponentialLeaching(;
λ::NTuple{𝒩,𝒯}=1.0,
C::𝒯=1.0,
σ::𝒯=0.0,
seed::Union{Nothing,Integer}=nothing,
)
Keyword Arguments
- The
λ
parameter is tuple of decay/loss rates C
is a floor, above which the leache fraction will never cross.- The
σ
parameter adds noise to the model, but should be used with caution because the noise is not symmetrical and can change the average leached fraction at a given point in time. - If there is noise, the internal
rng
can be initialized using theseed
keyword argument.
Monty.LeachingModels.SeasonalLeaching
— TypeLeaching model with seasonally varying loss over time, representing an annual cycle. The period of the cycles is exactly one year. The internal fields are
λ::Any
C::Any
A::Any
γ::UInt8
ϕ::Any
σ::Any
rng::Random.Xoshiro
The constructor is
function SeasonalLeaching(;
λ=1.0,
C=1.0,
floor=0.0,
power::Integer=1,
phase=π,
σ=0.0,
seed::Union{Nothing,Integer}=nothing,
)
Keyword Arguments
- The
λ
parameter is the exponential decay/loss rate C
is a floor, above which the leache fraction will never cross.floor
sets the minimum value of the sinusoid that is integrated to produce monotonically increasing loss fractions. The details are not that important. It sets the minimum leaching rate. For example, iffloor
is zero, there is a point in each annual cycle where the leaching rate is also zero. Asfloor
is increased, the minimum leaching rate over each annual cycle will increase.power
defines how wide the cycles are, which is analogous to how long the "winter" is when the leaching rate is slow.phase
shifts the cycle in time.- The
σ
parameter adds noise to the model, but should be used with caution because the noise is not symmetrical and can change the average leached fraction at a given point in time. - If there is noise, the internal
rng
can be initialized using theseed
keyword argument.
Here are some a example leaching models:
# time points where models are evaluated
t = LinRange(-1.0, 4.0, 51) |> collect
# models
exp_model = ExponentialLeaching(λ=1.5, C=0.9)
multi_exp_model = MultiExponentialLeaching(λ=(10.0, 1.0), C=0.9)
seasonal_model = SeasonalLeaching(λ=1.0, floor=0.05, power=2, C=0.85)
Simulation
The main simulation function is simulationstack
and an example is shown in the Efficient Simulations page.
Monty.Simulating.moisturefraction
— Functionmoisturefraction(Ω) -> Any
Computes the moisture fraction ($\Phi$) from the moisture ratio ($\Omega$). The "ratio" is the water mass divided by the mass of dry material. The "fraction" is the water mass divided by the total mass. Evaluates
\[\Omega / (1 + \Omega)\]
Monty.Simulating.moistureratio
— Functionmoistureratio(Φ) -> Any
Computes the moisture ratio ($\Omega$) from the moisture fraction ($\Phi$). The "ratio" is the water mass divided by the mass of dry material. The "fraction" is the water mass divided by the total mass. Evaluates
\[\Phi / (1 - \Phi)\]
Monty.Simulating.spreading!
— Functionspreading!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯, 𝒩, 𝒦},
plan::SamplePlan,
X::Distributions.UnivariateDistribution
)
Samples spreading/application rates from a distribution or Simulator
(or Cosimulator
), automatically ignoring control points as identified by the provided plan
.
spreading!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯},
plan::SamplePlan,
X
)
Samples any object for which rand!
can be called to apply feedstock, ignoring controls.
Monty.Simulating.unmixed!
— Functionunmixed!(rng::Random.AbstractRNG, sim::Simulation{𝒯}; depth)
Sets feedstock fractions and sample depths assuming the feedstock is resting in a layer on top of soil (no mixing).
Monty.Simulating.triangularmixing!
— Functiontriangularmixing!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯};
depth,
upper
)
Assumes feedstock mixing profiles with a wedge shape
Monty.Simulating.uniformmixing!
— Functionuniformmixing!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯};
depth,
upper
)
Assumes feedstock mixing profiles uniform over a depth interval
Monty.Simulating.exponentialmixing!
— Functionexponentialmixing!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯};
depth,
scale
)
Assumes exponentially decaying feedstock mixing profiles
Monty.Simulating.feedstockconcentration!
— Functionfeedstockconcentration!(
sim::Simulation{𝒯, 𝒩, 𝒦},
concentrations::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}}
)
Sets feedstock concentrations to constants
feedstockconcentration!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯, 𝒩, 𝒦},
μ::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
σ
)
Sets feedstock concentrations using a mean and relative standard deviation for each analyte
Monty.Simulating.soilconcentration!
— Functionsoilconcentration!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯},
analyte::Symbol,
X::Distributions.Distribution
)
Sets soil analyte concentrations using any distribution
soilconcentration!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯, 𝒩, 𝒦},
μ::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
σ
)
Sets soil analyte concentrationss using means and relative standard deviation
soilconcentration!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯},
samp::CoreSet{𝒯},
analyte::Symbol,
μ,
σ::GeoStatsFunctions.Covariance
)
Sets soil analyte concentrations using a multivariate normal distribution defined by a Covariance
soilconcentration!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯},
gc::GaussianCosimulator{𝒯, 𝒦}
)
Sets soil analyte concentrations using a GaussianSimulator
Monty.Simulating.leaching!
— Functionleaching!(
𝓁::Array{𝒯, 2},
model::AbstractLeachingModel{𝒯},
time::AbstractArray{𝒯, 1}
)
Sets leached fractions for one analyte using a Leaching Model
leaching!(
sim::Simulation{𝒯, 𝒩, 𝒦},
analyte::Symbol,
model::AbstractLeachingModel{𝒯},
time::AbstractArray{𝒯, 1}
)
Sets leached fractions for one analyte using a Leaching Model
leaching!(
sim::Simulation{𝒯, 𝒩, 𝒦},
analyte::Symbol,
model::AbstractLeachingModel{𝒯},
plan::SamplePlan{𝒯}
)
Sets leached fractions using a Leaching Model and times from a SamplePlan
leaching!(
sim::Simulation{𝒯, 𝒩, 𝒦},
models::NamedTuple{𝒦, Tuple{Vararg{ℳ<:AbstractLeachingModel, 𝒩}}},
time::AbstractArray{𝒯, 1}
)
Sets leached fractions using a Leaching Model for each analyte
leaching!(
sim::Simulation{𝒯, 𝒩, 𝒦},
models::NamedTuple{𝒦, Tuple{Vararg{ℳ<:AbstractLeachingModel, 𝒩}}},
plan::SamplePlan{𝒯}
)
Sets leached fractions using a Leaching Model for each analyte and times from a SamplePlan
Monty.Simulating.massloss!
— Functionmassloss!(
sim::Simulation{𝒯, 𝒩, 𝒦},
plan::SamplePlan{𝒯},
loss::Function
)
Sets feedstock mass loss fraction using a function of analyte leached fractions
Monty.Simulating.core!
— Functioncore!(sim::Simulation{𝒯, 𝒩, 𝒦})
Executes the core collection process internally in a Simulation
Monty.Simulating.composite!
— Functioncomposite!(sim::Simulation)
Executes the core compositing process internally in a Simulation
Monty.Simulating.measure!
— Functionmeasure!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯, 𝒩, 𝒦},
σ::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
σₘ
)
Executes the composite sample measurement process internally in a Simulation
using a tuple of relative standard deviations for analytes and a relative standard deviation for the mass
Monty.Simulating.analyze!
— Functionanalyze!(
rng::Random.AbstractRNG,
sim::Simulation{𝒯, 𝒩, 𝒦},
σ::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}},
args...
)
Executes the entire core collection, compositing, and measurement sequence. That is, the analyze!
function
- calls
core!
- calls
composite!
- calls
measure
, passing inputs through to that function
Monty.Simulating.simulationstack
— Functionsimulationstack(
simulate!::Function,
nrealization::Integer,
sim::Simulation{𝒯},
samp::CoreSet{𝒯},
plan::SamplePlan{𝒯};
show_progress
) -> DimensionalData.DimStack{(:data, :x, :y, :control, :location, :round, :time), T, _A, L, _B, Tuple{}, LD, DimensionalData.Dimensions.Lookups.NoMetadata, @NamedTuple{data::DimensionalData.Dimensions.Lookups.NoMetadata, x::DimensionalData.Dimensions.Lookups.NoMetadata, y::DimensionalData.Dimensions.Lookups.NoMetadata, control::DimensionalData.Dimensions.Lookups.NoMetadata, location::DimensionalData.Dimensions.Lookups.NoMetadata, round::DimensionalData.Dimensions.Lookups.NoMetadata, time::DimensionalData.Dimensions.Lookups.NoMetadata}} where {T<:(NamedTuple{(:data, :x, :y, :control, :location, :round, :time), T} where T), _A, L<:(NamedTuple{(:data, :x, :y, :control, :location, :round, :time), <:Tuple{AbstractArray{_A, 3} where _A, Matrix, Matrix, ReadOnlyArrays.ReadOnlyVector{Bool, Vector{Bool}}, ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}, ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}, ReadOnlyArrays.ReadOnlyArray{_A, 1, Vector{_A}} where _A}}), _B<:Tuple, LD<:(NamedTuple{(:data, :x, :y, :control, :location, :round, :time), <:Tuple{Any, Tuple{Any, Any}, Tuple{Any, Any}, Vararg{Tuple{Any}, 4}}})}
Runs repeated simulations. See the Efficient Simulation example.
Monty.Simulating.tonetcdf
— Functiontonetcdf(fn::AbstractString, sims::DimensionalData.DimStack)
Writes a simulation stack to netcdf format
Monty.Simulating.tocsv
— Functiontocsv(
fn::AbstractString,
sims::DimensionalData.DimStack,
realization::Integer
)
Writes one realization of a simulation stack to csv format
Container
Monty.Simulating.Simulation
— TypeThe Simulation
type is a container for running simulations. See the simulationstack
function for more detail.
The fields are
nsamp::UInt16
ncore::UInt16
γ::Matrix
d::Matrix
a::Any
Q::Matrix
ρf::Matrix
cf::NamedTuple{𝒦, Tuple{Vararg{Matrix{𝒯}, 𝒩}}} where {𝒯, 𝒩, 𝒦}
ρs::Matrix
cs::NamedTuple{𝒦, Tuple{Vararg{Matrix{𝒯}, 𝒩}}} where {𝒯, 𝒩, 𝒦}
𝓁::NamedTuple{𝒦, Tuple{Vararg{Matrix{𝒯}, 𝒩}}} where {𝒯, 𝒩, 𝒦}
ℒ::Matrix
cores::Array{Sample{𝒩, 𝒦, 𝒯, 𝒯}, 2} where {𝒯, 𝒩, 𝒦}
composites::Array{Sample{𝒩, 𝒦, 𝒯, 𝒯}, 1} where {𝒯, 𝒩, 𝒦}
measurements::Array{Measurement{𝒩, 𝒦, 𝒯}, 1} where {𝒯, 𝒩, 𝒦}
Monty.Simulating.clear!
— Functionclear!(sim::Simulation{𝒯, 𝒩})
Clears all fields of a Simulation
Gaussian Simulators
There are two types for simulating from multivariate gaussian distributions, which are useful for generating vectors with correlated elements. Both of them can be updated from a Covariance
model using the updategaussian!
methods, which recomputes the necessary Cholesky factorization in-place using the covariance model and a group of points. Both types can also be sampled with rand
and rand!
.
Monty.Gaussian.GaussianSimulator
— TypeThe GaussianSimulator
type is for simulating a multivariate distribution over points in space and efficiently reloading the correlation matrix with a new set of points. See the Efficient Simulation example.
Constructors
GaussianSimulator(N::Integer, μ::AbstractVector{𝒯}) where {𝒯}
GaussianSimulator(samp::CoreSet{𝒯}, μ::AbstractVector{𝒯}) where {𝒯}
GaussianSimulator(samp::CoreSet{𝒯}, μ::𝒯) where {𝒯}
Monty.Gaussian.GaussianCosimulator
— TypeThe GaussianCosimulator
type is for simulating a multivariate distribution over points for two fields simultaneously, with cross-correlation, and efficiently reloading the correlation matrix with a new set of points. See the Efficient Simulation example.
Constructors
GaussianCosimulator(
N::Integer,
μ::NamedTuple{𝒦,NTuple{2,Vector{𝒯}}},
ρ::𝒯,
)
GaussianCosimulator(
samp::CoreSet{𝒯},
μ::NamedTuple{𝒦,NTuple{2,Vector{𝒯}}},
ρ::𝒯,
)
GaussianCosimulator(
samp::CoreSet{𝒯},
μ::NamedTuple{𝒦,NTuple{2,𝒯}},
ρ::𝒯,
)
Monty.Gaussian.updategaussian!
— Functionupdategaussian!(
gs::GaussianSimulator{𝒯},
points::AbstractArray{Meshes.Point{2, 𝒯}},
c::GeoStatsFunctions.Covariance
)
Updates the covariance matrix for the Simulator
using a
Covariance` model and a group of points.
updategaussian!(
gc::GaussianCosimulator{𝒯},
points::AbstractArray{Meshes.Point{2, 𝒯}},
c::GeoStatsFunctions.Covariance
)
Updates the covariance matrix for the Cosimulator
using a Covariance
model and a group of points.
Random.rand!
— Functionrand!(
rng::Random.AbstractRNG,
gs::GaussianSimulator{𝒯},
y::AbstractArray{𝒯, 1}
)
Samples from the Simulator
in-place
rand!(
rng::Random.AbstractRNG,
gc::GaussianCosimulator{𝒯, 𝒦},
y::NamedTuple{𝒦}
)
Samples from the Cosimulator
in-place, where y
is a named tuple that includes the two vectors to fill. The keys of the named tuple must include the analytes that the Cosimulator
expects.
Base.rand
— Functionrand(
rng::Random.AbstractRNG,
gs::GaussianSimulator{𝒯}
) -> Vector
Samples from the Simulator
, returning a new vector
rand(
rng::Random.AbstractRNG,
gc::GaussianCosimulator{𝒯, 𝒦}
) -> NamedTuple{_A, <:Tuple{Any, Any}} where _A
Samples from the Cosimulator
, returning a new vector
Measurement
Monty.Measuring.noise
— Functionnoise(rng::Random.AbstractRNG, x::Number, σᵣ::Number) -> Any
Apply normally distributed noise to a number x
, where the noise magnitude is expressed by the relative standard devation (σᵣ
) of the number (the coefficient of variation or cv).
Monty.Measuring.Measurement
— TypeA Measurement
behaves much like a Sample
but has no core count. It represents observed values for a sample, after measurement noise is applied, and is produced by the measure
methods.
The fields are
concentrations
mass
Monty.Measuring.measure
— Functionmeasure(
rng::Random.AbstractRNG,
sample::Sample{𝒩, 𝒦},
σᵣ::NamedTuple{𝒦, Tuple{Vararg{𝒯<:Real, 𝒩}}},
σₘ::Real
) -> Measurement
Computes measured analyte concentrations from a Sample
by applying random normally distributed measurement noise to the exact values in the sample. Noise magnitude for analyte concentrations is defined by the relative standard deviation σᵣ
, a named tuple with one value for each analyte in the sample. The measured sample mass noise is defined by relative standard deviation σᵣ
. Returns a Measurement
instance.
Tabulation
Each of the main composite types in Monty can be exported to a GeoTable
, which can then be exported to a number of file formats using GeoIO.jl
.
GeoTables.GeoTable
— TypeGeoTable(
sim::Simulation,
plan::SamplePlan
) -> GeoTable{T} where T<:(NamedTuple{names, T} where {T<:Tuple, names})
Creates a tabular representation of the simulation using the GeoTable
format. The measurement for each composited location is assigned from the sample plan.
GeoTable(
sim::Simulation,
samp::CoreSet,
plan::SamplePlan
) -> Any
Creates a tabular representation of the simulation using the GeoTable
format. The measurement for each composited location is assigned by averaging the locations of each core in the core set.
GeoTable(
plan::SamplePlan
) -> GeoTable{T} where T<:(NamedTuple{(:location, :round, :time, :control), <:Tuple{ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}, ReadOnlyArrays.ReadOnlyVector{UInt16, Vector{UInt16}}, ReadOnlyArrays.ReadOnlyArray{𝒯, 1, Vector{𝒯}} where 𝒯, ReadOnlyArrays.ReadOnlyVector{Bool, Vector{Bool}}}})
Creates a tabular representation of the sample plan using the GeoTable
format.
GeoTable(samp::CoreSet, plan::SamplePlan) -> Any
Creates a tabular representation of the core set using the GeoTable
format. The locations of each core in the CoreSet
are tabulated along with the metadata for each group from the sample plan.
CDR Potential
There are a few convenience functions for computing the CDR potential of a feedstock.
Monty.CDRPotential.cationCO2
— FunctioncationCO2(cation::Symbol) -> Float64
Computes the mass of CO2 captured per unit mass of a mobile cation. The cation must be one of [:Ca, :Mg, :Na, :K].
Monty.CDRPotential.cdrpotential
— Functioncdrpotential(
cation::Union{String, Symbol},
concentration
) -> Any
Computes the maximum amount of CDR available for a given feedstock composition.
cdrpotential(
conc::NamedTuple{𝒦, Tuple{Vararg{𝒯, 𝒩}}}
) -> Any
Computes CDR potential from a named tuple of feedstock concentrations.
cdrpotential(conc::Dict) -> Any
Computes CDR potential from a dict of feedstock concentrations.