asd
This commit is contained in:
parent
2d3873605d
commit
b7d7695faf
940
codes/CS.py
940
codes/CS.py
File diff suppressed because it is too large
Load Diff
|
@ -586,25 +586,15 @@ def CenterComparison(A,B,C,R,center):
|
|||
|
||||
def VelocityChannel(M,repeat,recorder):
|
||||
[row,col,numt2] = M.shape
|
||||
|
||||
|
||||
[X,Y] = np.meshgrid(np.linspace(0,col,col),np.linspace(0,row,row))
|
||||
|
||||
plt.ion()
|
||||
|
||||
rown = row*6/row
|
||||
coln = col*6/row
|
||||
|
||||
fig = plt.figure()#figsize=(4, 6) , dpi=200)
|
||||
ax = fig.add_subplot(111, projection='3d')
|
||||
|
||||
|
||||
for rr in range(-1,repeat):
|
||||
|
||||
for t in range(numt2):
|
||||
|
||||
V = M[:,:,t]
|
||||
|
||||
#ax.plot_surface(X, Y, V, cmap=plt.cm.magma, vmin=-30, vmax=50, linewidth=0, antialiased=False)
|
||||
#ax.plot_wireframe(X, Y, V,rcount=20,ccount=20,linewidth=0.5)
|
||||
ax.plot_surface(X, Y, V,cmap='magma',vmin=-30, vmax=100, linewidth=0, antialiased=False)
|
||||
|
@ -615,7 +605,6 @@ def VelocityChannel(M,repeat,recorder):
|
|||
ax.set_xlabel('$x$')
|
||||
ax.set_ylabel('$y$')
|
||||
ax.set_zlabel('$v(r)$')
|
||||
|
||||
ax.set_title('phase ' + str(t))
|
||||
plt.pause(0.001)
|
||||
plt.draw()
|
||||
|
@ -634,116 +623,7 @@ def PlotTri(tri,pos,p):
|
|||
#ax.plot_trisurf(pos[:,0], pos[:,1], pos[:,2], triangles=tri.simplices, cmap=plt.cm.Spectral,linewidth=0.1,edgecolors='k')
|
||||
#ax.tripcolor(pos[:,0], pos[:,1], pos[:,2], triangles=tri.simplices, facecolors=p2.T, edgecolor='black')
|
||||
plt.show()
|
||||
|
||||
def PlotPressureDrop(mode):
|
||||
|
||||
barye2mmHg = 1/1333.22387415
|
||||
|
||||
CT = np.loadtxt('Pressure/DROPS/pd_NS_coarse.txt')
|
||||
CT2 = np.loadtxt('Pressure/DROPS/pd_NS_coarse2.txt')
|
||||
|
||||
ref_ao = np.loadtxt('Pressure/DROPS2/refPPE1_coarse.txt')
|
||||
ref = np.loadtxt('Pressure/DROPS2/refPPE1_coarse_leo1.txt')
|
||||
CS2 = np.loadtxt('Pressure/DROPS2/CSPPE2_coarse_leo1.txt')
|
||||
|
||||
|
||||
PPE_CT = np.loadtxt('Pressure/DROPS/pd_PPE_NS_coarse.txt')
|
||||
PPE_CT_leo = np.loadtxt('Pressure/DROPS/pd_PPE_NS_coarse_leo1.txt')
|
||||
|
||||
|
||||
STE_CT = np.loadtxt('Pressure/DROPS/test_STE_R1_coarse.txt')
|
||||
test_STE_CT = np.loadtxt('Pressure/DROPS/test2_STE_R1_coarse_leo1.txt')
|
||||
|
||||
STEint_CT = np.loadtxt('Pressure/DROPS/test_STEint_R1_coarse.txt')
|
||||
test_STEint_CT = np.loadtxt('Pressure/DROPS/test2_STEint_R1_coarse_leo1.txt')
|
||||
|
||||
|
||||
# UNDERSAMPLING
|
||||
PPE_R1_leo1 = np.loadtxt('Pressure/DROPS/test_PPE_R1_coarse_leo1.txt')
|
||||
|
||||
PPE_KT_R2_leo1 = np.loadtxt('Pressure/DROPS/KT_PPE_R2_coarse_leo1.txt')
|
||||
PPE_KT_R4_leo1 = np.loadtxt('Pressure/DROPS/KT_PPE_R4_coarse_leo1.txt')
|
||||
PPE_KT_R8_leo1 = np.loadtxt('Pressure/DROPS/KT_PPE_R8_coarse_leo1.txt')
|
||||
PPE_KT_R12_leo1 = np.loadtxt('Pressure/DROPS/KT_PPE_R12_coarse_leo1.txt')
|
||||
PPE_KT_R20_leo1 = np.loadtxt('Pressure/DROPS/KT_PPE_R20_coarse_leo1.txt')
|
||||
|
||||
PPE_CS_R2_leo1 = np.loadtxt('Pressure/DROPS/CS_PPE_R2_coarse_leo1.txt')
|
||||
PPE_CS_R4_leo1 = np.loadtxt('Pressure/DROPS/CS_PPE_R4_coarse_leo1.txt')
|
||||
PPE_CS_R8_leo1 = np.loadtxt('Pressure/DROPS/CS_PPE_R8_coarse_leo1.txt')
|
||||
PPE_CS_R12_leo1 = np.loadtxt('Pressure/DROPS/CS_PPE_R12_coarse_leo1.txt')
|
||||
PPE_CS_R20_leo1 = np.loadtxt('Pressure/DROPS/CS_PPE_R20_coarse_leo1.txt')
|
||||
|
||||
#CT_fine = np.loadtxt('Pressure/DROPS/pd_NS_fine.txt')
|
||||
#CT_fine_T = np.loadtxt('Pressure/DROPS/pd_NS_fine_T.txt')
|
||||
#PPE_CT_fine = np.loadtxt('Pressure/DROPS/pd_PPE_NS_fine.txt')
|
||||
#PPE_CT_fine_leo3 = np.loadtxt('Pressure/DROPS/pd_PPE_NS_fine_leo3.txt')
|
||||
|
||||
|
||||
tvec2 = np.linspace(0, 2.5 ,PPE_CT_leo.size)
|
||||
tvec = np.linspace(tvec2[1]*0.5 ,2.5+tvec2[1]*0.5 , CT.size)
|
||||
#tvec_T = np.linspace(0,2.5,CT_fine_T.size)
|
||||
|
||||
fig = plt.figure()
|
||||
|
||||
if mode=='KT':
|
||||
plt.plot(tvec,CT,'-k',linewidth=2,label='$ref$')
|
||||
plt.plot(tvec2,PPE_R1_leo1,'xkcd:red',linewidth=2,linestyle='-' , label='$R = 1$')
|
||||
plt.plot(tvec2,PPE_KT_R2_leo1,'xkcd:blue',linewidth=2,linestyle='-' ,label='$R = 2$')
|
||||
plt.plot(tvec2,PPE_KT_R4_leo1,'xkcd:green',linewidth=2,linestyle='-',label='$R = 4$')
|
||||
plt.plot(tvec2,PPE_KT_R8_leo1,'xkcd:orange',linewidth=2,linestyle='-',label='$R = 8$')
|
||||
plt.plot(tvec2,PPE_KT_R20_leo1,'xkcd:magenta',linewidth=2,linestyle='-', label='$R = 20$')
|
||||
plt.title('$kt-BLAST$',fontsize=20)
|
||||
|
||||
if mode=='CS':
|
||||
plt.plot(tvec,CT,'-k',linewidth=2,label='$ref$')
|
||||
plt.plot(tvec2,ref_ao,'xkcd:red',linewidth=2,linestyle='--' , label='$aorta$')
|
||||
plt.plot(tvec2,ref,'xkcd:red',linewidth=2,linestyle='-' , label='$leo$')
|
||||
plt.plot(tvec2,CS2,'xkcd:blue',linewidth=2,linestyle='-' ,label='$R = 2$')
|
||||
|
||||
#plt.plot(tvec2,PPE_R1_leo1,'xkcd:red',linewidth=2,linestyle='-' , label='$R = 1$')
|
||||
#plt.plot(tvec2,PPE_CS_R2_leo1,'xkcd:blue',linewidth=2,linestyle='-' ,label='$R = 2$')
|
||||
#plt.plot(tvec2,PPE_CS_R4_leo1,'xkcd:green',linewidth=2,linestyle='-',label='$R = 4$')
|
||||
#plt.plot(tvec2,PPE_CS_R8_leo1,'xkcd:orange',linewidth=2,linestyle='-',label='$R = 8$')
|
||||
#plt.plot(tvec2,PPE_CS_R20_leo1,'xkcd:magenta',linewidth=2,linestyle='-', label='$R = 20$')
|
||||
plt.title('$Compressed \ \ Sensing$',fontsize=20)
|
||||
|
||||
|
||||
|
||||
if mode=='STE':
|
||||
plt.plot(tvec,CT,'-k',linewidth=2,label='$ref$')
|
||||
plt.plot(tvec2,STE_CT , 'xkcd:purple' , label='STE-CT aorta')
|
||||
plt.plot(tvec2,test_STE_CT , 'xkcd:purple' , linestyle='--', marker='o', label='STE-CT leo')
|
||||
|
||||
|
||||
if mode=='STEint':
|
||||
plt.plot(tvec,CT,'-k',linewidth=2,label='$ref$')
|
||||
plt.plot(tvec2,STEint_CT, 'xkcd:aquamarine', label='STEint-CT aorta')
|
||||
plt.plot(tvec2,test_STEint_CT, 'xkcd:aquamarine', linestyle='--', marker='o',label='STEint-CT aorta')
|
||||
|
||||
|
||||
plt.ylim([-2,7])
|
||||
plt.xlabel(r'$time \ \ \ (s)$',fontsize=20)
|
||||
plt.ylabel(r'$\delta p \ \ \ (mmHg) $',fontsize=20)
|
||||
plt.legend(fontsize=16)
|
||||
##############################################################################################################################
|
||||
|
||||
|
||||
#fig = plt.figure()
|
||||
#plt.plot(tvec2,CT_fine,'-ok',label='CT')
|
||||
##plt.plot(tvec_T,CT_fine_T,'--k',label='CT T')
|
||||
#plt.plot(tvec2 ,PPE_CT_fine ,'-om',label='PPE-CT aorta')
|
||||
#plt.plot(tvec2 ,PPE_CT_fine_leo3,'-oc',label='PPE-CT leo3')
|
||||
#plt.title('aorta fine')
|
||||
#plt.xlabel(r'$time \ \ (s) $',fontsize=20)
|
||||
#plt.ylabel(r'$\delta p \ \ \ (mmHg) $',fontsize=20)
|
||||
#plt.legend(fontsize=14)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
def Plot_flux(masterpath,meshpath,options,mode,R):
|
||||
|
||||
mesh = Mesh()
|
||||
|
@ -1090,8 +970,7 @@ def Plot_dP(masterpath,options,mode,R):
|
|||
tcat[l-2] = float(row[0])
|
||||
tcat = tcat+shift_t
|
||||
ax.plot(tcat[cstar[0]:tcat.size-cstar[1]],catheter[cstar[0]:tcat.size-cstar[1]],'white',linewidth=linesize,linestyle='--',label='$catheter$')
|
||||
|
||||
|
||||
|
||||
tm = np.linspace(0,Dt*tend,tend)
|
||||
ax.set_xlim([-0.05,0.81])
|
||||
|
||||
|
@ -1131,226 +1010,7 @@ def Plot_dP(masterpath,options,mode,R):
|
|||
|
||||
|
||||
plt.show()
|
||||
|
||||
def Plot_peaksystole(datapath,options,meshes,dt,R):
|
||||
import pickle
|
||||
barye2mmHg = 1/1333.22387415
|
||||
|
||||
|
||||
for mesh_size in meshes:
|
||||
t_star = 6
|
||||
|
||||
|
||||
PPE_MEAN = np.zeros([len(R)])
|
||||
PPE_STD = np.zeros([len(R)])
|
||||
STE_MEAN = np.zeros([len(R)])
|
||||
STE_STD = np.zeros([len(R)])
|
||||
V_MEAN = np.zeros([len(R)])
|
||||
V_STD = np.zeros([len(R)])
|
||||
|
||||
ref_P = 0
|
||||
ref_V = 0
|
||||
|
||||
|
||||
|
||||
|
||||
if mesh_size=='Ucoarse':
|
||||
ref_V = 326.95828118309191
|
||||
if mesh_size=='Ufine':
|
||||
ref_V = 232.95021682714497
|
||||
if mesh_size=='Uffine':
|
||||
ref_V = 234.66445211879045
|
||||
|
||||
|
||||
|
||||
|
||||
for l in range(len(R)):
|
||||
if R[l]==0:
|
||||
ref = np.loadtxt('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/ref_'+mesh_size+'.txt')
|
||||
PPE0_raw = open('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/R0/pdrop_PPE_impl_stan.dat','rb')
|
||||
STE0_raw = open('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/R0/pdrop_STE_impl_stan.dat','rb')
|
||||
PPE0 = pickle.load(PPE0_raw)['pdrop']*(-barye2mmHg)
|
||||
STE0 = pickle.load(STE0_raw)['pdrop']*(-barye2mmHg)
|
||||
|
||||
curpath = datapath + 'sequences/aorta_'+mesh_size+'.npz'
|
||||
p = np.load(curpath)
|
||||
px = p['x']
|
||||
py = p['y']
|
||||
pz = p['z']
|
||||
v = np.sqrt(px[:,:,:,t_star]**2 + py[:,:,:,t_star]**2 + pz[:,:,:,t_star]**2)
|
||||
max0 = np.where(v==np.max(v))
|
||||
|
||||
ref_P = ref[6]
|
||||
V_MEAN[l] = ref_V
|
||||
V_STD[l] = 0
|
||||
PPE_MEAN[l] = PPE0[6]
|
||||
PPE_STD[l] = 0
|
||||
STE_MEAN[l] = STE0[6]
|
||||
STE_STD[l] = 0
|
||||
else:
|
||||
PPE_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/ppemean_R'+ str(R[l]) +'.txt')
|
||||
PPE_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/ppestd_R'+ str(R[l]) +'.txt')
|
||||
STE_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/stemean_R'+ str(R[l]) +'.txt')
|
||||
STE_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/stestd_R'+ str(R[l]) +'.txt')
|
||||
V_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/vmean_R'+ str(R[l]) +'.txt')
|
||||
V_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/vstd_R'+ str(R[l]) +'.txt')
|
||||
|
||||
|
||||
|
||||
plt.figure(figsize=(10, 6), dpi=100)
|
||||
Rvec = np.linspace(-10,R[-1]+5,100)
|
||||
hline = Rvec*0+ref_P
|
||||
plt.subplot(1,2,1)
|
||||
plt.plot([0],[ref_P],color='k',marker='o',label= '$ref$')
|
||||
plt.plot(Rvec,hline,color='k',linestyle='--')
|
||||
plt.errorbar(R,PPE_MEAN, yerr=PPE_STD,color=options['ppecol'],marker='o',label= '$PPE$')
|
||||
plt.errorbar(R,STE_MEAN, yerr=STE_STD,color=options['stecol'],marker='o',label= '$STE$')
|
||||
plt.xlim([-2,R[-1]+5])
|
||||
plt.ylim([-7,18])
|
||||
plt.xlabel(r'$R$',fontsize=20)
|
||||
plt.title('$Peak \ Systole \ pressure$',fontsize=18)
|
||||
plt.ylabel(r'$ max \ \big ( \delta P \big ) \ \ mmHg$',fontsize=16)
|
||||
|
||||
|
||||
plt.subplot(1,2,2)
|
||||
#plt.plot([0],[ref_V],color='k',marker='o',label= '$ref$')
|
||||
Rvec = np.linspace(-10,R[-1]+5,100)
|
||||
hline = Rvec*0+ref_V
|
||||
plt.plot(Rvec,hline,color='k',linestyle='--')
|
||||
plt.errorbar(R,V_MEAN, yerr=V_STD,color='royalblue',marker='o',label= '$' + mesh_size + '$')
|
||||
plt.xlim([-2,R[-1]+5])
|
||||
plt.ylim([0,350])
|
||||
plt.xlabel(r'$R$',fontsize=20)
|
||||
plt.ylabel(r'$ max \ \big ( v \big ) \ \ cm/s$',fontsize=16)
|
||||
plt.title('$Peak \ Systole \ velocity$',fontsize=18)
|
||||
#plt.legend(fontsize=15)
|
||||
|
||||
plt.annotate('$'+mesh_size+'$', xy=(-0.2, 1.1), xycoords='axes fraction',fontsize=15)
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
def Plot_peaksystole_flux(datapath,options,meshes,dt,R):
|
||||
import pickle
|
||||
barye2mmHg = 1/1333.22387415
|
||||
|
||||
|
||||
for mesh_size in meshes:
|
||||
t_star = 6
|
||||
PPE_MEAN = np.zeros([len(R)])
|
||||
PPE_STD = np.zeros([len(R)])
|
||||
STE_MEAN = np.zeros([len(R)])
|
||||
STE_STD = np.zeros([len(R)])
|
||||
V_MEAN = np.zeros([len(R)])
|
||||
V_STD = np.zeros([len(R)])
|
||||
Q_MEAN = np.zeros([len(R)])
|
||||
Q_STD = np.zeros([len(R)])
|
||||
|
||||
ref_V = 0
|
||||
|
||||
if mesh_size=='Ucoarse':
|
||||
ref_V = 326.95828118309191
|
||||
if mesh_size=='Ufine':
|
||||
ref_V = 232.95021682714497
|
||||
if 'Uffine' in mesh_size:
|
||||
ref_V = 226.93523675462458
|
||||
maxv1 = 184.05091675316763
|
||||
ref_Q = 454.77517472437495
|
||||
maxq1 = 429.01393994253556
|
||||
|
||||
|
||||
for l in range(len(R)):
|
||||
if R[l]==0:
|
||||
ref = np.loadtxt('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/ref_'+mesh_size+'.txt')
|
||||
PPE0_raw = open('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/R0/pdrop_PPE_impl_stan.dat','rb')
|
||||
STE0_raw = open('/home/yeye/N_MRI/codes/pressure_drop/'+mesh_size+'/dt' + str(dt) + '/R0/pdrop_STE_impl_stan.dat','rb')
|
||||
PPE0 = pickle.load(PPE0_raw)['pdrop']*(-barye2mmHg)
|
||||
STE0 = pickle.load(STE0_raw)['pdrop']*(-barye2mmHg)
|
||||
|
||||
curpath = datapath + 'sequences/aorta_'+mesh_size+'.npz'
|
||||
p = np.load(curpath)
|
||||
px = p['x']
|
||||
py = p['y']
|
||||
pz = p['z']
|
||||
v = np.sqrt(px[:,:,:,t_star]**2 + py[:,:,:,t_star]**2 + pz[:,:,:,t_star]**2)
|
||||
max0 = np.where(v==np.max(v))
|
||||
V_MEAN[l] = ref_V
|
||||
V_STD[l] = 0
|
||||
PPE_MEAN[l] = PPE0[6]
|
||||
PPE_STD[l] = 0
|
||||
STE_MEAN[l] = STE0[6]
|
||||
STE_STD[l] = 0
|
||||
elif R[l]==1:
|
||||
PPE_MEAN[l] = 0
|
||||
PPE_STD[l] = 0
|
||||
STE_MEAN[l] = 0
|
||||
STE_STD[l] = 0
|
||||
V_MEAN[l] = maxv1
|
||||
V_STD[l] = 0
|
||||
Q_MEAN[l] = maxq1
|
||||
Q_STD[l] = 0
|
||||
|
||||
else:
|
||||
PPE_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/ppemean_R'+ str(R[l]) +'.txt')
|
||||
PPE_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/ppestd_R'+ str(R[l]) +'.txt')
|
||||
STE_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/stemean_R'+ str(R[l]) +'.txt')
|
||||
STE_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/stestd_R'+ str(R[l]) +'.txt')
|
||||
V_MEAN[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/vmean_R'+ str(R[l]) +'.txt')
|
||||
V_STD[l] = np.loadtxt(datapath + 'maxpv/'+mesh_size + '/vstd_R'+ str(R[l]) +'.txt')
|
||||
Q_MEAN[l] = -np.loadtxt(datapath + 'maxpv/'+mesh_size + '/Q2_R'+ str(R[l]) +'.txt')
|
||||
Q_STD[l] = -np.loadtxt(datapath + 'maxpv/'+mesh_size + '/Qstd2_R'+ str(R[l]) +'.txt')
|
||||
|
||||
|
||||
|
||||
plt.figure(figsize=(15, 5), dpi=100)
|
||||
plt.annotate('$'+mesh_size+'$', xy=(-0.2, 1.1), xycoords='axes fraction',fontsize=15)
|
||||
|
||||
|
||||
Rvec = np.linspace(-10,R[-1]+5,100)
|
||||
plt.subplot(1,3,1)
|
||||
#plt.plot(Rvec,hline,color='k',linestyle='--')
|
||||
plt.errorbar(R,PPE_MEAN, yerr=PPE_STD,color=options['ppecol'],marker='o',label= '$PPE$')
|
||||
plt.errorbar(R,STE_MEAN, yerr=STE_STD,color=options['stecol'],marker='o',label= '$STE$')
|
||||
plt.xlim([-2,R[-1]+5])
|
||||
plt.ylim([-0.1,2.0])
|
||||
plt.xlabel(r'$R$',fontsize=20)
|
||||
plt.legend(fontsize=12,loc=2)
|
||||
plt.title('$ l_2 \ error \ in \ Peak \ pressure$',fontsize=16)
|
||||
plt.xticks(R)
|
||||
plt.ylabel(r'$ || p - p^{ref} ||/|| p^{ref} ||_{l2} $',fontsize=16)
|
||||
|
||||
|
||||
plt.subplot(1,3,2)
|
||||
#plt.plot([0],[ref_V],color='k',marker='o',label= '$ref$')
|
||||
Rvec = np.linspace(-10,R[-1]+7,100)
|
||||
hline = Rvec*0+ref_V
|
||||
plt.plot(Rvec,hline,color='royalblue',linestyle='--')
|
||||
plt.errorbar(R,V_MEAN, yerr=V_STD,color='royalblue',marker='o',label= '$' + mesh_size + '$')
|
||||
plt.xlim([-2,R[-1]+5])
|
||||
plt.ylim([0,350])
|
||||
plt.xlabel(r'$R$',fontsize=20)
|
||||
plt.ylabel(r'$ v \ \ cm/s$',fontsize=16)
|
||||
plt.xticks(R)
|
||||
plt.title('$Peak \ velocity$',fontsize=16)
|
||||
#plt.legend(fontsize=15)
|
||||
|
||||
plt.subplot(1,3,3)
|
||||
Rvec = np.linspace(-10,R[-1]+7,100)
|
||||
hline = Rvec*0+ref_Q
|
||||
plt.plot(Rvec,hline,color='mediumvioletred',linestyle='--')
|
||||
plt.errorbar(R,Q_MEAN, yerr=Q_STD,color='mediumvioletred',marker='o',label= '$' + mesh_size + '$')
|
||||
plt.xlim([-2,R[-1]+5])
|
||||
plt.xlabel(r'$R$',fontsize=20)
|
||||
plt.ylabel(r'$ Q \ \ ml/s$',fontsize=16)
|
||||
plt.xticks(R)
|
||||
plt.ylim([150,550])
|
||||
plt.title('$Peak \ Flux $',fontsize=16)
|
||||
|
||||
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
def CLOCK(t1, t2):
|
||||
tot_time = np.round(t2 - t1, 2)
|
||||
if tot_time < 60:
|
||||
|
@ -1411,6 +1071,9 @@ def ROUTINE(options):
|
|||
if options['Error-curves']['apply']:
|
||||
print('--- Error-curves analysis ---')
|
||||
ratio = False
|
||||
fac=1
|
||||
if '11mm' in options['Error-curves']['subfolders']:
|
||||
fac=100
|
||||
for types in options['Error-curves']['type']:
|
||||
if types=='mean_ratio':
|
||||
types = 'mean'
|
||||
|
@ -1418,6 +1081,9 @@ def ROUTINE(options):
|
|||
if types=='max_ratio':
|
||||
types = 'max'
|
||||
ratio = True
|
||||
if types=='norm2_m':
|
||||
types='norm2'
|
||||
meas=True
|
||||
nc = 0
|
||||
if len(options['Error-curves']['subfolders'])==0:
|
||||
ucomp = []
|
||||
|
@ -1445,46 +1111,262 @@ def ROUTINE(options):
|
|||
for subf in options['Error-curves']['subfolders']:
|
||||
ucomp = []
|
||||
wcomp = []
|
||||
colorset = options['Error-curves']['colors']
|
||||
if 'colors' in options['Error-curves']:
|
||||
print('colors setted...')
|
||||
colorset = options['Error-curves']['colors']
|
||||
colorsetted = True
|
||||
else:
|
||||
colorsetted = False
|
||||
styles = options['Error-curves']['styles']
|
||||
labelset = options['Error-curves']['labels']
|
||||
path = options['Error-curves']['folder'] + subf + '/'
|
||||
try:
|
||||
ucomp = np.loadtxt(path + '/u'+types+'.txt')
|
||||
wcomp = np.loadtxt(path + '/w'+types+'.txt')
|
||||
times = np.loadtxt(path + '/times.txt')
|
||||
except IOError:
|
||||
print('no cError-curves for ' + subf)
|
||||
wcomp = np.loadtxt(path + 'w'+types+'.txt')
|
||||
times = np.loadtxt(path + 'times.txt')
|
||||
if types != 'grad':
|
||||
ucomp = np.loadtxt(path + 'u'+types+'.txt')
|
||||
|
||||
if not ratio:
|
||||
plt.plot(
|
||||
times, ucomp, color=colorset[nc], linestyle='-', label= '$u'+ subf +'$' )
|
||||
|
||||
plt.plot(
|
||||
times, wcomp, color=colorset[nc], linestyle='--', label='$w'+subf+'$')
|
||||
if colorsetted:
|
||||
if not ratio:
|
||||
if types not in ['grad']:
|
||||
if meas:
|
||||
plt.plot(times, fac*ucomp, color=colorset[nc], linestyle='--', label= '$ u \ '+ labelset[nc] +'$',linewidth=2.5 )
|
||||
plt.plot(times, fac*wcomp, color=colorset[nc], linestyle=styles[nc], label= '$ w \ '+ labelset[nc] +'$',linewidth=2.5)
|
||||
else:
|
||||
wu = wcomp/ucomp
|
||||
plt.plot(
|
||||
times, wu, color=colorset[nc], linestyle=styles[nc], label= '$'+ labelset[nc] +'$' )
|
||||
nc +=1
|
||||
else:
|
||||
wu = wcomp/ucomp
|
||||
plt.plot(
|
||||
times, wu, color=colorset[nc], linestyle='-', label= '$'+ labelset[nc] +'$' )
|
||||
nc +=1
|
||||
if not ratio:
|
||||
if types not in ['grad']:
|
||||
if meas:
|
||||
plt.plot(times, fac*ucomp, linestyle='--', label= '$'+ labelset[nc] +'$' )
|
||||
else:
|
||||
plt.plot(times, fac*ucomp, linestyle='--', label= '$'+ labelset[nc] +'$' )
|
||||
plt.plot(
|
||||
times, fac*wcomp, linestyle=styles[nc], label= '$'+ labelset[nc] +'$')
|
||||
else:
|
||||
wu = wcomp/ucomp
|
||||
plt.plot(
|
||||
times, wu, linestyle=styles[nc], label= '$'+ labelset[nc] +'$' )
|
||||
nc +=1
|
||||
|
||||
|
||||
|
||||
#plt.ylim([0, 170])
|
||||
plt.xlabel('$time \ \ (s)$', fontsize=18)
|
||||
plt.legend(fontsize=16)
|
||||
plt.legend(fontsize=14)
|
||||
if options['Error-curves']['title']:
|
||||
plt.title(options['Error-curves']['title'], fontsize=18)
|
||||
|
||||
if not ratio:
|
||||
plt.ylabel('$velocity \ \ (cm/s)$', fontsize=18)
|
||||
if types == 'grad':
|
||||
plt.ylim([0, 230])
|
||||
plt.ylabel('$ |grad(w)|_2 \ \ (1/s)$', fontsize=18)
|
||||
elif types == 'norm2':
|
||||
plt.ylim([0, 52])
|
||||
plt.ylabel('$ |w|_2 \ \ (cm/s)$', fontsize=18)
|
||||
else:
|
||||
plt.ylabel('$velocity \ \ (cm/s)$', fontsize=18)
|
||||
plt.savefig(options['Error-curves']['outpath'] + types + '.png', dpi=500, bbox_inches='tight')
|
||||
else:
|
||||
plt.ylabel('$w/u$', fontsize=18)
|
||||
if 'max' in types:
|
||||
plt.ylim([0, 1.8])
|
||||
plt.ylabel('$|w/u|$', fontsize=18)
|
||||
#if 'max' in types:
|
||||
#plt.ylim([0, 1.8])
|
||||
plt.savefig(options['Error-curves']['outpath'] + types + '_ratio.png', dpi=500, bbox_inches='tight')
|
||||
plt.show()
|
||||
|
||||
if 'Histograms_checkpoint' in options:
|
||||
if options['Histograms_checkpoint']['apply']:
|
||||
print('--- Histograms ---')
|
||||
path = options['Histograms_checkpoint']['path']
|
||||
freq = np.loadtxt(path + 'hist_freq.txt')
|
||||
edges = np.loadtxt(path + 'hist_edges.txt')
|
||||
fig, ax = plt.subplots()
|
||||
#ax.bar(edges[:-1], freq, width=np.diff(edges), edgecolor="black", align="edge")
|
||||
ax.bar(edges[:-1], freq, width=np.diff(edges), align="edge")
|
||||
plt.title(options['Histograms_checkpoint']['title'], fontsize=18)
|
||||
plt.xlim([0 , 50])
|
||||
plt.ylim([0 , 1.8])
|
||||
plt.savefig(path + 'hist.png', dpi=500, bbox_inches='tight')
|
||||
plt.show()
|
||||
|
||||
if 'Pressure_drops' in options:
|
||||
if options['Pressure_drops']['apply']:
|
||||
print('--- Pressure_drops ---')
|
||||
import pickle
|
||||
nc = 0
|
||||
tommhg = options['Pressure_drops']['convertor']
|
||||
|
||||
for subf in options['Pressure_drops']['subfolders']:
|
||||
ucomp = []
|
||||
wcomp = []
|
||||
if 'colors' in options['Pressure_drops']:
|
||||
colorset = options['Pressure_drops']['colors']
|
||||
colorsetted = True
|
||||
else:
|
||||
colorsetted = False
|
||||
styles = options['Pressure_drops']['styles']
|
||||
labelset = options['Pressure_drops']['labels']
|
||||
path = options['Pressure_drops']['folder'] + subf + '/'
|
||||
dataname = 'pdrop_COR_impl_stan.dat'
|
||||
if 'STE' in path:
|
||||
dataname = 'pdrop_STE_impl_stan.dat'
|
||||
if labelset[nc]=='ref':
|
||||
dataname = 'pdrop.dat'
|
||||
data = open(path+dataname, 'rb')
|
||||
p_drop = pickle.load(data)['pdrop']/tommhg
|
||||
data = open(path+dataname, 'rb')
|
||||
times = pickle.load(data)['time']
|
||||
|
||||
if labelset[nc] == 'ref':
|
||||
plt.plot(times, p_drop,color='black', linestyle='-', label= '$ref$' )
|
||||
else:
|
||||
|
||||
if colorsetted:
|
||||
plt.plot(
|
||||
times, p_drop, color=colorset[nc], linestyle=styles[nc], label= '$'+ labelset[nc] +'$' )
|
||||
else:
|
||||
plt.plot(times, p_drop, linestyle=styles[nc], label= '$'+ labelset[nc] +'$' )
|
||||
|
||||
if options['Pressure_drops']['catheter']:
|
||||
|
||||
c_path = '/home/yeye/Desktop/PhD/MEDICAL_DATA/Study_David/catheter_data/catheter_'+ labelset[nc]+'_rest_stats.csv'
|
||||
|
||||
|
||||
with open(c_path, 'r') as csvfile:
|
||||
mylist = [row[0] for row in csv.reader(csvfile, delimiter=';')]
|
||||
|
||||
Values = np.array(mylist)
|
||||
catheter = np.zeros([len(Values)-2])
|
||||
tcat = np.zeros([len(Values)-2])
|
||||
for l in range(2,len(Values)):
|
||||
row = Values[l].split(',')
|
||||
catheter[l-2] = float(row[5])
|
||||
tcat[l-2] = float(row[0])
|
||||
|
||||
|
||||
if '11mm' in subf:
|
||||
tdelay = 0.015
|
||||
elif '9mm' in subf:
|
||||
tdelay = -0.12
|
||||
elif '13mm' in subf:
|
||||
tdelay = 0.1
|
||||
elif 'Normal' in subf:
|
||||
tdelay = -0.01
|
||||
|
||||
plt.plot(tcat+tdelay,catheter,color=colorset[nc],linestyle='--')# ,label='$cat' + subf + '$')
|
||||
|
||||
nc +=1
|
||||
|
||||
|
||||
#plt.ylim([0, 170])
|
||||
plt.xlabel('$time \ \ (s)$', fontsize=18)
|
||||
plt.legend(fontsize=14)
|
||||
if options['Pressure_drops']['title']:
|
||||
plt.title(options['Pressure_drops']['title'], fontsize=18)
|
||||
plt.ylabel('$ \delta P \ \ (mmHg)$', fontsize=18)
|
||||
plt.savefig(options['Pressure_drops']['outpath'] + 'pressure_drops.png', dpi=500, bbox_inches='tight')
|
||||
plt.show()
|
||||
|
||||
if 'l2_comp' in options:
|
||||
if options['l2_comp']['apply']:
|
||||
print('--- L2 component analysis ---')
|
||||
fig, ax = plt.subplots()
|
||||
for subf in options['l2_comp']['subfolder']:
|
||||
path = options['l2_comp']['folder'] + subf + '/'
|
||||
colors = options['l2_comp']['colors']
|
||||
mode = options['l2_comp']['mode']['type']
|
||||
|
||||
if mode in ['gain','gain_compressed']:
|
||||
gain = True
|
||||
path_to_comp = options['l2_comp']['mode']['comp']
|
||||
wx = np.loadtxt(path_to_comp + '/wx.txt')
|
||||
wy = np.loadtxt(path_to_comp + '/wy.txt')
|
||||
wz = np.loadtxt(path_to_comp + '/wz.txt')
|
||||
else:
|
||||
gain = False
|
||||
wx = np.loadtxt(path + '/wx.txt')
|
||||
wy = np.loadtxt(path + '/wy.txt')
|
||||
wz = np.loadtxt(path + '/wz.txt')
|
||||
|
||||
times = np.loadtxt(path + '/times.txt')
|
||||
if subf != 'SNRinfV120' and gain:
|
||||
varux = np.loadtxt(path + '/varux.txt')
|
||||
varuy = np.loadtxt(path + '/varuy.txt')
|
||||
varuz = np.loadtxt(path + '/varuz.txt')
|
||||
if 'SNRinfV120' in subf:
|
||||
lsty = '--'
|
||||
labels = ['','','','','']
|
||||
else:
|
||||
lsty = '-'
|
||||
lsty2 = '--'
|
||||
labels = ['$wx$','$wy$','$wz$','$div$']
|
||||
labels2 = ['$\delta u_x$','$\delta u_y$','$\delta u_z$']
|
||||
labels3 = ['$x$','$y$','$z$']
|
||||
|
||||
if mode == 'gain':
|
||||
plt.plot(times, varux, color = colors[0], linestyle=lsty2 , label= labels2[0] )
|
||||
plt.plot(times, varuy, color = colors[1], linestyle=lsty2 , label= labels2[1] )
|
||||
plt.plot(times, varuz, color = colors[2], linestyle=lsty2 , label= labels2[2] )
|
||||
plt.plot(times, wx, color = colors[0], linestyle=lsty, label= labels[0] )
|
||||
plt.plot(times, wy, color = colors[1], linestyle=lsty, label= labels[1] )
|
||||
plt.plot(times, wz, color = colors[2], linestyle=lsty, label= labels[2] )
|
||||
elif mode == 'gain_compressed':
|
||||
plt.plot(times, varux-wx, color = colors[0], linestyle=lsty, label= labels3[0] )
|
||||
plt.plot(times, varuy-wy, color = colors[1], linestyle=lsty, label= labels3[1] )
|
||||
plt.plot(times, varuz-wz, color = colors[2], linestyle=lsty, label= labels3[2] )
|
||||
else:
|
||||
plt.plot(times, wx, color = colors[0], linestyle=lsty, label= labels[0] )
|
||||
plt.plot(times, wy, color = colors[1], linestyle=lsty, label= labels[1] )
|
||||
plt.plot(times, wz, color = colors[2], linestyle=lsty, label= labels[2] )
|
||||
|
||||
plt.xlabel('$time \ \ (s)$', fontsize=18)
|
||||
|
||||
if options['l2_comp']['div']:
|
||||
div = np.loadtxt(path + 'div.txt')
|
||||
div_rescaled = div*0.01
|
||||
div_rescaled = div_rescaled + 0.1
|
||||
plt.plot(times, div_rescaled, color = 'indigo', linestyle=lsty, label= labels[3] )
|
||||
|
||||
if 'title' in options['l2_comp']:
|
||||
if options['l2_comp']['title']:
|
||||
plt.title(options['l2_comp']['title'], fontsize=18)
|
||||
|
||||
|
||||
|
||||
if options['l2_comp']['aliasing']:
|
||||
if 'Poiseuille' in options['l2_comp']['folder']:
|
||||
print('adding alaising color in Poiseuille')
|
||||
import matplotlib.transforms as mtransforms
|
||||
trans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)
|
||||
if 'SNR10' in subf:
|
||||
time_al = [0.15,0.78]
|
||||
elif 'SNRinf' in subf:
|
||||
time_al = [0.21,0.78]
|
||||
pm_al = 0.5*(time_al[1] + time_al[0])
|
||||
r_al = 0.5*(time_al[1] - time_al[0])
|
||||
ax.fill_between(times, 0, 1, where=np.abs(times -pm_al)<= r_al ,facecolor='gold', alpha=0.4, transform=trans)
|
||||
if mode == 'gain_compressed':
|
||||
ax.text(pm_al/times[-1], 0.55, '$aliasing$', horizontalalignment='center',verticalalignment='center', transform=ax.transAxes,fontsize=17)
|
||||
else:
|
||||
ax.text(pm_al/times[-1], 0.82, '$aliasing$', horizontalalignment='center',verticalalignment='center', transform=ax.transAxes,fontsize=17)
|
||||
|
||||
leg = plt.legend(fancybox=True,fontsize=16)
|
||||
leg.get_frame().set_linewidth(0.0)
|
||||
ax.tick_params(axis='both', which='major', labelsize=14)
|
||||
#plt.ylim([-0.005 , 0.235])
|
||||
|
||||
if mode == 'gain_compressed':
|
||||
plt.ylim([-0.25 , 1.75])
|
||||
plt.ylabel('$|| \delta u ||_{L2} - || w ||_{L2}$', fontsize=18)
|
||||
if not gain:
|
||||
plt.ylim([-0.005 , 0.5])
|
||||
plt.ylabel('$ \sqrt{\int w^2 dx /| \Omega|}/ venc$', fontsize=18)
|
||||
|
||||
plt.savefig(options['l2_comp']['folder'] + options['l2_comp']['name'] + '.png', dpi=500, bbox_inches='tight')
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
191
codes/MRI.py
191
codes/MRI.py
|
@ -3,13 +3,10 @@
|
|||
# Workspace for MRI analysis of the 4Dflow data
|
||||
#
|
||||
# written by Jeremias Garay L: j.e.garay.labra@rug.nl
|
||||
# Fernanda te amo
|
||||
# for autoreload in ipython3
|
||||
# %load_ext autoreload
|
||||
# %autoreload 2
|
||||
################################################################
|
||||
import h5py
|
||||
from dPdirectestim.dPdirectestim import *
|
||||
from dolfin import *
|
||||
import dolfin
|
||||
import numpy as np
|
||||
|
@ -999,14 +996,8 @@ def CLOCK(rank,t1,t2):
|
|||
print('Total time: ' + str(time_hour) + ' hrs, ' + str(time_min) + ' min, ' + str(time_sec) + ' s')
|
||||
|
||||
|
||||
|
||||
def SCANNER(options):
|
||||
|
||||
########################################
|
||||
#
|
||||
# Basic Tools
|
||||
#
|
||||
########################################
|
||||
if 'kspace_cib' in options:
|
||||
if options['kspace_cib']['apply']:
|
||||
print('--- kspace from CIB data ---')
|
||||
|
@ -1416,24 +1407,18 @@ def SCANNER(options):
|
|||
else:
|
||||
CIBtoH5(path_to_cib,times,dt,outpath,flip=flip)
|
||||
|
||||
########################################
|
||||
#
|
||||
# Undersampling
|
||||
#
|
||||
########################################
|
||||
if 'cs' in options:
|
||||
if options['cs']['apply']:
|
||||
if rank==0:
|
||||
print('Applying Compressed Sensing')
|
||||
|
||||
|
||||
[Sqx, Sqy, Sqz] = LOADsequences(options['cs']['seqpath'])
|
||||
|
||||
|
||||
import CS
|
||||
if options['cs']['short']:
|
||||
[Mx,My,Mz] = LOADsequences(options['cs']['Mpath'])
|
||||
CS.undersampling_short(Mx,My,Mz,options)
|
||||
if 'short' in options['cs']:
|
||||
if options['cs']['short']:
|
||||
[Mx,My,Mz] = LOADsequences(options['cs']['Mpath'])
|
||||
CS.undersampling_short(Mx,My,Mz,options)
|
||||
else:
|
||||
CS.undersampling(Sqx,Sqy,Sqz,options,options['cs']['savepath'])
|
||||
|
||||
|
@ -1457,12 +1442,6 @@ def SCANNER(options):
|
|||
print('saving the sequences' + options['SENSE']['savepath'])
|
||||
np.savez_compressed(options['SENSE']['savepath'], x=MxS,y=MyS,z=MzS)
|
||||
|
||||
########################################
|
||||
#
|
||||
# Writing Checkpoint from Sequence
|
||||
#
|
||||
########################################
|
||||
|
||||
if 'create_checkpoint' in options:
|
||||
if options['create_checkpoint']['apply']:
|
||||
print('--- Create Checkpoint ---')
|
||||
|
@ -1529,7 +1508,7 @@ def SCANNER(options):
|
|||
comm = MESH['mesh'].mpi_comm()
|
||||
dt = options['create_checkpoint']['dt']
|
||||
if options['create_checkpoint']['xdmf']:
|
||||
xdmf_u = XDMFFile(options['create_checkpoint']['savepath']+'u.xdmf')
|
||||
xdmf_u = XDMFFile(options['create_checkpoint']['savepath']+ 'R' + str(r) + '/u.xdmf')
|
||||
|
||||
for l in range(len(vel_seq)):
|
||||
if rank == 0:
|
||||
|
@ -1545,11 +1524,6 @@ def SCANNER(options):
|
|||
inout.write_HDF5_data(
|
||||
comm, path + '/u.h5', vel_seq[l], '/u', t=l*dt)
|
||||
|
||||
########################################
|
||||
#
|
||||
# Relative Pressure Estimators
|
||||
#
|
||||
########################################
|
||||
if 'reference' in options:
|
||||
if options['reference']['apply']:
|
||||
if rank == 0:
|
||||
|
@ -1688,157 +1662,6 @@ def SCANNER(options):
|
|||
if rank==0:
|
||||
print(' ')
|
||||
|
||||
if 'peak_pv' in options:
|
||||
|
||||
if options['peak_pv']['apply']:
|
||||
import CS
|
||||
import pickle
|
||||
import sys
|
||||
import logging
|
||||
# DPestim
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
parameters['form_compiler']['optimize'] = True
|
||||
parameters['form_compiler']['cpp_optimize'] = True
|
||||
parameters['form_compiler']['cpp_optimize_flags'] = '-O3 -ffast-math -march=native'
|
||||
infile_dp = options['peak_pv']['infile_dp']
|
||||
estimator = DPDirectEstim(infile_dp)
|
||||
|
||||
barye2mmHg = 1/1333.22387415
|
||||
t_star = 0.185
|
||||
if rank==0:
|
||||
print('Computing Velocity and Pressure at Peak Systole')
|
||||
print('The inlet max occurs at ' + str(t_star) + ' sec')
|
||||
|
||||
|
||||
[BOX,AORTA,LEO] = CREATEmeshes(options)
|
||||
|
||||
if options['peak_pv']['mesh_into']=='leo':
|
||||
MESH = LEO
|
||||
del AORTA
|
||||
if options['peak_pv']['mesh_into']=='aorta':
|
||||
MESH = AORTA
|
||||
del LEO
|
||||
|
||||
if options['peak_pv']['p_comp']=='error':
|
||||
if rank==0:
|
||||
print('Reading Pressure Reference')
|
||||
P0_PPE = READcheckpoint(MESH,'p',options,options['checkpoint_path'],'p_PPE_impl_stan')
|
||||
P0_STE = READcheckpoint(MESH,'p',options,options['checkpoint_path'],'p_STE_impl_stan')
|
||||
|
||||
[Sqx,Sqy,Sqz] = LOADsequences(options['peak_pv']['orig_seq'])
|
||||
Nite = options['peak_pv']['N_CS']
|
||||
[row,col,dep,numt] = Sqz.shape
|
||||
frms_num = 3
|
||||
peakslice = options['peak_pv']['peak_slice']
|
||||
R = options['peak_pv']['R']
|
||||
|
||||
v0 = np.sqrt(Sqx[:,:,:,peakslice]**2 + Sqy[:,:,:,peakslice]**2 + Sqz[:,:,:,peakslice]**2)
|
||||
max0 = np.where(v0==np.max(v0))
|
||||
|
||||
qqvec = {}
|
||||
for ss in options['peak_pv']['flux_bnd']:
|
||||
qqvec[ss] = np.zeros([Nite])
|
||||
|
||||
ppemax = np.zeros([Nite])
|
||||
stemax = np.zeros([Nite])
|
||||
vmax = np.zeros([Nite])
|
||||
slrdmax = peakslice
|
||||
# Selecting around the max only
|
||||
slrdmax = 1
|
||||
Sqx = Sqx[:,:,:,peakslice-1:peakslice+2]
|
||||
Sqy = Sqy[:,:,:,peakslice-1:peakslice+2]
|
||||
Sqz = Sqz[:,:,:,peakslice-1:peakslice+2]
|
||||
|
||||
for l in range(len(R)):
|
||||
if rank==0:
|
||||
print('Peak Systole velocity and pressure at R = ' + str(R[l]))
|
||||
|
||||
sx_cs = np.zeros([row,col,dep,frms_num,Nite])
|
||||
sy_cs = np.zeros([row,col,dep,frms_num,Nite])
|
||||
sz_cs = np.zeros([row,col,dep,frms_num,Nite])
|
||||
|
||||
for k in range(Nite):
|
||||
if rank==0:
|
||||
print('CS iteration number ' + str(k+1))
|
||||
[xcs,ycs,zcs] = CS.undersampling_peakpv(Sqx,Sqy,Sqz,options,R[l])
|
||||
sx_cs[:,:,:,:,k] = xcs
|
||||
sy_cs[:,:,:,:,k] = ycs
|
||||
sz_cs[:,:,:,:,k] = zcs
|
||||
vk = np.sqrt(sx_cs[:,:,:,1,k]**2 + sy_cs[:,:,:,1,k]**2 + sz_cs[:,:,:,1,k]**2)
|
||||
vmax[k] = vk[max0]
|
||||
|
||||
if rank==0:
|
||||
print('\n CS done')
|
||||
|
||||
# To write the checkpoints
|
||||
vel_seq = SqtoH5(BOX,MESH,sx_cs[:,:,:,:,k],sy_cs[:,:,:,:,k],sz_cs[:,:,:,:,k])
|
||||
comm = MESH['mesh'].mpi_comm()
|
||||
|
||||
# Computing the Fluxes
|
||||
if rank==0:
|
||||
print('\n Computing the Flux')
|
||||
QQ = Fluxes(MESH,vel_seq,options,options['peak_pv']['flux_bnd'])
|
||||
|
||||
for ss in options['peak_pv']['flux_bnd']:
|
||||
qqvec[ss][k] = QQ[ss][slrdmax]
|
||||
|
||||
if rank==0:
|
||||
print('\n Writing checkpoints')
|
||||
|
||||
for ns in range(len(vel_seq)):
|
||||
pathss = options['peak_pv']['savepath'] + 'H5/checkpoint/{i}/'.format(i=ns)
|
||||
if l<10 and l>0:
|
||||
pathss = options['peak_pv']['savepath'] + 'H5/checkpoint/0{i}/'.format(i=ns)
|
||||
inout.write_HDF5_data(comm, pathss + '/u.h5', vel_seq[ns], '/u', t=0)
|
||||
if rank==0:
|
||||
print('\n The checkpoints were wrote')
|
||||
|
||||
# Computing the Pressure Drop
|
||||
estimator.estimate()
|
||||
# Reading the results
|
||||
if options['peak_pv']['p_comp']=='peak':
|
||||
ppe_raw = open(options['peak_pv']['savepath'] + '/H5/pdrop_PPE_impl_stan.dat','rb')
|
||||
ste_raw = open(options['peak_pv']['savepath'] + '/H5/pdrop_STE_impl_stan.dat','rb')
|
||||
ppe = pickle.load(ppe_raw)['pdrop']*(-barye2mmHg)
|
||||
ste = pickle.load(ste_raw)['pdrop']*(-barye2mmHg)
|
||||
p1max[k] = ppe[slrdmax]
|
||||
p2max[k] = ste[slrdmax]
|
||||
elif options['peak_pv']['p_comp']=='error':
|
||||
PPE = READcheckpoint(MESH,'p',options,options['peak_pv']['savepath']+'H5/checkpoint/','p_PPE_impl_stan')
|
||||
STE = READcheckpoint(MESH,'p',options,options['peak_pv']['savepath']+'H5/checkpoint/','p_STE_impl_stan')
|
||||
ppe_vec_0 = P0_PPE[peakslice].vector().get_local() - P0_PPE[peakslice].vector().get_local()[0]
|
||||
ppe_vec = PPE[slrdmax].vector().get_local() - PPE[slrdmax].vector().get_local()[0]
|
||||
ste_vec_0 = P0_STE[peakslice].vector().get_local() - P0_STE[peakslice].vector().get_local()[0]
|
||||
ste_vec = STE[slrdmax].vector().get_local() - STE[slrdmax].vector().get_local()[0]
|
||||
ppemax[k] = np.linalg.norm(ppe_vec_0 - ppe_vec)/np.linalg.norm(ppe_vec_0)
|
||||
stemax[k] = np.linalg.norm(ste_vec_0 - ste_vec)/np.linalg.norm(ste_vec_0)
|
||||
else:
|
||||
raise Exception('Pressure computation not recognize!')
|
||||
|
||||
|
||||
# VELOCITIES
|
||||
vmean = np.mean(vmax)
|
||||
vstd = np.std(vmax)
|
||||
# PRESSURES
|
||||
ppemean = np.mean(ppemax)
|
||||
stemean = np.mean(stemax)
|
||||
ppestd = np.std(ppemax)
|
||||
stestd = np.std(stemax)
|
||||
|
||||
|
||||
if options['peak_pv']['save']:
|
||||
if rank==0:
|
||||
print('\n saving the files in ' + options['peak_pv']['savepath'])
|
||||
for ss in options['peak_pv']['flux_bnd']:
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'Q'+str(ss) +'_R'+str(R[l])+'.txt', [np.mean(qqvec[ss])])
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'Qstd'+str(ss) +'_R'+str(R[l])+'.txt', [np.std(qqvec[ss])])
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'ppemean_R'+str(R[l])+'.txt', [ppemean] )
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'stemean_R'+str(R[l])+'.txt', [stemean] )
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'vmean_R'+str(R[l])+'.txt', [vmean] )
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'ppestd_R'+str(R[l])+'.txt', [ppestd] )
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'stestd_R'+str(R[l])+'.txt', [stestd] )
|
||||
np.savetxt( options['peak_pv']['savepath'] + 'vstd_R'+str(R[l])+'.txt', [vstd] )
|
||||
|
||||
if 'change_mesh' in options:
|
||||
if options['change_mesh']['apply']:
|
||||
if rank == 0:
|
||||
|
@ -1861,9 +1684,9 @@ def SCANNER(options):
|
|||
changed = {}
|
||||
#W = LEO['FEM'].sub(0).collapse()
|
||||
comm = MESH_out['mesh'].mpi_comm()
|
||||
v2 = Function(MESH_out['FEM'])
|
||||
|
||||
for k in range(len(list(origin))):
|
||||
v2 = Function(MESH_out['FEM'])
|
||||
if rank == 0:
|
||||
print('CHANGING: index', k)
|
||||
LagrangeInterpolator.interpolate(v2, origin[k])
|
||||
|
@ -1878,7 +1701,7 @@ def SCANNER(options):
|
|||
if rank == 0:
|
||||
print('saving checkpoint', l)
|
||||
path = options['change_mesh']['savepath'] + \
|
||||
'R1/checkpoint/{i}/'.format(i=l)
|
||||
'checkpoint/{i}/'.format(i=l)
|
||||
writepath = path + '/'+options['change_mesh']['mode']+'.h5'
|
||||
inout.write_HDF5_data(
|
||||
comm, writepath, changed[l] ,'/'+options['change_mesh']['mode'], t=l*dt)
|
||||
|
|
|
@ -109,14 +109,10 @@ def WORKcheck(MESH, mode, output_path, checkpoint_path, filename, outname, optio
|
|||
|
||||
if mode == 'p' or mode == 'p_cib':
|
||||
xdmf_p = XDMFFile(output_path+outname+'.xdmf')
|
||||
for k in range(0, len(indexes), 1):
|
||||
dt = options['Pressure']['dt']
|
||||
for k in range(0, len(indexes), options['Pressure']['undersampling']):
|
||||
te = k*dt
|
||||
path = checkpoint_path + str(indexes[k]) + '/'+filename+'.h5'
|
||||
|
||||
if filename == 'p':
|
||||
if k < 10 and k > 0:
|
||||
path = checkpoint_path + '0' + \
|
||||
str(indexes[k]) + '/'+filename+'.h5'
|
||||
|
||||
p = Function(W)
|
||||
if mode == 'p':
|
||||
barye2mmHg = 1/1333.22387415
|
||||
|
@ -126,36 +122,10 @@ def WORKcheck(MESH, mode, output_path, checkpoint_path, filename, outname, optio
|
|||
hdf = HDF5File(MESH['mesh'].mpi_comm(), path, 'r')
|
||||
hdf.read(p, 'p/vector_0')
|
||||
hdf.close()
|
||||
|
||||
p1vec = p.vector().get_local()
|
||||
p1vec = p1vec - np.mean(p1vec)
|
||||
#p1vec = p1vec - np.mean(p1vec)
|
||||
p.vector()[:] = p1vec*barye2mmHg
|
||||
xdmf_p.write(p, te)
|
||||
te = te + dt
|
||||
numt = numt + 1
|
||||
|
||||
if mode == 'divu':
|
||||
xdmf_u = XDMFFile(output_path+outname+'.xdmf')
|
||||
for k in range(0, len(indexes), 1):
|
||||
path = checkpoint_path + str(indexes[k]) + '/'+filename+'.h5'
|
||||
|
||||
if indexes[k] < 10 and indexes[k] > 0:
|
||||
path = checkpoint_path + '0' + \
|
||||
str(indexes[k]) + '/'+filename+'.h5'
|
||||
|
||||
v = Function(V)
|
||||
dv = Function(W)
|
||||
|
||||
dv.rename('div', outname)
|
||||
comm = MPI.COMM_WORLD
|
||||
hdf = HDF5File(MESH['mesh'].mpi_comm(), path, 'r')
|
||||
hdf.read(v, 'u/vector_0')
|
||||
|
||||
hdf.close()
|
||||
dv.assign(project(div(v), W))
|
||||
xdmf_u.write(dv, te)
|
||||
te = te + dt
|
||||
numt = numt + 1
|
||||
|
||||
def READcheckpoint(MESH, mode, output_path, checkpoint_path, filename, outname, options, flow=False, bnds=None):
|
||||
|
||||
|
@ -203,7 +173,7 @@ def READcheckpoint(MESH, mode, output_path, checkpoint_path, filename, outname,
|
|||
freq,edges = np.histogram(ValuesPeak, bins=80, density=True)
|
||||
#Saving the histogram
|
||||
print('Saving at ' + output_path)
|
||||
np.savetxt(output_path + 'hist_frew.txt', freq)
|
||||
np.savetxt(output_path + 'hist_freq.txt', freq)
|
||||
np.savetxt(output_path + 'hist_edges.txt', edges)
|
||||
|
||||
if mode == 'perturbation':
|
||||
|
@ -235,6 +205,20 @@ def READcheckpoint(MESH, mode, output_path, checkpoint_path, filename, outname,
|
|||
|
||||
noise_in_coil = options['Perturbation']['type']['coil']
|
||||
|
||||
umaxima = []
|
||||
for k in indexes:
|
||||
path = checkpoint_path + str(k) + '/'+filename+'.h5'
|
||||
hdf = HDF5File(MESH['mesh'].mpi_comm(), path, 'r')
|
||||
hdf.read(u, 'u/vector_0')
|
||||
time = hdf.attributes('u/vector_0').to_dict()['timestamp']
|
||||
hdf.close()
|
||||
uvec = u.vector().get_local()
|
||||
umaxima.append(np.max(uvec))
|
||||
|
||||
ufactor = options['Perturbation']['type']['phase_contrast']/100
|
||||
VENC = np.floor(np.ceil(np.max(umaxima))*ufactor)
|
||||
print('VENC chosen = ',VENC)
|
||||
|
||||
for k in indexes:
|
||||
path = checkpoint_path + str(k) + '/'+filename+'.h5'
|
||||
hdf = HDF5File(MESH['mesh'].mpi_comm(), path, 'r')
|
||||
|
@ -244,9 +228,7 @@ def READcheckpoint(MESH, mode, output_path, checkpoint_path, filename, outname,
|
|||
uvec = u.vector().get_local()
|
||||
|
||||
if Phase_Contrast:
|
||||
ufactor = options['Perturbation']['type']['phase_contrast']/100
|
||||
VENC = np.max(np.abs(uvec))*ufactor
|
||||
gamma = 267.513e6 # rad/Tesla/sec Gyromagnetic ratio for H nuclei
|
||||
#gamma = 267.513e6 # rad/Tesla/sec Gyromagnetic ratio for H nuclei
|
||||
B0 = 1.5 # Tesla Magnetic Field Strenght
|
||||
TE = 5e-3 # Echo-time
|
||||
Phi1 = 1*B0*TE + 0*uvec
|
||||
|
@ -474,7 +456,11 @@ def ERRORmap(MESH, mode, outpath, reference_path, checkpoint_path, refname,comna
|
|||
|
||||
from dolfin import HDF5File
|
||||
V = MESH['FEM']
|
||||
V1 = MESH['FEM'].sub(1).collapse()
|
||||
W = MESH['FEM'].sub(0).collapse()
|
||||
DGs = FunctionSpace( MESH['mesh'], 'DG',0)
|
||||
cellv = CellVolume(MESH['mesh'])
|
||||
h = CellDiameter(MESH['mesh'])
|
||||
unsort_indexes = os.listdir(checkpoint_path)
|
||||
indexes = [int(x) for x in unsort_indexes]
|
||||
indexes.sort()
|
||||
|
@ -486,6 +472,80 @@ def ERRORmap(MESH, mode, outpath, reference_path, checkpoint_path, refname,comna
|
|||
if len(indexes)!=len(indexes0):
|
||||
raise Exception('The lengh of the checkpoints are not the same!')
|
||||
|
||||
if mode == 'algebra':
|
||||
outname = options['Algebra']['outname']
|
||||
output = XDMFFile(outpath+outname+'.xdmf')
|
||||
checkpoint = options['Algebra']['checkpoint']
|
||||
v1 = Function(W)
|
||||
v2 = Function(W)
|
||||
vout = Function(W)
|
||||
vout.rename('velocity','velocity')
|
||||
vout_vec = np.zeros(vout.vector().get_local().size)
|
||||
times_vec = np.zeros(len(indexes0))
|
||||
vdict1 = {}
|
||||
vdict2 = {}
|
||||
if options['Algebra']['mode'] == 'aliasing':
|
||||
print('Assuming the corrector in the second path entered')
|
||||
|
||||
# Reading all the timestamps first
|
||||
for k in range(len(indexes)):
|
||||
path_v1 = reference_path + str(indexes0[k]) + '/'+refname+'.h5'
|
||||
path_v2 = checkpoint_path + str(indexes[k]) + '/'+comname+'.h5'
|
||||
hdf_v1 = HDF5File(MESH['mesh'].mpi_comm(), path_v1, 'r')
|
||||
|
||||
if 'w' in refname:
|
||||
hdf_v1.read(v1, 'w/vector_0')
|
||||
time = hdf_v1.attributes('w/vector_0').to_dict()['timestamp']
|
||||
else:
|
||||
hdf_v1.read(v1, 'u/vector_0')
|
||||
time = hdf_v1.attributes('u/vector_0').to_dict()['timestamp']
|
||||
times_vec[k] = time
|
||||
hdf_v2 = HDF5File(MESH['mesh'].mpi_comm(), path_v2, 'r')
|
||||
if 'w' in comname:
|
||||
hdf_v2.read(v2, 'w/vector_0')
|
||||
else:
|
||||
hdf_v2.read(v2, 'u/vector_0')
|
||||
|
||||
print('computing algebra for the time',time)
|
||||
hdf_v1.close()
|
||||
hdf_v2.close()
|
||||
vdict1[k] = v1.vector().get_local()
|
||||
vdict2[k] = v2.vector().get_local()
|
||||
|
||||
|
||||
for k in range(len(indexes)):
|
||||
if options['Algebra']['mode'] == '+':
|
||||
vout.vector()[:] = vdict1[k] + vdict2[k]
|
||||
elif options['Algebra']['mode'] == '-':
|
||||
vout.vector()[:] = vdict1[k] - vdict2[k]
|
||||
elif options['Algebra']['mode'] == 'aliasing':
|
||||
VENC = options['Algebra']['VENC']
|
||||
aliasing = False
|
||||
for l in range(len(vout_vec)):
|
||||
if k>0:
|
||||
#mean1 = abs(np.mean(vdict2[0][:]))
|
||||
#mean2 = abs(np.mean(vdict2[1][:]))
|
||||
#mean3 = abs(np.mean(vdict2[2][:]))
|
||||
#treshold = 10*max(mean1,mean2,mean3)
|
||||
#if abs(np.mean(vdict2[k][:]))>treshold:
|
||||
# vout_vec[l] = 0
|
||||
if vdict1[k][l]-vdict1[k-1][l] < -VENC:
|
||||
vdict1[k][l] = vdict1[k][l] + 2*VENC
|
||||
vout_vec[l] = vdict1[k][l]
|
||||
else:
|
||||
vout_vec[l] = vdict1[k][l]
|
||||
else:
|
||||
vout_vec[l] = vdict1[k][l] # first case is suppouse to be aliasing-free
|
||||
|
||||
vout.vector()[:] = vout_vec
|
||||
else:
|
||||
raise Exception('Not supported operation between vectors!')
|
||||
|
||||
output.write(vout, times_vec[k])
|
||||
if checkpoint:
|
||||
path = outpath + 'checkpoint/' + str(indexes[k]) + '/' + 'u.h5'
|
||||
inout.write_HDF5_data(MESH['mesh'].mpi_comm(), path , vout, '/u', t=times_vec[k])
|
||||
|
||||
if mode =='curves':
|
||||
|
||||
if options['Error-curves']['undersampling']>1:
|
||||
|
@ -495,27 +555,54 @@ def ERRORmap(MESH, mode, outpath, reference_path, checkpoint_path, refname,comna
|
|||
|
||||
u = Function(W)
|
||||
w = Function(W)
|
||||
ones = interpolate(Constant(1), V.sub(1).collapse())
|
||||
L_sys = assemble(ones*dx)
|
||||
VENC = options['Error-curves']['VENC']
|
||||
|
||||
for typs in options['Error-curves']['type']:
|
||||
ucomp = []
|
||||
wcomp = []
|
||||
div_array = []
|
||||
varu = []
|
||||
times = []
|
||||
dt = options['Error-curves']['dt']
|
||||
for k in range(1,len(indexes)):
|
||||
path_w = checkpoint_path + str(indexes[k]) + '/'+comname+'.h5'
|
||||
path_u = reference_path + str(indexes0[k]) + '/'+refname+'.h5'
|
||||
|
||||
if typs == 'l2_comp':
|
||||
wy = Function(V1)
|
||||
wz = Function(V1)
|
||||
comname2 = comname
|
||||
wx_array = []
|
||||
wy_array = []
|
||||
wz_array = []
|
||||
|
||||
if typs == 'utrue-uobs':
|
||||
u_path = options['Error-curves']['true_check'] + 'checkpoint/'
|
||||
w_path = options['Error-curves']['ref_check'] + 'checkpoint/'
|
||||
comname2 = 'u'
|
||||
varux_array = []
|
||||
varuy_array = []
|
||||
varuz_array = []
|
||||
else:
|
||||
u_path = reference_path
|
||||
w_path = checkpoint_path
|
||||
|
||||
dt = options['Error-curves']['dt']
|
||||
|
||||
for k in range(1,len(indexes)):
|
||||
path_w = w_path + str(indexes[k]) + '/'+comname2+'.h5'
|
||||
path_u = u_path + str(indexes0[k]) + '/'+refname+'.h5'
|
||||
u.rename('meas', 'meas')
|
||||
w.rename('w', 'w')
|
||||
hdf_w = HDF5File(MESH['mesh'].mpi_comm(),path_w,'r')
|
||||
if 'w' in comname:
|
||||
if 'w' in comname2:
|
||||
hdf_w.read(w, 'w/vector_0')
|
||||
else:
|
||||
hdf_w.read(w, 'u/vector_0')
|
||||