Skip to content

Commit

Permalink
update test data loading from tutorials folder
Browse files Browse the repository at this point in the history
  • Loading branch information
srcole committed Sep 25, 2018
1 parent f2b7ad8 commit c15a875
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 35 deletions.
Binary file removed bycycle/tests/data/sim_bursting.npy
Binary file not shown.
Binary file removed bycycle/tests/data/sim_stationary.npy
Binary file not shown.
8 changes: 6 additions & 2 deletions bycycle/tests/test_burst.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import numpy as np
from bycycle import burst, filt, features
import itertools
import os

# Set data path
data_path = '/'.join(os.path.dirname(bycycle.__file__).split('/')[:-1]) + '/tutorials/data/'


def test_detect_bursts_cycles():
"""Test amplitude and period consistency burst detection"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand Down Expand Up @@ -43,7 +47,7 @@ def test_detect_bursts_df_amp():
"""Test amplitde-threshold burst detection"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range
signal = filt.lowpass_filter(signal, Fs, 30, N_seconds=.3,
Expand Down
10 changes: 7 additions & 3 deletions bycycle/tests/test_cyclepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
from bycycle import cyclepoints
import numpy as np
from scipy.signal import argrelextrema
import os

# Set data path
data_path = '/'.join(os.path.dirname(bycycle.__file__).split('/')[:-1]) + '/tutorials/data/'


def test_find_extrema():
"""Test ability to find peaks and troughs"""

# Load signal
signal = np.load('data/sim_stationary.npy')
signal = np.load(data_path + 'sim_stationary.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand All @@ -42,7 +46,7 @@ def test_find_zerox():
"""Test ability to find peaks and troughs"""

# Load signal
signal = np.load('data/sim_stationary.npy')
signal = np.load(data_path + 'sim_stationary.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand All @@ -64,7 +68,7 @@ def test_extrema_interpolated_phase():
"""Test waveform phase estimate"""

# Load signal
signal = np.load('data/sim_stationary.npy')
signal = np.load(data_path + 'sim_stationary.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand Down
31 changes: 5 additions & 26 deletions bycycle/tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,21 @@
-----
The tests here are not strong tests for accuracy.
They serve rather as 'smoke tests', for if anything fails completely.
Code to generate data from bycycle v.0.1.0 before sim module was removed:
from bycycle import sim
import numpy as np
# Stationary oscillator
np.random.seed(0)
cf = 10 # Oscillation center frequency
T = 10 # Recording duration (seconds)
Fs = 1000 # Sampling rate
rdsym = .3
signal = sim.sim_oscillator(T, Fs, cf, rdsym=rdsym)
np.save('sim_stationary.npy', signal)
# Bursting oscillator
np.random.seed(0)
cf = 10 # Oscillation center frequency
T = 10 # Recording duration (seconds)
Fs = 1000 # Sampling rate
signal = sim.sim_noisy_bursty_oscillator(T, Fs, cf, prob_enter_burst=.1,
prob_leave_burst=.1, SNR=5)
np.save('sim_bursting.npy', signal)
"""

import numpy as np
from bycycle import features
import os

# Set data path
data_path = '/'.join(os.path.dirname(bycycle.__file__).split('/')[:-1]) + '/tutorials/data/'


def test_compute_features():
"""Test cycle-by-cycle feature computation"""

# Load signal
signal = np.load('data/sim_stationary.npy')
signal = np.load(data_path + 'sim_stationary.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand Down
12 changes: 8 additions & 4 deletions bycycle/tests/test_filt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

from bycycle import filt
import numpy as np
import os

# Set data path
data_path = '/'.join(os.path.dirname(bycycle.__file__).split('/')[:-1]) + '/tutorials/data/'


def test_bandpass():
"""Test bandpass filter functionality"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate

# Test output same length as input
Expand Down Expand Up @@ -56,7 +60,7 @@ def test_lowpass():
"""Test lowpass filter functionality"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate

# Test output same length as input
Expand Down Expand Up @@ -86,7 +90,7 @@ def test_amp():
"""Test phase time series functionality"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand Down Expand Up @@ -123,7 +127,7 @@ def test_phase():
"""Test phase time series functionality"""

# Load signal
signal = np.load('data/sim_bursting.npy')
signal = np.load(data_path + 'sim_bursting.npy')
Fs = 1000 # Sampling rate
f_range = (6, 14) # Frequency range

Expand Down
62 changes: 62 additions & 0 deletions tutorials/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import bycycle\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/gh/bv/bycycle/tutorials/data/'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'/'.join(os.path.dirname(bycycle.__file__).split('/')[:-1]) + '/tutorials/data/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit c15a875

Please sign in to comment.