• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NeuralEnsemble / elephant / 8645033486

11 Apr 2024 10:08AM CUT coverage: 88.264% (+0.04%) from 88.224%
8645033486

Pull #629

github

web-flow
Merge ca9ce7e3e into 15e8ef8e2
Pull Request #629: [Main] Bump Version number after release

6701 of 7592 relevant lines covered (88.26%)

4.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.9
/elephant/current_source_density_src/basis_functions.py
1
#!/usr/bin/env python
2
"""
5✔
3
This script is used to generate basis sources for the
4
kCSD method Jan et.al (2012) for 1D,2D and 3D cases.
5
Two 'types' are described here, gaussian and step source,
6
These can be easily extended.
7
These scripts are based on Grzegorz Parka's,
8
Google Summer of Code 2014, INFC/pykCSD
9
This was written by :
10
Michal Czerwinski, Chaitanya Chintaluri
11
Laboratory of Neuroinformatics,
12
Nencki Institute of Experimental Biology, Warsaw.
13
"""
14
from __future__ import division
5✔
15

16
import numpy as np
5✔
17

18
def gauss(d, stdev, dim):
5✔
19
    """Gaussian function
20
    Parameters
21
    ----------
22
    d : floats or np.arrays
23
        Distance array to the point of evaluation
24
    stdev : float
25
        cutoff range
26
    dim : int
27
        dimension of the gaussian function
28
    Returns
29
    -------
30
    Z : floats or np.arrays
31
        function evaluated
32
    """
33
    Z = np.exp(-(d**2) / (2* stdev**2) ) / (np.sqrt(2*np.pi)*stdev)**dim
5✔
34
    return Z
5✔
35

36
def step_1D(d, R):
5✔
37
    """Returns normalized 1D step function.
38
    Parameters
39
    ----------
40
    d : floats or np.arrays
41
        Distance array to the point of evaluation
42
    R : float
43
        cutoff range
44
    Returns
45
    -------
46
    s : Value of the function (d  <= R) / R
47
    """
48
    s = (d  <= R)
×
49
    s = s / R #normalize with width
×
50
    return s
×
51

52
def gauss_1D(d, three_stdev):
5✔
53
    """Returns normalized gaussian 2D scale function
54
    Parameters
55
    ----------
56
    d : floats or np.arrays
57
        Distance array to the point of evaluation
58
    three_stdev : float
59
        3 * standard deviation of the distribution
60
    Returns
61
    -------
62
    Z : (three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *(d**2))
63
    """
64
    stdev = three_stdev/3.0
5✔
65
    Z = gauss(d, stdev, 1)
5✔
66
    return Z
5✔
67

68
def gauss_lim_1D(d, three_stdev):
5✔
69
    """Returns gausian 2D function cut off after 3 standard deviations.
70
    Parameters
71
    ----------
72
    d : floats or np.arrays
73
        Distance array to the point of evaluation
74
    three_stdev : float
75
        3 * standard deviation of the distribution
76
    Returns
77
    -------
78
    Z : (three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *((x-mu)**2)),
79
        cut off = three_stdev
80
    """
81
    Z = gauss_1D(d, three_stdev)
×
82
    Z *= (d < three_stdev)
×
83
    return Z
×
84

85
def step_2D(d, R):
5✔
86
    """Returns normalized 2D step function.
87
    Parameters
88
    ----------
89
    d : float or np.arrays
90
        Distance array to the point of evaluation
91
    R : float
92
        cutoff range
93

94
    Returns
95
    -------
96
    s : step function
97
    """
98
    s = (d <= R) / (np.pi*(R**2))
×
99
    return s
×
100

101
def gauss_2D(d, three_stdev):
5✔
102
    """Returns normalized gaussian 2D scale function
103
    Parameters
104
    ----------
105
    d : floats or np.arrays
106
         distance at which we need the function evaluated
107
    three_stdev : float
108
        3 * standard deviation of the distribution
109
    Returns
110
    -------
111
    Z : function
112
        Normalized gaussian 2D function
113
    """
114
    stdev = three_stdev/3.0
5✔
115
    Z = gauss(d, stdev, 2)
5✔
116
    return Z
5✔
117

118
def gauss_lim_2D(d, three_stdev):
5✔
119
    """Returns gausian 2D function cut off after 3 standard deviations.
120
    Parameters
121
    ----------
122
    d : floats or np.arrays
123
         distance at which we need the function evaluated
124
    three_stdev : float
125
        3 * standard deviation of the distribution
126
    Returns
127
    -------
128
    Z : function
129
        Normalized gaussian 2D function cut off after three_stdev
130
    """
131
    Z = (d <= three_stdev)*gauss_2D(d, three_stdev)
×
132
    return Z
×
133

134
def gauss_3D(d, three_stdev):
5✔
135
    """Returns normalized gaussian 3D scale function
136
    Parameters
137
    ----------
138
    d : floats or np.arrays
139
        distance at which we need the function evaluated
140
    three_stdev : float
141
        3 * standard deviation of the distribution
142
    Returns
143
    -------
144
    Z : funtion
145
        Normalized gaussian 3D function
146
    """
147
    stdev = three_stdev/3.0
×
148
    Z = gauss(d, stdev, 3)
×
149
    return Z
×
150

151
def gauss_lim_3D(d, three_stdev):
5✔
152
    """Returns normalized gaussian 3D scale function cut off after 3stdev
153
    Parameters
154
    ----------
155
    d : floats or np.arrays
156
        distance at which we need the function evaluated
157
    three_stdev : float
158
        3 * standard deviation of the distribution
159
    Returns
160
    -------
161
    Z : funtion
162
        Normalized gaussian 3D function cutoff three_Stdev
163
    """
164
    Z = gauss_3D(d, three_stdev)
×
165
    Z = Z * (d < (three_stdev))
×
166
    return Z
×
167

168
def step_3D(d, R):
5✔
169
    """Returns normalized 3D step function.
170
    Parameters
171
    ----------
172
    d : floats or np.arrays
173
        distance at which we need the function evaluated
174
    R : float
175
        cutoff range
176
    Returns
177
    -------
178
    s : step function in 3D
179
    """
180

181
    s = 3/(4*np.pi*R**3)*(d <= R)
5✔
182
    return s
5✔
183

184
basis_1D = {
5✔
185
    "step": step_1D,
186
    "gauss": gauss_1D,
187
    "gauss_lim": gauss_lim_1D,
188
}
189

190

191
basis_2D = {
5✔
192
    "step": step_2D,
193
    "gauss": gauss_2D,
194
    "gauss_lim": gauss_lim_2D,
195
}
196

197
basis_3D = {
5✔
198
    "step": step_3D,
199
    "gauss": gauss_3D,
200
    "gauss_lim": gauss_lim_3D,
201
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc