Skip to content

Commit

Permalink
interpolate current if present
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaquier Aurélien Tristan committed Sep 28, 2023
1 parent b2ee3df commit e7565d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions efel/DependencyV5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ LibV5:current #LibV1:interpolate
LibV5:time #LibV1:interpolate
LibV5:steady_state_voltage_stimend #LibV1:interpolate
LibV5:voltage_base #LibV1:interpolate
LibV5:current_base
LibV5:current_base #LibV1:interpolate
LibV5:decay_time_constant_after_stim #LibV1:interpolate
LibV5:sag_time_constant #LibV1:minimum_voltage #LibV5:steady_state_voltage_stimend #LibV5:sag_amplitude #LibV1:interpolate
LibV5:multiple_decay_time_constant_after_stim #LibV5:decay_time_constant_after_stim #LibV1:interpolate
Expand All @@ -172,7 +172,7 @@ LibV5:ADP_peak_indices #LibV5:min_AHP_indices #LibV5:min_between_peaks_indice
LibV5:ADP_peak_values #LibV5:ADP_peak_indices #LibV1:interpolate
LibV5:ADP_peak_amplitude #LibV5:ADP_peak_values #LibV5:min_AHP_values #LibV1:interpolate
LibV5:interburst_min_indices #LibV5:peak_indices #LibV5:burst_end_indices #LibV1:interpolate
LibV5:interburst_min_values #LibV5:interburst_min_indices #LibV1: interpolate
LibV5:interburst_min_values #LibV5:interburst_min_indices #LibV1:interpolate
LibV5:postburst_min_indices #LibV5:peak_indices #LibV5:burst_end_indices #LibV1:interpolate
LibV5:postburst_min_values #LibV5:postburst_min_indices #LibV1: interpolate
LibV5:postburst_min_values #LibV5:postburst_min_indices #LibV1:interpolate
LibV5:time_to_interburst_min #LibV5:interburst_min_indices #LibV1:peak_time #LibV5:burst_end_indices #LibV1:interpolate
9 changes: 9 additions & 0 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ int LibV1::interpolate(mapStr2intVec& IntFeatureData,
setVec(DoubleFeatureData, StringData, "V", VIntrpol);
setVec(DoubleFeatureData, StringData, "T", TIntrpol);
setVec(IntFeatureData, StringData, "interpolate", intrpolte);

// also interpolate current if present
vector<double> I, IIntrpol, TIntrpolI;
int retValI;
retValI = getVec(DoubleFeatureData, StringData, "I", I);
if (retValI > 0){
LinearInterpolation(InterpStep, T, I, TIntrpolI, IIntrpol);
setVec(DoubleFeatureData, StringData, "I", IIntrpol);
}
return retVal;
}

Expand Down
36 changes: 16 additions & 20 deletions tests/test_pyfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def _load_trace(trace_name):
'stim_end': [trace_data['stim_end']],
}

if trace_name == "current":
trace['T'] = trace['T'] * 1000.0 # s -> ms

if 'i_col' in trace_data:
trace['I'] = efel.io.load_fragment('%s#col=%d' %
(url, trace_data['i_col']))
Expand Down Expand Up @@ -331,18 +334,6 @@ def test_pydistance_featurefail():
trace_check=True), 250.0)


def test_current():
"""pyfeatures: Test current feature"""

feature_name = 'current'
data = numpy.loadtxt(os.path.join(os.path.abspath(testdata_dir),
'basic',
'current.txt'))
current = data[:, 1]
expected_values = {'current': current}
_test_expected_value(feature_name, expected_values)


def test_interpolate_current():
"""pyfeatures: Test interpolation of current"""

Expand All @@ -357,16 +348,21 @@ def interpolate(time, voltage, new_dt):
data = numpy.loadtxt(os.path.join(os.path.abspath(testdata_dir),
'basic',
'current.txt'))
time = data[:, 0]
time = data[:, 0] * 1000.0 # -> ms
current = data[:, 1]
voltage = data[:, 2]

feature_name = ['time', 'current', 'voltage']
trace = _load_trace('current')
feature_values = efel.getFeatureValues([trace], ['current'])
interp_time, interp_current = interpolate(time, current, new_dt=0.00025)

assert len(interp_time) == len(time)
assert len(interp_current) == len(current)
assert len(voltage) == len(current)
assert numpy.allclose(interp_current, current)
feature_values = efel.getFeatureValues([trace], feature_name)
feature_time = feature_values[0]["time"]
feature_current = feature_values[0]["current"]
feature_voltage = feature_values[0]["voltage"]
interp_time, interp_current = interpolate(time, current, new_dt=0.1)
_, interp_voltage = interpolate(time, voltage, new_dt=0.1)

assert len(interp_time) == len(feature_time)
assert len(interp_current) == len(feature_current)
assert len(interp_voltage) == len(feature_voltage)
assert len(feature_voltage) == len(feature_current)
assert numpy.allclose(interp_current, feature_current, atol=1e-6)

0 comments on commit e7565d8

Please sign in to comment.