Visualising surrogate realizations and creating gifs

Visualizing surrogates

Autocorrelation / periodogram panels

Visualizing a surrogate realization is easy.

Let's say we want to generate an IAAFT surrogate and visualize the time series and surrogate time series, together with the corresponding periodograms, autocorrelation functions and histograms. This can be done as follows:

using TimeseriesSurrogates
ts = diff(rand(300))
iaaft_plot(ts)
0 100 200 300 -1.0 -0.5 0.0 0.5 1.0 Time step Value 5 10 15 20 25 -0.3 0.0 0.3 0.6 0.9 Lag Autocorrelation 0.0 0.1 0.2 0.3 0.4 0.5 0.0 0.5 1.0 1.5 Binned frequency Power -1.0 -0.5 0.0 0.5 1.0 0 10 20 30 40 50 Binned value Frequency Original Surrogate

Here, the blue lines correspond to the original time series, while orange lines correspond to the surrogate time series. In this particular case, it seems that the IAAFT surrogate well reproduced the autocorrelation of the original time series.

All surrogate functions come have a complementary functions that also plots a panel showing the autocorrelation function and periodogram of the time series and its surrogate realization:

Animate panels (and export to .gif)

Say you want to examine which surrogate method is suited for a particular dataset. It would then be useful to visualize multiple surrogate realizations for that time series.

For this purpose, each surrogate function comes with a corresponding animation functions (randomphases_anim, randomamplitudes_anim, aaft_anim, iaaft_anim) and gif creation functions (randomphases_gif, randomamplitudes_gif, aaft_gif, iaaft_gif).

You can either generate the gif file directly, or create a Plots.animation instance containing the animation.

Here's some examples:

using TimeseriesSurrogates
ts = diff(rand(300))

# Creating a gif directly

# Create a gif using the default number (15) surrogates
iaaft_gif(ts)
iaaft_gif(ts, fps = 3) # specify frame rate

# Specify that we want 100 different surrogate realizations
iaaft_gif(ts, n_iters = 100)
iaaft_gif(ts, n_iters = 100, fps = 1) # specify frame rate

If you for some reason don't want a gif directly, then you could do

# Use the `gif` function from `Plots.jl` to create a gif
anim = iaaft_anim(ts, n_iters = 50) # create an animation
gif(anim)
gif(anim, fps = 3) # specifying frame rate

Examples

IAAFT realizations of an AR1 process

iaaft_AR1_gif(n_iters = 20, fps = 2)

20 IAAFT surrogate realizations for an AR(1) process.

IAAFT realizations of a NSAR2 process

iaaft_NSAR2_gif(n_iters = 100, fps = 10)

100 IAAFT surrogate realizations for a cyclostationary AR(2) process.

Random phase realizations of a random walk

randomphases_randomwalk_gif(n_iters = 10, fps = 1, new_realization_every_iter = true)

10 random phase surrogate realizations for a random walk.

Plot/animation/gif docs

You can use any of the following functions to generate plots, animations and the animations as gif files.

    `TimeseriesSurrogates.randomshuffle_plot(ts)`

Visualize a `TimeseriesSurrogates.randomshuffle` surrogate.
source
    `TimeseriesSurrogates.randomamplitudes_plot(ts)`

Visualize a `TimeseriesSurrogates.randomamplitudes` surrogate.
source
    `TimeseriesSurrogates.randomphases_plot(ts)`

Visualize a `TimeseriesSurrogates.randomphases` surrogate.
source
    `TimeseriesSurrogates.aaft_plot(ts)`

Visualize a `TimeseriesSurrogates.aaft` surrogate.
source
    `TimeseriesSurrogates.iaaft_plot(ts)`

Visualize a `TimeseriesSurrogates.iaaft` surrogate.
source
    `TimeseriesSurrogates.randomshuffle_anim(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomshuffle` surrogates for `ts` and animate them. Returns a `Plots.Animation` instance.
source
    `TimeseriesSurrogates.randomamplitudes_anim(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomamplitudes` surrogates for `ts` and animate them. Returns a `Plots.Animation` instance.
source
    `TimeseriesSurrogates.randomphases_anim(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomphases` surrogates for `ts` and animate them. Returns a `Plots.Animation` instance.
source
    `TimeseriesSurrogates.aaft_anim(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.aaft` surrogates for `ts` and animate them. Returns a `Plots.Animation` instance.
source
    `TimeseriesSurrogates.iaaft_anim(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.iaaft` surrogates for `ts` and animate them. Returns a `Plots.Animation` instance.
source
    `TimeseriesSurrogates.randomshuffle_gif(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomshuffle` surrogates for `ts`, animate them and create
a gif from the animation.
source
    `TimeseriesSurrogates.randomamplitudes_gif(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomamplitudes` surrogates for `ts`, animate them and create
a gif from the animation.
source
    `TimeseriesSurrogates.randomphases_gif(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.randomphases` surrogates for `ts`, animate them and create
a gif from the animation.
source
    `TimeseriesSurrogates.aaft_gif(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.aaft` surrogates for `ts`, animate them and create
a gif from the animation.
source
    `TimeseriesSurrogates.iaaft_gif(ts; [n_iters::Int])`

Create `n_iters` `TimeseriesSurrogates.iaaft` surrogates for `ts`, animate them and create
a gif from the animation.
source