Skip to content

Commit 9f6ceee

Browse files
authored
Move to Julia extensions (v1.9) + fix an export (#152)
* remove requires dep * add makie weak deap * fix standardize export * move plotting function to extension file * port uncertain data to extensions file * correct codecov * more powerful plotting * remove uncertain data * remove requires * make proper module structure for surrogates plot * finish everything * correct display of surroplot in docs * remove global `using StatsBase`
1 parent 054e0a4 commit 9f6ceee

9 files changed

+79
-70
lines changed

.codecov.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

Project.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "TimeseriesSurrogates"
22
uuid = "c804724b-8c18-5caa-8579-6025a0767c70"
33
authors = ["Kristian Agasøster Haaga <kahaaga@gmail.com>", "George Datseris"]
44
repo = "https://github.com/JuliaDynamics/TimeseriesSurrogates.jl.git"
5-
version = "2.4.0"
5+
version = "2.5.0"
66

77
[deps]
88
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -14,13 +14,20 @@ Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1414
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1515
LombScargle = "fc60dff9-86e7-5f2f-a8a0-edeadbb75bd9"
1616
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
17-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1817
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1918
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
2019
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2120
StateSpaceSets = "40b095a5-5852-4c12-98c7-d43bf788e795"
2221
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
2322

23+
[weakdeps]
24+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
25+
# UncertainData = "dcd9ba68-c27b-5cea-ae21-829cd07325bf"
26+
27+
[extensions]
28+
TimeseriesSurrogatesVisualizations = "Makie"
29+
# TimeseriesSurrogatesUncertainData = "UncertainData"
30+
2431
[compat]
2532
AbstractFFTs = "1"
2633
DSP = "^0.5.2, 0.6, ^1, 0.7"
@@ -29,12 +36,12 @@ Distances = "0.10, 1"
2936
Distributions = "0.21, 1, 0.23, 0.24, 0.25"
3037
Interpolations = "^0.12, ^1, 0.13, 0.14"
3138
LombScargle = "1"
32-
Requires = "^0.5.2, ^1"
39+
Makie = "≥ 0.19"
3340
StatsAPI = "1.6"
3441
StatsBase = "^0.32.0, ^1, 0.33"
3542
StateSpaceSets = "1"
3643
Wavelets = "^0.8.0, 0.9, 1"
37-
julia = "^1.1"
44+
julia = "^1.9"
3845

3946
[extras]
4047
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

codecov.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# sample regex patterns
2+
ignore:
3+
- "src/deprecated.jl"
4+
- "plotting/*"
5+
- "ext/*"

docs/src/index.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,15 @@ noiseradius
108108

109109
TimeseriesSurrogates.jl has defined a simple function `surroplot(x, s)`.
110110
This comes into scope when `using Makie` (you also need a plotting backend).
111+
This functionality requires you to be using Julia 1.9 or later versions.
111112

112-
To load the function, do:
113+
Example:
113114

114115
```@example MAIN
115116
using TimeseriesSurrogates
116-
using CairoMakie, Makie
117-
using TimeseriesSurrogates, CairoMakie, Makie
118-
ts = AR1() # create a realization of a random AR(1) process
119-
s = surrogate(ts, AAFT())
120-
fig = surroplot(ts, s)
117+
using CairoMakie
118+
x = AR1() # create a realization of a random AR(1) process
119+
fig = surroplot(x, AAFT())
121120
save("surroplot.png", fig); # hide
122121
```
123122

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module TimeseriesSurrogatesUncertainData
2+
3+
using TimeseriesSurrogates
4+
import UncertainData: UncertainDataset, UncertainIndexDataset, UncertainValueDataset, resample
5+
6+
TimeseriesSurrogates.surrogate(x::UncertainDataset, method::Surrogate) = surrogate(resample(x), method)
7+
TimeseriesSurrogates.surrogate(x::UncertainValueDataset, method::Surrogate) = surrogate(resample(x), method)
8+
TimeseriesSurrogates.surrogate(x::UncertainIndexDataset, method::Surrogate) = surrogate(resample(x), method)
9+
10+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module TimeseriesSurrogatesVisualizations
2+
3+
using TimeseriesSurrogates, Makie
4+
5+
function TimeseriesSurrogates.surroplot(x, s;
6+
cx = "#191E44", cs = ("#7143E0", 0.9), resolution = (500, 500),
7+
nbins = 50,
8+
)
9+
10+
t = 1:length(x)
11+
fig = Makie.Figure(resolution = resolution)
12+
13+
# Time series
14+
ax1, _ = Makie.lines(fig[1,1], t, x; color = cx, linewidth = 2)
15+
Makie.lines!(ax1, t, s; color = cs, linewidth = 2)
16+
17+
# Binned multitaper periodograms
18+
p, psurr = TimeseriesSurrogates.DSP.mt_pgram(x), TimeseriesSurrogates.DSP.mt_pgram(s)
19+
ax3 = Makie.Axis(fig[2,1]; yscale = log10)
20+
Makie.lines!(ax3, p.freq, p.power; color = cx, linewidth = 3)
21+
Makie.lines!(ax3, psurr.freq, psurr.power; color = cs, linewidth = 3)
22+
23+
# Histograms
24+
ax4 = Makie.Axis(fig[3,1])
25+
Makie.hist!(ax4, x; label = "original", bins = nbins, color = cx)
26+
Makie.hist!(ax4, s; label = "surrogate", bins = nbins, color = cs)
27+
Makie.axislegend(ax4)
28+
29+
ax1.xlabel = "time step"
30+
ax1.ylabel = "value"
31+
ax3.xlabel = "frequency"
32+
ax3.ylabel = "power"
33+
ax4.xlabel = "binned value"
34+
ax4.ylabel = "histogram"
35+
return fig
36+
end
37+
38+
function TimeseriesSurrogates.surroplot(x, method::Surrogate; kwargs...)
39+
s = surrogate(x, method)
40+
return surroplot(x, s; kwargs...)
41+
end
42+
43+
end

src/TimeseriesSurrogates.jl

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ end TimeseriesSurrogates
1010
using Random
1111
using Distributions
1212
using Distances # Will be used by the LombScargle method
13-
using StatsBase
1413
using AbstractFFTs
1514
using DSP
1615
using Interpolations
1716
using Wavelets
18-
using Requires
1917
using StateSpaceSets
20-
standardize = StateSpaceSets.standardize
2118
export standardize
2219

2320
include("core/api.jl")
2421
include("core/surrogate_test.jl")
2522

2623
include("utils/testsystems.jl")
24+
include("plotting/surrogate_plot.jl")
2725

2826
# The different surrogate routines
2927
include("methods/randomshuffle.jl")
@@ -43,20 +41,5 @@ include("methods/trend_based.jl")
4341
# Methods for irregular time series
4442
include("methods/lombscargle.jl")
4543

46-
# Visualization routine for time series + surrogate + periodogram/acf/histogram
47-
using Requires
48-
function __init__()
49-
@require UncertainData="dcd9ba68-c27b-5cea-ae21-829cd07325bf" begin
50-
include("utils/uncertaindatasets.jl")
51-
end
52-
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
53-
include("plotting/surrogate_plot.jl")
54-
end
55-
end
56-
57-
export surroplot_path
58-
function surroplot_path()
59-
joinpath(@__DIR__, "plotting", "surrogate_plot.jl")
60-
end
6144

6245
end # module

src/plotting/surrogate_plot.jl

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
1-
using TimeseriesSurrogates.StatsBase
2-
using TimeseriesSurrogates.DSP
3-
41
"""
52
surroplot(x, s; kwargs...) → fig
3+
surroplot(x, method::Surrogate; kwargs...) → fig
64
75
Plot a timeseries `x` along with its surrogate realization `s`, and compare the
8-
power spectrum and histogram of the two time series.
6+
power spectrum and histogram of the two time series. If given a method to generate
7+
surrogates, create a surrogate from `x` and plot it.
98
109
## Keyword arguments
1110
- `cx` and `cs`: Colors of the original and the surrogate time series, respectively.
1211
- `nbins`: The number of bins for the histograms.
1312
- `resolution`: A tuple giving the resolution of the figure.
1413
"""
15-
function surroplot(x, s;
16-
cx = "#1B1B1B", cs = ("#2DB9C5", 0.9), resolution = (500, 500),
17-
nbins = 50,
18-
)
19-
20-
t = 1:length(x)
21-
fig = Makie.Figure(resolution = resolution)
22-
23-
# Time series
24-
ax1, _ = Makie.lines(fig[1,1], t, x; color = cx)
25-
Makie.lines!(ax1, t, s; color = cs)
26-
27-
# Binned multitaper periodograms
28-
p, psurr = DSP.mt_pgram(x), DSP.mt_pgram(s)
29-
ax3 = Makie.Axis(fig[2,1]; yscale = log10)
30-
Makie.lines!(ax3, p.freq, p.power; color = cx)
31-
Makie.lines!(ax3, psurr.freq, psurr.power; color = cs)
32-
33-
# Histograms
34-
ax4 = Makie.Axis(fig[3,1])
35-
Makie.hist!(ax4, x; label = "original", bins = nbins, color = cx)
36-
Makie.hist!(ax4, s; label = "surrogate", bins = nbins, color = cs)
37-
Makie.axislegend(ax4)
38-
39-
ax1.xlabel = "time step"
40-
ax1.ylabel = "value"
41-
ax3.xlabel = "frequency"
42-
ax3.ylabel = "power"
43-
ax4.xlabel = "binned value"
44-
ax4.ylabel = "histogram"
45-
return fig
46-
end
14+
function surroplot end
4715
export surroplot

src/utils/uncertaindatasets.jl

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)