Example #1
0
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2018 00:00:00'
N = 7 * 1440 * 2  # *sampling_period
n_array = np.geomspace(5, 1000, num=40, endpoint=True, dtype=int)
q_array = [-5, -3, -1, 0, 1, 3, 5]

# Stochastic generators
bn = BrownianNoise(t=1)
fbm = FractionalBrownianMotion(hurst=0.9, t=1)
fgn = FractionalGaussianNoise(hurst=0.6, t=1)

np.random.seed(0)

# Brownian noise: h(q) = 1+H with H=0.5
bn_sample = generate_series(bn.sample(N - 1),
                            start=start_time,
                            sampling_period=sampling_period)

# Fractional Brownian motion: h(q) = 1+H with H = 0.9 (in this example)
fbm_sample = generate_series(fbm.sample(N - 1),
                             start=start_time,
                             sampling_period=sampling_period)

# Fractional Gaussian noise: h(q) = H with H = 0.6 (in this example)
fgn_sample = generate_series(fgn.sample(N),
                             start=start_time,
                             sampling_period=sampling_period)

# Associated fluctuations
test_bn = Fractal.dfa(bn_sample, n_array, deg=2, log=False)
test_bn_parallel = Fractal.dfa_parallel(bn_sample,
Example #2
0
import pyActigraphy
import pytest

sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2018 00:00:00'
N = 30240*sampling_period
period = pd.Timedelta(N, unit='s')
seq_prob = 0.7
seq_max_length = 50

sequences = generate_series(
    generate_sequences(
        N=N-1,
        p=seq_prob,
        max_rand_int=seq_max_length
    ),
    start=start_time,
    sampling_period=sampling_period
)

seq = pyActigraphy.io.BaseRaw(
    name='raw_sequence',
    uuid='XXXXXXXX',
    format='CUSTOM',
    axial_mode=None,
    start_time=pd.to_datetime(start_time),
    period=period,
    frequency=frequency,
    data=sequences,
    light=None
Example #3
0
from generate_dataset import generate_series
from generate_dataset import generate_squarewave
from generate_dataset import generate_sinewave

import pandas as pd
import pyActigraphy
from pytest import approx

sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2018 08:00:00'
N = 20160 * sampling_period
period = pd.Timedelta(N, unit='s')

gaussian_noise = generate_series(generate_gaussian_noise(N=N - 1),
                                 start=start_time,
                                 sampling_period=sampling_period)
square_wave = generate_series(generate_squarewave(N=N - 1),
                              start=start_time,
                              sampling_period=sampling_period)
sine_wave = generate_series(generate_sinewave(N=N - 1),
                            start=start_time,
                            sampling_period=sampling_period)

raw_gaussian = pyActigraphy.io.BaseRaw(name='raw_gaussian',
                                       uuid='XXXXXXXX',
                                       format='CUSTOM',
                                       axial_mode=None,
                                       start_time=pd.to_datetime(start_time),
                                       period=period,
                                       frequency=frequency,
Example #4
0
from generate_dataset import generate_series
from generate_dataset import generate_sinewave

import pandas as pd
import pyActigraphy

sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2018 08:00:00'
N = 20800 * sampling_period
period = pd.Timedelta(N, unit='s')

sine_wave = generate_series(generate_sinewave(A=100, offset=True, N=N - 1),
                            start=start_time,
                            sampling_period=sampling_period)

raw_sinewave = pyActigraphy.io.BaseRaw(name='raw_sinewave',
                                       uuid='XXXXXXXX',
                                       format='CUSTOM',
                                       axial_mode=None,
                                       start_time=pd.to_datetime(start_time),
                                       period=period,
                                       frequency=frequency,
                                       data=sine_wave,
                                       light=None)


def test_smp_sinewave():

    assert raw_sinewave.SleepMidPoint(
        freq='5min', algo='Roenneberg') == pd.Timedelta('0 days 02:00:00')
Example #5
0
from generate_dataset import generate_series
# from generate_dataset import generate_squarewave
from generate_dataset import generate_sinewave

import pandas as pd
import pyActigraphy
from pytest import approx

sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2018 08:00:00'
N = 20160
period = pd.Timedelta(N * sampling_period, unit='s')

sine_wave_mask = generate_series(generate_sinewave(N=N, offset=True),
                                 start=start_time,
                                 sampling_period=sampling_period)
sine_wave_mask.loc['2018-01-03 06:00:00':'2018-01-03 14:00:00'] = 0

raw_sinewave_mask = pyActigraphy.io.BaseRaw(
    name='raw_sinewave',
    uuid='XXXXXXXX',
    format='CUSTOM',
    axial_mode=None,
    start_time=pd.to_datetime(start_time),
    period=period,
    frequency=frequency,
    data=sine_wave_mask,
    light=None)

Example #6
0
import numpy as np
import pandas as pd
import pyActigraphy

from pytest import approx
from generate_dataset import generate_series
from generate_dataset import generate_sinewave

sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '2018/01/01 08:00:00'
N = 20160
period = pd.Timedelta(N, unit='T')

sine_wave = generate_series(generate_sinewave(N=N, offset=True),
                            start=start_time,
                            sampling_period=sampling_period)

# Sleep characteristics:
# - start_time: 8h
# - sleep onset: 22h01
# - periode awake: 14h
# - sleep offset: 6h
# - periode asleep:7h59min
n_epochs_nan_trend = int(pd.Timedelta('12h') / frequency)
n_epochs_awake_prior_sleep = int(pd.Timedelta('2h01min') / frequency)
n_epochs_awake_after_sleep = int(pd.Timedelta('14h') / frequency)
n_epochs_asleep = int(pd.Timedelta('7h59min') / frequency)
n_days = int(period / pd.Timedelta('1D')) - 1

# Create associated sleep signal (awake:0, sleep:1)
Example #7
0
sampling_period = 60
frequency = pd.Timedelta(sampling_period, unit='s')
start_time = '01/01/2000 08:00:00'
N = 10080
period = pd.Timedelta(N * sampling_period, unit='s')

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

sine_wave = generate_series(
    generate_sinewave(
        N=N,  # number of samples
        T=1440 * 60,  # period in sec: 24*60*60
        Ts=60,  # sampling rate (sec.)
        A=100,  # oscillation amplitude
        add_noise=True,  # add gaussian noise
        noise_power=100,
        offset=True  # offset oscillations between 0 and +2A
    ),
    start=start_time,
    sampling_period=sampling_period)

raw_sinewave = pyActigraphy.io.BaseRaw(name='raw_sinewave',
                                       uuid='XXXXXXXX',
                                       format='CUSTOM',
                                       axial_mode=None,
                                       start_time=pd.to_datetime(start_time),
                                       period=period,
                                       frequency=frequency,
                                       data=sine_wave,
                                       light=None)