forked from Neuroinflab/kCSD-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSD.py
More file actions
112 lines (93 loc) · 3.01 KB
/
Copy pathCSD.py
File metadata and controls
112 lines (93 loc) · 3.01 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
This script is used to generate Current Source Density Estimates,
And serves as base class for the kCSD method Jan et.al (2012).
This was written by :
Chaitanya Chintaluri,
Laboratory of Neuroinformatics,
Nencki Institute of Exprimental Biology, Warsaw.
"""
import numpy as np
import utility_functions as utils
class CSD(object):
"""CSD - The base class for CSD methods."""
def __init__(self, ele_pos, pots):
"""Initialize CSD Class.
Parameters
----------
ele_pos : numpy array
positions of electrodes
pots : numpy array
potentials measured by electrodes
Returns
-------
None
"""
self.validate(ele_pos, pots)
self.ele_pos = ele_pos
self.pots = pots
self.n_ele = self.ele_pos.shape[0]
self.n_time = self.pots.shape[1]
self.dim = self.ele_pos.shape[1]
self.cv_error = None
return
def validate(self, ele_pos, pots):
"""Basic checks to see if inputs are okay
Parameters
----------
ele_pos : numpy array
positions of electrodes
pots : numpy array
potentials measured by electrodes
Returns
-------
None
"""
if ele_pos.shape[0] != pots.shape[0]:
raise Exception("Number of measured potentials is not equal "
"to electrode number!")
if ele_pos.shape[0] < 1+ele_pos.shape[1]: #Dim+1
raise Exception("Number of electrodes must be at least :",
1+ele_pos.shape[1])
if utils.check_for_duplicated_electrodes(ele_pos) is False:
raise Exception("Error! Duplicated electrode!")
return
def method(self):
"""Place holder for the actual method that computes the CSD.
Parameters
----------
None
Returns
-------
None
"""
pass
def values(self):
"""Place holder for obtaining CSD at the pos_csd locations, it uses the method
function to obtain the CSD.
Parameters
----------
None
Returns
-------
None
"""
pass
def sanity(self, true_csd, pos_csd):
"""Useful for comparing TrueCSD with reconstructed CSD. Computes, the RMS error
between the true_csd and the reconstructed csd at pos_csd using the
method defined.
Parameters
----------
true_csd : csd values used to generate potentials
pos_csd : csd estimatation from the method
Returns
-------
RMSE : root mean squared difference
"""
csd = self.values(pos_csd)
RMSE = np.sqrt(np.mean(np.square(true_csd - csd)))
return RMSE
if __name__ == '__main__':
ele_pos = np.array([[-0.2, -0.2], [0, 0], [0, 1], [1, 0], [1,1], [0.5, 0.5], [1.2, 1.2]])
pots = np.array([[-1], [-1], [-1], [0], [0], [1], [-1.5]])
test_class = CSD(ele_pos, pots)