@@ -2,6 +2,9 @@ using ArgParse
22using YAXArrays: YAXDefaults
33
44const argparsesettings = ArgParseSettings ()
5+
6+ ArgParse. parse_item (:: Type{Date} , x:: AbstractString ) = Date (x)
7+
58@add_arg_table! argparsesettings begin
69 " --threshold" , " -t"
710 help = " Threshold for the recurrence matrix computation"
@@ -11,12 +14,17 @@ const argparsesettings = ArgParseSettings()
1114 help = " Polarisation that should be stacked"
1215 default = " VH"
1316
14- " --years" , " --year" , " -y"
15- help = " Year in which the RQA Trend should be detected.
16- We take a buffer of six month before and after the year to end up with two years of data."
17- default = [2018 , 2019 , 2020 , 2021 , 2022 , 2023 ]
18- nargs = ' +'
19- arg_type = Int
17+ " --start-date"
18+ help = " Start date of the time series to analyze in ISO 8601 format YYYY-MM-DD"
19+ required = true
20+ arg_type = Date
21+ dest_name = " start_date"
22+
23+ " --end-date"
24+ help = " End date of the time series to analyze in ISO 8601 format YYYY-MM-DD"
25+ required = true
26+ arg_type = Date
27+ dest_name = " end_date"
2028
2129 " --orbit" , " -o"
2230 help = " One of: Orbit number, 'A' for ascending, 'D' for descending, '*' for all orbits"
5866
5967function main (;
6068 tiles:: Vector{String} ,
61- continent:: String ,
69+ continent:: String ,
6270 indir:: String ,
6371 outdir= " out.zarr" ,
64- years= [2018 , 2019 , 2020 , 2021 , 2022 , 2023 ],
65- polarisation= " VH" ,
66- orbit= " *" ,
67- threshold= 3.0 ,
72+ start_date:: Date ,
73+ end_date:: Date ,
74+ polarisation= " VH" ,
75+ orbit= " *" ,
76+ threshold= 3.0 ,
6877 folders= [" V01R01" , " V0M2R4" , " V1M0R1" , " V1M1R1" , " V1M1R2" ]
6978)
7079 if isdir (indir) && isempty (indir)
@@ -76,6 +85,11 @@ function main(;
7685 mkdir (outdir)
7786 @info " Write output to $outdir "
7887 end
88+
89+ if monthday (start_date) != monthday (end_date)
90+ @warn " Selected time series does not include a multiple of whole years. This might introduce seasonal bias."
91+ end
92+
7993 YAXDefaults. workdir[] = outdir
8094
8195 corruptedfiles = " corrupted_tiles.txt"
@@ -89,42 +103,39 @@ function main(;
89103 relorbits = unique ([split (basename (x), " _" )[5 ][2 : end ] for x in allfilenames])
90104 @show relorbits
91105 for relorbit in relorbits
92- for y in years
93-
94- filenames = allfilenames[findall (contains (" $(relorbit) _E" ), allfilenames)]
95- @time cube = gdalcube (filenames)
96-
97- path = joinpath (YAXDefaults. workdir[], " $(tilefolder) _rqatrend_$(polarisation) _$(relorbit) _thresh_$(threshold) _year_$(y) " )
98- @show path
99- ispath (path * " .done" ) && continue
100- ispath (path * " _zerotimesteps.done" ) && continue
106+ filenames = allfilenames[findall (contains (" $(relorbit) _E" ), allfilenames)]
107+ @time cube = gdalcube (filenames)
108+
109+ path = joinpath (YAXDefaults. workdir[], " $(tilefolder) _rqatrend_$(polarisation) _$(relorbit) _thresh_$(threshold) " )
110+ @show path
111+ ispath (path * " .done" ) && continue
112+ ispath (path * " _zerotimesteps.done" ) && continue
113+
114+ tcube = cube[Time= start_date .. end_date]
115+ @show size (cube)
116+ @show size (tcube)
117+ if size (tcube, 3 ) == 0
118+ touch (path * " _zerotimesteps.done" )
119+ continue
120+ end
121+ try
122+ @time rqatrend (tcube; thresh= threshold, outpath= path * " .zarr" , overwrite= true )
123+ catch e
101124
102- tcube = cube[Time= Date (y - 1 , 7 , 1 ) .. Date (y + 1 , 7 , 1 )]
103- @show size (cube)
104- @show size (tcube)
105- if size (tcube, 3 ) == 0
106- touch (path * " _zerotimesteps.done" )
125+ if hasproperty (e, :captured ) && e. captured. ex isa ArchGDAL. GDAL. GDALError
126+ println (" Found GDALError:" )
127+ println (e. captured. ex. msg)
107128 continue
129+ else
130+ rethrow (e)
108131 end
109- try
110- @time rqatrend (tcube; thresh= threshold, outpath= path * " .zarr" , overwrite= true )
111- catch e
112-
113- if hasproperty (e, :captured ) && e. captured. ex isa ArchGDAL. GDAL. GDALError
114- println (" Found GDALError:" )
115- println (e. captured. ex. msg)
116- continue
117- else
118- rethrow (e)
119- end
120- end
121- #= @everywhere begin
122- fname = "$(VERSION)_$(getpid())_$(time_ns()).heapsnapshot"
123- Profile.take_heap_snapshot(fname;streaming=true)
124- end
125- =#
126- touch (path * " .done" )
127132 end
133+ #= @everywhere begin
134+ fname = "$(VERSION)_$(getpid())_$(time_ns()).heapsnapshot"
135+ Profile.take_heap_snapshot(fname;streaming=true)
136+ end
137+ =#
138+ touch (path * " .done" )
128139 end
129140 end
130141end
0 commit comments