I am learning python and wanted to ask for the community help in writing an integration equation in python
I am attempting to implement a method for estimating stroke volume from arterial pulse pressure.
The equation involves an integration to calculate the integral of p(t) from the start of diastole (t_d) to the end of diastole (equation shown in the image). equation
I was hoping to benefit from the community insights and help validate my code to ensure it accurately represents the adopted equation
I am also attaching a visual plot of a wave to help understand the pressure data Pressure wave sample
#td_list and ts_list are the position points within pressure array of diastole and end of systole
ts_list = [338, 674, 1013, 1347, 1682, 2017, 2353, 2688, 3026, 3360, 3699, 4031, 4370, 4706, 5043, 5384, 5719, 6050, 6384, 6726, 7063, 7401, 7741]
td_list = [256, 595, 932, 1267, 1603, 1948, 2273, 2609, 2945, 3280, 3617, 3954, 4292, 4627, 4963, 5300, 5636, 5973, 6310, 6647, 6984, 7323, 7661]
p = df["pressure_column"]
def pulse_contour_integration(P, td, ts):
"""
Parameters:
- P: pressure strip (P(t)).
- td: Diastolic time (start of systole).
- ts: Systolic time (end of systole).
Returns:
- stroke area (sap).
"""
# Create a time array x for the interval [td, ts]
# Calculate the area using Pulse Contour Integration
# equivelant to equation 10 in stephen bennett paper
# Calculates height (pressur at time point and subtract from diastole through x)
x = np.arange(td, ts) # will creat a sequence of number for td to ts
sap = np.trapz((P[x] - P[td]), x)
return sap
#Calculating SA for each beat and add it to a list
SA_list = []
for i, k in enumerate(td_list):
td = td_list[i]
ts = ts_list[i]
if i != (len(td_list)-1):
wave = p[td_list[i]: td_list[i+1]]
else:
break
sap = pulse_contour_integration(wave, td, ts)
SA_list.append(sap)