Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add series duplicate_first test #493

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/series.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Rasters, Test, Dates, DimensionalData
using Rasters.LookupArrays, Rasters.Dimensions
include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))

# RasterSeries from Raster/RasterStack components

Expand Down Expand Up @@ -115,3 +116,13 @@ end
@test occursin("Raster", sh)
@test occursin("X", sh)
end

@testset "duplicate_first & lazy" begin
temporary_random_rasters(3, (10,10,3), UInt8) do filenames
times = Ti(DateTime.(sort(rand(UInt16, length(filenames)))))
series = RasterSeries(filenames, times; duplicate_first=true, lazy=true)
@test all(Rasters.filename.(series) .== filenames)
first_dims = dims(first(series))
@test all(dims(r) == first_dims for r in series)
end
end
15 changes: 15 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using ArchGDAL

# Loader for external sources
maybedownload(url, filename=splitdir(url)[2]) = begin
dirpath = joinpath(dirname(pathof(Rasters)), "../test/data")
Expand All @@ -6,3 +8,16 @@ maybedownload(url, filename=splitdir(url)[2]) = begin
isfile(filepath) || download(url, filepath)
filepath
end

# create `N` random rasters with eltype `type` and x,y,band size `size`
function temporary_random_rasters(f, N, size, type=UInt8)
filenames = [tempname() * ".tif" for _ in 1:N]
try
for f in filenames
write(f, Raster(rand(type, size); dims=(X(1:size[1]), Y(1:size[2]), Band(1:size[3]))))
end
f(filenames)
finally
rm.(filenames; force=true)
end
end
Loading