Compute Index
SpectralIndices.compute_index Function
compute_index(index, params, [online]; kwargs...) -> AnyComputes one or more Spectral Indices.
Arguments
index: Name of the spectral index or a list of index names to compute.params: (Optional) Dictionary of parameters used as inputs for the computation. If not provided, parameters can be passed using keyword arguments.online: (Optional) Flag indicating whether to retrieve the most recent list of indices online. Default isfalse.kwargs: Additional parameters used as inputs for the computation, provided as keyword pairs.
Examples
julia> using SpectralIndices
julia> compute_index("NDVI"; N=0.643, R=0.175)
0.5721271393643031
julia> compute_index("NDVI"; N=fill(0.643, (5, 5)), R=fill(0.175, (5, 5)))
5×5 Matrix{Float64}:
0.572127 0.572127 0.572127 0.572127 0.572127
0.572127 0.572127 0.572127 0.572127 0.572127
0.572127 0.572127 0.572127 0.572127 0.572127
0.572127 0.572127 0.572127 0.572127 0.572127
0.572127 0.572127 0.572127 0.572127 0.572127
julia> compute_index("NDVI"; N=fill(0.643, 5), R=fill(0.175, 5))
5-element Vector{Float64}:
0.5721271393643031
0.5721271393643031
0.5721271393643031
0.5721271393643031
0.5721271393643031
julia> compute_index(["NDVI", "SAVI"]; N=0.643, R=0.175, L=0.5)
2-element Vector{Any}:
0.5721271393643031
0.5326251896813354
julia> compute_index(["NDVI", "SAVI"]; N=fill(0.643, (2, 2)), R=fill(0.175, (2, 2)), L=fill(0.5, (2,2)))
2-element Vector{Any}:
[0.5721271393643031 0.5721271393643031; 0.5721271393643031 0.5721271393643031]
[0.5326251896813354 0.5326251896813354; 0.5326251896813354 0.5326251896813354]SpectralIndices.compute_kernel Function
compute_kernel(kernel, params=nothing; kwargs...)Compute a specified kernel using either provided parameters or keyword arguments.
Arguments
kernel: The kernel function to use. Should be one oflinear,poly, orRBF.params: (Optional) ADict,DataFrame, orYAXArraycontaining parameters for the kernel computation.kwargs...: Keyword arguments that will be converted to parameters ifparamsis not provided.
Examples
The behaviour of compute_kernel is identical to compute_index. The function takes as keywork arguments the parameters needed for computation:
julia> using SpectralIndices
julia> knr = compute_kernel(RBF; a=fill(0.1, 5), b=fill(0.2, 5), sigma=fill(0.3, 5))
5-element Vector{Float64}:
0.9459594689067654
0.9459594689067654
0.9459594689067654
0.9459594689067654
0.9459594689067654Additionally it can also take The a positional argument params, which can be a Dict, a DataFrame, or YAXArray. Let us demonstrate with a Dict:
julia> params = Dict("a" => 0.1, "b" => 0.2, "sigma" => 0.3)
Dict{String, Float64} with 3 entries:
"sigma" => 0.3
"b" => 0.2
"a" => 0.1
julia> knr = compute_kernel(RBF, params)
0.9459594689067654SpectralIndices.linear Function
linear(a::Number, b::Number)
linear(a::AbstractArray, b::AbstractArray)
linear(params::Dict{String, T})
linear(params::DataFrame)
linear(params::YAXArray)Compute the linear kernel a * b. This function supports various input types, including numbers, arrays, dictionaries, data frames, and YAXArrays.
Arguments
a: First parameter for the linear kernel. Can be a number or an array.b: Second parameter for the linear kernel. Can be a number or an array.params: A dictionary, data frame, or YAXArray containing the parameters "a" and "b".
Returns
- The result of
a * b. The output type depends on the input types:If
aandbare numbers, the result is a number.If
aandbare arrays, the result is an array with element-wise multiplication.If
paramsis used, the result is in the same format asparams(either a dictionary, DataFrame, or YAXArray).
Examples
# Using numbers
result = linear(2, 3)
# Using arrays
result = linear([1, 2, 3], [4, 5, 6])
# Using a dictionary
result = linear(Dict("a" => 2, "b" => 3))
# Using a DataFrame
df = DataFrame(; a=[1, 2, 3], b=[4, 5, 6])
result = linear(df)SpectralIndices.poly Function
poly(a::T, b::T, c::T, p::T) where T <: Number
poly(a::T, b::T, c::T, p::T) where T <: AbstractArray
poly(params::Dict{String, T})
poly(params::DataFrame)
poly(params::YAXArray)Compute the polynomial kernel (a * b + c) ^ p. This function supports various input types, including numbers, arrays, dictionaries, data frames, and YAXArrays.
Arguments
a: First parameter for the polynomial kernel. Can be a number or an array.b: Second parameter for the polynomial kernel. Can be a number or an array.c: Coefficient added to the product ofaandb. Can be a number or an array.p: Exponent to which the sum of the product and coefficient is raised. Can be a number or an array.params: A dictionary, data frame, or YAXArray containing the parameters "a", "b", "c", and "p".
Returns
- The result of
(a * b + c) ^ p. The output type depends on the input types:If
a,b,c, andpare numbers, the result is a number.If
a,b,c, andpare arrays, the result is an array with the operation applied element-wise.If
paramsis used, the result matches the format ofparams(either a dictionary, DataFrame, or YAXArray).
Examples
# Using numbers
result = poly(2, 3, 1, 2)
# Using arrays
result = poly([1, 2, 3], [4, 5, 6], [1, 1, 1], [2, 2, 2])
# Using a dictionary
result = poly(Dict("a" => 2, "b" => 3, "c" => 1, "p" => 2))
# Using a DataFrame
df = DataFrame(; a=[1, 2, 3], b=[4, 5, 6], c=[1, 1, 1], p=[2, 2, 2])
result = poly(df)SpectralIndices.RBF Function
RBF(a::T, b::T, sigma::T) where T <: Number
RBF(a::T, b::T, sigma::T) where T <: AbstractArray
RBF(params::Dict{String, T})
RBF(params::DataFrame)
RBF(params::YAXArray)Compute the Radial Basis Function (RBF) kernel exp((-1.0 * (a - b) ^ 2.0) / (2.0 * sigma ^ 2.0)). This function supports various input types, including numbers, arrays, dictionaries, data frames, and YAXArrays.
Arguments
a: First parameter for the RBF kernel. Can be a number or an array.b: Second parameter for the RBF kernel. Can be a number or an array.sigma: Length-scale parameter for the RBF kernel. Can be a number or an array.params: A dictionary, data frame, or YAXArray containing the parameters "a", "b", and "sigma".
Returns
- The result of the RBF kernel. The output type depends on the input types:
If
a,b, andsigmaare numbers, the result is a number.If
a,b, andsigmaare arrays, the result is an array with the operation applied element-wise.If
paramsis used, the result matches the format ofparams(either a dictionary, DataFrame, or YAXArray).
Examples
# Using numbers
result = RBF(1, 2, 0.5)
# Using arrays
result = RBF([1, 2, 3], [4, 5, 6], [0.5, 0.5, 0.5])
# Using a dictionary
result = RBF(Dict("a" => 1, "b" => 2, "sigma" => 0.5))
# Using a DataFrame
df = DataFrame(; a=[1, 2, 3], b=[4, 5, 6], sigma=[0.5, 0.5, 0.5])
result = RBF(df)