瀏覽代碼

Cleanup of Harmonic modelling, only 1 frequency currently allowed.

tags/1.6.1
Trevor Irons 5 年之前
父節點
當前提交
2fc0bf5501
共有 5 個文件被更改,包括 258 次插入94 次删除
  1. 22
    6
      akvo/gui/akvoGUI.py
  2. 188
    37
      akvo/gui/main.ui
  3. 29
    47
      akvo/tressel/harmonic.py
  4. 18
    3
      akvo/tressel/mrsurvey.py
  5. 1
    1
      setup.py

+ 22
- 6
akvo/gui/akvoGUI.py 查看文件

168
         self.ui.calcQGO.pressed.connect( self.calcQ )
168
         self.ui.calcQGO.pressed.connect( self.calcQ )
169
         self.ui.FDSmartStackGO.pressed.connect( self.FDSmartStack )
169
         self.ui.FDSmartStackGO.pressed.connect( self.FDSmartStack )
170
         self.ui.harmonicGO.pressed.connect( self.harmonicModel )       
170
         self.ui.harmonicGO.pressed.connect( self.harmonicModel )       
171
+
172
+        self.ui.f0K1Spin.valueChanged.connect( self.LCDHarmonics )
173
+        self.ui.f0KNSpin.valueChanged.connect( self.LCDHarmonics )
174
+        self.ui.f0KsSpin.valueChanged.connect( self.LCDHarmonics )
175
+        self.ui.f0Spin.valueChanged.connect( self.LCDHarmonics )
171
  
176
  
172
         self.ui.plotQD.setEnabled(False) 
177
         self.ui.plotQD.setEnabled(False) 
173
         self.ui.plotQD.pressed.connect( self.plotQD )
178
         self.ui.plotQD.pressed.connect( self.plotQD )
228
         self.ui.loopTableWidget.setDragEnabled(False)
233
         self.ui.loopTableWidget.setDragEnabled(False)
229
         #self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
234
         #self.ui.loopTableWidget.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
230
 
235
 
231
-        self.loops = {}        
236
+        self.loops = {}          
232
 
237
 
233
         ##########################################################################
238
         ##########################################################################
234
         # layer Table 
239
         # layer Table 
254
                 self.ui.layerTableWidget.setItem(ir, ic, pCell)
259
                 self.ui.layerTableWidget.setItem(ir, ic, pCell)
255
         self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged) 
260
         self.ui.layerTableWidget.cellChanged.connect(self.sigmaCellChanged) 
256
 
261
 
262
+    def LCDHarmonics(self):
263
+        self.ui.lcdH1F.setEnabled(True)
264
+        self.ui.lcdH1F.display( self.ui.f0Spin.value() * self.ui.f0K1Spin.value() )
265
+        self.ui.lcdHNF.setEnabled(True)
266
+        self.ui.lcdHNF.display( self.ui.f0Spin.value() * self.ui.f0KNSpin.value() )
267
+        self.ui.lcdf0NK.setEnabled(True)
268
+        self.ui.lcdf0NK.display( (self.ui.f0KNSpin.value()+1-self.ui.f0K1Spin.value()) * self.ui.f0KsSpin.value() )
269
+
257
     def closeTabs(self):
270
     def closeTabs(self):
258
         #self.ui.ProcTabs.removeTab(idx)    
271
         #self.ui.ProcTabs.removeTab(idx)    
259
         self.ui.ProcTabs.clear( )    
272
         self.ui.ProcTabs.clear( )    
1084
 
1097
 
1085
     def harmonicModel(self):
1098
     def harmonicModel(self):
1086
 
1099
 
1087
-
1088
         if "Harmonic modelling" not in self.YamlNode.Processing.keys():
1100
         if "Harmonic modelling" not in self.YamlNode.Processing.keys():
1089
             self.YamlNode.Processing["Harmonic modelling"] = {}
1101
             self.YamlNode.Processing["Harmonic modelling"] = {}
1090
             self.YamlNode.Processing["Harmonic modelling"]["NF"] = str( self.ui.NHarmonicsFreqsSpin.value() ) 
1102
             self.YamlNode.Processing["Harmonic modelling"]["NF"] = str( self.ui.NHarmonicsFreqsSpin.value() ) 
1091
-            self.YamlNode.Processing["Harmonic modelling"]["Nk"] = str( self.ui.NKHarmonicsSpin.value() )
1092
-            self.YamlNode.Processing["Harmonic modelling"]["f0"] = str( self.ui.f0Spin.value() )
1103
+            self.YamlNode.Processing["Harmonic modelling"]["f0K1"] = str( self.ui.f0K1Spin.value() )
1104
+            self.YamlNode.Processing["Harmonic modelling"]["f0KN"] = str( self.ui.f0KNSpin.value() )
1105
+            self.YamlNode.Processing["Harmonic modelling"]["f0Ks"] = str( self.ui.f0KsSpin.value() )
1093
             self.YamlNode.Processing["Harmonic modelling"]["f1"] = str( self.ui.f1Spin.value() )
1106
             self.YamlNode.Processing["Harmonic modelling"]["f1"] = str( self.ui.f1Spin.value() )
1094
             self.YamlNode.Processing["Harmonic modelling"]["Segments"] = str( 1 ) # Future 
1107
             self.YamlNode.Processing["Harmonic modelling"]["Segments"] = str( 1 ) # Future 
1095
             self.Log()
1108
             self.Log()
1104
         thread.start_new_thread(self.RAWDataProc.harmonicModel, \
1117
         thread.start_new_thread(self.RAWDataProc.harmonicModel, \
1105
                 ( \
1118
                 ( \
1106
                  self.ui.NHarmonicsFreqsSpin.value(), \
1119
                  self.ui.NHarmonicsFreqsSpin.value(), \
1107
-                 self.ui.NKHarmonicsSpin.value(), \
1108
                  self.ui.f0Spin.value(), \
1120
                  self.ui.f0Spin.value(), \
1121
+                 self.ui.f0K1Spin.value(), \
1122
+                 self.ui.f0KNSpin.value(), \
1123
+                 self.ui.f0KsSpin.value(), \
1109
                  self.ui.f1Spin.value(), \
1124
                  self.ui.f1Spin.value(), \
1110
                  self.ui.plotHarmonic.isChecked(), \
1125
                  self.ui.plotHarmonic.isChecked(), \
1111
-                 self.ui.mplwidget) \
1126
+                 self.ui.mplwidget \
1127
+                ) \
1112
         )
1128
         )
1113
 
1129
 
1114
     def FDSmartStack(self):
1130
     def FDSmartStack(self):

+ 188
- 37
akvo/gui/main.ui 查看文件

1005
               <property name="maximumSize">
1005
               <property name="maximumSize">
1006
                <size>
1006
                <size>
1007
                 <width>16777215</width>
1007
                 <width>16777215</width>
1008
-                <height>200</height>
1008
+                <height>350</height>
1009
                </size>
1009
                </size>
1010
               </property>
1010
               </property>
1011
               <property name="toolTip">
1011
               <property name="toolTip">
1021
                <bool>true</bool>
1021
                <bool>true</bool>
1022
               </property>
1022
               </property>
1023
               <layout class="QGridLayout" name="gridLayout_9">
1023
               <layout class="QGridLayout" name="gridLayout_9">
1024
-               <item row="2" column="0">
1025
-                <widget class="QLabel" name="label_25">
1024
+               <item row="1" column="2">
1025
+                <widget class="Line" name="line_2">
1026
+                 <property name="orientation">
1027
+                  <enum>Qt::Horizontal</enum>
1028
+                 </property>
1029
+                </widget>
1030
+               </item>
1031
+               <item row="8" column="1">
1032
+                <widget class="Line" name="line_8">
1033
+                 <property name="orientation">
1034
+                  <enum>Qt::Horizontal</enum>
1035
+                 </property>
1036
+                </widget>
1037
+               </item>
1038
+               <item row="5" column="0">
1039
+                <widget class="QLabel" name="label_33">
1040
+                 <property name="text">
1041
+                  <string>Sub-harmonics </string>
1042
+                 </property>
1043
+                </widget>
1044
+               </item>
1045
+               <item row="7" column="1">
1046
+                <widget class="QDoubleSpinBox" name="f1Spin">
1047
+                 <property name="maximum">
1048
+                  <double>25000.000000000000000</double>
1049
+                 </property>
1050
+                 <property name="value">
1051
+                  <double>60.000000000000000</double>
1052
+                 </property>
1053
+                </widget>
1054
+               </item>
1055
+               <item row="8" column="2">
1056
+                <widget class="Line" name="line_9">
1057
+                 <property name="orientation">
1058
+                  <enum>Qt::Horizontal</enum>
1059
+                 </property>
1060
+                </widget>
1061
+               </item>
1062
+               <item row="3" column="0">
1063
+                <widget class="QLabel" name="label_11">
1026
                  <property name="text">
1064
                  <property name="text">
1027
-                  <string>Base freq.</string>
1065
+                  <string>First harmonic 1</string>
1066
+                 </property>
1067
+                </widget>
1068
+               </item>
1069
+               <item row="6" column="1">
1070
+                <widget class="Line" name="line_5">
1071
+                 <property name="orientation">
1072
+                  <enum>Qt::Horizontal</enum>
1028
                  </property>
1073
                  </property>
1029
                 </widget>
1074
                 </widget>
1030
                </item>
1075
                </item>
1031
                <item row="1" column="1">
1076
                <item row="1" column="1">
1032
-                <widget class="QSpinBox" name="NKHarmonicsSpin">
1033
-                 <property name="minimum">
1034
-                  <number>5</number>
1077
+                <widget class="Line" name="line">
1078
+                 <property name="orientation">
1079
+                  <enum>Qt::Horizontal</enum>
1035
                  </property>
1080
                  </property>
1036
-                 <property name="maximum">
1037
-                  <number>50</number>
1081
+                </widget>
1082
+               </item>
1083
+               <item row="8" column="0">
1084
+                <widget class="Line" name="line_7">
1085
+                 <property name="orientation">
1086
+                  <enum>Qt::Horizontal</enum>
1087
+                 </property>
1088
+                </widget>
1089
+               </item>
1090
+               <item row="10" column="1">
1091
+                <widget class="QCheckBox" name="plotHarmonic">
1092
+                 <property name="text">
1093
+                  <string>Plot</string>
1094
+                 </property>
1095
+                 <property name="checked">
1096
+                  <bool>true</bool>
1097
+                 </property>
1098
+                </widget>
1099
+               </item>
1100
+               <item row="6" column="2">
1101
+                <widget class="Line" name="line_6">
1102
+                 <property name="orientation">
1103
+                  <enum>Qt::Horizontal</enum>
1104
+                 </property>
1105
+                </widget>
1106
+               </item>
1107
+               <item row="4" column="2">
1108
+                <widget class="QLCDNumber" name="lcdHNF">
1109
+                 <property name="styleSheet">
1110
+                  <string notr="true">#lcdHNF {
1111
+  color: green;
1112
+  background: black;
1113
+}
1114
+
1115
+#lcdHNF:disabled {
1116
+  color: grey;
1117
+  background: dark grey;
1118
+}</string>
1119
+                 </property>
1120
+                </widget>
1121
+               </item>
1122
+               <item row="4" column="1">
1123
+                <widget class="QSpinBox" name="f0KNSpin">
1124
+                 <property name="minimum">
1125
+                  <number>2</number>
1038
                  </property>
1126
                  </property>
1039
                  <property name="value">
1127
                  <property name="value">
1040
                   <number>40</number>
1128
                   <number>40</number>
1041
                  </property>
1129
                  </property>
1042
                 </widget>
1130
                 </widget>
1043
                </item>
1131
                </item>
1132
+               <item row="2" column="0">
1133
+                <widget class="QLabel" name="label_25">
1134
+                 <property name="text">
1135
+                  <string>Base freq. 1</string>
1136
+                 </property>
1137
+                </widget>
1138
+               </item>
1044
                <item row="2" column="1">
1139
                <item row="2" column="1">
1045
                 <widget class="QDoubleSpinBox" name="f0Spin">
1140
                 <widget class="QDoubleSpinBox" name="f0Spin">
1046
                  <property name="maximum">
1141
                  <property name="maximum">
1054
                  </property>
1149
                  </property>
1055
                 </widget>
1150
                 </widget>
1056
                </item>
1151
                </item>
1057
-               <item row="3" column="1">
1058
-                <widget class="QDoubleSpinBox" name="f1Spin">
1059
-                 <property name="maximum">
1060
-                  <double>25000.000000000000000</double>
1061
-                 </property>
1062
-                 <property name="value">
1063
-                  <double>60.000000000000000</double>
1152
+               <item row="3" column="2">
1153
+                <widget class="QLCDNumber" name="lcdH1F">
1154
+                 <property name="styleSheet">
1155
+                  <string notr="true">#lcdH1F {
1156
+  color: green;
1157
+  background: black;
1158
+}
1159
+
1160
+#lcdH1F:disabled {
1161
+  color: grey;
1162
+  background: dark grey;
1163
+}</string>
1064
                  </property>
1164
                  </property>
1065
                 </widget>
1165
                 </widget>
1066
                </item>
1166
                </item>
1067
-               <item row="0" column="0">
1068
-                <widget class="QLabel" name="label_26">
1167
+               <item row="7" column="0">
1168
+                <widget class="QLabel" name="label_27">
1069
                  <property name="text">
1169
                  <property name="text">
1070
-                  <string>N freqs</string>
1170
+                  <string>Base freq. 2 </string>
1071
                  </property>
1171
                  </property>
1072
                 </widget>
1172
                 </widget>
1073
                </item>
1173
                </item>
1077
                   <number>1</number>
1177
                   <number>1</number>
1078
                  </property>
1178
                  </property>
1079
                  <property name="maximum">
1179
                  <property name="maximum">
1080
-                  <number>2</number>
1180
+                  <number>1</number>
1081
                  </property>
1181
                  </property>
1082
                  <property name="value">
1182
                  <property name="value">
1083
                   <number>1</number>
1183
                   <number>1</number>
1084
                  </property>
1184
                  </property>
1085
                 </widget>
1185
                 </widget>
1086
                </item>
1186
                </item>
1087
-               <item row="1" column="0">
1088
-                <widget class="QLabel" name="label_11">
1089
-                 <property name="text">
1090
-                  <string>N harmonics</string>
1187
+               <item row="6" column="0">
1188
+                <widget class="Line" name="line_4">
1189
+                 <property name="orientation">
1190
+                  <enum>Qt::Horizontal</enum>
1091
                  </property>
1191
                  </property>
1092
                 </widget>
1192
                 </widget>
1093
                </item>
1193
                </item>
1094
-               <item row="3" column="0">
1095
-                <widget class="QLabel" name="label_27">
1194
+               <item row="4" column="0">
1195
+                <widget class="QLabel" name="label_31">
1096
                  <property name="text">
1196
                  <property name="text">
1097
-                  <string>Base freq. 2 </string>
1197
+                  <string>Last harmonic 1</string>
1098
                  </property>
1198
                  </property>
1099
                 </widget>
1199
                 </widget>
1100
                </item>
1200
                </item>
1101
-               <item row="3" column="2">
1201
+               <item row="5" column="1">
1202
+                <widget class="QSpinBox" name="f0KsSpin">
1203
+                 <property name="toolTip">
1204
+                  <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Would you like to calculate subharmonics? For instance, setting this to 1, will calculate only the exact harmonics, setting this to 2 will calculate 1/2 step subharmonics (i.e. if the baseline frequency is 60 Hz, this will result in calcualtion of 30 Hz subharmonics)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1205
+                 </property>
1206
+                 <property name="minimum">
1207
+                  <number>1</number>
1208
+                 </property>
1209
+                 <property name="maximum">
1210
+                  <number>3</number>
1211
+                 </property>
1212
+                 <property name="value">
1213
+                  <number>1</number>
1214
+                 </property>
1215
+                </widget>
1216
+               </item>
1217
+               <item row="1" column="0">
1218
+                <widget class="Line" name="line_3">
1219
+                 <property name="orientation">
1220
+                  <enum>Qt::Horizontal</enum>
1221
+                 </property>
1222
+                </widget>
1223
+               </item>
1224
+               <item row="10" column="2">
1102
                 <widget class="QPushButton" name="harmonicGO">
1225
                 <widget class="QPushButton" name="harmonicGO">
1103
                  <property name="layoutDirection">
1226
                  <property name="layoutDirection">
1104
                   <enum>Qt::LeftToRight</enum>
1227
                   <enum>Qt::LeftToRight</enum>
1112
                  </property>
1235
                  </property>
1113
                 </widget>
1236
                 </widget>
1114
                </item>
1237
                </item>
1115
-               <item row="2" column="2">
1116
-                <widget class="QCheckBox" name="plotHarmonic">
1238
+               <item row="3" column="1">
1239
+                <widget class="QSpinBox" name="f0K1Spin">
1240
+                 <property name="minimum">
1241
+                  <number>1</number>
1242
+                 </property>
1243
+                 <property name="maximum">
1244
+                  <number>50</number>
1245
+                 </property>
1246
+                 <property name="value">
1247
+                  <number>1</number>
1248
+                 </property>
1249
+                </widget>
1250
+               </item>
1251
+               <item row="0" column="0">
1252
+                <widget class="QLabel" name="label_26">
1117
                  <property name="text">
1253
                  <property name="text">
1118
-                  <string>Plot</string>
1254
+                  <string>N freqs</string>
1119
                  </property>
1255
                  </property>
1120
-                 <property name="checked">
1121
-                  <bool>true</bool>
1256
+                </widget>
1257
+               </item>
1258
+               <item row="5" column="2">
1259
+                <widget class="QLCDNumber" name="lcdf0NK">
1260
+                 <property name="styleSheet">
1261
+                  <string notr="true">#lcdf0NK { 
1262
+ color: green;
1263
+ background: black;
1264
+}
1265
+
1266
+#lcdf0NK:disabled {
1267
+  color: grey;
1268
+  background: dark grey;
1269
+}</string>
1270
+                 </property>
1271
+                 <property name="intValue" stdset="0">
1272
+                  <number>0</number>
1122
                  </property>
1273
                  </property>
1123
                 </widget>
1274
                 </widget>
1124
                </item>
1275
                </item>
2273
               <rect>
2424
               <rect>
2274
                <x>0</x>
2425
                <x>0</x>
2275
                <y>0</y>
2426
                <y>0</y>
2276
-               <width>100</width>
2277
-               <height>30</height>
2427
+               <width>96</width>
2428
+               <height>26</height>
2278
               </rect>
2429
               </rect>
2279
              </property>
2430
              </property>
2280
              <attribute name="label">
2431
              <attribute name="label">
2286
               <rect>
2437
               <rect>
2287
                <x>0</x>
2438
                <x>0</x>
2288
                <y>0</y>
2439
                <y>0</y>
2289
-               <width>411</width>
2290
-               <height>77</height>
2440
+               <width>96</width>
2441
+               <height>26</height>
2291
               </rect>
2442
               </rect>
2292
              </property>
2443
              </property>
2293
              <attribute name="label">
2444
              <attribute name="label">

+ 29
- 47
akvo/tressel/harmonic.py 查看文件

4
 from scipy.linalg import lstsq as sclstsq
4
 from scipy.linalg import lstsq as sclstsq
5
 import scipy.linalg as lin
5
 import scipy.linalg as lin
6
 
6
 
7
-def harmonicEuler ( f0, sN, fs, nK, t ): 
7
+#def harmonicEuler ( f0, sN, fs, nK, t ): 
8
+def harmonicEuler ( sN, fs, t, f0, k1, kN, ks ): 
8
     """
9
     """
9
     Performs inverse calculation of harmonics contaminating a signal. 
10
     Performs inverse calculation of harmonics contaminating a signal. 
10
     Args:
11
     Args:
11
-        f0 = base frequency of the sinusoidal noise 
12
         sN = signal containing noise 
12
         sN = signal containing noise 
13
         fs = sampling frequency
13
         fs = sampling frequency
14
-        nK = number of harmonics to calculate 
15
         t = time samples 
14
         t = time samples 
15
+        f0 = base frequency of the sinusoidal noise 
16
+        nK = number of harmonics to calculate 
17
+
16
     """
18
     """
17
     
19
     
18
-    A = np.exp(1j* np.tile( np.arange(1,nK+1),(len(t), 1)) * 2*np.pi* (f0/fs) * np.tile( np.arange(1, len(t)+1, 1),(nK,1)).T  )
20
+    #A = np.exp(1j* np.tile( np.arange(1,nK+1),(len(t), 1)) * 2*np.pi* (f0/fs) * np.tile( np.arange(1, len(t)+1, 1),(nK,1)).T  )
21
+    KK = np.arange(k1, kN+1, 1/ks )
22
+    nK = len(KK)
23
+    A = np.exp(1j* np.tile(KK,(len(t), 1)) * 2*np.pi* (f0/fs) * np.tile( np.arange(1, len(t)+1, 1),(nK,1)).T  )
19
 
24
 
20
     v = np.linalg.lstsq(A, sN, rcond=None) 
25
     v = np.linalg.lstsq(A, sN, rcond=None) 
21
     alpha = np.real(v[0]) 
26
     alpha = np.real(v[0]) 
25
     phase = np.angle(v[0]) 
30
     phase = np.angle(v[0]) 
26
 
31
 
27
     h = np.zeros(len(t))
32
     h = np.zeros(len(t))
28
-    for ik in range(nK):
29
-        h +=  2*amp[ik] * np.cos( 2.*np.pi*(ik+1) * (f0/fs) * np.arange(1, len(t)+1, 1 )  + phase[ik] )
33
+    #for ik in range(nK):
34
+    #    h +=  2*amp[ik] * np.cos( 2.*np.pi*(ik+1) * (f0/fs) * np.arange(1, len(t)+1, 1 )  + phase[ik] )
35
+    for ik, k in enumerate(KK):
36
+        h +=  2*amp[ik] * np.cos( 2.*np.pi*(k) * (f0/fs) * np.arange(1, len(t)+1, 1 )  + phase[ik] )
30
     
37
     
31
     return sN-h
38
     return sN-h
32
     
39
     
33
     res = sN-h # residual 
40
     res = sN-h # residual 
34
 
41
 
35
-    # calculate jacobian 
36
-    #J = jacEuler(f0, sN, fs, nK, t)
37
-    #plt.matshow(np.real(J), aspect='auto')
38
-    
39
-    #Jv = J * np.tile(v[0], (len(t) ,1)) 
40
-    #plt.matshow(np.real(Jv), aspect='auto')
41
-    
42
-    #print ("shape J",  np.shape(J))
43
-    #print ("shape v",  np.shape(v[0]))
44
-    #print ("shape Jv",  np.shape(Jv))
45
-
46
-    #plt.figure()
47
-    #plt.plot(v[0])
48
-    #plt.figure()
49
-    #plt.plot(Jv)
50
-    #plt.show()
51
-    #exit()
52
-
53
-    #jac =  np.linalg.norm( np.dot(Jv.T, res)) 
54
-    #print("norm ||", jac , "||", " at freq", f0)
42
+def harmonicNorm (f0, sN, fs, t, k1, kN, ks): 
43
+    return np.linalg.norm( harmonicEuler(sN, fs, t, f0, k1, kN, ks)) 
55
 
44
 
56
-    #return res, jac 
57
-
58
-
59
-def jacEuler( f0, sN, fs, nK, t):
60
-    print("building Jacobian matrix ")
61
-    J = np.zeros( (len(t),  nK), dtype=np.complex64 )
62
-    for it, tt in enumerate(t):
63
-        for ik, k in enumerate( np.arange(0, nK) ):
64
-            c = 1j*2.*np.pi*(ik+1.)
65
-            J[it, ik] = (c*np.exp(it*c*f0/fs)) / fs 
66
-    return J
45
+def minHarmonic(sN, fs, t, f0, k1, kN, ks):
46
+    # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
47
+    res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, t, k1, kN, ks), jac='2-point', method='BFGS') # hess=None, bounds=None )
48
+    print(res)
49
+    return harmonicEuler(sN, fs, t, res.x[0], k1, kN, ks)#[0]
67
 
50
 
68
 def harmonicEuler2 ( f0, f1, sN, fs, nK, t ): 
51
 def harmonicEuler2 ( f0, f1, sN, fs, nK, t ): 
69
     """
52
     """
93
 
76
 
94
     return sN-h
77
     return sN-h
95
 
78
 
96
-def harmonicNorm ( f0, sN, fs, nK, t ): 
97
-    return np.linalg.norm( harmonicEuler(f0, sN, fs, nK, t) )
98
-
99
 def harmonic2Norm ( f0, sN, fs, nK, t ): 
79
 def harmonic2Norm ( f0, sN, fs, nK, t ): 
100
     return np.linalg.norm(harmonicEuler2(f0[0], f0[1], sN, fs, nK, t))
80
     return np.linalg.norm(harmonicEuler2(f0[0], f0[1], sN, fs, nK, t))
101
 
81
 
102
-def minHarmonic(f0, sN, fs, nK, t):
103
-    f02 = guessf0(sN, fs)
104
-    print("minHarmonic", f0, fs, nK, " guess=", f02)
105
-    # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
106
-    res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, nK, t), jac='2-point', method='BFGS') #, jac=jacEuler) #, hess=None, bounds=None )
107
-    print(res)
108
-    return harmonicEuler(res.x[0], sN, fs, nK, t)#[0]
82
+#def minHarmonic(f0, sN, fs, nK, t):
83
+#    f02 = guessf0(sN, fs)
84
+#    print("minHarmonic", f0, fs, nK, " guess=", f02)
85
+#    # CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr
86
+#    res = minimize(harmonicNorm, np.array((f0)), args=(sN, fs, nK, t), jac='2-point', method='BFGS') #, jac=jacEuler) #, hess=None, bounds=None )
87
+#    print(res)
88
+#    return harmonicEuler(res.x[0], sN, fs, nK, t)#[0]
89
+
90
+
109
 
91
 
110
 def minHarmonic2(f1, f2, sN, fs, nK, t):
92
 def minHarmonic2(f1, f2, sN, fs, nK, t):
111
     #f02 = guessf0(sN, fs)
93
     #f02 = guessf0(sN, fs)

+ 18
- 3
akvo/tressel/mrsurvey.py 查看文件

517
         canvas.draw()
517
         canvas.draw()
518
         self.doneTrigger.emit() 
518
         self.doneTrigger.emit() 
519
 
519
 
520
-    def harmonicModel(self, nF, nK, f0, f1, plot, canvas):
520
+    #def harmonicModel(self, nF, nK, f0, f1, plot, canvas):
521
+    
522
+    def harmonicModel(self, nF, f0, f0K1, f0KN, f0Ks, f1, plot, canvas):
523
+        """ nF = number of base frequencies, must be 1 or 2 
524
+            f0 = first base frequency  
525
+            f0K1 = first harmonic to model for first base frequency 
526
+            f0KN = last harmonic to model for the first base frequency 
527
+            f0Ks = subharmonic spacing, set to 1 for no subharmonics.
528
+            plot = should Akvo plot the results 
529
+            f1 = second base frequency  
530
+            canvas = mpl plotting axis      
531
+        """
521
         #print("harmonic modelling...", f0)
532
         #print("harmonic modelling...", f0)
522
         #plot = True
533
         #plot = True
523
         if plot:
534
         if plot:
543
                                 label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " rchan="  + str(ichan))
554
                                 label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " rchan="  + str(ichan))
544
 
555
 
545
                         if nF == 1:
556
                         if nF == 1:
546
-                            self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
557
+                            #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
558
+                            self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
559
+                                f0, f0K1, f0KN, f0Ks ) 
547
                         elif nF == 2:
560
                         elif nF == 2:
548
                             self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
561
                             self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
549
 
562
 
559
                                 label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
572
                                 label = "orig " +  pulse + " ipm=" + str(ipm) + " istack=" + str(istack) + " chan="  + str(ichan))
560
                         
573
                         
561
                         if nF == 1:
574
                         if nF == 1:
562
-                            self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
575
+                            #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
576
+                            self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic( self.DATADICT[pulse][ichan][ipm][istack], self.samp,  self.DATADICT[pulse]["TIMES"], \
577
+                                f0, f0K1, f0KN, f0Ks ) 
563
                         elif nF == 2:
578
                         elif nF == 2:
564
                             self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
579
                             self.DATADICT[pulse][ichan][ipm][istack] = harmonic.minHarmonic2( f0-1e-2, f1+1e-2, self.DATADICT[pulse][ichan][ipm][istack], self.samp, nK, self.DATADICT[pulse]["TIMES"] ) 
565
                         #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.harmonicEuler( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, 20, self.DATADICT[pulse]["TIMES"] ) 
580
                         #self.DATADICT[pulse][ichan][ipm][istack] = harmonic.harmonicEuler( f0, self.DATADICT[pulse][ichan][ipm][istack], self.samp, 20, self.DATADICT[pulse]["TIMES"] ) 

+ 1
- 1
setup.py 查看文件

21
     long_description = fh.read()
21
     long_description = fh.read()
22
 
22
 
23
 setup(name='Akvo',
23
 setup(name='Akvo',
24
-      version='1.0.23',
24
+      version='1.2.1',
25
       description='Surface nuclear magnetic resonance workbench',
25
       description='Surface nuclear magnetic resonance workbench',
26
       long_description=long_description,
26
       long_description=long_description,
27
       long_description_content_type='text/markdown',
27
       long_description_content_type='text/markdown',

Loading…
取消
儲存