Skip to content

Commit e853686

Browse files
danlooomeggart
andauthored
Add mock rqatrend (#41) close #35
* Add mock rqatrend * Add testdata as artifact (#50) * add testdata as artifact * Add test-specific project.toml * manually install artifacts * Add mock rqatrend * Fix duplicate packages in test * Merge testsets * Add show difference in test * Relax test --------- Co-authored-by: Fabian Gans <fabiancoding@gmail.com>
1 parent 20f4df2 commit e853686

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/RQADeforestation.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ include("analysis.jl") # TODO what is still needed from analysis now that rqatr
1616
include("timestats.jl")
1717

1818

19-
function main(tiles = ["E048N018T3"]; pol="VH", orbit="*", thresh=3.0)
19+
function main(tiles=["E048N018T3"]; pol="VH", orbit="*", thresh=3.0)
2020
indir = "/eodc/products/eodc.eu/S1_CSAR_IWGRDH/SIG0/"
2121
continent = "EU"
22-
folders = ["V01R01","V0M2R4", "V1M0R1", "V1M1R1", "V1M1R2"]
22+
folders = ["V01R01", "V0M2R4", "V1M0R1", "V1M1R1", "V1M1R2"]
2323
corruptedfiles = "corrupted_tiles.txt"
2424
# TODO save the corrupt files to a txt for investigation
2525
for tilefolder in tiles
@@ -32,35 +32,35 @@ function main(tiles = ["E048N018T3"]; pol="VH", orbit="*", thresh=3.0)
3232
relorbits = unique([split(basename(x), "_")[5][2:end] for x in allfilenames])
3333
@show relorbits
3434
for relorbit in relorbits
35-
for y in [2018,2019,2020,2021,2022, 2023]
35+
for y in [2018, 2019, 2020, 2021, 2022, 2023]
3636

37-
filenames = allfilenames[findall(contains("$(relorbit)_E"), allfilenames)]
38-
@time cube = gdalcube(filenames)
37+
filenames = allfilenames[findall(contains("$(relorbit)_E"), allfilenames)]
38+
@time cube = gdalcube(filenames)
3939

4040
path = joinpath(YAXDefaults.workdir[], "$(tilefolder)_rqatrend_$(pol)_$(relorbit)_thresh_$(thresh)_year_$(y)")
4141
@show path
42-
ispath(path*".done") && continue
43-
ispath(path*"_zerotimesteps.done") && continue
42+
ispath(path * ".done") && continue
43+
ispath(path * "_zerotimesteps.done") && continue
4444

45-
tcube = cube[Time=Date(y-1, 7,1)..Date(y+1,7,1)]
45+
tcube = cube[Time=Date(y - 1, 7, 1) .. Date(y + 1, 7, 1)]
4646
@show size(cube)
4747
@show size(tcube)
4848
if size(tcube, Ti) == 0
49-
touch(path*"_zerotimesteps.done")
49+
touch(path * "_zerotimesteps.done")
5050
continue
5151
end
52-
try
53-
@time rqatrend(tcube; thresh, outpath=path * ".zarr", overwrite=true)
54-
catch e
55-
56-
if e.captured.ex isa ArchGDAL.GDAL.GDALError
57-
println("Found GDALError:")
58-
println(e.captured.ex.msg)
59-
continue
60-
else
61-
rethrow(e)
52+
try
53+
@time rqatrend(tcube; thresh, outpath=path * ".zarr", overwrite=true)
54+
catch e
55+
56+
if e.captured.ex isa ArchGDAL.GDAL.GDALError
57+
println("Found GDALError:")
58+
println(e.captured.ex.msg)
59+
continue
60+
else
61+
rethrow(e)
62+
end
6263
end
63-
end
6464
#=@everywhere begin
6565
fname = "$(VERSION)_$(getpid())_$(time_ns()).heapsnapshot"
6666
Profile.take_heap_snapshot(fname;streaming=true)

test/Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
55
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
6-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
7+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
9+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
10+
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"

test/runtests.jl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ using Test
33
import AllocCheck
44
import Random
55
import Pkg: Artifacts.@artifact_str, ensure_artifact_installed
6+
using DimensionalData
7+
using YAXArrays
8+
using Dates
9+
using Random
10+
using Statistics
11+
612
Random.seed!(1234)
713

814
ensure_artifact_installed("rqatestdata", "Artifacts.toml")
915
testdatapath = joinpath(artifact"rqatestdata", "RQADeforestationTestData-1.0")
1016

11-
@testset "Test data" begin
12-
@test isfile(joinpath(testdatapath, "V01R01", "EQUI7_EU020M", "E051N018T3", "SIG0_20210818T051717__VH_D095_E051N018T3_EU020M_V01R01_S1BIWGRDH.tif"))
13-
end
14-
1517
@testset "RQADeforestation.jl" begin
16-
# Write your tests here.
18+
@test isfile(joinpath(testdatapath, "V01R01", "EQUI7_EU020M", "E051N018T3", "SIG0_20210818T051717__VH_D095_E051N018T3_EU020M_V01R01_S1BIWGRDH.tif"))
1719

1820
x = 1:0.01:30
1921
y = sin.(x) + 0.1x + rand(length(x))
@@ -22,12 +24,25 @@ end
2224
@test isempty(AllocCheck.check_allocs(RQADeforestation.rqatrend_impl, Tuple{Vector{Float64}}))
2325

2426

25-
y2 = similar(y, Union{Float64, Missing})
27+
y2 = similar(y, Union{Float64,Missing})
2628
copy!(y2, y)
27-
y2[[1,4,10,20,33,65]] .= missing
29+
y2[[1, 4, 10, 20, 33, 65]] .= missing
2830

2931

3032
@test isapprox(RQADeforestation.rqatrend_impl(y2; thresh=0.5), -0.11069045524336744)
3133
@test isempty(AllocCheck.check_allocs(RQADeforestation.rqatrend_impl, Tuple{Vector{Union{Float64,Missing}}}))
3234

35+
mock_axes = (
36+
Ti(Date("2022-01-01"):Day(1):Date("2022-01-30")),
37+
X(range(1, 10, length=10)),
38+
Y(range(1, 5, length=15)),
39+
)
40+
mock_data = rand(30, 10, 15)
41+
mock_props = Dict()
42+
mock_cube = YAXArray(mock_axes, mock_data, mock_props)
43+
44+
mock_trend = rqatrend(mock_cube; thresh=0.5)
45+
@test mock_trend.axes == (mock_cube.X, mock_cube.Y)
46+
diff = abs(mean(mock_trend))
47+
@test diff < 0.2
3348
end

0 commit comments

Comments
 (0)