Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables Ext #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[extensions]
SpectralIndicesDataFramesExt = "DataFrames"
SpectralIndicesYAXArraysExt = ["YAXArrays", "DimensionalData"]
SpectralIndicesTablesExt = "Tables"

[compat]
DataFrames = "1"
Dates = "1"
DimensionalData = "0.26"
Downloads = "1"
JSON = "0.21"
Tables = "1.11"
YAXArrays = "0.5"
julia = "1.6"

Expand All @@ -36,8 +39,11 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"

[targets]
test = ["Test", "SafeTestsets", "Aqua", "JET", "JuliaFormatter", "DataFrames", "YAXArrays", "Random", "Combinatorics", "StatsBase", "DimensionalData"]
test = ["Test", "SafeTestsets", "Aqua", "JET", "JuliaFormatter",
"DataFrames", "YAXArrays", "Random", "Combinatorics", "StatsBase",
"DimensionalData", "Tables"]
58 changes: 58 additions & 0 deletions ext/SpectralIndicesTablesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module SpectralIndicesTablesExt

using SpectralIndices
using Tables
import Tables: Table
import SpectralIndices:
_create_params,
AbstractSpectralIndex,
compute_index,
_create_indices,
linear,
poly,
RBF,
load_dataset,
_load_json


function _check_params(index::AbstractSpectralIndex, params::Tables.AbstractColumns)
column_names = Tables.columnnames(params)
for band in index.bands
if !(band in column_names)
throw(
ArgumentError(
"'$band' is missing in the parameters for $index computation!"
)
)
end
end
end


function _order_params(index::AbstractSpectralIndex, params::Tables.AbstractColumns)
new_params = []
for (bidx, band) in enumerate(index.bands)
if hasproperty(params, band)
push!(new_params, getproperty(params, band))
else
throw(ArgumentError("'$band' is missing in the parameters for $index computation!"))
end
end

return new_params
end

function _create_params(kw_args::Pair{Symbol,<:Tables.AbstractColumns}...)
column_data = []
column_names = []

for (key, value) in kw_args
push!(column_data, value)
push!(column_names, String(key))
end
new_params = Tables.columntable(Dict(column_names .=> column_data))

return new_params
end

end #module
Loading