Skip to content
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
1 change: 0 additions & 1 deletion src/RQADeforestation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ include("metrics.jl")
include("auxil.jl")
include("rqatrend.jl")
include("analysis.jl") # TODO what is still needed from analysis now that rqatrend is in its own file?
include("timestats.jl")
include("main.jl")

end
81 changes: 7 additions & 74 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,83 +35,16 @@ countvalid(cube; path=tempname() * ".zarr") = mapCube(countvalid, cube; indims=I
Y(range(1, 5, length=15)),
)
mock_data = allowmissing(rand(30, 10, 15))
mock_data[1:10,1,1] .= missing
mock_data[:, 2,1] .= missing
mock_data[[1,5,9], 2,2] .= missing
mock_data[1:10, 1, 1] .= missing
mock_data[:, 2, 1] .= missing
mock_data[[1, 5, 9], 2, 2] .= missing
mock_props = Dict()
mock_cube = YAXArray(mock_axes, mock_data, mock_props)

mock_count = RQADeforestation.countvalid(mock_cube)
@test mock_count.axes == (mock_cube.X, mock_cube.Y)
@test mock_count[1,1] == 20
@test mock_count[1,2] == 30
@test mock_count[2,2] == 27
@test mock_count[2,1] == 0
end

"""
rqatrend(xout, xin, thresh)

Compute the RQA trend metric for the non-missing time steps of xin, and save it to xout.
`thresh` specifies the epsilon threshold of the Recurrence Plot computation
"""
function rqatrend_recurrenceanalysis(pix_trend, pix, thresh=2)
ts = collect(skipmissing(pix))
tau_pix = tau_recurrence(ts, thresh)
pix_trend .= RA._trend(tau_pix)
end

function rqatrend_matrix(pix_trend, pix, thresh=2)
#replace!(pix, -9999 => missing)
ts = collect(skipmissing(pix))
rm = RecurrenceMatrix(ts, thresh)
pix_trend .= RA.trend(rm)
end

#=
"""
rqatrend_shuffle(cube; thresh=2, path=tempname() * ".zarr", numshuffle=300)
Compute the RQA trend metric for shuffled time series of the data cube `cube` with the epsilon threshold `thresh` for `numshuffle` tries and save it into `path`.
"""
function rqatrend_shuffle(cube; thresh=2, path=tempname() * ".zarr", numshuffle=300)
# This should be made a random shuffle
# TODO this looks completely broken
sg = surrogenerator(collect(eachindex(water[overlap])), BlockShuffle(7, shift=true))
end
=#


"""
anti_diagonal_density(ts, thresh, metric)
Compute the average density of the diagonals perpendicular to the main diagonal for data series `ts`.
Uses the threshold `thresh` and `metric` for the computation of the similarities.
"""
function anti_diagonal_density(ts::AbstractVector, thresh, metric=Euclidean())
n = length(ts)
ad_densities = zeros(2 * n - 3)
for col in 1:n
for row in 1:(col-1)
d = evaluate(metric, ts[col], ts[row])
#@show row, col, d
ad_densities[col+row-2] += d <= thresh
end
end
half = div(n, 2)
maxdensities = collect(Iterators.flatten([(n, n) for n in 1:half-1]))
diagonallengths = [maxdensities..., half, reverse(maxdensities)...]
ad_densities ./ diagonallengths
end

"""
Compute the forest masking thresholding and clustering of the rqadata in one step
"""
function inner_postprocessing(rqadata, forestmask; threshold=-1.28, clustersize=30)
@time rqamasked = rqadata .* forestmask
@time rqathresh = map(rqamasked) do x
if !ismissing(x)
x > threshold ? zero(Float32) : one(Float32)
else
x
end
end
@test mock_count[1, 1] == 20
@test mock_count[1, 2] == 30
@test mock_count[2, 2] == 27
@test mock_count[2, 1] == 0
end
37 changes: 0 additions & 37 deletions src/timestats.jl

This file was deleted.

2 changes: 1 addition & 1 deletion test/Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
git-tree-sha1 = "1dc9d7aa975de4f5ecc652f34d6bbee706fcb7bd"

[[rqatestdata.download]]
url = "https://github.com/meggart/RQADeforestationTestData/archive/refs/tags/v2.0.tar.gz"
url = "https://github.com/EarthyScience/RQADeforestationTestData/archive/refs/tags/v2.0.tar.gz"
sha256 = "38a3e66a0505ed9d22c6e065627039089a421b0b143ac4c8d78aac45dd3dd497"
Loading