Change: flow inlet plot, skyprow, +1...
This commit is contained in:
parent
c3c570764b
commit
7ef2f1fc35
74
functions.py
74
functions.py
|
@ -15,11 +15,10 @@ from math import floor
|
||||||
from statistics import mean
|
from statistics import mean
|
||||||
from scipy.signal import find_peaks
|
from scipy.signal import find_peaks
|
||||||
|
|
||||||
def cycle(folder,dt,save_path):
|
def cycle(folder,dt,N_ts,save_path):
|
||||||
pressure = np.loadtxt(folder + '/PHistRCR.dat',skiprows=2)
|
pressure = np.loadtxt(folder + '/PHistRCR.dat',skiprows=1)
|
||||||
N_ts = pressure.shape[0]
|
|
||||||
T = round(dt*N_ts,3)
|
T = round(dt*N_ts,3)
|
||||||
time = np.linspace(0,T,N_ts)
|
time = np.linspace(0,T,N_ts+1)
|
||||||
# Find peaks, keep only the maximums
|
# Find peaks, keep only the maximums
|
||||||
peaks, _ = find_peaks(pressure[:,-1])
|
peaks, _ = find_peaks(pressure[:,-1])
|
||||||
idx = np.where(pressure[peaks,-1] >= np.mean(pressure))
|
idx = np.where(pressure[peaks,-1] >= np.mean(pressure))
|
||||||
|
@ -92,8 +91,8 @@ def error_plot(folder,t_step,r_criteria,save_path):
|
||||||
|
|
||||||
|
|
||||||
def periodicity(project,folder,dt,T_cyc,n_cyc,save_path):
|
def periodicity(project,folder,dt,T_cyc,n_cyc,save_path):
|
||||||
pressure = np.loadtxt(folder+'/PHistRCR.dat',skiprows=2,)
|
pressure = np.loadtxt(folder+'/PHistRCR.dat',skiprows=1,)
|
||||||
time = np.linspace(0,T_cyc*n_cyc,round(T_cyc/dt*n_cyc))
|
time = np.linspace(0,T_cyc*n_cyc,round(T_cyc/dt*n_cyc)+1)
|
||||||
peak_P = []
|
peak_P = []
|
||||||
peak_P_pos = []
|
peak_P_pos = []
|
||||||
Nc = round(T_cyc/dt)
|
Nc = round(T_cyc/dt)
|
||||||
|
@ -119,10 +118,13 @@ def periodicity(project,folder,dt,T_cyc,n_cyc,save_path):
|
||||||
if (peak_Pdiff[-1]<=1):
|
if (peak_Pdiff[-1]<=1):
|
||||||
print('The numerical simulation \'{0}\' has achieve periodicity!\nSystolic Blood Pressure (SBP):\nsecond-last cycle = {1:.2f} mmHg,\nlast cycle = {2:.2f} mmHg,\n\u0394mmHg = {3:.2f} mmHg'.format(project,peak_P[-2],peak_P[-1],peak_Pdiff[-1]))
|
print('The numerical simulation \'{0}\' has achieve periodicity!\nSystolic Blood Pressure (SBP):\nsecond-last cycle = {1:.2f} mmHg,\nlast cycle = {2:.2f} mmHg,\n\u0394mmHg = {3:.2f} mmHg'.format(project,peak_P[-2],peak_P[-1],peak_Pdiff[-1]))
|
||||||
txt = ['The numerical simulation \'{0}\' has achieved periodicity.'.format(project), 'Systolic Blood Pressure (SBP):', 'Second-last cycle = {0:.2f} mmHg'.format(peak_P[-2]), 'Last cycle = {0:.2f} mmHg'.format(peak_P[-1]), 'Delta_mmHg = {0:.2f} mmHg'.format(peak_Pdiff[-1])]
|
txt = ['The numerical simulation \'{0}\' has achieved periodicity.'.format(project), 'Systolic Blood Pressure (SBP):', 'Second-last cycle = {0:.2f} mmHg'.format(peak_P[-2]), 'Last cycle = {0:.2f} mmHg'.format(peak_P[-1]), 'Delta_mmHg = {0:.2f} mmHg'.format(peak_Pdiff[-1])]
|
||||||
|
else:
|
||||||
|
print('The numerical simulation \'{0}\' has not achieve periodicity...\nSystolic Blood Pressure (SBP):\nsecond-last cycle = {1:.2f} mmHg,\nlast cycle = {2:.2f} mmHg,\n\u0394mmHg = {3:.2f} mmHg'.format(project,peak_P[-2],peak_P[-1],peak_Pdiff[-1]))
|
||||||
|
txt = ['The numerical simulation \'{0}\' has achieved periodicity.'.format(project), 'Systolic Blood Pressure (SBP):', 'Second-last cycle = {0:.2f} mmHg'.format(peak_P[-2]), 'Last cycle = {0:.2f} mmHg'.format(peak_P[-1]), 'Delta_mmHg = {0:.2f} mmHg'.format(peak_Pdiff[-1])]
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def pressure(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
def pressure(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
||||||
pressure = np.loadtxt(folder+'/PHistRCR.dat',skiprows=2,)
|
pressure = np.loadtxt(folder+'/PHistRCR.dat',skiprows=1,)
|
||||||
Nc = round(T_cyc/dt)
|
Nc = round(T_cyc/dt)
|
||||||
time = np.linspace(0,T_cyc,Nc)
|
time = np.linspace(0,T_cyc,Nc)
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
|
@ -147,14 +149,14 @@ def pressure(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
||||||
|
|
||||||
|
|
||||||
def flow(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
def flow(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
||||||
flow = np.loadtxt(folder+'/QHistRCR.dat',skiprows=2,)
|
flow = np.loadtxt(folder+'/QHistRCR.dat',skiprows=1,)
|
||||||
Nc = round(T_cyc/dt)
|
Nc = round(T_cyc/dt)
|
||||||
time = np.linspace(0,T_cyc,Nc)
|
time = np.linspace(0,T_cyc,Nc)
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
Q = np.empty(flow.shape[1])
|
Q = np.empty(flow.shape[1])
|
||||||
for i in range(0,flow.shape[1]):
|
for i in range(0,flow.shape[1]):
|
||||||
ax.plot(time,flow[N_ts-Nc:N_ts,i],label='ROI-'+str(i+2))
|
ax.plot(time,flow[N_ts-Nc+1:N_ts+1,i],label='ROI-'+str(i+2))
|
||||||
Q[i] = (mean(flow[N_ts-Nc:N_ts,i]))
|
Q[i] = (mean(flow[N_ts-Nc+1:N_ts+1,i]))
|
||||||
|
|
||||||
ax.set(xlabel='time [s]', ylabel='Flow [mL/s]',
|
ax.set(xlabel='time [s]', ylabel='Flow [mL/s]',
|
||||||
title='Flow at each outlet')
|
title='Flow at each outlet')
|
||||||
|
@ -169,7 +171,10 @@ def flow(folder,N_ts,T_cyc,dt,n_cyc,save_path):
|
||||||
def inlet_flow_waveform(project_folder,t_btw_rst,N_ts,dt,T_cyc,n_cyc,save_path):
|
def inlet_flow_waveform(project_folder,t_btw_rst,N_ts,dt,T_cyc,n_cyc,save_path):
|
||||||
x = np.loadtxt(project_folder+'/ROI-1.flow')
|
x = np.loadtxt(project_folder+'/ROI-1.flow')
|
||||||
t = x[:,0]
|
t = x[:,0]
|
||||||
Q = -x[:,1]
|
if (x[4,1] < 0):
|
||||||
|
Q = -x[:,1]
|
||||||
|
else:
|
||||||
|
Q = x[:,1]
|
||||||
Nt_pts = np.linspace(t_btw_rst,N_ts,int(N_ts/t_btw_rst))
|
Nt_pts = np.linspace(t_btw_rst,N_ts,int(N_ts/t_btw_rst))
|
||||||
t_pts = Nt_pts*dt
|
t_pts = Nt_pts*dt
|
||||||
# Put all the time values on a single cardiac cylce
|
# Put all the time values on a single cardiac cylce
|
||||||
|
@ -224,10 +229,11 @@ def barPlot(project_folder,DBP,MBP,SBP,PP,Q_avg,save_path):
|
||||||
aimed_all = [1] #No li agrada fer append en una llista buida, no recordo perquè i segur que es pot fer millor
|
aimed_all = [1] #No li agrada fer append en una llista buida, no recordo perquè i segur que es pot fer millor
|
||||||
f = open(project_folder+'/aimed.txt', 'r') #obrir el fitxer
|
f = open(project_folder+'/aimed.txt', 'r') #obrir el fitxer
|
||||||
for line in f:
|
for line in f:
|
||||||
aimed_all = line.split() #fas una llista amb cada valor de la línia carregan-te els espais buits
|
aimed_all.append(line.split()) #fas una llista amb cada valor de la línia carregan-te els espais buits
|
||||||
del aimed_all[0] #esborrar el primer valor que has posat perquè no estigues buida la llista
|
|
||||||
|
|
||||||
def plot_bar(CFD,aimed,name,save_path,unit):
|
del aimed_all[0] #esborrar el primer valor que has posat perquè no estigues buida la llista
|
||||||
|
|
||||||
|
def plot_bar(CFD,aimed,name,save_path,unit,decimals):
|
||||||
labels = []
|
labels = []
|
||||||
for i in range(0,len(CFD)):
|
for i in range(0,len(CFD)):
|
||||||
labels.append('ROI-'+str(i+2))
|
labels.append('ROI-'+str(i+2))
|
||||||
|
@ -243,19 +249,19 @@ def barPlot(project_folder,DBP,MBP,SBP,PP,Q_avg,save_path):
|
||||||
ax.legend()
|
ax.legend()
|
||||||
high = max(max(aimed,CFD))
|
high = max(max(aimed,CFD))
|
||||||
ax.set_ylim(top = 1.7*high)
|
ax.set_ylim(top = 1.7*high)
|
||||||
def autolabel(rects):
|
def autolabel(rects,decimals):
|
||||||
"""Attach a text label above each bar in *rects*, displaying its height."""
|
"""Attach a text label above each bar in *rects*, displaying its height."""
|
||||||
for rect in rects:
|
for rect in rects:
|
||||||
height = rect.get_height()
|
height = rect.get_height()
|
||||||
ax.annotate('{}'.format(height),
|
ax.annotate(decimals.format(height),
|
||||||
xy=(rect.get_x() + rect.get_width() / 2, height),
|
xy=(rect.get_x() + rect.get_width() / 2, height),
|
||||||
xytext=(0,3), # 3 points vertical offset
|
xytext=(0,3), # 3 points vertical offset
|
||||||
textcoords="offset points",
|
textcoords="offset points",
|
||||||
ha='center', va='bottom',
|
ha='center', va='bottom',
|
||||||
fontsize = 7.5)
|
fontsize = 7.5)
|
||||||
|
|
||||||
autolabel(rects1)
|
autolabel(rects1,decimals)
|
||||||
autolabel(rects2)
|
autolabel(rects2,decimals)
|
||||||
# Create labels
|
# Create labels
|
||||||
err = []
|
err = []
|
||||||
zip_object = zip(CFD, aimed)
|
zip_object = zip(CFD, aimed)
|
||||||
|
@ -272,26 +278,26 @@ def barPlot(project_folder,DBP,MBP,SBP,PP,Q_avg,save_path):
|
||||||
fig.savefig(save_path + '/'+name+'_bar.jpg',dpi=150)
|
fig.savefig(save_path + '/'+name+'_bar.jpg',dpi=150)
|
||||||
|
|
||||||
# DBP
|
# DBP
|
||||||
CFD = [round(float(i),1) for i in DBP]
|
CFD = [float(i) for i in DBP]
|
||||||
aimed = [round(float(i),1) for i in aimed_all[0]]
|
aimed = [float(i) for i in aimed_all[0]]
|
||||||
plot_bar(CFD,aimed,'DBP',save_path,' [mmHg]')
|
plot_bar(CFD,aimed,'DBP',save_path,' [mmHg]','{0:.1f}')
|
||||||
|
|
||||||
# MBP
|
# MBP
|
||||||
CFD = [round(float(i),1) for i in MBP]
|
CFD = [float(i) for i in MBP]
|
||||||
aimed = [round(float(i),1) for i in aimed_all[1]]
|
aimed = [float(i) for i in aimed_all[1]]
|
||||||
plot_bar(CFD,aimed,'MBP',save_path,' [mmHg]')
|
plot_bar(CFD,aimed,'MBP',save_path,' [mmHg]','{0:.1f}')
|
||||||
|
|
||||||
# SBP
|
# SBP
|
||||||
CFD = [round(float(i),1) for i in SBP]
|
CFD = [float(i) for i in SBP]
|
||||||
aimed = [round(float(i),1) for i in aimed_all[2]]
|
aimed = [float(i) for i in aimed_all[2]]
|
||||||
plot_bar(CFD,aimed,'SBP',save_path,' [mmHg]')
|
plot_bar(CFD,aimed,'SBP',save_path,' [mmHg]','{0:.1f}')
|
||||||
|
|
||||||
# PP
|
# PP
|
||||||
CFD = [round(float(i),1) for i in PP]
|
CFD = [float(i) for i in PP]
|
||||||
aimed = [round(float(i),1) for i in aimed_all[3]]
|
aimed = [float(i) for i in aimed_all[3]]
|
||||||
plot_bar(CFD,aimed,'PP',save_path,' [mmHg]')
|
plot_bar(CFD,aimed,'PP',save_path,' [mmHg]','{0:.1f}')
|
||||||
|
|
||||||
# DBP
|
# Q_avg
|
||||||
CFD = [round(float(i),1) for i in Q_avg]
|
CFD = [float(i) for i in Q_avg]
|
||||||
aimed = [round(float(i),1) for i in aimed_all[4]]
|
aimed = [float(i) for i in aimed_all[4]]
|
||||||
plot_bar(CFD,aimed,'Q_avg',save_path,' [mL/s]')
|
plot_bar(CFD,aimed,'Q_avg',save_path,' [mL/s]','{0:.2f}')
|
Loading…
Reference in New Issue
Block a user