From 79ed9372c16d7bbb4387119c53bf365266ffea29 Mon Sep 17 00:00:00 2001 From: MartinuzziFrancesco <10376688+MartinuzziFrancesco@users.noreply.github.com> Date: Thu, 4 Apr 2024 01:16:40 +0000 Subject: [PATCH] Format .jl files --- ext/SpectralIndicesDataFramesExt.jl | 17 ++++++++---- ext/SpectralIndicesYAXArraysExt.jl | 20 ++++++++++----- src/compute_index.jl | 40 +++++++++++++++++------------ test/compute_index.jl | 1 - 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/ext/SpectralIndicesDataFramesExt.jl b/ext/SpectralIndicesDataFramesExt.jl index ce734d1..88f905d 100644 --- a/ext/SpectralIndicesDataFramesExt.jl +++ b/ext/SpectralIndicesDataFramesExt.jl @@ -2,8 +2,16 @@ module SpectralIndicesDataFramesExt using SpectralIndices using DataFrames -import SpectralIndices: _create_params, AbstractSpectralIndex, compute_index, - _create_indices, linear, poly, RBF, load_dataset, _load_json +import SpectralIndices: + _create_params, + AbstractSpectralIndex, + compute_index, + _create_indices, + linear, + poly, + RBF, + load_dataset, + _load_json function _create_params(kw_args::Pair{Symbol,DataFrame}...) combined_df = DataFrame() @@ -21,9 +29,8 @@ function compute_index( ) # Convert DataFrame to a dictionary for each row and compute the index results = [ - compute_index( - index, Dict(zip(names(params), row)); indices=indices - ) for row in eachrow(params) + compute_index(index, Dict(zip(names(params), row)); indices=indices) for + row in eachrow(params) ] # Return the results as a DataFrame with the column named after the index diff --git a/ext/SpectralIndicesYAXArraysExt.jl b/ext/SpectralIndicesYAXArraysExt.jl index ec87835..cb2aa9a 100644 --- a/ext/SpectralIndicesYAXArraysExt.jl +++ b/ext/SpectralIndicesYAXArraysExt.jl @@ -3,9 +3,18 @@ module SpectralIndicesYAXArraysExt using SpectralIndices using YAXArrays using DimensionalData -import SpectralIndices: _check_params, _create_params, _order_params, - AbstractSpectralIndex, compute_index, _create_indices, - linear, poly, RBF, load_dataset, _load_json +import SpectralIndices: + _check_params, + _create_params, + _order_params, + AbstractSpectralIndex, + compute_index, + _create_indices, + linear, + poly, + RBF, + load_dataset, + _load_json function _check_params(index::AbstractSpectralIndex, params::YAXArray) for band in index.bands @@ -42,9 +51,8 @@ end ## TODO: simplify even further # this is same function contente as dispatch on Dict -function compute_index(index::AbstractSpectralIndex, - params::YAXArray; - indices=_create_indices() +function compute_index( + index::AbstractSpectralIndex, params::YAXArray; indices=_create_indices() ) _check_params(index, params) params = _order_params(index, params) diff --git a/src/compute_index.jl b/src/compute_index.jl index 8639b2e..4428915 100644 --- a/src/compute_index.jl +++ b/src/compute_index.jl @@ -54,9 +54,12 @@ julia> compute_index( ``` """ function compute_index( - index::AbstractSpectralIndex, params=nothing, online::Bool=false; indices=indices, kwargs... + index::AbstractSpectralIndex, + params=nothing, + online::Bool=false; + indices=indices, + kwargs..., ) - if isnothing(params) params = _create_params(kwargs...) end @@ -73,13 +76,13 @@ function compute_index( return results end -function compute_index(index::Vector{<:AbstractSpectralIndex}, +function compute_index( + index::Vector{<:AbstractSpectralIndex}, params=nothing, online::Bool=false; indices=_create_indices(online), - kwargs... + kwargs..., ) - if isnothing(params) params = _create_params(kwargs...) end @@ -87,12 +90,13 @@ function compute_index(index::Vector{<:AbstractSpectralIndex}, return compute_index(index, params; indices=indices) end -function compute_index(index::Vector{String}, +function compute_index( + index::Vector{String}, params=nothing, online::Bool=false; - indices = _create_indices(online), - kwargs...) - + indices=_create_indices(online), + kwargs..., +) names = keys(indices) for idx in index @assert idx in names "$index is not a valid Spectral Index!" @@ -113,7 +117,9 @@ end # TODO: return results in a matrix columnswise #multi_result = compute_index(["NDVI", "SAVI"], N = fill(0.643, 5), R = fill(0.175, 5), L = fill(0.5, 5)) -function compute_index(index::Vector{<:AbstractSpectralIndex}, params::Dict; indices=indices) +function compute_index( + index::Vector{<:AbstractSpectralIndex}, params::Dict; indices=indices +) results = [] for (nidx, idx) in enumerate(index) result = compute_index(idx, params; indices=indices) @@ -124,17 +130,15 @@ function compute_index(index::Vector{<:AbstractSpectralIndex}, params::Dict; ind end #_compute_index(idx::AbstractSpectralIndex, prms::Number...) = idx(prms...) -function _compute_index(::Type{T}, - idx::AbstractSpectralIndex, - prms::Number... +function _compute_index( + ::Type{T}, idx::AbstractSpectralIndex, prms::Number... ) where {T<:Number} return idx(T, prms...) end #_compute_index(idx::AbstractSpectralIndex, prms::AbstractArray...) = idx.(prms...) -function _compute_index(::Type{T}, - idx::AbstractSpectralIndex, - prms::AbstractArray... +function _compute_index( + ::Type{T}, idx::AbstractSpectralIndex, prms::AbstractArray... ) where {T<:Number} return idx.(T, prms...) end @@ -148,7 +152,9 @@ function compute_index(index::AbstractSpectralIndex, params::NamedTuple; indices return result_nt end -function compute_index(index::Vector{<:AbstractSpectralIndex}, params::NamedTuple; indices=indices) +function compute_index( + index::Vector{<:AbstractSpectralIndex}, params::NamedTuple; indices=indices +) results_dict = Dict{Symbol,Any}() for idx in index result_nt = compute_index(idx, params; indices=indices) diff --git a/test/compute_index.jl b/test/compute_index.jl index 060fa3b..b83a4f9 100644 --- a/test/compute_index.jl +++ b/test/compute_index.jl @@ -122,7 +122,6 @@ end GC.gc() end - msi = custom_key_combinations(indices, 2, 200) @testset "Built-in types compute_index $T multiple indices tests: $idxs" for idxs in msi,