Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Oct 24, 2023
1 parent 6a1e6f3 commit da33a3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
11 changes: 6 additions & 5 deletions test/sources/gdal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gdalpath = maybedownload(url)
named = set(A, Band => string.(Ref("layer_"), dims(A, Band)))
tempfile = tempname() * ".tif"
write(tempfile, named)
@test parent(dims(Raster(tempfile), Band)) == ["layer_1", "layer_2"]
@test lookup(Raster(tempfile), Band) == ["layer_1", "layer_2"]
@test keys(RasterStack(tempfile; layersfrom=Band)) == (:layer_1, :layer_2)
rm(tempfile)
end
Expand Down Expand Up @@ -265,6 +265,7 @@ gdalpath = maybedownload(url)

@testset "2d" begin
filename = tempname() * ".asc"
gdalarray
@time write(filename, gdalarray)
saved1 = Raster(filename);
@test all(saved1 .== gdalarray)
Expand Down Expand Up @@ -351,13 +352,13 @@ gdalpath = maybedownload(url)
ga = Raster(rand(100, 200), (X, Y))
write(filename, ga)
saved = Raster(filename)
@test all(reverse(saved[Band(1)]; dims=Y) .=== ga)
@test saved[1, end] == saved[At(1.0), At(1.0)]
@test saved[100, 1] == saved[At(100), At(200)]
@test all(saved[Band(1)] .=== ga)
@test saved[At(1.0), At(1.0)] == saved[1, 1]
@test saved[end, end] == saved[At(100), At(200)]
filename2 = tempname() * ".tif"
ga2 = Raster(rand(100, 200), (X(Sampled(101:200)), Y(Sampled(1:200))))
write(filename2, ga2)
@test reverse(Raster(filename2)[Band(1)]; dims=Y) == ga2
@test Raster(filename2) == ga2
end

@testset "to netcdf" begin
Expand Down
17 changes: 5 additions & 12 deletions test/sources/ncdatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ end

@testset "Raster" begin
@time ncarray = Raster(ncsingle)
plot(ncarray)

@time lazyarray = Raster(ncsingle; lazy=true);
@time eagerarray = Raster(ncsingle; lazy=false);
@test_throws ArgumentError Raster("notafile.nc")
Expand Down Expand Up @@ -211,9 +209,7 @@ end
a = ncarray[X(At(21.0)), Y(Between(50, 52)), Ti(Near(DateTime360Day(2002, 12)))]
@test bounds(a) == ((50.0, 52.0),)
x = ncarray[X(Near(150)), Y(Near(30)), Ti(1)]
size(ncarray)
@test x isa Float32
lookup(ncarray)
dimz = X(Between(-0.0, 360)), Y(Between(-90, 90)),
Ti(Between(DateTime360Day(2001, 1, 1), DateTime360Day(2003, 01, 02)))
@test size(ncarray[dimz...]) == (180, 170, 24)
Expand Down Expand Up @@ -308,29 +304,26 @@ end
@test convert(ProjString, crs(gdalarray)) == convert(ProjString, EPSG(4326))
@test bounds(gdalarray) == bounds(nccleaned)
# Tiff locus = Start, Netcdf locus = Center
@test reverse(index(gdalarray, Y)) .+ 0.5 index(nccleaned, Y)
@test index(gdalarray, Y) .+ 0.5 index(nccleaned, Y)
@test index(gdalarray, X) .+ 1.0 index(nccleaned, X)
@test reverse(Raster(gdalarray); dims=Y()) nccleaned
@test Raster(gdalarray); dims=Y() nccleaned
end
@testset "to grd" begin
nccleaned = replace_missing(ncarray[Ti(1)], -9999.0)
write("testgrd.gri", nccleaned; force=true)
grdarray = Raster("testgrd.gri");
@test crs(grdarray) == convert(ProjString, EPSG(4326))
@test bounds(grdarray) == bounds(nccleaned)
@test reverse(index(grdarray, Y)) index(nccleaned, Y) .- 0.5
@test index(grdarray, Y) index(nccleaned, Y) .- 0.5
@test index(grdarray, X) index(nccleaned, X) .- 1.0
@test Raster(grdarray) reverse(nccleaned; dims=Y)
@test Raster(grdarray) nccleaned
rm("testgrd.gri")
rm("testgrd.grd")
end
end

@testset "no missing value" begin
write("nomissing.nc",
boolmask(ncarray)
.* 1
)
write("nomissing.nc", boolmask(ncarray) .* 1)
nomissing = Raster("nomissing.nc")
@test missingval(nomissing) == nothing
rm("nomissing.nc")
Expand Down

0 comments on commit da33a3d

Please sign in to comment.