Skip to content

Commit bb264ae

Browse files
authored
Fix format and style (#105)
* Fix format * Fix format * Fix index style
1 parent d93555a commit bb264ae

File tree

2 files changed

+79
-79
lines changed

2 files changed

+79
-79
lines changed

src/auxil.jl

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using YAXArrayBase: backendlist, get_var_handle
1+
using YAXArrayBase: backendlist, get_var_handle
22
using DiskArrayTools
33
using DiskArrays: DiskArrays, GridChunks
44
using DiskArrayEngine: DiskArrayEngine as DAE
@@ -17,27 +17,27 @@ struct LazyAggDiskArray{T,F,A} <: AbstractDiskArray{T,3}
1717
inds::IrregularChunks
1818
s::Tuple{Int,Int,Int}
1919
end
20-
function LazyAggDiskArray(f,arrays,groups)
21-
allequal(size,arrays) || error("All Arrays must have same size")
22-
allequal(eltype,arrays) || error("All Arrays must have same element type")
23-
inds = IrregularChunks(;chunksizes=last(rle(groups)))
24-
s = (size(first(arrays))...,length(inds))
25-
T = Base.promote_op(f,Vector{eltype(first(arrays))})
26-
LazyAggDiskArray{T,typeof(f),typeof(arrays)}(f,arrays,inds,s)
20+
function LazyAggDiskArray(f, arrays, groups)
21+
allequal(size, arrays) || error("All Arrays must have same size")
22+
allequal(eltype, arrays) || error("All Arrays must have same element type")
23+
inds = IrregularChunks(; chunksizes=last(rle(groups)))
24+
s = (size(first(arrays))..., length(inds))
25+
T = Base.promote_op(f, Vector{eltype(first(arrays))})
26+
LazyAggDiskArray{T,typeof(f),typeof(arrays)}(f, arrays, inds, s)
2727
end
2828
Base.size(a::LazyAggDiskArray) = a.s
2929
DiskArrays.haschunks(a::LazyAggDiskArray) = DiskArrays.haschunks(first(a.arrays))
30-
function DiskArrays.readblock!(a::LazyAggDiskArray,aout,i::UnitRange{Int}...)
31-
i1,i2,itime = i
32-
max_n_array = maximum(it->length(a.inds[it]),itime)
33-
buf = zeros(eltype(first(a.arrays)),length(i1),length(i2),max_n_array)
30+
function DiskArrays.readblock!(a::LazyAggDiskArray, aout, i::UnitRange{Int}...)
31+
i1, i2, itime = i
32+
max_n_array = maximum(it -> length(a.inds[it]), itime)
33+
buf = zeros(eltype(first(a.arrays)), length(i1), length(i2), max_n_array)
3434
for (j, it) in enumerate(itime)
3535
arrays_now = a.arrays[a.inds[it]]
36-
for ia in 1:length(arrays_now)
37-
DiskArrays.readblock!(arrays_now[ia],view(buf,:,:,ia),i1,i2)
36+
for ia in eachindex(arrays_now)
37+
DiskArrays.readblock!(arrays_now[ia], view(buf, :, :, ia), i1, i2)
3838
end
39-
vbuf = view(buf,:,:,1:length(arrays_now))
40-
map!(a.f,view(aout,:,:,j),eachslice(vbuf,dims=(1,2)))
39+
vbuf = view(buf, :, :, 1:length(arrays_now))
40+
map!(a.f, view(aout, :, :, j), eachslice(vbuf, dims=(1, 2)))
4141
end
4242
end
4343

@@ -76,8 +76,8 @@ end
7676

7777
@testitem "getdate" begin
7878
using Dates
79-
@test RQADeforestation.getdate("sometext20200919T202020_somemoretext1234") == DateTime(2020,9,19, 20,20,20)
80-
@test_throws Exception RQADeforestation.getdate("sometext")
79+
@test RQADeforestation.getdate("sometext20200919T202020_somemoretext1234") == DateTime(2020, 9, 19, 20, 20, 20)
80+
@test_throws Exception RQADeforestation.getdate("sometext")
8181
end
8282

8383
"""
@@ -103,7 +103,7 @@ function grouptimes(times, timediff=200000)
103103
group = [1]
104104
groups = [group]
105105

106-
for i in 2:length(times)
106+
for i in eachindex(times)[2:end]
107107
t = times[i]
108108
period = t - times[group[end]]
109109
if period.value < timediff
@@ -123,12 +123,12 @@ function stackindices(times, timediff=200000)
123123
group = 1
124124
groups[1] = group
125125

126-
for i in 2:length(times)
126+
for i in eachindex(times)[2:end]
127127
period = times[i] - times[i-1]
128128
if period.value < timediff
129129
groups[i] = group
130130
else
131-
group += 1
131+
group += 1
132132
groups[i] = group
133133
end
134134
end
@@ -166,61 +166,61 @@ function gdalcube(filenames::AbstractVector{<:AbstractString}, stackgroups=:dae)
166166
#@show sdates
167167
# Put the dates which are 200 seconds apart into groups
168168
if stackgroups in [:dae, :lazyagg]
169-
groupinds = grouptimes(sdates, 200000)
170-
onefile = first(sfiles)
171-
gd = backendlist[:gdal]
172-
yax1 = gd(onefile)
173-
#gdb = yax1["Gray"]
174-
#onecube = Cube(onefile)
175-
#@show onecube.axes
176-
gdb = get_var_handle(yax1, "Gray")
177-
gdbband = gdb.band
178-
gdbsize = gdb.size
179-
gdbattrs = gdb.attrs
180-
gdbcs = gdb.cs
181-
group_gdbs = map(sfiles) do f
169+
groupinds = grouptimes(sdates, 200000)
170+
onefile = first(sfiles)
171+
gd = backendlist[:gdal]
172+
yax1 = gd(onefile)
173+
#gdb = yax1["Gray"]
174+
#onecube = Cube(onefile)
175+
#@show onecube.axes
176+
gdb = get_var_handle(yax1, "Gray")
177+
gdbband = gdb.band
178+
gdbsize = gdb.size
179+
gdbattrs = gdb.attrs
180+
gdbcs = gdb.cs
181+
group_gdbs = map(sfiles) do f
182182
BufferGDALBand{eltype(gdb)}(f, gdbband, gdbsize, gdbattrs, gdbcs, Dict{Int,AG.IRasterBand}())
183-
end
183+
end
184+
185+
cubelist = CFDiskArray.(group_gdbs, (gdbattrs,))
186+
stackinds = stackindices(sdates)
187+
aggdata = if stackgroups == :dae
188+
gcube = diskstack(cubelist)
189+
aggdata = DAE.aggregate_diskarray(gcube, mean skipmissing, (3 => stackinds,); strategy=:direct)
190+
else
191+
println("Construct lazy diskarray")
192+
LazyAggDiskArray(mean skipmissing, cubelist, stackinds)
193+
end
194+
# data = DiskArrays.ConcatDiskArray(reshape(groupcubes, (1,1,length(groupcubes))))
195+
dates_grouped = [sdates[group[begin]] for group in groupinds]
184196

185-
cubelist = CFDiskArray.(group_gdbs, (gdbattrs,))
186-
stackinds = stackindices(sdates)
187-
aggdata = if stackgroups == :dae
188-
gcube = diskstack(cubelist)
189-
aggdata = DAE.aggregate_diskarray(gcube, mean skipmissing, (3=> stackinds,); strategy=:direct)
197+
taxis = DD.Ti(dates_grouped)
198+
gcube = Cube(sfiles[1])
199+
return YAXArray((DD.dims(gcube)[1:2]..., taxis), aggdata, gcube.properties,)
190200
else
191-
println("Construct lazy diskarray")
192-
LazyAggDiskArray(mean skipmissing, cubelist, stackinds)
193-
end
194-
# data = DiskArrays.ConcatDiskArray(reshape(groupcubes, (1,1,length(groupcubes))))
195-
dates_grouped = [sdates[group[begin]] for group in groupinds]
196-
197-
taxis = DD.Ti(dates_grouped)
198-
gcube = Cube(sfiles[1])
199-
return YAXArray((DD.dims(gcube)[1:2]..., taxis), aggdata, gcube.properties,)
200-
else
201-
#datasets = AG.readraster.(sfiles)
202-
taxis = DD.Ti(sdates)
203-
204-
onefile = first(sfiles)
205-
gd = backendlist[:gdal]
206-
yax1 = gd(onefile)
207-
onecube = Cube(onefile)
208-
#@show onecube.axes
209-
gdb = get_var_handle(yax1, "Gray")
210-
211-
#@assert gdb isa GDALBand
212-
all_gdbs = map(sfiles) do f
213-
BufferGDALBand{eltype(gdb)}(f, gdb.band, gdb.size, gdb.attrs, gdb.cs, Dict{Int,AG.IRasterBand}())
214-
end
215-
stacked_gdbs = diskstack(all_gdbs)
216-
attrs = copy(gdb.attrs)
217-
#attrs["add_offset"] = Float16(attrs["add_offset"])
218-
if haskey(attrs, "scale_factor")
219-
attrs["scale_factor"] = Float16(attrs["scale_factor"])
201+
#datasets = AG.readraster.(sfiles)
202+
taxis = DD.Ti(sdates)
203+
204+
onefile = first(sfiles)
205+
gd = backendlist[:gdal]
206+
yax1 = gd(onefile)
207+
onecube = Cube(onefile)
208+
#@show onecube.axes
209+
gdb = get_var_handle(yax1, "Gray")
210+
211+
#@assert gdb isa GDALBand
212+
all_gdbs = map(sfiles) do f
213+
BufferGDALBand{eltype(gdb)}(f, gdb.band, gdb.size, gdb.attrs, gdb.cs, Dict{Int,AG.IRasterBand}())
214+
end
215+
stacked_gdbs = diskstack(all_gdbs)
216+
attrs = copy(gdb.attrs)
217+
#attrs["add_offset"] = Float16(attrs["add_offset"])
218+
if haskey(attrs, "scale_factor")
219+
attrs["scale_factor"] = Float16(attrs["scale_factor"])
220+
end
221+
all_cfs = CFDiskArray(stacked_gdbs, attrs)
222+
return YAXArray((onecube.axes..., taxis), all_cfs, onecube.properties)
220223
end
221-
all_cfs = CFDiskArray(stacked_gdbs, attrs)
222-
return YAXArray((onecube.axes..., taxis), all_cfs, onecube.properties)
223-
end
224224
#datasetgroups = [datasets[group] for group in groupinds]
225225
#We have to save the vrts because the usage of nested vrts is not working as a rasterdataset
226226
#temp = tempdir()

src/rqatrend.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function rqatrend_impl(data; thresh=2, border=10, theiler=1, metric=CheckedEucli
5757
# simplified implementation of https://stats.stackexchange.com/a/370175 and https://github.com/joshday/OnlineStats.jl/blob/b89a99679b13e3047ff9c93a03c303c357931832/src/stats/linreg.jl
5858
# x is the diagonal offset, y the percentage of local recurrence
5959
# we compute the slope of a simple linear regression with bias from x to y
60-
xs = 1+theiler : length(data)-border
60+
xs = 1+theiler:length(data)-border
6161
x_mean = mean(xs)
6262
xx_mean = sqmean_step1_range(xs) # mean(x*x for x in xs)
6363

@@ -70,18 +70,18 @@ function rqatrend_impl(data; thresh=2, border=10, theiler=1, metric=CheckedEucli
7070
n += 1.0
7171
y = tau_rr(data, x; thresh, metric)
7272
y_mean = smooth(y_mean, y, inv(n))
73-
xy_mean = smooth(xy_mean, x*y, inv(n))
73+
xy_mean = smooth(xy_mean, x * y, inv(n))
7474
end
75-
A = SA_F64[
75+
A = SA_F64[
7676
xx_mean x_mean
77-
x_mean 1.0
77+
x_mean 1.0
7878
]
7979
b = SA_F64[xy_mean, y_mean]
8080
# OnlineStats uses `Symmetric(A) \ b`, however this does not work for StaticArrays
8181
# `cholesky(A) \ b` is recommended instead at discourse https://discourse.julialang.org/t/staticarrays-solve-symmetric-linear-system-seems-typeinstable/124634
8282
# some timings show that there is no significant speedup when adding cholesky or doing plain static linear regression
8383
# hence leaving it out for now
84-
return 1000.0*(A \ b)[1] # slope
84+
return 1000.0 * (A\b)[1] # slope
8585
end
8686

8787

@@ -123,7 +123,7 @@ function tau_rr(y, d; thresh=2, metric=CheckedEuclidean())
123123
nominator += evaluate(metric, y[i], y[i+d]) <= _thresh
124124
denominator += 1
125125
end
126-
return nominator/denominator
126+
return nominator / denominator
127127
end
128128
end
129129

@@ -135,7 +135,7 @@ function sqmean_step1_range(xs)
135135
end
136136

137137
# assumes n is Int for optimal performance
138-
sumofsquares(n) = n*(n+1)*(2*n+1)/6
138+
sumofsquares(n) = n * (n + 1) * (2 * n + 1) / 6
139139

140140
"""
141141
smooth(a, b, γ)

0 commit comments

Comments
 (0)