Browse Source

Logging improvements with saved files

add-license-1
T-bone 7 years ago
parent
commit
f35c5f014b
2 changed files with 69 additions and 50 deletions
  1. 38
    20
      akvo/gui/akvoGUI.py
  2. 31
    30
      akvo/tressel/rotate.py

+ 38
- 20
akvo/gui/akvoGUI.py View File

53
         return "np.array(%r)" % (self.data)
53
         return "np.array(%r)" % (self.data)
54
 
54
 
55
 from collections import OrderedDict
55
 from collections import OrderedDict
56
-def represent_ordereddict(dumper, data):
57
-    value = []
58
-    for item_key, item_value in data.items():
59
-        node_key = dumper.represent_data(item_key)
60
-        node_value = dumper.represent_data(item_value)
61
-        value.append((node_key, node_value))
62
-    return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)
63
-yaml.add_representer(OrderedDict, represent_ordereddict)
56
+#def represent_ordereddict(dumper, data):
57
+#    print("representing IN DA HOUSE!!!!!!!!!!!!!!!!!!!!!")
58
+#    value = []
59
+#    for item_key, item_value in data.items():
60
+#        node_key = dumper.represent_data(item_key)
61
+#        node_value = dumper.represent_data(item_value)
62
+#        value.append((node_key, node_value))
63
+#    return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)
64
+#yaml.add_representer(OrderedDict, represent_ordereddict)
65
+
66
+def setup_yaml():
67
+    """ https://stackoverflow.com/a/8661021 """
68
+    represent_dict_order = lambda self, data:  self.represent_mapping('tag:yaml.org,2002:map', data.items())
69
+    yaml.add_representer(OrderedDict, represent_dict_order)    
70
+setup_yaml()
64
 
71
 
65
 class AkvoYamlNode(yaml.YAMLObject):
72
 class AkvoYamlNode(yaml.YAMLObject):
66
     yaml_tag = u'!AkvoData'
73
     yaml_tag = u'!AkvoData'
67
     def __init__(self):
74
     def __init__(self):
68
         self.Akvo_VERSION = version
75
         self.Akvo_VERSION = version
69
-        self.Import = {}
76
+        self.Import = OrderedDict() # {}
70
         self.Processing = OrderedDict() 
77
         self.Processing = OrderedDict() 
71
-        #self.ProcessingFlow = []
72
-        #self.Data = {}
73
-    # For going the other way, data import based on Yaml serialization, 
78
+    #def __init__(self, node):
79
+    #    self.Akvo_VERSION = node["version"]
80
+    #    self.Import = OrderedDict( node["Import"] ) # {}
81
+    #    self.Processing = OrderedDict( node["Processing"] ) 
74
     def __repr__(self):
82
     def __repr__(self):
75
         return "%s(name=%r, Akvo_VESION=%r, Import=%r, Processing=%r)" % (
83
         return "%s(name=%r, Akvo_VESION=%r, Import=%r, Processing=%r)" % (
76
-            self.__class__.__name__, self.Akvo_VERSION, self.Import, OrderedDict(dict(self.Processing)) ) 
84
+            #self.__class__.__name__, self.Akvo_VERSION, self.Import, self.Processing )
85
+            self.__class__.__name__, self.Akvo_VERSION, self.Import, OrderedDict(self.Processing) ) 
86
+            #self.__class__.__name__, self.Akvo_VERSION, self.Import, OrderedDict(self.Processing)) 
77
     
87
     
78
 try:    
88
 try:    
79
     import thread 
89
     import thread 
563
             # Window centres 
573
             # Window centres 
564
 
574
 
565
         with open(SaveStr, 'w') as outfile:
575
         with open(SaveStr, 'w') as outfile:
566
-            for line in self.logText:
567
-                outfile.write(line+"\n")
576
+            #for line in self.logText:
577
+            #    outfile.write(line+"\n")
578
+            yaml.dump(self.YamlNode, outfile)   
568
             yaml.dump(INFO, outfile, default_flow_style=False)   
579
             yaml.dump(INFO, outfile, default_flow_style=False)   
569
  
580
  
570
     def SavePreprocess(self):
581
     def SavePreprocess(self):
604
         INFO["transFreq"] = self.RAWDataProc.transFreq
615
         INFO["transFreq"] = self.RAWDataProc.transFreq
605
         INFO["headerstr"] = str(self.headerstr)
616
         INFO["headerstr"] = str(self.headerstr)
606
         INFO["log"] = yaml.dump( self.YamlNode )  #self.logText  #MAK 20170127
617
         INFO["log"] = yaml.dump( self.YamlNode )  #self.logText  #MAK 20170127
607
-        
608
-        print ("YAML NODE", yaml.dump( self.YamlNode ) )
609
     
618
     
610
         self.RAWDataProc.DATADICT["INFO"] = INFO 
619
         self.RAWDataProc.DATADICT["INFO"] = INFO 
611
 
620
 
670
             #print ( self.RAWDataProc.DATADICT["INFO"]["log"] )
679
             #print ( self.RAWDataProc.DATADICT["INFO"]["log"] )
671
         
680
         
672
         self.logText = self.RAWDataProc.DATADICT["INFO"]["log"] # YAML 
681
         self.logText = self.RAWDataProc.DATADICT["INFO"]["log"] # YAML 
673
-        self.YamlNode = yaml.load( self.logText ) 
682
+
683
+        self.YamlNode = AkvoYamlNode( )  #self.logText )
684
+        self.YamlNode.Akvo_VERSION = (yaml.load( self.logText )).Akvo_VERSION
685
+        self.YamlNode.Import = OrderedDict((yaml.load( self.logText )).Import)
686
+        self.YamlNode.Processing = OrderedDict((yaml.load( self.logText )).Processing)
687
+        #self.YamlNode.Akvo_VERSION =  2 #yaml.load( self.logText )["Akvo_VERSION"] #, Loader=yaml.RoundTripLoader) # offending line! 
688
+        #self.YamlNode = AkvoYamlNode( self.logText ) # offending line! 
689
+        #print("import type", type( self.YamlNode.Processing ))
690
+        self.Log() 
674
             #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False)  )
691
             #self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False)  )
675
         #except KeyError:
692
         #except KeyError:
676
         #    pass
693
         #    pass
848
         #for line in nlogText: 
865
         #for line in nlogText: 
849
         #    self.ui.logTextBrowser.append( line )
866
         #    self.ui.logTextBrowser.append( line )
850
         #    self.logText.append( line ) 
867
         #    self.logText.append( line ) 
851
-            
852
-        self.ui.logTextBrowser.clear() 
868
+        self.ui.logTextBrowser.clear()
853
         self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False)  )
869
         self.ui.logTextBrowser.append( yaml.dump(self.YamlNode)) #, default_flow_style=False)  )
854
 
870
 
855
     def disable(self):
871
     def disable(self):
954
 
970
 
955
     def calcQ(self):
971
     def calcQ(self):
956
         if "Calc Q" not in self.YamlNode.Processing.keys():
972
         if "Calc Q" not in self.YamlNode.Processing.keys():
973
+            print("In CalcQ", yaml.dump(self.YamlNode.Processing)  )
957
             self.YamlNode.Processing["Calc Q"] = True
974
             self.YamlNode.Processing["Calc Q"] = True
975
+            print( yaml.dump(self.YamlNode.Processing)  )
958
             self.Log()
976
             self.Log()
959
         else:
977
         else:
960
             err_msg = "Q values have already been calculated"
978
             err_msg = "Q values have already been calculated"

+ 31
- 30
akvo/tressel/rotate.py View File

133
 
133
 
134
 def gateIntegrate(T2D, T2T, gpd, sigma, stackEfficiency=2.):
134
 def gateIntegrate(T2D, T2T, gpd, sigma, stackEfficiency=2.):
135
     """ Gate integrate the signal to gpd, gates per decade
135
     """ Gate integrate the signal to gpd, gates per decade
136
+        T2D = the time series to gate integrate, complex 
137
+        T2T = the abscissa values 
138
+        gpd = gates per decade 
139
+        sigma = estimate of standard deviation for theoretical gate noise 
140
+        stackEfficiency = exponential in theoretical gate noise, 2 represents ideal stacking
136
     """
141
     """
137
     
142
     
138
     # use artificial time gates so that early times are fully captured
143
     # use artificial time gates so that early times are fully captured
140
     T2TD = T2T[0] - (T2T[1]-T2T[0])
145
     T2TD = T2T[0] - (T2T[1]-T2T[0])
141
     T2T -= T2TD
146
     T2T -= T2TD
142
     
147
     
143
-    # calculate total number of decades
144
-    nd = np.log10(T2T[-1]/T2T[0]) #np.log10(self.T2T[-1]) -  np.log10(self.T2T[-1])
148
+    #####################################
149
+    # calculate total number of decades #
150
+    # windows edges are approximate until binning but will be adjusted to reflect data timing, this 
151
+    # primarily impacts bins with a few samples  
152
+    nd = np.log10(T2T[-1]/T2T[0])               
145
     tdd = np.logspace( np.log10(T2T[0]), np.log10(T2T[-1]), (int)(gpd*nd)+1, base=10, endpoint=True) 
153
     tdd = np.logspace( np.log10(T2T[0]), np.log10(T2T[-1]), (int)(gpd*nd)+1, base=10, endpoint=True) 
146
-    tdl = tdd[0:-1]     # these are left edges
147
-    tdr = tdd[1::]      # these are left edges
148
-    td = (tdl+tdr) / 2. # window centres
154
+    tdl = tdd[0:-1]                 # approximate window left edges
155
+    tdr = tdd[1::]                  # approximate window right edges
156
+    td = (tdl+tdr) / 2.             # approximate window centres
149
 
157
 
150
-    Vars = np.ones( len(td) ) * sigma**2 #* .15**2
158
+
159
+    Vars = np.zeros( len(td) ) 
151
     htd = np.zeros( len(td), dtype=complex )
160
     htd = np.zeros( len(td), dtype=complex )
152
-    isum = np.zeros( len(td) )
153
-    ii = 0
161
+    isum = np.zeros( len(td), dtype=int )  
154
 
162
 
155
-    SIGSTACK = {}
156
-    SIGSTACK[ii]= []
163
+    ii = 0
157
     for itd in range(len(T2T)):
164
     for itd in range(len(T2T)):
158
         if ( T2T[itd] > tdr[ii] ):
165
         if ( T2T[itd] > tdr[ii] ):
159
-            if (ii < len(td)-1):
160
-                ii += 1
161
-                SIGSTACK[ii] = []
162
-            else:
163
-                #print "overshoot??", ii
164
-                break
166
+            ii += 1
167
+            # correct window edges to centre about data 
168
+            tdr[ii-1] = (T2T[itd-1]+T2T[itd])*.5 
169
+            tdl[ii  ] = (T2T[itd-1]+T2T[itd])*.5
165
         isum[ii] += 1
170
         isum[ii] += 1
166
         htd[ii] += T2D[ itd ]
171
         htd[ii] += T2D[ itd ]
167
-        SIGSTACK[ii].append(T2D[itd])
168
         Vars[ii] += sigma**2
172
         Vars[ii] += sigma**2
173
+        
174
+    td = (tdl+tdr) / 2.             # actual window centres
175
+    sigma2 = np.sqrt( Vars * ((1/(isum))**stackEfficiency) ) 
169
 
176
 
170
-    sigma = np.sqrt( Vars  * (1/isum)**stackEfficiency ) 
171
-    for ii in range(len(td)):
172
-        if len(SIGSTACK[ii]) > 30:
173
-            sigma[ii] = np.var(SIGSTACK[ii]) / ((len(SIGSTACK[ii])-1)**(1/stackEfficiency))
174
-            #sigma[ii] = np.std(SIGSTACK[ii]) * ( 1./(len(SIGSTACK[ii]))**stackEfficiency)
177
+    # Reset abscissa where isum == 1 
178
+    # when there is no windowing going on 
179
+    td[isum==1] = T2T[0:len(td)][isum==1]
175
 
180
 
176
-    # RESET times where isum == 1
177
-    ii = 0
178
-    while (isum[ii] == 1):
179
-        td[ii] = T2T[ii]
180
-        ii += 1
181
+    tdd = np.append(tdl, tdr[-1])
181
 
182
 
182
-    htd /= isum
183
-    T2T += T2TD  
184
-    return td+T2TD, htd, tdd+T2TD, sigma, isum  # centre abscissa, data, window edges, error  
183
+    htd /= isum # average
184
+    T2T += T2TD 
185
+    return td+T2TD, htd, tdd+T2TD, sigma2, isum  # centre abscissa, data, window edges, error 
185
 
186
 
186
 if __name__ == "__main__":
187
 if __name__ == "__main__":
187
 
188
 

Loading…
Cancel
Save