/
test_dipole.py
33 lines (28 loc) · 1.06 KB
/
test_dipole.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
import matplotlib
import os.path as op
import numpy as np
from numpy.testing import assert_array_equal
import hnn_core
from hnn_core import read_params, import_dipole
from hnn_core.dipole import Dipole
matplotlib.use('agg')
def test_dipole():
"""Test dipole object."""
hnn_core_root = op.join(op.dirname(hnn_core.__file__), '..')
params_fname = op.join(hnn_core_root, 'param', 'default.json')
dpl_out_fname = '/tmp/dpl1.txt'
params = read_params(params_fname)
times = np.random.random(6000)
data = np.random.random((6000, 3))
dipole = Dipole(times, data)
dipole.baseline_renormalize(params)
dipole.convert_fAm_to_nAm()
dipole.scale(params['dipole_scalefctr'])
dipole.smooth(params['dipole_smooth_win'] / params['dt'])
dipole.plot(layer='agg')
dipole.write(dpl_out_fname)
dipole_read = import_dipole(dpl_out_fname)
assert_array_equal(dipole_read.t, dipole.t.round(3))
for dpl_key in dipole.dpl.keys():
assert_array_equal(dipole_read.dpl[dpl_key],
dipole.dpl[dpl_key].round(4))