Skip to content

Commit

Permalink
Extending testing coverage (#24)
Browse files Browse the repository at this point in the history
* more testing for compute_kernel

* added JET tests

* added yaxarrays tests for kernels

* added tests for multiple indices with YAXArrays

* dropped nightly from testing
  • Loading branch information
MartinuzziFrancesco authored Jan 25, 2024
1 parent a9406af commit e064e74
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 14 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
version:
- '1.9'
- '1'
- 'nightly'
os:
- ubuntu-latest
arch:
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

| **Documentation** | **Build Status** | **Julia** | **Testing** |
|:-----------------:|:----------------:|:---------:|:---------|
| [![docs][docs-img]][docs-url] | [![CI][ci-img]][ci-url] [![codecov][cc-img]][cc-url] | [![Julia][julia-img]][julia-url] [![Code Style: Blue][style-img]][style-url] | [![Aqua QA][aqua-img]][aqua-url] |
| [![docs][docs-img]][docs-url] | [![CI][ci-img]][ci-url] [![codecov][cc-img]][cc-url] | [![Julia][julia-img]][julia-url] [![Code Style: Blue][style-img]][style-url] | [![Aqua QA][aqua-img]][aqua-url] [![JET][jet-img]][jet-url] |

[docs-img]: https://img.shields.io/badge/docs-stable-blue.svg
[docs-url]: https://awesome-spectral-indices.github.io/SpectralIndices.jl/dev/
Expand All @@ -26,6 +26,9 @@
[aqua-img]: https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl

[jet-img]: https://img.shields.io/badge/%E2%9C%88%EF%B8%8F%20tested%20with%20-%20JET.jl%20-%20red
[jet-url]: https://github.com/aviatesk/JET.jl

## Overview

SpectralIndices.jl is a Julia package for working with spectral indices commonly used in remote sensing and earth observation applications. It provides a convenient way to compute various spectral indices using Julia's high-performance capabilities.
Expand Down
17 changes: 8 additions & 9 deletions test/compute_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,18 @@ end
axes = (Dim{:Lon}(1:5), Dim{:Lat}(1:5), Dim{:Time}(1:10))
nds = YAXArray(axes, fill(0.643, (5, 5, 10)))
rds = YAXArray(axes, fill(0.175, (5, 5, 10)))
lds = YAXArray(axes, fill(0.5, (5, 5, 10)))

@testset "Single Index Tests" begin
nr_ds = concatenatecubes([nds, rds], Dim{:Variables}(["N", "R"]))
result_yaxa_single = compute_index("NDVI", nr_ds)
@test result_yaxa_single isa YAXArray
@test size(result_yaxa_single) == size(rds) == size(nds)
end
@testset "Multiple Indices Tests" begin
nrl_ds = concatenatecubes([nds, rds, lds], Dim{:Variables}(["N", "R", "L"]))
result_yaxa_multiple = compute_index(["NDVI", "SAVI"], nrl_ds)
@test result_yaxa_multiple isa YAXArray
@test size(result_yaxa_multiple)[1:(end - 1)] == size(rds) == size(nds) == size(lds)
end
end

# multiple indices # TODO
# as params
#result_yaxa_single = compute_index(["NDVI", "SAVI"], nrl_ds)
#@test size(result_yaxa_single) == size(rds) == size(nds) == size(lds)
# as kwargs
#result_yaxa_single2 = compute_index(["NDVI", "SAVI"]; N=nds, R=rds, L=lds)
#@test size(result_yaxa_single2) == size(rds) == size(nds) == size(lds)
#@test result_yaxa_single == result_yaxa_single2
61 changes: 61 additions & 0 deletions test/compute_kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,64 @@ types = [Float64, Float32, Float16]
end
end
end

@testset "Compute Kernel Tests" begin
# Test linear kernel
@testset "Linear Kernel" begin
params = Dict("a" => 2, "b" => 3)
@test compute_kernel(linear, params) == 6

params = Dict("a" => [1, 2], "b" => [3, 4])
@test compute_kernel(linear, params) == [3, 8]
end

# Test polynomial kernel
@testset "Polynomial Kernel" begin
params = Dict("a" => 2, "b" => 3, "c" => 1, "p" => 2)
@test compute_kernel(poly, params) == 49

params = Dict("a" => [1, 2], "b" => [2, 3], "c" => [1, 1], "p" => [2, 3])
@test compute_kernel(poly, params) == [9, 343]
end

# Test RBF kernel
@testset "RBF Kernel" begin
params = Dict("a" => 1, "b" => 2, "sigma" => 1)
@test compute_kernel(RBF, params) exp(-0.5)

params = Dict("a" => [1, 2], "b" => [2, 1], "sigma" => [1, 2])
@test compute_kernel(RBF, params) [exp(-0.5), exp(-0.125)]
end
end

@testset "SpectralIndices Kernel Functions with YAXArrays" begin
# Create dimensions and data for testing
axlist = (
Dim{:time}(range(1, 20; length=20)),
Dim{:Lon}(1:5),
Dim{:Lat}(1:5),
Dim{:Variable}(["a", "b", "c", "p", "sigma"]),
)
data = rand(20, 5, 5, 5)

# Create YAXArray instances
yax = YAXArray(axlist, data)

# Test SpectralIndices.linear
@testset "SpectralIndices.linear" begin
result = SpectralIndices.linear(yax)
@test result isa YAXArray
end

# Test SpectralIndices.poly
@testset "SpectralIndices.poly" begin
result = SpectralIndices.poly(yax)
@test result isa YAXArray
end

# Test SpectralIndices.RBF
@testset "SpectralIndices.RBF" begin
result = SpectralIndices.RBF(yax)
@test result isa YAXArray
end
end
4 changes: 2 additions & 2 deletions test/qa.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using SpectralIndices
using JuliaFormatter: JuliaFormatter
#using JET: JET
using JET: JET
using Aqua: Aqua

Aqua.test_all(SpectralIndices; ambiguities=false, deps_compat=(check_extras = false))
@test JuliaFormatter.format(SpectralIndices; verbose=false, overwrite=false)
#JET.test_package(SpectralIndices; target_defined_modules=true)
JET.test_package(SpectralIndices; target_defined_modules=true)
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ end
include("axioms.jl")
end

@safetestset "Compute" begin
@safetestset "Compute Indices" begin
include("compute_index.jl")
end

@safetestset "Compute Kernels" begin
include("compute_kernel.jl")
end

Expand Down

0 comments on commit e064e74

Please sign in to comment.