forked from cortex-lab/phy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
85 lines (71 loc) · 2.55 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""py.test utilities."""
#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------
import os
import numpy as np
from pytest import yield_fixture
from phy.electrode.mea import load_probe
from phy.io.mock import artificial_traces
from phy.utils._types import Bunch
from phy.utils.tempdir import TemporaryDirectory
from phy.utils.settings import _load_default_settings
from phy.utils.datasets import download_test_data
#------------------------------------------------------------------------------
# Common fixtures
#------------------------------------------------------------------------------
@yield_fixture
def tempdir():
with TemporaryDirectory() as tempdir:
yield tempdir
@yield_fixture
def chdir_tempdir():
curdir = os.getcwd()
with TemporaryDirectory() as tempdir:
os.chdir(tempdir)
yield tempdir
os.chdir(curdir)
@yield_fixture
def tempdir_bis():
with TemporaryDirectory() as tempdir:
yield tempdir
@yield_fixture(params=['null', 'artificial', 'real'])
def raw_dataset(request):
sample_rate = 20000
params = _load_default_settings()['spikedetekt']
data_type = request.param
if data_type == 'real':
path = download_test_data('test-32ch-10s.dat')
traces = np.fromfile(path, dtype=np.int16).reshape((200000, 32))
traces = traces[:45000]
n_samples, n_channels = traces.shape
params['use_single_threshold'] = False
probe = load_probe('1x32_buzsaki')
else:
probe = {'channel_groups': {
0: {'channels': [0, 1, 2],
'graph': [[0, 1], [0, 2], [1, 2]],
},
1: {'channels': [3],
'graph': [],
'geometry': {3: [0., 0.]},
}
}}
if data_type == 'null':
n_samples, n_channels = 25000, 4
traces = np.zeros((n_samples, n_channels))
elif data_type == 'artificial':
n_samples, n_channels = 25000, 4
traces = artificial_traces(n_samples, n_channels)
traces[5000:5010, 1] *= 5
traces[15000:15010, 3] *= 5
n_samples_w = params['extract_s_before'] + params['extract_s_after']
yield Bunch(n_channels=n_channels,
n_samples=n_samples,
sample_rate=sample_rate,
n_samples_waveforms=n_samples_w,
traces=traces,
params=params,
probe=probe,
)