-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* calculate step more precisely and maybe round it * do not do try to improve accuracy for integers * Update src/sources/commondatamodel.jl * rounding atol is based on index eltype * add tests --------- Co-authored-by: Rafael Schouten <[email protected]>
- Loading branch information
1 parent
51ec72e
commit df8d76e
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Rasters, NCDatasets, Test | ||
import Rasters: ForwardOrdered, ReverseOrdered, Regular | ||
@testset "step" begin | ||
# test if regular indices are correctly rounded | ||
f32_indices = range(0.075f0, 10.075f0; step = 0.05f0) |> collect | ||
@test Rasters._cdmspan(f32_indices, ForwardOrdered())[1] === Regular(0.05) | ||
|
||
f32_indices_rev = range(10.075f0, 0.075f0; step = -0.05f0) |> collect | ||
@test Rasters._cdmspan(f32_indices_rev, ReverseOrdered())[1] === Regular(-0.05) | ||
|
||
# test if regular indices are not rounded when they should not | ||
indices_one_third = range(0, 10; length = 31) |> collect | ||
@test Rasters._cdmspan(indices_one_third, ForwardOrdered())[1] === Regular(1/3) | ||
|
||
# test when reading a file | ||
ras = Raster(rand(X(f32_indices), Y(indices_one_third))) | ||
tempfile = tempname() * ".nc" | ||
write(tempfile, ras) | ||
ras_read = Raster(tempfile) | ||
steps = step.(dims(ras_read)) | ||
@test steps[1] == 0.05 | ||
@test steps[2] == 1/3 | ||
|
||
end |