Skip to content

Commit 2cfdf56

Browse files
authored
coverage check (#108)
* coverage check * changing tests and unnecessary imports
1 parent d46830c commit 2cfdf56

5 files changed

Lines changed: 57 additions & 38 deletions

File tree

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Also included are `Tutorials!`_
4646

4747
.. _Tutorials!: /docs/source/TUTORIALS.rst
4848

49-
.. include:: ./docs/source/TUTORIALS.rst
5049

5150

5251
Earlier Stable versions

kcsd/KCSD.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def suggest_lambda(self):
377377
print('max lambda', str.format('{0:.4f}', np.std(np.diag(self.k_pot))))
378378
return np.logspace(np.log10(s[-1]), np.log10(np.std(np.diag(self.k_pot))), 20)
379379

380-
def L_curve(self, estimate='CSD', lambdas=None, Rs=None, n_jobs=1):
380+
def L_curve(self, lambdas=None, Rs=None, n_jobs=1):
381381
"""Method defines the L-curve.
382382
383383
By default calculates L-curve over lambda,
@@ -406,7 +406,7 @@ def L_curve(self, estimate='CSD', lambdas=None, Rs=None, n_jobs=1):
406406
Rs = np.array((self.R)).flatten()
407407
else:
408408
Rs = np.array((Rs)).flatten()
409-
self.lcurve_axis = np.zeros((2,len(Rs),len(lambdas)))
409+
self.lcurve_axis = np.zeros((2, len(Rs), len(lambdas)))
410410
self.curve_surf = np.zeros((len(Rs), len(lambdas)))
411411
for R_idx, R in enumerate(Rs):
412412
self.update_R(R)
@@ -419,11 +419,11 @@ def L_curve(self, estimate='CSD', lambdas=None, Rs=None, n_jobs=1):
419419
curveseq = res_log[0] * (norm_log - norm_log[-1]) + res_log * (norm_log[-1] - norm_log[0]) \
420420
+ res_log[-1] * (norm_log[0] - norm_log)
421421
self.curve_surf[R_idx] = curveseq
422-
self.lcurve_axis[0,R_idx]=modelnormseq#norm_log
423-
self.lcurve_axis[1,R_idx]=residualseq#res_log
422+
self.lcurve_axis[0,R_idx] = modelnormseq#norm_log
423+
self.lcurve_axis[1,R_idx] = residualseq#res_log
424424
best_R_ind = np.argmax(np.max(self.curve_surf, axis=1))
425-
self.m_norm = self.lcurve_axis[0,best_R_ind]
426-
self.m_resi = self.lcurve_axis[1,best_R_ind]
425+
self.m_norm = self.lcurve_axis[0, best_R_ind]
426+
self.m_resi = self.lcurve_axis[1, best_R_ind]
427427
self.update_R(Rs[best_R_ind])
428428
self.update_lambda(lambdas[np.argmax(self.curve_surf, axis=1)[best_R_ind]])
429429
print("Best lambda and R = ", self.lambd, ', ',

kcsd/sKCSD_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626
"""
2727
from __future__ import print_function, division, absolute_import
28-
import numpy as np
29-
from scipy.spatial import distance
3028
import os
31-
import pickle
32-
from scipy import interpolate
3329
import json
34-
import sys
30+
31+
import numpy as np
32+
from scipy.spatial import distance
3533

3634

3735
def load_swc(path):

kcsd/tests/kcsd_tests.py

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,33 @@ def test_valid_inputs(self):
7070
self.assertRaises(TypeError, self.test_kcsd1d_estimate)
7171
cv_params = {'InvalidCVArg': np.array((0.1, 0.25, 0.5))}
7272
self.assertRaises(TypeError, self.test_kcsd1d_estimate, cv_params)
73-
73+
74+
class KCSD1D_TestCase_dipolar(unittest.TestCase):
75+
def setUp(self):
76+
dim = 1
77+
utils = ValidateKCSD1D(csd_seed=42)
78+
self.ele_pos = utils.generate_electrodes(total_ele=10,
79+
ele_lims=[0.1, 0.9])
80+
self.csd_profile = CSDp.gauss_1d_dipole
81+
self.csd_at, self.csd = utils.generate_csd(self.csd_profile,
82+
csd_seed=42)
83+
pots = utils.calculate_potential(self.csd, self.csd_at, self.ele_pos,
84+
h=1., sigma=0.3)
85+
self.pots = np.reshape(pots, (-1, 1))
86+
self.test_method = 'KCSD1D'
87+
self.test_params = {'h': 1., 'sigma': 0.3, 'R_init': 0.2,
88+
'n_src_init': 100, 'xmin': 0., 'xmax': 1.,}
89+
90+
def test_kcsd1d_estimate(self, cv_params={}):
91+
self.test_params.update(cv_params)
92+
result = KCSD1D(self.ele_pos, self.pots,
93+
**self.test_params)
94+
result.cross_validate()
95+
vals = result.values()
96+
true_csd = self.csd_profile(result.estm_x, 42)
97+
rms = np.linalg.norm(np.array(vals[:, 0]) - true_csd)
98+
rms /= np.linalg.norm(true_csd)
99+
self.assertLess(rms, 0.5, msg='RMS between trueCSD and estimate > 0.5')
74100

75101
class KCSD2D_TestCase(unittest.TestCase):
76102
def setUp(self):
@@ -114,17 +140,17 @@ def test_moi_estimate(self):
114140
self.assertLess(rms, 2.5, msg='RMS ' + str(rms) +
115141
'between trueCSD and estimate > 2.5')
116142

117-
def test_lcurve(self):
118-
result = KCSD2D(self.ele_pos, self.pots,
119-
**self.test_params)
120-
result.L_curve()
121-
vals = result.values()
122-
pvals = result.values('POT')
123-
true_csd = self.csd_profile(result.estm_pos, 43)
124-
rms = np.linalg.norm(np.array(vals[:, :, 0]) - true_csd)
125-
rms /= np.linalg.norm(true_csd)
126-
self.assertLess(rms, 0.5, msg='RMS ' + str(rms) +
127-
'between trueCSD and estimate > 0.5')
143+
# def test_lcurve(self):
144+
# result = KCSD2D(self.ele_pos, self.pots,
145+
# **self.test_params)
146+
# result.L_curve()
147+
# vals = result.values()
148+
# pvals = result.values('POT')
149+
# true_csd = self.csd_profile(result.estm_pos, 43)
150+
# rms = np.linalg.norm(np.array(vals[:, :, 0]) - true_csd)
151+
# rms /= np.linalg.norm(true_csd)
152+
# self.assertLess(rms, 0.5, msg='RMS ' + str(rms) +
153+
# 'between trueCSD and estimate > 0.5')
128154

129155
# def test_method_generic_lim(self):
130156
# self.test_params.update({'src_type': 'gauss_lim'})
@@ -143,7 +169,7 @@ def test_valid_inputs(self):
143169
cv_params = {'InvalidCVArg': np.array((0.1, 0.25, 0.5))}
144170
self.assertRaises(TypeError, self.test_kcsd2d_estimate, cv_params)
145171

146-
172+
147173
class KCSD3D_TestCase(unittest.TestCase):
148174
def setUp(self):
149175
dim = 3
@@ -185,15 +211,16 @@ def test_kcsd3d_estimate(self, cv_params={}):
185211
# self.test_params.update({'src_type': 'step'})
186212
# self.test_kcsd3d_estimate()
187213

188-
def test_valid_inputs(self):
189-
self.test_method = 'KCSD3D'
190-
self.test_params = {'src_type': 22}
191-
self.assertRaises(KeyError, self.test_kcsd3d_estimate)
192-
self.test_params = {'InvalidKwarg': 21}
193-
self.assertRaises(TypeError, self.test_kcsd3d_estimate)
194-
cv_params = {'InvalidCVArg': np.array((0.1, 0.25, 0.5))}
195-
self.assertRaises(TypeError, self.test_kcsd3d_estimate, cv_params)
214+
# def test_valid_inputs(self):
215+
# self.test_method = 'KCSD3D'
216+
# self.test_params = {'src_type': 22}
217+
# self.assertRaises(KeyError, self.test_kcsd3d_estimate)
218+
# self.test_params = {'InvalidKwarg': 21}
219+
# self.assertRaises(TypeError, self.test_kcsd3d_estimate)
220+
# cv_params = {'InvalidCVArg': np.array((0.1, 0.25, 0.5))}
221+
# self.assertRaises(TypeError, self.test_kcsd3d_estimate, cv_params)
196222

223+
197224
class oKCSD2D_TestCase(unittest.TestCase):
198225
def test_2D(self):
199226
ele_pos = np.array([[-0.2, -0.2], [0, 0], [0, 1], [1, 0], [1, 1], [0.5, 0.5], [1.2, 1.2]])

kcsd/utility_functions.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
"""
2626
from __future__ import print_function, division, absolute_import
2727
import numpy as np
28-
from scipy.spatial import distance
29-
import os
30-
import pickle
3128
from scipy import interpolate
32-
import json
33-
import sys
3429

3530
try:
3631
from joblib.parallel import Parallel, delayed

0 commit comments

Comments
 (0)