Skip to content

Commit

Permalink
πŸ› correct check on layer inner type (#146)
Browse files Browse the repository at this point in the history
* πŸ› correct check on layer inner type

* 🟩 prepare for tests

* βš™οΈ handle the internal type check gracefully

* βœ… read/write test passing
  • Loading branch information
tpoisot authored Feb 17, 2023
1 parent 572e0d5 commit e0049b5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpeciesDistributionToolkit"
uuid = "72b53823-5c0b-4575-ad0e-8e97227ad13b"
authors = ["TimothΓ©e Poisot <timothee.poisot@umontreal.ca>"]
version = "0.0.3"
version = "0.0.4"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down
5 changes: 3 additions & 2 deletions src/io/geotiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ function _prepare_layer_for_burnin(
layer::SimpleSDMPredictor{T},
nodata::T,
) where {T <: Number}
@assert eltype(layer) <: Number
K = SimpleSDMLayers._inner_type(layer)
@assert K <: Number
array = replace(layer.grid, nothing => nodata)
array = convert(Matrix{eltype(layer)}, array)
array = convert(Matrix{K}, array)
dtype = eltype(array)
array_t = reverse(permutedims(array, [2, 1]); dims = 2)
return array_t
Expand Down
20 changes: 20 additions & 0 deletions test/01_integration_read.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module TestThatWeCanReadStuff

using SpeciesDistributionToolkit
using Test

# Get some EarthEnv data
layer = SimpleSDMPredictor(RasterData(EarthEnv, LandCover); layer = 1)
D = SimpleSDMLayers._inner_type(layer)

# Write the data
f = tempname()
SpeciesDistributionToolkit._write_geotiff(f, [layer]; driver = "GTiff", nodata = typemax(D))
@test isfile(f)

# Read the data
layer2 = SpeciesDistributionToolkit._read_geotiff(f, SimpleSDMPredictor)
@test typeof(layer2) <: SimpleSDMPredictor
@test all(values(layer) .== values(layer2))

end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
27 changes: 26 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
nothing
using SpeciesDistributionToolkit
using Test

global anyerrors = false

tests = [
"read/write layers" => "01_integration_read.jl",
]

for test in tests
try
include(test.second)
println("\033[1m\033[32mβœ“\033[0m\t$(test.first)")
catch e
global anyerrors = true
println("\033[1m\033[31mΓ—\033[0m\t$(test.first)")
println("\033[1m\033[38m→\033[0m\ttest/$(test.second)")
showerror(stdout, e, backtrace())
println()
break
end
end

if anyerrors
throw("Tests failed")
end

2 comments on commit e0049b5

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77860

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.4 -m "<description of version>" e0049b56bdd0dd8ef2175beff8c4a03d238efddc
git push origin v0.0.4

Please sign in to comment.