Browse Source

OrderedDict used to preserve processing flow

HEAD
T-bone 7 years ago
parent
commit
6cbab34210
2 changed files with 120 additions and 58 deletions
  1. 114
    55
      akvo/gui/akvoGUI.py
  2. 6
    3
      akvo/gui/main.ui

+ 114
- 55
akvo/gui/akvoGUI.py View File

@@ -53,17 +53,28 @@ class VectorXr(yaml.YAMLObject):
53 53
         # Converts to numpy array on import 
54 54
         return "np.array(%r)" % (self.data)
55 55
 
56
+from collections import OrderedDict
57
+def represent_ordereddict(dumper, data):
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
+
56 66
 class AkvoYamlNode(yaml.YAMLObject):
57 67
     yaml_tag = u'!AkvoData'
58 68
     def __init__(self):
59 69
         self.Akvo_VERSION = version
60 70
         self.Import = {}
61
-        self.Processing = {}
71
+        self.Processing = OrderedDict() 
72
+        #self.ProcessingFlow = []
62 73
         #self.data = {}
63 74
     # For going the other way, data import based on Yaml serialization, 
64 75
     def __repr__(self):
65 76
         return "%s(name=%r, Akvo_VESION=%r, Import=%r, Processing=%r)" % (
66
-            self.__class__.__name__, self.Akvo_VERSION, self.Import, self.Processing) #self.name, self.hp, self.ac, self.attacks, self.thingy)
77
+            self.__class__.__name__, self.Akvo_VERSION, self.Import, OrderedDict(dict(self.Processing)) ) 
67 78
     
68 79
 try:    
69 80
     import thread 
@@ -416,7 +427,8 @@ class ApplicationWindow(QtWidgets.QMainWindow):
416 427
             self.ui.FIDProcComboBox.setCurrentIndex (0)
417 428
     
418 429
     def ExportPreprocess(self):
419
-
430
+        """ This method export to YAML 
431
+        """
420 432
         try:
421 433
             with open('.akvo.last.yaml.path') as f: 
422 434
                 fpath = f.readline()  
@@ -443,8 +455,6 @@ class ApplicationWindow(QtWidgets.QMainWindow):
443 455
         #INFO["deadTime"] = self.RAWDataProc.deadTime
444 456
         INFO["transFreq"] = self.RAWDataProc.transFreq.tolist()
445 457
         INFO["processed"] = "Akvo v. 1.0, on " + time.strftime("%d/%m/%Y")
446
-        #INFO["log"] = self.logText   #MAK 20170128 # TI moved to direct write, this is already YAML compliant 
447
-
448 458
         # Pulse current info
449 459
         ip = 0
450 460
         INFO["Pulses"] = {}
@@ -875,35 +885,56 @@ class ApplicationWindow(QtWidgets.QMainWindow):
875 885
                 self.ui.mplwidget))
876 886
 
877 887
     def calcQ(self):
888
+        if "Calc Q" not in self.YamlNode.Processing.keys():
889
+            self.YamlNode.Processing["Calc Q"] = True
890
+            self.Log()
891
+        else:
892
+            err_msg = "Q values have already been calculated"
893
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
894
+                err_msg) 
895
+            return 
896
+
878 897
         self.lock("pulse moment calculation")
879 898
         thread.start_new_thread(self.RAWDataProc.effectivePulseMoment, \
880 899
                 (self.ui.CentralVSpinBox.value(), \
881 900
                 self.ui.mplwidget_2))
882 901
 
883 902
     def FDSmartStack(self):
903
+
904
+        if "TD stack" not in self.YamlNode.Processing.keys():
905
+            self.YamlNode.Processing["TD stack"] = {}
906
+            self.YamlNode.Processing["TD stack"]["outlier"] = str( self.ui.outlierTestCB.currentText() ) 
907
+            self.YamlNode.Processing["TD stack"]["cutoff"] = str( self.ui.MADCutoff.value() )
908
+            self.Log()
909
+        else:
910
+            err_msg = "TD noise cancellation has already been applied!"
911
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
912
+                err_msg) 
913
+            return 
884 914
         
885 915
         self.lock("time-domain smart stack")
886
-        nlogText = []
887
-        nlogText.append("TD_stack: ") 
888
-        nlogText.append("  outlier: " + str( self.ui.outlierTestCB.currentText() ) ) 
889
-        nlogText.append("  cutoff: " + str( self.ui.MADCutoff.value()  ) ) 
890
-        self.Log(nlogText)
891
-        
892 916
         thread.start_new_thread(self.RAWDataProc.TDSmartStack, \
893 917
                 (str(self.ui.outlierTestCB.currentText()), \
894 918
                 self.ui.MADCutoff.value(),
895 919
                 self.ui.mplwidget_2))
896 920
 
897 921
     def adaptFilter(self):
922
+
923
+        if "TD noise cancellation" not in self.YamlNode.Processing.keys():
924
+            self.YamlNode.Processing["TD noise cancellation"] = {}
925
+            self.YamlNode.Processing["TD noise cancellation"]["n_Taps"] = str(self.ui.MTapsSpinBox.value())
926
+            self.YamlNode.Processing["TD noise cancellation"]["lambda"] = str(self.ui.adaptLambdaSpinBox.value())
927
+            self.YamlNode.Processing["TD noise cancellation"]["truncate"] = str(self.ui.adaptTruncateSpinBox.value())
928
+            self.YamlNode.Processing["TD noise cancellation"]["mu"] = str(self.ui.adaptMuSpinBox.value()) 
929
+            self.YamlNode.Processing["TD noise cancellation"]["PCA"] = str(self.ui.PCAComboBox.currentText())
930
+            self.Log()
931
+        else:
932
+            err_msg = "TD noise cancellation has already been applied!"
933
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
934
+                err_msg) 
935
+            return 
936
+        
898 937
         self.lock("TD noise cancellation filter")
899
-        nlogText = []
900
-        nlogText.append("TD_noise_cancellation: ") 
901
-        nlogText.append("  n_Taps: " + str(self.ui.MTapsSpinBox.value()) ) 
902
-        nlogText.append("  lambda: " + str(self.ui.adaptLambdaSpinBox.value()) ) 
903
-        nlogText.append("  truncate: " + str(self.ui.adaptTruncateSpinBox.value()) ) 
904
-        nlogText.append("  mu: " + str(self.ui.adaptMuSpinBox.value()) ) 
905
-        nlogText.append("  PCA: " + str(self.ui.PCAComboBox.currentText()) ) 
906
-        self.Log(nlogText)
907 938
         thread.start_new_thread(self.RAWDataProc.adaptiveFilter, \
908 939
                 (self.ui.MTapsSpinBox.value(), \
909 940
                 self.ui.adaptLambdaSpinBox.value(), \
@@ -913,11 +944,17 @@ class ApplicationWindow(QtWidgets.QMainWindow):
913 944
                 self.ui.mplwidget))
914 945
 
915 946
     def sumDataChans(self): 
947
+
948
+        if "Data sum" not in self.YamlNode.Processing.keys():
949
+            self.YamlNode.Processing["Data sum"] = True
950
+            self.Log()
951
+        else:
952
+            err_msg = "Data channels have already been summed!"
953
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
954
+                err_msg) 
955
+            return 
956
+
916 957
         self.lock("Summing data channels")
917
-        nlogText = []
918
-        nlogText.append("Data_sum: ") 
919
-        nlogText.append( "  summed_channel: " +  str(self.dataChan[0]) ) 
920
-        self.Log(nlogText)
921 958
         self.dataChan = [self.dataChan[0]]
922 959
         self.ui.sumDataBox.setEnabled(False)    
923 960
         thread.start_new_thread( self.RAWDataProc.sumData, ( self.ui.mplwidget, 7 ) )
@@ -931,17 +968,21 @@ class ApplicationWindow(QtWidgets.QMainWindow):
931 968
                 self.ui.mplwidget))
932 969
 
933 970
     def bandPassFilter(self):
934
-        self.lock("bandpass filter")
935
-        nlogText = []
936
-        nlogText.append("bandpass_filter: ") 
937
-        nlogText.append("  central_nu: "+str(self.ui.CentralVSpinBox.value()))
938
-        nlogText.append("  passband: "+str(self.ui.passBandSpinBox.value()) )
939
-        nlogText.append("  stopband: "+str(self.ui.stopBandSpinBox.value()) )
940
-        nlogText.append("  gpass: "+str(self.ui.gpassSpinBox.value()) )
941
-        nlogText.append("  gstop: "+str(self.ui.gstopSpinBox.value()) )
942
-        nlogText.append("  type: "+str(self.ui.fTypeComboBox.currentText()) )
943
-        self.Log(nlogText) 
944
-        
971
+        if "Bandpass filter" not in self.YamlNode.Processing.keys():
972
+            self.YamlNode.Processing["Bandpass filter"] = {}
973
+            self.YamlNode.Processing["Bandpass filter"]["central_nu"] = str(self.ui.CentralVSpinBox.value())
974
+            self.YamlNode.Processing["Bandpass filter"]["passband"] = str(self.ui.passBandSpinBox.value())
975
+            self.YamlNode.Processing["Bandpass filter"]["stopband"] = str(self.ui.stopBandSpinBox.value()) 
976
+            self.YamlNode.Processing["Bandpass filter"]["gpass"] = str(self.ui.gpassSpinBox.value())
977
+            self.YamlNode.Processing["Bandpass filter"]["gstop"] = str(self.ui.gstopSpinBox.value())
978
+            self.YamlNode.Processing["Bandpass filter"]["type"] = str(self.ui.fTypeComboBox.currentText())
979
+            self.Log()
980
+        else:
981
+            err_msg = "Bandpass filter has already been applied!"
982
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
983
+                err_msg) 
984
+            return 
985
+        self.lock("bandpass filter")        
945 986
         nv = self.ui.lcdTotalDeadTime.value( ) + self.ui.lcdNumberFTauDead.value()
946 987
         self.ui.lcdTotalDeadTime.display( nv )
947 988
         thread.start_new_thread(self.RAWDataProc.bandpassFilter, \
@@ -949,23 +990,33 @@ class ApplicationWindow(QtWidgets.QMainWindow):
949 990
 
950 991
     def downsample(self):
951 992
         self.lock("resampling")
952
-        nlogText = list(['Resample: '])
953
-        nlogText.append("  downsample_factor: " + str(self.ui.downSampleSpinBox.value() ) )
954
-        nlogText.append("  truncate_length: " + str( self.ui.truncateSpinBox.value() ) )
955
-        self.Log(nlogText)
993
+        
994
+        if "Resample" not in self.YamlNode.Processing.keys():
995
+            self.YamlNode.Processing["Resample"] = {}
996
+            self.YamlNode.Processing["Resample"]["downsample factor"] = [] 
997
+            self.YamlNode.Processing["Resample"]["truncate length"] = []  
998
+        self.YamlNode.Processing["Resample"]["downsample factor"].append( str(self.ui.downSampleSpinBox.value() ) )
999
+        self.YamlNode.Processing["Resample"]["truncate length"].append(  str( self.ui.truncateSpinBox.value() ) )
1000
+        self.Log( )
1001
+        
956 1002
         thread.start_new_thread(self.RAWDataProc.downsample, \
957 1003
                 (self.ui.truncateSpinBox.value(), \
958 1004
                 self.ui.downSampleSpinBox.value(),
959 1005
                 self.ui.mplwidget))
960 1006
 
961 1007
     def quadDet(self):
962
-        self.lock("quadrature detection")
963
-        nlogText = []
964
-        nlogText.append("quadrature_detection: ") 
965
-        nlogText.append("  trim: " + str( self.ui.trimSpin.value() )) 
966
-        #nlogText.append("  representation:" + str(  self.ui.QDType.currentText() )) 
967
-        self.Log(nlogText)
968 1008
 
1009
+        if "Quadrature detection" not in self.YamlNode.Processing.keys():
1010
+            self.YamlNode.Processing["Quadrature detection"] = {}
1011
+            self.YamlNode.Processing["Quadrature detection"]["trim"] = str( self.ui.trimSpin.value() )
1012
+            self.Log()
1013
+        else:
1014
+            err_msg = "Quadrature detection has already been done!"
1015
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
1016
+                err_msg) 
1017
+            return 
1018
+
1019
+        self.lock("quadrature detection")
969 1020
         thread.start_new_thread(self.RAWDataProc.quadDet, \
970 1021
                 (self.ui.trimSpin.value(), int(self.ui.QDType.currentIndex()), self.ui.mplwidget_2))
971 1022
 
@@ -979,12 +1030,13 @@ class ApplicationWindow(QtWidgets.QMainWindow):
979 1030
 
980 1031
 
981 1032
     def gateIntegrate(self):
982
-        self.lock("gate integration")
983
-        nlogText = []
984
-        nlogText.append("gate_integrate: ") 
985
-        nlogText.append("  gpd: " + str(self.ui.GPDspinBox.value( ) )) 
986
-        self.Log(nlogText)
1033
+        
1034
+        if "Gate integrate" not in self.YamlNode.Processing.keys():
1035
+            self.YamlNode.Processing["Gate integrate"] = {}
1036
+        self.YamlNode.Processing["Gate integrate"]["gpd"] = str(self.ui.GPDspinBox.value( ) )
1037
+        self.Log()
987 1038
  
1039
+        self.lock("gate integration")
988 1040
         thread.start_new_thread(self.RAWDataProc.gateIntegrate, \
989 1041
                 (self.ui.GPDspinBox.value(), self.ui.trimSpin.value(), self.ui.mplwidget_2))
990 1042
         
@@ -1013,13 +1065,20 @@ class ApplicationWindow(QtWidgets.QMainWindow):
1013 1065
         #   self.ui.lcdNumberTauPulse2.display(1e3*self.RAWDataProc.pulseLength[1])
1014 1066
     
1015 1067
     def windowFilter(self):
1068
+        
1069
+        if "Window filter" not in self.YamlNode.Processing.keys():
1070
+            self.YamlNode.Processing["Window filter"] = {}
1071
+            self.YamlNode.Processing["Window filter"]["type"] = str(self.ui.windowTypeComboBox.currentText()) 
1072
+            self.YamlNode.Processing["Window filter"]["width"] = str(self.ui.windowBandwidthSpinBox.value()) 
1073
+            self.YamlNode.Processing["Window filter"]["centre"] = str(self.ui.CentralVSpinBox.value() )
1074
+            self.Log()
1075
+        else:
1076
+            err_msg = "FD window has already been applied!"
1077
+            reply =QtWidgets.QMessageBox.critical(self, 'Error', 
1078
+                err_msg) 
1079
+            return 
1080
+
1016 1081
         self.lock("window filter")
1017
-        nlogText = []
1018
-        nlogText.append("FD_window: ") 
1019
-        nlogText.append("  type: " + str(self.ui.windowTypeComboBox.currentText()) )
1020
-        nlogText.append("  width: " + str(self.ui.windowBandwidthSpinBox.value()) )  
1021
-        nlogText.append("  centre: " + str(self.ui.CentralVSpinBox.value() ))
1022
-        self.Log(nlogText)
1023 1082
         thread.start_new_thread(self.RAWDataProc.windowFilter, \
1024 1083
                 (str(self.ui.windowTypeComboBox.currentText()), \
1025 1084
                 self.ui.windowBandwidthSpinBox.value(), \

+ 6
- 3
akvo/gui/main.ui View File

@@ -73,8 +73,8 @@
73 73
         <rect>
74 74
          <x>0</x>
75 75
          <y>0</y>
76
-         <width>982</width>
77
-         <height>921</height>
76
+         <width>966</width>
77
+         <height>919</height>
78 78
         </rect>
79 79
        </property>
80 80
        <layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -1298,6 +1298,9 @@ background: dark grey;
1298 1298
                <height>25</height>
1299 1299
               </rect>
1300 1300
              </property>
1301
+             <property name="minimum">
1302
+              <number>1</number>
1303
+             </property>
1301 1304
              <property name="maximum">
1302 1305
               <number>5</number>
1303 1306
              </property>
@@ -3124,7 +3127,7 @@ p, li { white-space: pre-wrap; }
3124 3127
      <x>0</x>
3125 3128
      <y>0</y>
3126 3129
      <width>1000</width>
3127
-     <height>19</height>
3130
+     <height>20</height>
3128 3131
     </rect>
3129 3132
    </property>
3130 3133
    <widget class="QMenu" name="menuFile">

Loading…
Cancel
Save