Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft for JOSS paper #70

Merged
merged 15 commits into from
Feb 19, 2024
Merged
23 changes: 23 additions & 0 deletions .github/workflows/draft-pdf.yml
Datseris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
3 changes: 3 additions & 0 deletions paper/code/Project.toml
Datseris marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
60 changes: 60 additions & 0 deletions paper/code/ewstools-tuto-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import time
import numpy as np
import matplotlib.pyplot as plt
import ewstools
from ewstools.models import simulate_ricker

# Set seed for reproducibility
np.random.seed(0)

# Initialize time series and spectrum computation
series = simulate_ricker(tmax=1000, F=[0,2.7])
ts = ewstools.TimeSeries(data=series, transition=860)
ts.detrend(method='Lowess', span=0.2)
ts.state[['state','smoothing']].plot()
ts.compute_spectrum(rolling_window=0.5, ham_length=40)

# Initialize parameters for timing functions
rw = 0.5
n = 100
t_elapsed = np.zeros(10)

# Time functions (in a not very elegant way)
t0 = time.time()
for i in range(n):
ts.compute_var(rolling_window=rw)
t_elapsed[0] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_cv()
t_elapsed[1] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_skew(rolling_window=rw)
t_elapsed[2] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_kurt()
t_elapsed[3] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_auto(rolling_window=rw, lag=1)
t_elapsed[4] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_smax()
t_elapsed[5] = time.time() - t0

t0 = time.time()
for i in range(n):
ts.compute_ktau()
t_elapsed[6] = time.time() - t0

t0 = time.time()
surro = ewstools.core.block_bootstrap(ts.state.residuals, n, bs_type='Stationary', block_size=10)
t_elapsed[7] = time.time() - t0
16 changes: 16 additions & 0 deletions paper/code/figure1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using TransitionsInTimeseries, DelimitedFiles, CairoMakie, Random

x = readdlm("ewstools-tuto-1.csv", ',')[:, end]
t = eachindex(x)

# Choose the indicators and how to measure their change over time
indicators = (var, ar1_whitenoise)
change_metrics = (kendalltau, kendalltau)
config = SegmentedWindowConfig(indicators, change_metrics, [t[1]], [t[end]];
width_ind = length(x) ÷ 2, whichtime = last, min_width_cha = 50)
results = estimate_indicator_changes(config, x, t)
signif = SurrogatesSignificance(n = 1000, tail = [:right, :right], rng = Xoshiro(1995))
flags = significant_transitions(results, signif)
fig = plot_changes_significance(results, signif)
ylims!(contents(fig[2, 1])[2], (0.037, 0.045))
save("../figures/figure1.png", fig)
71 changes: 71 additions & 0 deletions paper/code/figure2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using TransitionsInTimeseries, DelimitedFiles, CairoMakie, Random

coefficient_of_variation(x) = std(x) / mean(x)

function main()
x = readdlm("ewstools-tuto-1.csv", ',')[:, end]
t = eachindex(x)

# Choose the indicators and how to measure their change over time
indicators = (var, coefficient_of_variation, skewness, kurtosis,
ar1_whitenoise, LowfreqPowerSpectrum())
stride = [1, 1, 1, 1, 1, 40]
n, m = 100, length(indicators)
t_elapsed = zeros(m+2)


for (i, ind) in enumerate(indicators)
# Build configuration with adequate parameters of the sliding window
config = SegmentedWindowConfig((ind, ind), (nothing, nothing), [t[1]], [t[end]];
width_ind = length(x) ÷ 2, stride_ind = stride[i], whichtime = last,
min_width_cha = 1)

t0 = time()
for i in 1:n
# Compute the metrics over sliding windows and their significance
results = estimate_indicator_changes(config, x, t)
end
t_elapsed[i] = (time() - t0) / 2
end

config = SegmentedWindowConfig((nothing, nothing), (kendalltau, kendalltau), [t[1]], [t[end]];
width_ind = length(x) ÷ 2, stride_ind = 1, whichtime = last, min_width_cha = 1)
t0 = time()
for i in 1:n
results = estimate_indicator_changes(config, x, t)
end
t_elapsed[m+1] = (time() - t0) / 2

sgen = surrogenerator(x, BlockShuffle(), Xoshiro(1995))
t0 = time()
for i in 1:n
s = sgen()
end
t_elapsed[m+2] = time() - t0

return t_elapsed
end

t_tt = main()
t_et = [0.03840542, 0.05554581, 0.03895116, 0.04029274, 7.96556187,
2.73067856, 0.39529872, 0.02751493]

# [0.04681492, 8.13679838, 0.04035759, 0.09219241]
inds = eachindex(t_et)
w = 0.4

fig, ax = barplot(inds .- 0.5*w, t_et, label = L"ewstools $\,$", width = w,
fillto = 1e-5)
barplot!(ax, inds .+ 0.5*w, t_tt, label = L"TransitionsInTimeseries.jl $\,$",
width = w, fillto = 1e-5)
ax.yscale = log10
ax.xticks = (1:8, [L"Variance $\,$", L"Coeff. of variation $\,$", L"Skewness $\,$",
L"Kurtosis $\,$", L"Lag-1 autocorr. $\,$", L"Spectral $\,$",
L"Kendall $\tau$ corr. coeff.", L"Block bootstrap $\,$"])
ax.ylabel = L"Run time (s) of 100 computations on Ricker model data $\,$"
ax.yticks = (10.0 .^ (-5:1), [L"10^{%$e}" for e in -5:1])
ax.xgridvisible = false
ax.ygridvisible = false
ax.xticklabelrotation = π / 4
axislegend(ax, position = :lt)
save("../figures/figure2.png", fig)
Binary file added paper/figures/figure1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paper/figures/figure2.png
Datseris marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading