From 825dd53a687bfbeeefc04e7af13fc85dca4f4c2d Mon Sep 17 00:00:00 2001
From: Laura Pfeiffer <laura.pfeiffer@kit.edu>
Date: Wed, 10 Jul 2024 20:31:17 +0200
Subject: [PATCH] started with evaluating LV and RV

---
 tools/evaluation/thesisCoupled.py       |  64 ++++++++++-
 tools/evaluation/utility/latexTables.py |  12 ++-
 tools/evaluation/utility/plotting.py    |  48 +++++++++
 tools/evaluation/utility/reading.py     | 137 ++++++++++++++++++------
 4 files changed, 219 insertions(+), 42 deletions(-)

diff --git a/tools/evaluation/thesisCoupled.py b/tools/evaluation/thesisCoupled.py
index 3a58bf638..75cd26696 100644
--- a/tools/evaluation/thesisCoupled.py
+++ b/tools/evaluation/thesisCoupled.py
@@ -78,16 +78,22 @@ def ErrorExtraVInt(case):
 
 def ErrorExtra(case):
     lL=[1,2,3,4]
-    tL=[1,2,3,4]
+    tL=[0,1,2,3,4]
     sdt=0.0004
     endTime=0.6
-    listEvaluationPoints=[1,2,3,4,5,6,7,8,9]
+    if case=='Volumes':
+        listEvaluationPoints=[1,2]
+    else:
+        listEvaluationPoints=[1,2,3,4,5,6,7,8,9]
     nL=['\\SIOC']
     fL=[fSIOC]
     
     savePath='../../../thesis-lindner/thesis/tables/erstmal/coupled/'
     tabWriter = TableWriter(lL,tL,sdt,endTime,1,[fSIOC],listEvaluationPoints)
-    tabWriter.writeErrorExtraTab(eP,fL,savePath,nL,case)
+    if case=='Volumes':
+        tabWriter.writeVolumesExtraError(path,fN,savePath,nL)
+    else:
+        tabWriter.writeErrorExtraTab(eP,fL,savePath,nL,case)
 
 def WorkPrecisonDiagram(case):
     lL=[1,2,3,4]
@@ -202,6 +208,53 @@ def plotGamma():
         plot.plotSpaceForPointp(fSIOC,p,j,1,resize,'SpaceGamma','Gamma') 
         plot.plotTimeForPointp(fSIOC,p,4,1,resize,'TimeGamma','Gamma')
     plot.plotSpaceForPointp(fSIOC,10,j,1,resize,'SpaceGammaINfty','GammaInfty')
+    
+def plotSpaceConVolume(path,j,lL,plotname,resize):
+    lvRvLabel=["LV volume", "RV volume"]
+    for l in lL:
+       vol, dataTime, dataStep = read.VolumeDataFromLog(path, read.createFilename(l,j,1))
+       resizeLV=[]
+       resizeRV=[]
+       resizeVol=[]
+       resizetime=[]
+       number=resize*2**(j)
+       
+       for i in range(len(dataTime)):
+            if i%number==0:
+                resizetime.append(dataTime[i])
+                resizeLV.append(vol[0][i])
+                resizeRV.append(vol[1][i])
+       resizeVol.append(resizeLV)
+       resizeVol.append(resizeRV)
+       
+       for i in range(len(resizeVol)):
+           plt.plot(resizetime, resizeVol[i], label = lvRvLabel[i]+', $\ell='+str(l)+'$',linewidth=2.5)
+    plt.legend(bbox_to_anchor=(1.05,1.00), loc="upper left")
+    plt.xlabel('Zeit (s)')
+    plt.ylabel('Volumen (ml)')
+    #plt.show()
+    import tikzplotlib
+    tikzplotlib.save(path+'/tex/'+plotname+ ".tex")
+    plt.close()
+    
+def plotVolumen():
+    lL=[1,2,3,4]
+    tL=[0,1,2,3,4]
+    sdt=0.0004
+    endTime=0.6
+    listEvaluationPoints=[1,2,3,4,5,6,7,8,9]
+    
+    #read.writeVolumeDataInFile(fSIOC,lL,tL,1,True)
+    #read.writeVolumeDataInFile(fSISVI,[4],[2,3,4],1,True)
+    #read.writeVolumeDataInFile(fGS,lL,tL,1,True)
+    j=2
+    l=4
+    resize=10
+    plot=Plot(lL,tL,sdt,endTime,1,listEvaluationPoints)
+    #LV
+    plot.plotSpaceVolumes(fSIOC,j,resize) 
+    plot.plotTimeVolumes(fSIOC,l,resize)
+    
 if __name__=="__main__":
     language='d'
     
@@ -217,7 +270,7 @@ if __name__=="__main__":
     #DifferencePerPointTabs(diffcase)
     #tactValuesAndErrorPerPoint()
     #ErrorExtraVInt('')
-    WorkPrecisonDiagram('')
+    #WorkPrecisonDiagram('')
     case='Ca'
     #plotCa()
     #ErrorExtra(case)
@@ -228,7 +281,8 @@ if __name__=="__main__":
    
     #plotGamma()
     
-    
+    #plotVolumen()
+    ErrorExtra('Volumes')
     
     #print(read.getActivaitionTimeFromLog(4,4,1, fSIOC, 8,threshold,False,''))
     #print(read.getActivaitionTimeFromLog(4,4,1, fSIOC, 8,threshold,True,''))
diff --git a/tools/evaluation/utility/latexTables.py b/tools/evaluation/utility/latexTables.py
index ab2e84db5..ddeaae11e 100644
--- a/tools/evaluation/utility/latexTables.py
+++ b/tools/evaluation/utility/latexTables.py
@@ -2122,7 +2122,7 @@ class Table:
         block+='\cmidrule(lr){3-'+str(len(fL)+2)+'}\n'
         tact_ref=comp.getTextFullExtrapolate(self.lL[-1],self.tL[-1],1,p,self.exP,th,case)
         (t_f,VInt_full)=comp.getVIntFullExtrapolate(self.lL[-1],self.tL[-1],1,p,self.exP,self.sdt,th,durEvalActi,tact_ref,case)
-        norm_full=comp.L2(VInt_full,self.sdt,self.T,self.tL[-2],False)
+        ´norm_full=comp.L2(VInt_full,self.sdt,self.T,self.tL[-2],False)
         
         for l in self.lL:
             block+='$\\ell='+str(l)+'$'
@@ -2895,11 +2895,19 @@ class TableWriter:
                 cap='Der  Fehler $\\errorG^{j,\ell,'+str(p)+'}$ der Näherungslösungen  bezüglich der Orts-Zeit-Grenzwertlösung $\\gf'+'^{\\infty,\\infty,'+str(p)+'}$ in der  $\\LtwonormT$-Norm auf dem biventrikulären Gebiet'# mit $\\Tact=\\tact+'+str(durEvalActi)+'$\,'
                 label ='tab:ErrorExtraGammaP'+str(p)
                 filename=savePath +'ErrorExtraGammaP'+str(p)
+            elif case=='Volumes':
+                cap='Der  Fehler $\\errorLV^{j,\ell}$ bzw. $\\errorRV^{j,\ell}$ der Näherungslösungen  bezüglich der Orts-Zeit-Grenzwertlösung $\\LV'+'^{\\infty,\\infty,}$ bzw.$\\RV'+'^{\\infty,\\infty,}$  in der  $\\LtwonormT$-Norm auf dem biventrikulären Gebiet'# mit $\\Tact=\\tact+'+str(durEvalActi)+'$\,'
+                label ='tab:ErrorVolumes'
+                filename=savePath +'ErrorVolumes'
             with open(filename+'.tex', 'w') as output_file:
                 output_file.write(self.tab.writeBeginApproxAndDurationTabList(p,cap,label,fN,False))
                 output_file.write(self.tab.writeExtraErrorTab(fN,nL,p,case))
                 output_file.write(self.tab.writeEndTable())
-            
+    def writeVolumesExtraError(self,path,fN,savePath,nL):
+        cap='Der  Fehler $\\errorLV^{j,\ell}$ bzw. $\\errorRV^{j,\ell}$ der Näherungslösungen  bezüglich der Orts-Zeit-Grenzwertlösung $\\LV'+'^{\\infty,\\infty,}$ bzw.$\\RV'+'^{\\infty,\\infty,}$  in der  $\\LtwonormT$-Norm auf dem biventrikulären Gebiet'
+        label ='tab:ErrorVolumes'
+        filename=savePath +'ErrorVolumes'
+        
     def writeErrorExtraVIntTab(self,path,fN,savePath,nL,threshold,case=''):
         for p in self.evalP:
             if case=='Ca':
diff --git a/tools/evaluation/utility/plotting.py b/tools/evaluation/utility/plotting.py
index 2e95526d0..fbf596a8a 100644
--- a/tools/evaluation/utility/plotting.py
+++ b/tools/evaluation/utility/plotting.py
@@ -158,6 +158,8 @@ class Plot:
             plt.legend(loc='lower right')
         elif fnfix=='':
             plt.legend(bbox_to_anchor=(1.05,1.0), loc="upper left")
+        elif fnfix=='Volumes':
+            plt.legend(bbox_to_anchor=(1.05,1.0), loc="upper left")
     def plotVIntRef(self,fnfix,resize,p,path):
         th=-50.0
         if fnfix=='Ca':
@@ -233,7 +235,51 @@ class Plot:
         self.definePositionOfLegendByPrefix(fnfix)
         self.saveTikz(path+'/tex/', plotname)
         plt.close()
+    
+    def plotSpaceVolumes(self,path,j,n):
+        for l in self.lL:
+            (time_lv,LV)= read.getDataFromTXT(path,read.createFilename(l,j,1)+'Volumes',1)
+            (time_rv,RV)= read.getDataFromTXT(path,read.createFilename(l,j,1)+'Volumes',2)
+            for i in range(len(LV)):
+                LV[i] = float(LV[i])
+                RV[i] = float(RV[i])
+            (time_lv,LV)=self.resizeData(time_lv,LV,n,len(time_lv))
+            (time_rv,RV)=self.resizeData(time_rv,RV,n,len(time_rv))
+            labelname = 'LV $\\ell='+str(l)+'$'
+            plt.plot(time_lv,LV, label = labelname,linewidth=2.5,color=self.colorList[l])
+            labelname = 'RV $\\ell='+str(l)+'$'
+            plt.plot(time_rv,RV, label = labelname,linewidth=2.5,color=self.colorList[l],linestyle='dotted')
+        
+        plotname ='SpaceVolumes'+ 'j'+str(j)
+        self.plotDataDeutsch(False,'Volumes')
+        self.definePositionOfLegendByPrefix('Volumes')
+        #plt.show()
+        self.saveTikz(path+'/tex/', plotname)
+        plt.close()
+    
+    def plotTimeVolumes(self,path,l,n):
+        for j in self.tL:
+            (time_lv,LV)= read.getDataFromTXT(path,read.createFilename(l,j,1)+'Volumes',1)
+            (time_rv,RV)= read.getDataFromTXT(path,read.createFilename(l,j,1)+'Volumes',2)
+            for i in range(len(LV)):
+                LV[i] = float(LV[i])
+                RV[i] = float(RV[i])
+            (time_lv,LV)=self.resizeData(time_lv,LV,n,len(time_lv))
+            (time_rv,RV)=self.resizeData(time_rv,RV,n,len(time_rv))
+            labelname = 'LV $j='+str(j)+'$'
+            plt.plot(time_lv,LV, label = labelname,linewidth=2.5,color=self.colorList[j])
+            labelname = 'RV $j='+str(j)+'$'
+            plt.plot(time_rv,RV, label = labelname,linewidth=2.5,color=self.colorList[j],linestyle='dotted')
         
+        plotname ='TimeVolumes'+ 'l'+str(l)
+        self.plotDataDeutsch(False,'Volumes')
+        self.definePositionOfLegendByPrefix('Volumes')
+        plt.show()
+        self.saveTikz(path+'/tex/', plotname)
+        plt.close()
+    
+    
+    #####################################################################################
     def plotSpaceForPointpWithRef(self,path,p,j,m,L,J,resize,interval=None):
         levelList=[]
         if L==self.lL[-1]:
@@ -899,6 +945,8 @@ class Plot:
             plt.ylabel('$\\gf$')
         elif fnfix=='GammaInfty':
             plt.ylabel('$\\|\\gf \\|_\\infty$')
+        elif fnfix=='Volumes':
+            plt.ylabel('Volumen (ml)')
     def plotData(self,inMS=False):
         xmin, xmax, ymin, ymax = 0.0, self.T+0.05, -100.0,70.0
         if inMS:
diff --git a/tools/evaluation/utility/reading.py b/tools/evaluation/utility/reading.py
index 7e7427419..098d10166 100644
--- a/tools/evaluation/utility/reading.py
+++ b/tools/evaluation/utility/reading.py
@@ -292,40 +292,11 @@ def NormsOfGammaAndIota(path,fn):
     f.close()
     return iota,gamma,iotaPot,gammaPot
 
-def VolumeDataFromLog(path,fn):
-
-    lv = []
-    rv = []
-    t = []
-    s = []
-    volume = []
-    
-    f = open(path+'log/'+"log_"+fn)
-    for l in f:
-            l = l.strip()
-            lv_volume = re.search("LV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
-            if lv_volume:
-                lv.append(float(lv_volume.group(1))  )      
-                
-                
-            rv_volume = re.search("RV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
-            if rv_volume:
-                rv.append(float(rv_volume.group(1)))  
-               
-                
-            time = re.search("Time\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
-            if time:
-                t.append(float(time.group(1)))
-               
-            step = re.search("Step\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
-            if step:
-                s.append(float(step.group(1)))
-    volume.append(lv)
-    volume.append(rv)
-    f.close()
-    return volume,t,s
 
 
+################################################################################
+#Gamma
+################################################################################
 def writeGammaDataInFile(path,l_List,t_List,m,sizeEvalPoints,option=True):
     fn = ''
     for l in range(l_List[0],len(l_List)+l_List[0]):
@@ -439,7 +410,9 @@ def extractGammaDataFromLog(path,fn,sizeEvalPoints,option):
         out_f.write("{} {}\n".format('{:.8f}'.format(float(k)), " ".join(listVValues)))
         
     out_f.close()
-    
+################################################################################
+#Ca
+################################################################################    
 def writeCaDataInFile(path,l_List,t_List,m,sizeEvalPoints,option=True):
     fn = ''
     for l in range(l_List[0],len(l_List)+l_List[0]):
@@ -553,8 +526,102 @@ def extractCaDataFromLog(path,fn,sizeEvalPoints,option):
         out_f.write("{} {}\n".format('{:.8f}'.format(float(k)), " ".join(listVValues)))
         
     out_f.close()
+################################################################################
+#Volumes
+################################################################################
+def writeVolumeDataInFile(path,l_List,t_List,m,option=True):
+    fn = ''
+    for l in range(l_List[0],len(l_List)+l_List[0]):
+        for j in range(t_List[0],len(t_List)+ t_List[0]):
+            fn = createFilename(l,j,m)
+            print(fn)
+            extractVolumeDataFromLog(path,fn,option)
 
-            
+def extractVolumeDataFromLog(path,fn,option):
+    if fn=='logfile.log':
+        f=open(path+ 'log/'+fn)
+    else:
+        if option:
+            f = open(path+ 'log/'+"log_"+fn)
+        else:
+            f = open(path+"log_"+fn)
+    lv = []
+    rv = []
+    t = []
+    s = []
+    for l in f:
+        l = l.strip()
+        lv_volume = re.search("LV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
+        if lv_volume:
+                lv.append(float(lv_volume.group(1))  )      
+                
+        rv_volume = re.search("RV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
+        if rv_volume:
+            rv.append(float(rv_volume.group(1)))  
+               
+                
+        time = re.search("Time\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
+        if time:
+            t.append(float(time.group(1)))
+               
+        step = re.search("Step\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
+        if step:
+            s.append(float(step.group(1)))
+    f.close()
+    
+    if fn=='logfile.log':
+        out_f = open(path + 'log/logfile.txt', "w")
+    else:
+        if option:
+            out_f = open(path + 'data/' +fn +'Volumes.txt', "w")
+        else:
+            out_f = open(path +fn +'Volumes.txt', "w")
+
+    if len(lv)!=len(rv) or len(lv)!=len(t):
+        print('length of volumes or time mismatch')
+    else:
+        for i in range(len(t)):
+            out_f.write("{} {} {}\n".format('{:.8f}'.format(float(t[i])), '{:.8f}'.format(float(lv[i])),'{:.8f}'.format(float(rv[i]))))
+    out_f.close()
+        
+        
+def VolumeDataFromLog(path,fn):
+
+    lv = []
+    rv = []
+    t = []
+    s = []
+    volume = []
+    
+    f = open(path+'log/'+"log_"+fn)
+    for l in f:
+        l = l.strip()
+        lv_volume = re.search("LV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
+        if lv_volume:
+            lv.append(float(lv_volume.group(1))  )      
+                
+                
+        rv_volume = re.search("RV-Volume\s*=\s*([+\-eE\d]+\.{0,1}[\-e\d]*)",l)
+        if rv_volume:
+            rv.append(float(rv_volume.group(1)))  
+               
+                
+        time = re.search("Time\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
+        if time:
+            t.append(float(time.group(1)))
+               
+        step = re.search("Step\s*=\s*\s*([+\-eE\d]+\.{0,1}[+\-eE\d]*)", l)
+        if step:
+            s.append(float(step.group(1)))
+    volume.append(lv)
+    volume.append(rv)
+    f.close()
+    return volume,t,s        
+        
+        
+################################################################################
+#V
+################################################################################
 def writeDataInFile(path,l_List,t_List,m,option=True):
     fn = ''
     for l in range(l_List[0],len(l_List)+l_List[0]):
@@ -687,7 +754,7 @@ def extractDataFromLog(path,fn,option):
         out_f.write("{} {}\n".format('{:.8f}'.format(float(k)), " ".join(listVValues)))
         
     out_f.close()
-
+#########################################################################################
     
 def getDurationFromLog(path,fn):
     f = open(path+ 'log/'+"log_"+fn)
-- 
GitLab