Skip to content

Commit 50a2ac3

Browse files
authored
Fix main function (#91)
* Fix missing year variable * Fix missing output after calling julia_main * Update extrema tests * Fix indir path * Adjust time span * Re add test julia_main * Disentangle test dirs * Fix entangled test dirs in matrix CI * Fix default arg
1 parent 3311adf commit 50a2ac3

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/main.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ArgParse.parse_item(::Type{Date}, x::AbstractString) = Date(x)
2929

3030
"--orbit", "-o"
3131
help = "One of: Orbit number, 'A' for ascending, 'D' for descending, '*' for all orbits"
32-
default = "A"
32+
default = "D"
3333

3434
"--out-dir", "-d"
3535
help = "Path to output zarr dataset"
@@ -53,7 +53,7 @@ ArgParse.parse_item(::Type{Date}, x::AbstractString) = Date(x)
5353

5454
"--folders", "--folder"
5555
help = "subfolders taken into account"
56-
default = ["V01R01", "V0M2R4", "V1M0R1", "V1M1R1", "V1M1R2"]
56+
default = ["V1M0R1", "V1M1R1", "V1M1R2"]
5757
arg_type = String
5858
nargs = '*'
5959
end
@@ -98,17 +98,17 @@ function main(;
9898
corruptedfiles = "corrupted_tiles.txt"
9999
# TODO save the corrupt files to a txt for investigation
100100
for tilefolder in tiles
101-
102101
filenamelist = [glob("$(sub)/*$(continent)*20M/$(tilefolder)/*$(polarisation)_$(orbit)*.tif", indir) for sub in folders]
103102
allfilenames = collect(Iterators.flatten(filenamelist))
104103

105104
relorbits = unique([split(basename(x), "_")[5][2:end] for x in allfilenames])
106105
@show relorbits
106+
107107
for relorbit in relorbits
108108
filenames = allfilenames[findall(contains("$(relorbit)_E"), allfilenames)]
109109
@time cube = gdalcube(filenames, stack)
110110

111-
path = joinpath(YAXDefaults.workdir[], "$(tilefolder)_rqatrend_$(polarisation)_$(orbit)$(relorbit)_thresh_$(threshold)_year_$(y)")
111+
path = joinpath(YAXDefaults.workdir[], "$(tilefolder)_rqatrend_$(polarisation)_$(orbit)$(relorbit)_thresh_$(threshold)")
112112
@show path
113113
ispath(path * ".done") && continue
114114
ispath(path * "_zerotimesteps.done") && continue

test/testdata.jl

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11

2+
@testitem "testdata main" begin
3+
import Pkg: Artifacts.@artifact_str, ensure_artifact_installed
4+
5+
ensure_artifact_installed("rqatestdata", "Artifacts.toml")
6+
testdatapath = joinpath(artifact"rqatestdata", "RQADeforestationTestData-2.0")
7+
8+
testdir = tempname()
9+
rm(testdir, recursive=true, force=true)
10+
mkpath(testdir)
11+
outdir = "$testdir/out.zarr"
12+
indir = "$testdir/in"
13+
cp(testdatapath, indir)
14+
15+
using Zarr
16+
using YAXArrays
17+
using Dates
18+
RQADeforestation.main(;
19+
tiles=["E051N018T3"],
20+
continent="EU",
21+
indir=indir,
22+
start_date=Date("2021-01-01"),
23+
end_date=Date("2022-01-01"),
24+
outdir=outdir
25+
)
26+
a = open_dataset(outdir * "/E051N018T3_rqatrend_VH_D022_thresh_3.0.zarr").layer
27+
28+
@test size(a) == (50, 74)
29+
@test minimum(a) < 0
30+
@test maximum(a) > 0
31+
end
32+
233
@testitem "testdata julia_main" begin
334
import Pkg: Artifacts.@artifact_str, ensure_artifact_installed
435

536
ensure_artifact_installed("rqatestdata", "Artifacts.toml")
637
testdatapath = joinpath(artifact"rqatestdata", "RQADeforestationTestData-2.0")
738

8-
testdir = "tmp/testdata"
39+
testdir = tempname()
940
rm(testdir, recursive=true, force=true)
1041
mkpath(testdir)
1142
outdir = "$testdir/out.zarr"
@@ -17,7 +48,7 @@
1748
"--tile", "E051N018T3",
1849
"--continent", "EU",
1950
"--start-date", "2021-01-01",
20-
"--end-date", "2021-12-31",
51+
"--end-date", "2022-01-01",
2152
"--in-dir", indir,
2253
"--out-dir", outdir,
2354
])
@@ -26,4 +57,6 @@
2657
# test short cut implementation using cache files
2758
RQADeforestation.julia_main()
2859
copy!(ARGS, OLD_ARGS)
60+
61+
@test outdir |> readdir |> length > 1
2962
end

0 commit comments

Comments
 (0)