PropagationPropertiesCalculator.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "UblasIncludes.hpp"
00030 #include "PropagationPropertiesCalculator.hpp"
00031 #include "CellProperties.hpp"
00032 #include "Exception.hpp"
00033 #include <sstream>
00034
00035 PropagationPropertiesCalculator::PropagationPropertiesCalculator(Hdf5DataReader* pDataReader,
00036 const std::string voltageName)
00037 : mpDataReader(pDataReader),
00038 mVoltageName(voltageName)
00039 {}
00040
00041 PropagationPropertiesCalculator::~PropagationPropertiesCalculator()
00042 {
00043
00044 }
00045
00046 double PropagationPropertiesCalculator::CalculateMaximumUpstrokeVelocity(unsigned globalNodeIndex)
00047 {
00048 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00049 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00050 CellProperties cell_props(voltages, times);
00051 return cell_props.GetLastMaxUpstrokeVelocity();
00052 }
00053
00054 std::vector<double> PropagationPropertiesCalculator::CalculateAllMaximumUpstrokeVelocities(unsigned globalNodeIndex, double threshold)
00055 {
00056 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00057 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00058 CellProperties cell_props(voltages, times, threshold);
00059 return cell_props.GetMaxUpstrokeVelocities();
00060 }
00061
00062 std::vector<double> PropagationPropertiesCalculator::CalculateUpstrokeTimes(unsigned globalNodeIndex, double threshold)
00063 {
00064 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00065 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00066 CellProperties cell_props(voltages, times, threshold);
00067 return cell_props.GetTimesAtMaxUpstrokeVelocity();
00068 }
00069
00070 double PropagationPropertiesCalculator::CalculateActionPotentialDuration(const double percentage,
00071 unsigned globalNodeIndex)
00072 {
00073 if (percentage < 1.0 || percentage >= 100.0)
00074 {
00075 EXCEPTION("First argument of CalculateActionPotentialDuration() is expected to be a percentage");
00076 }
00077 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00078 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00079 CellProperties cell_props(voltages, times);
00080 return cell_props.GetLastActionPotentialDuration(percentage);
00081 }
00082
00083 std::vector<double> PropagationPropertiesCalculator::CalculateAllActionPotentialDurations(const double percentage,
00084 unsigned globalNodeIndex, double threshold)
00085 {
00086 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00087 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00088 CellProperties cell_props(voltages, times, threshold);
00089 return cell_props.GetAllActionPotentialDurations(percentage);
00090 }
00091
00092 double PropagationPropertiesCalculator::CalculatePeakMembranePotential(unsigned globalNodeIndex)
00093 {
00094 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00095 double max = -DBL_MAX;
00096 for(unsigned i=0; i<voltages.size(); i++)
00097 {
00098 if(voltages[i]>max)
00099 {
00100 max = voltages[i];
00101 }
00102 }
00103 return max;
00104 }
00105
00106 double PropagationPropertiesCalculator::CalculateConductionVelocity(unsigned globalNearNodeIndex,
00107 unsigned globalFarNodeIndex,
00108 const double euclideanDistance)
00109 {
00110 double t_near = 0;
00111 double t_far = 0;
00112 std::vector<double> near_voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNearNodeIndex);
00113 std::vector<double> far_voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalFarNodeIndex);
00114 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00115
00116 CellProperties near_cell_props(near_voltages, times);
00117 CellProperties far_cell_props(far_voltages, times);
00118
00119
00120 unsigned aps_near_node = near_cell_props.GetMaxUpstrokeVelocities().size();
00121 unsigned aps_far_node = far_cell_props.GetMaxUpstrokeVelocities().size();
00122
00123
00124 assert(aps_near_node > 0);
00125 assert(aps_far_node > 0);
00126
00127
00128 if (aps_near_node == aps_far_node)
00129 {
00130 t_near = near_cell_props.GetTimeAtLastMaxUpstrokeVelocity();
00131 t_far = far_cell_props.GetTimeAtLastMaxUpstrokeVelocity();
00132 }
00133
00134
00135
00136 else if (aps_near_node > aps_far_node)
00137 {
00138 t_near = near_cell_props.GetTimesAtMaxUpstrokeVelocity()[aps_far_node-1];
00139 t_far = far_cell_props.GetTimesAtMaxUpstrokeVelocity()[aps_far_node-1];
00140 }
00141 else
00142 {
00143 t_near = near_cell_props.GetTimesAtMaxUpstrokeVelocity()[aps_near_node-1];
00144 t_far = far_cell_props.GetTimesAtMaxUpstrokeVelocity()[aps_near_node-1];
00145 }
00146
00147 if ((globalNearNodeIndex == globalFarNodeIndex) || ( fabs(t_far - t_near) < 1e-8))
00148 {
00149
00150
00151
00152 return 0.0;
00153 }
00154 else
00155 {
00156 return euclideanDistance / (t_far - t_near);
00157 }
00158
00159
00160 }
00161
00162 std::vector<double> PropagationPropertiesCalculator::CalculateAllConductionVelocities(unsigned globalNearNodeIndex,
00163 unsigned globalFarNodeIndex,
00164 const double euclideanDistance)
00165 {
00166 std::vector<double> conduction_velocities;
00167
00168 std::vector<double> t_near;
00169 std::vector<double> t_far;
00170 unsigned number_of_aps = 0;
00171
00172 std::vector<double> near_voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNearNodeIndex);
00173 std::vector<double> far_voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalFarNodeIndex);
00174 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00175
00176 CellProperties near_cell_props(near_voltages, times);
00177 CellProperties far_cell_props(far_voltages, times);
00178
00179 t_near = near_cell_props.GetTimesAtMaxUpstrokeVelocity();
00180 t_far = far_cell_props.GetTimesAtMaxUpstrokeVelocity();
00181
00182
00183
00184 assert(t_near.size() !=0);
00185 assert(t_far.size() !=0);
00186
00187
00188
00189 if (t_near.size() > t_far.size())
00190 {
00191 number_of_aps=t_far.size();
00192 }
00193 else
00194 {
00195 number_of_aps=t_near.size();
00196 }
00197
00198
00199 if (globalNearNodeIndex == globalFarNodeIndex)
00200 {
00201
00202 for (unsigned i = 0 ; i < number_of_aps;i++)
00203 {
00204 conduction_velocities.push_back(0.0);
00205 }
00206 }
00207 else
00208 {
00209 for (unsigned i = 0 ; i < number_of_aps;i++)
00210 {
00211 if ( fabs(t_far[i] - t_near[i]) < 1e-8)
00212 {
00213
00214 conduction_velocities.push_back(0.0);
00215 }
00216 else
00217 {
00218 conduction_velocities.push_back(euclideanDistance / (t_far[i] - t_near[i]));
00219 }
00220 }
00221 }
00222
00223 return conduction_velocities;
00224 }
00225
00226 std::vector<unsigned> PropagationPropertiesCalculator::CalculateAllAboveThresholdDepolarisations(unsigned globalNodeIndex, double threshold)
00227 {
00228 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00229 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00230 CellProperties cell_props(voltages, times, threshold);
00231 return cell_props.GetNumberOfAboveThresholdDepolarisationsForAllAps();
00232 }
00233
00234
00235 unsigned PropagationPropertiesCalculator::CalculateAboveThresholdDepolarisationsForLastAp(unsigned globalNodeIndex, double threshold)
00236 {
00237 std::vector<double> voltages = mpDataReader->GetVariableOverTime(mVoltageName, globalNodeIndex);
00238 std::vector<double> times = mpDataReader->GetUnlimitedDimensionValues();
00239 CellProperties cell_props(voltages, times, threshold);
00240 return cell_props.GetNumberOfAboveThresholdDepolarisationsForLastAp();
00241 }