@@ -35,83 +35,16 @@ countvalid(cube; path=tempname() * ".zarr") = mapCube(countvalid, cube; indims=I
3535 Y (range (1 , 5 , length= 15 )),
3636 )
3737 mock_data = allowmissing (rand (30 , 10 , 15 ))
38- mock_data[1 : 10 ,1 , 1 ] .= missing
39- mock_data[:, 2 ,1 ] .= missing
40- mock_data[[1 ,5 , 9 ], 2 ,2 ] .= missing
38+ mock_data[1 : 10 , 1 , 1 ] .= missing
39+ mock_data[:, 2 , 1 ] .= missing
40+ mock_data[[1 , 5 , 9 ], 2 , 2 ] .= missing
4141 mock_props = Dict ()
4242 mock_cube = YAXArray (mock_axes, mock_data, mock_props)
4343
4444 mock_count = RQADeforestation. countvalid (mock_cube)
4545 @test mock_count. axes == (mock_cube. X, mock_cube. Y)
46- @test mock_count[1 ,1 ] == 20
47- @test mock_count[1 ,2 ] == 30
48- @test mock_count[2 ,2 ] == 27
49- @test mock_count[2 ,1 ] == 0
50- end
51-
52- """
53- rqatrend(xout, xin, thresh)
54-
55- Compute the RQA trend metric for the non-missing time steps of xin, and save it to xout.
56- `thresh` specifies the epsilon threshold of the Recurrence Plot computation
57- """
58- function rqatrend_recurrenceanalysis (pix_trend, pix, thresh= 2 )
59- ts = collect (skipmissing (pix))
60- tau_pix = tau_recurrence (ts, thresh)
61- pix_trend .= RA. _trend (tau_pix)
62- end
63-
64- function rqatrend_matrix (pix_trend, pix, thresh= 2 )
65- # replace!(pix, -9999 => missing)
66- ts = collect (skipmissing (pix))
67- rm = RecurrenceMatrix (ts, thresh)
68- pix_trend .= RA. trend (rm)
69- end
70-
71- #=
72- """
73- rqatrend_shuffle(cube; thresh=2, path=tempname() * ".zarr", numshuffle=300)
74- 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`.
75- """
76- function rqatrend_shuffle(cube; thresh=2, path=tempname() * ".zarr", numshuffle=300)
77- # This should be made a random shuffle
78- # TODO this looks completely broken
79- sg = surrogenerator(collect(eachindex(water[overlap])), BlockShuffle(7, shift=true))
80- end
81- =#
82-
83-
84- """
85- anti_diagonal_density(ts, thresh, metric)
86- Compute the average density of the diagonals perpendicular to the main diagonal for data series `ts`.
87- Uses the threshold `thresh` and `metric` for the computation of the similarities.
88- """
89- function anti_diagonal_density (ts:: AbstractVector , thresh, metric= Euclidean ())
90- n = length (ts)
91- ad_densities = zeros (2 * n - 3 )
92- for col in 1 : n
93- for row in 1 : (col- 1 )
94- d = evaluate (metric, ts[col], ts[row])
95- # @show row, col, d
96- ad_densities[col+ row- 2 ] += d <= thresh
97- end
98- end
99- half = div (n, 2 )
100- maxdensities = collect (Iterators. flatten ([(n, n) for n in 1 : half- 1 ]))
101- diagonallengths = [maxdensities... , half, reverse (maxdensities)... ]
102- ad_densities ./ diagonallengths
103- end
104-
105- """
106- Compute the forest masking thresholding and clustering of the rqadata in one step
107- """
108- function inner_postprocessing (rqadata, forestmask; threshold= - 1.28 , clustersize= 30 )
109- @time rqamasked = rqadata .* forestmask
110- @time rqathresh = map (rqamasked) do x
111- if ! ismissing (x)
112- x > threshold ? zero (Float32) : one (Float32)
113- else
114- x
115- end
116- end
46+ @test mock_count[1 , 1 ] == 20
47+ @test mock_count[1 , 2 ] == 30
48+ @test mock_count[2 , 2 ] == 27
49+ @test mock_count[2 , 1 ] == 0
11750end
0 commit comments