Skip to content

Commit

Permalink
move Spikecount implementation to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Dec 21, 2023
1 parent 9e9286f commit 241a2d7
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 30 deletions.
3 changes: 1 addition & 2 deletions efel/DependencyV5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ LibV1:maximum_voltage #LibV1:interpolate
LibV1:minimum_voltage #LibV1:interpolate
LibV1:steady_state_voltage #LibV1:interpolate
LibV3:depolarized_base #LibV5:AP_end_indices #LibV5:AP_begin_indices #LibV1:interpolate
LibV1:ISI_CV #LibV1:ISI_values #LibV1:interpolate
LibV1:Spikecount #LibV5:peak_indices #LibV1:interpolate
LibV1:ISI_CV #LibV1:ISI_values #LibV1:interpolate
LibV5:Spikecount_stimint #LibV1:peak_time #LibV1:interpolate
LibV1:AHP_depth #LibV5:voltage_base #LibV5:min_AHP_values #LibV1:interpolate
LibV1:AHP_depth_slow #LibV5:voltage_base #LibV1:AHP_depth_abs_slow #LibV1:interpolate
Expand Down
1 change: 0 additions & 1 deletion efel/cppcore/FillFptrTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ int FillFptrTable() {
FptrTableV1["ISI_CV"] = &LibV1::ISI_CV;
FptrTableV1["AHP_depth_abs_slow"] = &LibV1::AHP_depth_abs_slow;
FptrTableV1["AHP_slow_time"] = &LibV1::AHP_slow_time;
FptrTableV1["Spikecount"] = &LibV1::Spikecount;
FptrTableV1["AHP_depth"] = &LibV1::AHP_depth;
FptrTableV1["AHP_depth_slow"] = &LibV1::AHP_depth_slow;
FptrTableV1["burst_number"] = &LibV1::burst_number;
Expand Down
11 changes: 0 additions & 11 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ int LibV1::interpolate(mapStr2intVec& IntFeatureData,
return 1;
}

// *** Spikecount ***
int LibV1::Spikecount(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
size_t spikecount_value = getFeature(IntFeatureData, {"peak_indices"}).size();
vector<int> spikecount(1, spikecount_value);
setVec(IntFeatureData, StringData, "Spikecount", spikecount);
return spikecount_value;
}
// end of Spikecount

int LibV1::ISI_values(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
Expand Down
2 changes: 0 additions & 2 deletions efel/cppcore/LibV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ int AHP_depth_abs_slow(mapStr2intVec& IntFeatureData,
mapStr2Str& StringData);
int AHP_slow_time(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);
int Spikecount(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);
int AHP_depth(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData, mapStr2Str& StringData);
int AHP_depth_slow(mapStr2intVec& IntFeatureData,
Expand Down
1 change: 0 additions & 1 deletion efel/cppcore/cfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void cFeature::fillfeaturetypes() {
featuretypes["ISI_CV"] = "double";
featuretypes["AHP_depth_abs_slow"] = "double";
featuretypes["AHP_slow_time"] = "double";
featuretypes["Spikecount"] = "int";
featuretypes["Spikecount_stimint"] = "int";
featuretypes["AHP_depth"] = "double";
featuretypes["AHP_depth_slow"] = "double";
Expand Down
23 changes: 19 additions & 4 deletions efel/pyfeatures/pyfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

from typing_extensions import deprecated

import numpy
import efel.cppcore
Expand All @@ -41,6 +42,7 @@
'initburst_sahp_ssse',
'depol_block',
'depol_block_bool',
'Spikecount',
'spikes_per_burst',
'spikes_per_burst_diff',
'spikes_in_burst1_burst2_diff',
Expand All @@ -59,6 +61,19 @@ def time():
return _get_cpp_feature("time")


@deprecated("Use spike_count instead.")
def Spikecount() -> numpy.ndarray:
return spike_count()


def spike_count() -> numpy.ndarray:
"""Get spike count."""
peak_indices = _get_cpp_feature("peak_indices")
if peak_indices is None:
return numpy.array([0])
return numpy.array([peak_indices.size])


def impedance():
from scipy.ndimage.filters import gaussian_filter1d

Expand All @@ -71,10 +86,10 @@ def impedance():
if current_trace is not None:
holding_current = _get_cpp_feature("current_base")
normalized_current = current_trace - holding_current
spike_count = _get_cpp_feature("Spikecount")
if spike_count is None:
spike_count = 0
if spike_count < 1: # if there is no spikes in ZAP
n_spikes = spike_count()
if n_spikes is None:
n_spikes = 0
if n_spikes < 1: # if there is no spikes in ZAP
fft_volt = numpy.fft.fft(normalized_voltage)
fft_cur = numpy.fft.fft(normalized_current)
if any(fft_cur) == 0:
Expand Down
3 changes: 1 addition & 2 deletions examples/deap/GranuleCell1/GranuleCellDeap1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
" times.append(time)\n",
" voltages.append(voltage)\n",
"\n",
" feature_values[0][\"Spikecount\"] = 0.0 # replace None with 0.0 \n",
" return feature_values, times, voltages\n",
"\n",
"orig_features, orig_times, orig_voltages = get_features(orig_conductances)"
Expand Down Expand Up @@ -406,7 +405,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
name="efel",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
install_requires=['numpy>=1.6', 'neo>=0.5.2'],
install_requires=['numpy>=1.6', 'neo>=0.5.2', 'typing-extensions>=4.8.0'],
packages=['efel', 'efel.pyfeatures', 'efel.units'],
author="BlueBrain Project, EPFL",
maintainer="Werner Van Geit",
Expand Down
1 change: 0 additions & 1 deletion tests/DependencyV5_LibV5peakindices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ LibV1:interpolate
LibV1:steady_state_voltage
LibV3:depolarized_base
LibV1:ISI_CV #LibV1:ISI_values
LibV1:Spikecount #LibV5:peak_indices
LibV1:AHP_depth #LibV5:voltage_base #LibV5:min_AHP_values
LibV2:AP_rise_indices #LibV5:peak_indices #LibV5:AP_begin_indices
LibV2:AP_end_indices #LibV5:peak_indices
Expand Down
2 changes: 1 addition & 1 deletion tests/test_allfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_allfeatures_on_constant_voltage():
"sag_amplitude", "voltage_after_stim", "steady_state_hyper",
"steady_state_voltage", "steady_state_voltage_stimend",
"voltage_deflection", "voltage_deflection_begin", "voltage_deflection_vb_ssse",
"depol_block", "depol_block_bool", "voltage_base"
"depol_block", "depol_block_bool", "voltage_base", "Spikecount"
]

for field in array_fields:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ def test_strict_stiminterval():
peak_indices = feature_values[0]['peak_indices']
peak_time = feature_values[0]['peak_time']
spikecount = feature_values[0]['Spikecount']

assert len(peak_indices) == n_of_spikes
assert len(peak_time) == n_of_spikes
assert spikecount == n_of_spikes
Expand Down Expand Up @@ -1132,7 +1131,6 @@ def test_getDistance_trace_check():
trace['stim_start'] = [10]
trace['stim_end'] = [70]
traces.append(trace)

numpy.testing.assert_allclose(
efel.getDistance(trace, 'Spikecount', 0, 1), 3.0
)
Expand Down Expand Up @@ -1638,8 +1636,8 @@ def test_spikecount2():
[trace],
features)

spikecount = feature_values[0]['Spikecount']
assert spikecount is None
spikecount = feature_values[0]['Spikecount'][0]
assert spikecount == 0


def test_min_voltage_between_spikes1():
Expand Down

0 comments on commit 241a2d7

Please sign in to comment.