From e064e741d0b21330e5d497cc404658ffef659f02 Mon Sep 17 00:00:00 2001 From: Francesco Martinuzzi Date: Thu, 25 Jan 2024 14:49:33 +0100 Subject: [PATCH 1/2] Extending testing coverage (#24) * more testing for compute_kernel * added JET tests * added yaxarrays tests for kernels * added tests for multiple indices with YAXArrays * dropped nightly from testing --- .github/workflows/CI.yml | 1 - README.md | 5 +++- test/compute_index.jl | 17 ++++++----- test/compute_kernel.jl | 61 ++++++++++++++++++++++++++++++++++++++++ test/qa.jl | 4 +-- test/runtests.jl | 5 +++- 6 files changed, 79 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1f40e27..14c0673 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,7 +17,6 @@ jobs: version: - '1.9' - '1' - - 'nightly' os: - ubuntu-latest arch: diff --git a/README.md b/README.md index 5619ed4..a5c701a 100644 --- a/README.md +++ b/README.md @@ -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/ @@ -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. diff --git a/test/compute_index.jl b/test/compute_index.jl index 307849e..41b8ea0 100644 --- a/test/compute_index.jl +++ b/test/compute_index.jl @@ -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 diff --git a/test/compute_kernel.jl b/test/compute_kernel.jl index 3f3a668..11504ca 100644 --- a/test/compute_kernel.jl +++ b/test/compute_kernel.jl @@ -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 diff --git a/test/qa.jl b/test/qa.jl index d03d23b..205086b 100644 --- a/test/qa.jl +++ b/test/qa.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index bd352b0..cfb1524 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From 0e80e6d448ca6d8a8312393869699096f75050d5 Mon Sep 17 00:00:00 2001 From: Francesco Martinuzzi Date: Sun, 28 Jan 2024 17:30:37 +0100 Subject: [PATCH 2/2] New version (#25) --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index baaf441..7f36710 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SpectralIndices" uuid = "df0093a1-273d-40bc-819a-796ec3476907" authors = ["MartinuzziFrancesco "] -version = "0.1.6" +version = "0.1.7" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"