40 #include "CellProperties.hpp"
44 enum APPhases { BELOWTHRESHOLD , ABOVETHRESHOLD };
51 EXCEPTION(
"Insufficient time steps to calculate physiological properties.");
56 EXCEPTION(
"Time and Voltage series should be the same length. Time.size() = " <<
mrTime.size() <<
", Voltage.size() = " <<
mrVoltage.size());
60 double max_upstroke_velocity = -DBL_MAX;
61 double current_time_of_upstroke_velocity = 0;
62 double current_resting_value=DBL_MAX;
63 double current_peak=-DBL_MAX;
64 double current_minimum_velocity=DBL_MAX;
65 double prev_voltage_derivative=0;
66 unsigned ap_counter = 0;
67 unsigned counter_of_plateau_depolarisations = 0;
69 bool switching_phase =
false;
70 bool found_a_flat_bit=
false;
71 APPhases ap_phase = BELOWTHRESHOLD;
73 unsigned time_steps =
mrTime.size()-1;
79 double voltage_derivative;
80 const double resting_potential_gradient_threshold = 1e-2;
82 for (
unsigned i=1; i<=time_steps; i++)
86 voltage_derivative = (t == prev_t) ? 0.0 : (v - prev_v) / (t - prev_t);
89 if (voltage_derivative >= max_upstroke_velocity)
91 max_upstroke_velocity = voltage_derivative;
92 current_time_of_upstroke_velocity = t;
102 if (fabs(voltage_derivative)<=current_minimum_velocity && fabs(voltage_derivative)<=resting_potential_gradient_threshold)
104 current_minimum_velocity=fabs(voltage_derivative);
105 current_resting_value = prev_v;
106 found_a_flat_bit=
true;
108 else if(prev_v < current_resting_value && !found_a_flat_bit)
110 current_resting_value = prev_v;
118 current_minimum_velocity = DBL_MAX;
119 current_resting_value = DBL_MAX;
130 switching_phase =
true;
131 found_a_flat_bit =
false;
132 ap_phase = ABOVETHRESHOLD;
150 if (prev_voltage_derivative<=0 && voltage_derivative>0 && !switching_phase)
152 counter_of_plateau_depolarisations++;
157 switching_phase =
false;
171 max_upstroke_velocity = -DBL_MAX;
176 current_time_of_upstroke_velocity = 0.0;
182 ap_phase = BELOWTHRESHOLD;
185 counter_of_plateau_depolarisations = 0;
191 prev_voltage_derivative = voltage_derivative;
215 unsigned APcounter=0;
216 bool apd_is_calculated=
true;
217 std::vector<double> apds;
218 double target = DBL_MAX;
219 bool apd_starting_time_found=
false;
220 double apd_start_time=DBL_MAX;
224 for (
unsigned i=1; i<
mrTime.size(); i++)
238 apd_is_calculated =
false;
242 if ( prev_v<v && prev_v<=target && v>=target && apd_starting_time_found==
false)
245 apd_start_time=t+( (target-prev_v)/(v-prev_v) )*(t-
mrTime[i-1]);
246 apd_starting_time_found =
true;
251 if ( prev_v>v && prev_v>=target && v<=target && apd_is_calculated==
false)
254 apds.push_back (t - apd_start_time + ( (target-prev_v)/(v-prev_v) )*(t-
mrTime[i-1]) );
256 apd_is_calculated =
true;
257 apd_starting_time_found =
false;
262 if (apds.size() == 0)
264 EXCEPTION(
"No full action potential was recorded");
273 std::vector<double> amplitudes(size);
274 for (
unsigned i=0; i< size ;i++)
293 EXCEPTION(
"AP did not occur, never exceeded threshold voltage.");
303 EXCEPTION(
"AP did not occur, never descended past threshold voltage.");
369 EXCEPTION(
"No peak potential matching a full action potential was recorded.");
394 EXCEPTION(
"No MaxUpstrokeVelocity matching a full action potential was recorded.");
412 double max_upstroke_time;
419 EXCEPTION(
"No TimeAtMaxUpstrokeVelocity matching a full action potential was recorded.");
425 return max_upstroke_time;
std::vector< double > GetAllActionPotentialDurations(const double percentage)
double GetLastMaxUpstrokeVelocity()
std::vector< double > mTimesAtMaxUpstrokeVelocity
double GetTimeAtLastCompleteMaxUpstrokeVelocity()
std::vector< double > GetRestingPotentials()
#define EXCEPTION(message)
std::vector< double > GetMaxUpstrokeVelocities()
const std::vector< double > & mrTime
double GetLastPeakPotential()
std::vector< double > GetActionPotentialAmplitudes()
std::vector< double > CalculateActionPotentialDurations(const double percentage)
unsigned GetNumberOfAboveThresholdDepolarisationsForLastAp()
std::vector< double > mCycleLengths
bool mUnfinishedActionPotentials
std::vector< double > GetTimesAtMaxUpstrokeVelocity()
double GetLastActionPotentialDuration(const double percentage)
double GetLastCompleteMaxUpstrokeVelocity()
double GetLastActionPotentialAmplitude()
void CheckExceededThreshold(void)
std::vector< double > mPeakValues
std::vector< double > mMaxUpstrokeVelocities
std::vector< unsigned > GetNumberOfAboveThresholdDepolarisationsForAllAps()
std::vector< double > mOnsets
std::vector< unsigned > mCounterOfPlateauDepolarisations
std::vector< double > GetCycleLengths()
double GetLastCompletePeakPotential()
double GetLastRestingPotential()
void CalculateProperties()
std::vector< double > mRestingValues
std::vector< double > GetPeakPotentials()
void CheckReturnedToThreshold(void)
const std::vector< double > & mrVoltage
double GetTimeAtLastMaxUpstrokeVelocity()