pygmi 2.2.7__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. pygmi-2.2.7/LICENSE.txt +623 -0
  2. pygmi-2.2.7/MANIFEST.in +7 -0
  3. pygmi-2.2.7/PKG-INFO +47 -0
  4. pygmi-2.2.7/README.md +55 -0
  5. pygmi-2.2.7/README.rst +20 -0
  6. pygmi-2.2.7/log.txt +242 -0
  7. pygmi-2.2.7/pygmi/__init__.py +22 -0
  8. pygmi-2.2.7/pygmi/clust/__init__.py +4 -0
  9. pygmi-2.2.7/pygmi/clust/crisp_clust.py +708 -0
  10. pygmi-2.2.7/pygmi/clust/datatypes.py +65 -0
  11. pygmi-2.2.7/pygmi/clust/fuzzy_clust.py +906 -0
  12. pygmi-2.2.7/pygmi/clust/graphs.py +421 -0
  13. pygmi-2.2.7/pygmi/clust/graphtool.py +667 -0
  14. pygmi-2.2.7/pygmi/clust/menu.py +139 -0
  15. pygmi-2.2.7/pygmi/clust/var_ratio.py +92 -0
  16. pygmi-2.2.7/pygmi/clust/xie_beni.py +93 -0
  17. pygmi-2.2.7/pygmi/helpdocs/linepointer.png +0 -0
  18. pygmi-2.2.7/pygmi/helpdocs/pygmi.main.html +31 -0
  19. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.ddisp.html +15 -0
  20. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.iodefs.exportkmz.html +13 -0
  21. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.iodefs.importpicture.html +16 -0
  22. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.layer.html +17 -0
  23. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.mext.html +44 -0
  24. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.misc.rangedcopy.html +16 -0
  25. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.param.html +37 -0
  26. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.prof.html +32 -0
  27. pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.pview.html +26 -0
  28. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.gradients.html +14 -0
  29. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.tilt.html +14 -0
  30. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.visibility.html +14 -0
  31. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datagrid.html +13 -0
  32. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datamerge.html +11 -0
  33. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datareproj.html +11 -0
  34. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.rtp.html +14 -0
  35. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.ginterp.html +31 -0
  36. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.igrf.html +20 -0
  37. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.normalisation.html +14 -0
  38. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.smooth.html +22 -0
  39. pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.tiltdepth.html +20 -0
  40. pygmi-2.2.7/pygmi/images/Help.png +0 -0
  41. pygmi-2.2.7/pygmi/images/bringtofront.png +0 -0
  42. pygmi-2.2.7/pygmi/images/cgs2.emf +0 -0
  43. pygmi-2.2.7/pygmi/images/delete.png +0 -0
  44. pygmi-2.2.7/pygmi/images/linepointer.png +0 -0
  45. pygmi-2.2.7/pygmi/images/logo256.ico +0 -0
  46. pygmi-2.2.7/pygmi/images/logo256.png +0 -0
  47. pygmi-2.2.7/pygmi/images/pointer.png +0 -0
  48. pygmi-2.2.7/pygmi/images/pygmi.png +0 -0
  49. pygmi-2.2.7/pygmi/images/sendtoback.png +0 -0
  50. pygmi-2.2.7/pygmi/main.py +1037 -0
  51. pygmi-2.2.7/pygmi/menu_default.py +327 -0
  52. pygmi-2.2.7/pygmi/misc.py +147 -0
  53. pygmi-2.2.7/pygmi/pfmod/__init__.py +6 -0
  54. pygmi-2.2.7/pygmi/pfmod/cubes.py +1488 -0
  55. pygmi-2.2.7/pygmi/pfmod/datatypes.py +292 -0
  56. pygmi-2.2.7/pygmi/pfmod/grvmag3d.py +1265 -0
  57. pygmi-2.2.7/pygmi/pfmod/iodefs.py +1001 -0
  58. pygmi-2.2.7/pygmi/pfmod/menu.py +107 -0
  59. pygmi-2.2.7/pygmi/pfmod/misc.py +301 -0
  60. pygmi-2.2.7/pygmi/pfmod/pfmod.py +248 -0
  61. pygmi-2.2.7/pygmi/pfmod/tab_ddisp.py +425 -0
  62. pygmi-2.2.7/pygmi/pfmod/tab_layer.py +490 -0
  63. pygmi-2.2.7/pygmi/pfmod/tab_mext.py +544 -0
  64. pygmi-2.2.7/pygmi/pfmod/tab_param.py +548 -0
  65. pygmi-2.2.7/pygmi/pfmod/tab_prof.py +946 -0
  66. pygmi-2.2.7/pygmi/pfmod/tab_pview.py +740 -0
  67. pygmi-2.2.7/pygmi/raster/IGRF11.COF +1635 -0
  68. pygmi-2.2.7/pygmi/raster/__init__.py +14 -0
  69. pygmi-2.2.7/pygmi/raster/cooper.py +718 -0
  70. pygmi-2.2.7/pygmi/raster/dataprep.py +1640 -0
  71. pygmi-2.2.7/pygmi/raster/datatypes.py +123 -0
  72. pygmi-2.2.7/pygmi/raster/equation_editor.py +256 -0
  73. pygmi-2.2.7/pygmi/raster/ginterp.py +1901 -0
  74. pygmi-2.2.7/pygmi/raster/graphs.py +531 -0
  75. pygmi-2.2.7/pygmi/raster/igrf.py +860 -0
  76. pygmi-2.2.7/pygmi/raster/iodefs.py +813 -0
  77. pygmi-2.2.7/pygmi/raster/menu.py +307 -0
  78. pygmi-2.2.7/pygmi/raster/normalisation.py +187 -0
  79. pygmi-2.2.7/pygmi/raster/show_table.py +245 -0
  80. pygmi-2.2.7/pygmi/raster/smooth.py +406 -0
  81. pygmi-2.2.7/pygmi/raster/tiltdepth.py +590 -0
  82. pygmi-2.2.7/pygmi/seis/__init__.py +0 -0
  83. pygmi-2.2.7/pygmi/seis/beachball.py +751 -0
  84. pygmi-2.2.7/pygmi/seis/datatypes.py +605 -0
  85. pygmi-2.2.7/pygmi/seis/del_rec.py +410 -0
  86. pygmi-2.2.7/pygmi/seis/iodefs.py +1261 -0
  87. pygmi-2.2.7/pygmi/seis/menu.py +136 -0
  88. pygmi-2.2.7/pygmi/seis/scan_imp.py +795 -0
  89. pygmi-2.2.7/pygmi/test/__init__.py +6 -0
  90. pygmi-2.2.7/pygmi/test/pfmod.py +212 -0
  91. pygmi-2.2.7/pygmi/test/tests.py +39 -0
  92. pygmi-2.2.7/pygmi/vector/__init__.py +7 -0
  93. pygmi-2.2.7/pygmi/vector/datatypes.py +74 -0
  94. pygmi-2.2.7/pygmi/vector/graphs.py +443 -0
  95. pygmi-2.2.7/pygmi/vector/iodefs.py +345 -0
  96. pygmi-2.2.7/pygmi/vector/menu.py +127 -0
  97. pygmi-2.2.7/pygmi.egg-info/PKG-INFO +47 -0
  98. pygmi-2.2.7/pygmi.egg-info/SOURCES.txt +105 -0
  99. pygmi-2.2.7/pygmi.egg-info/dependency_links.txt +1 -0
  100. pygmi-2.2.7/pygmi.egg-info/entry_points.txt +3 -0
  101. pygmi-2.2.7/pygmi.egg-info/not-zip-safe +1 -0
  102. pygmi-2.2.7/pygmi.egg-info/requires.txt +7 -0
  103. pygmi-2.2.7/pygmi.egg-info/top_level.txt +1 -0
  104. pygmi-2.2.7/quickstart.py +35 -0
  105. pygmi-2.2.7/setup.cfg +8 -0
  106. pygmi-2.2.7/setup.py +80 -0
@@ -0,0 +1,740 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Name: tab_pview.py (part of PyGMI)
3
+ #
4
+ # Author: Patrick Cole
5
+ # E-Mail: pcole@geoscience.org.za
6
+ #
7
+ # Copyright: (c) 2013 Council for Geoscience
8
+ # Licence: GPL-3.0
9
+ #
10
+ # This file is part of PyGMI
11
+ #
12
+ # PyGMI is free software: you can redistribute it and/or modify
13
+ # it under the terms of the GNU General Public License as published by
14
+ # the Free Software Foundation, either version 3 of the License, or
15
+ # (at your option) any later version.
16
+ #
17
+ # PyGMI is distributed in the hope that it will be useful,
18
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ # GNU General Public License for more details.
21
+ #
22
+ # You should have received a copy of the GNU General Public License
23
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
24
+ # -----------------------------------------------------------------------------
25
+ """ Profile Display Tab Routines """
26
+
27
+ from PyQt4 import QtGui, QtCore
28
+ import numpy as np
29
+ import scipy.ndimage as ndimage
30
+ from . import misc
31
+ import os
32
+
33
+ # from matplotlib.figure import Figure
34
+ import matplotlib.pyplot as plt
35
+ from matplotlib.backends.backend_qt4agg import FigureCanvas
36
+ from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as \
37
+ NavigationToolbar
38
+
39
+
40
+ class ProfileDisplay(object):
41
+ """ Widget class to call the main interface """
42
+ def __init__(self, parent):
43
+ self.parent = parent
44
+ self.lmod1 = parent.lmod1
45
+ self.lmod2 = parent.lmod2
46
+ self.showtext = parent.showtext
47
+ self.pbar = self.parent.pbar_sub
48
+ self.xnodes = self.lmod1.custprofx
49
+ self.ynodes = self.lmod1.custprofy
50
+ self.curprof = 0
51
+ self.pcntmax = len(self.xnodes)-1
52
+ self.viewmagnetics = True
53
+
54
+ self.userint = QtGui.QWidget()
55
+
56
+ self.mmc = MyMplCanvas(self, self.lmod1)
57
+ self.mpl_toolbar = NavigationToolbar(self.mmc, self.userint)
58
+
59
+ self.sb_profnum2 = QtGui.QSpinBox()
60
+ self.hslider_profile2 = QtGui.QSlider()
61
+ self.combo_profpic = QtGui.QComboBox()
62
+ self.hs_ppic_opacity = QtGui.QSlider()
63
+
64
+ self.rb_axis_datamax = QtGui.QRadioButton()
65
+ self.rb_axis_profmax = QtGui.QRadioButton()
66
+ self.rb_axis_calcmax = QtGui.QRadioButton()
67
+
68
+ self.sb_profile_linethick = QtGui.QSpinBox()
69
+ self.gridlayout_20 = QtGui.QGridLayout()
70
+ self.lw_prof_defs = QtGui.QListWidget()
71
+
72
+ self.pb_add_prof = QtGui.QPushButton()
73
+ self.pb_export_csv = QtGui.QPushButton()
74
+
75
+ self.setupui()
76
+
77
+ def setupui(self):
78
+ """ Setup UI """
79
+ gridlayout = QtGui.QGridLayout(self.userint)
80
+ groupbox = QtGui.QGroupBox()
81
+ verticallayout = QtGui.QVBoxLayout(groupbox)
82
+
83
+ self.sb_profnum2.setWrapping(True)
84
+ self.sb_profnum2.setMaximum(999999999)
85
+
86
+ sizepolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
87
+ QtGui.QSizePolicy.Fixed)
88
+ self.hslider_profile2.setSizePolicy(sizepolicy)
89
+ self.hs_ppic_opacity.setSizePolicy(sizepolicy)
90
+
91
+ self.lw_prof_defs.setFixedWidth(220)
92
+ self.hslider_profile2.setOrientation(QtCore.Qt.Horizontal)
93
+ self.hs_ppic_opacity.setMaximum(255)
94
+ self.hs_ppic_opacity.setProperty("value", 255)
95
+ self.hs_ppic_opacity.setOrientation(QtCore.Qt.Horizontal)
96
+ self.hs_ppic_opacity.setTickPosition(QtGui.QSlider.TicksAbove)
97
+ self.sb_profile_linethick.setMinimum(1)
98
+ self.sb_profile_linethick.setMaximum(1000)
99
+ self.rb_axis_datamax.setChecked(True)
100
+
101
+ gridlayout.addWidget(self.mpl_toolbar, 0, 0, 1, 1)
102
+ gridlayout.addWidget(self.mmc, 1, 0, 7, 1)
103
+ gridlayout.addWidget(self.sb_profnum2, 0, 1, 1, 1)
104
+ gridlayout.addWidget(self.hslider_profile2, 1, 1, 1, 1)
105
+ gridlayout.addWidget(self.combo_profpic, 2, 1, 1, 1)
106
+ gridlayout.addWidget(self.hs_ppic_opacity, 3, 1, 1, 1)
107
+ gridlayout.addWidget(self.lw_prof_defs, 4, 1, 1, 1)
108
+ gridlayout.addWidget(self.sb_profile_linethick, 5, 1, 1, 1)
109
+ gridlayout.addWidget(groupbox, 6, 1, 1, 1)
110
+ gridlayout.addWidget(self.pb_add_prof, 7, 1, 1, 1)
111
+ gridlayout.addWidget(self.pb_export_csv, 8, 1, 1, 1)
112
+
113
+ verticallayout.addWidget(self.rb_axis_datamax)
114
+ verticallayout.addWidget(self.rb_axis_profmax)
115
+ verticallayout.addWidget(self.rb_axis_calcmax)
116
+
117
+ groupbox.setTitle("Profile Y-Axis Scale")
118
+ self.sb_profnum2.setPrefix("Custom Profile: ")
119
+ self.pb_add_prof.setText("Add Custom Profile")
120
+ self.pb_export_csv.setText("Export Profile")
121
+ self.rb_axis_datamax.setText("Scale to dataset maximum")
122
+ self.rb_axis_profmax.setText("Scale to profile maximum")
123
+ self.rb_axis_calcmax.setText("Scale to calculated maximum")
124
+ self.sb_profile_linethick.setPrefix("Line Thickness: ")
125
+
126
+ # Buttons etc
127
+ self.sb_profile_linethick.valueChanged.connect(self.width)
128
+ self.lw_prof_defs.currentItemChanged.connect(self.change_defs)
129
+ self.pb_add_prof.clicked.connect(self.addprof)
130
+ self.hslider_profile2.valueChanged.connect(self.hprofnum)
131
+ self.hslider_profile2.sliderReleased.connect(self.hprofnum)
132
+ self.sb_profnum2.valueChanged.connect(self.sprofnum)
133
+ self.rb_axis_calcmax.clicked.connect(self.rb_plot_scale)
134
+ self.rb_axis_profmax.clicked.connect(self.rb_plot_scale)
135
+ self.rb_axis_datamax.clicked.connect(self.rb_plot_scale)
136
+ self.pb_export_csv.clicked.connect(self.export_csv)
137
+ self.hs_ppic_opacity.sliderMoved.connect(self.profpic_hs)
138
+ self.combo_profpic.currentIndexChanged.connect(self.profpic_hs)
139
+
140
+ def addprof(self):
141
+ """ add another profile """
142
+ self.update_model()
143
+ (tx0, okay) = QtGui.QInputDialog.getDouble(
144
+ self.parent, 'Add Custom Profile',
145
+ 'Please enter first x coordinate', self.lmod1.xrange[0])
146
+ if not okay:
147
+ return
148
+ (ty0, okay) = QtGui.QInputDialog.getDouble(
149
+ self.parent, 'Add Custom Profile',
150
+ 'Please enter first y coordinate', self.lmod1.yrange[0])
151
+ if not okay:
152
+ return
153
+ (tx1, okay) = QtGui.QInputDialog.getDouble(
154
+ self.parent, 'Add Custom Profile',
155
+ 'Please enter last x coordinate', self.lmod1.xrange[-1])
156
+ if not okay:
157
+ return
158
+ (ty1, okay) = QtGui.QInputDialog.getDouble(
159
+ self.parent, 'Add Custom Profile',
160
+ 'Please enter last y coordinate', self.lmod1.yrange[-1])
161
+ if not okay:
162
+ return
163
+
164
+ self.pcntmax += 1
165
+ self.xnodes[self.pcntmax] = [float(tx0), float(tx1)]
166
+ self.ynodes[self.pcntmax] = [float(ty0), float(ty1)]
167
+
168
+ self.hslider_profile2.valueChanged.disconnect()
169
+ self.combo_profpic.currentIndexChanged.disconnect()
170
+ self.sb_profnum2.valueChanged.disconnect()
171
+
172
+ self.hslider_profile2.setMaximum(self.pcntmax)
173
+ self.sb_profnum2.setMaximum(self.pcntmax)
174
+
175
+ self.sb_profnum2.valueChanged.connect(self.sprofnum)
176
+ self.hslider_profile2.valueChanged.connect(self.hprofnum)
177
+ self.combo_profpic.currentIndexChanged.connect(self.profpic_hs)
178
+
179
+ def change_defs(self):
180
+ """ List box in profile tab for definitions """
181
+
182
+ i = self.lw_prof_defs.currentRow()
183
+ if i == -1:
184
+ misc.update_lith_lw(self.lmod1, self.lw_prof_defs)
185
+ i = 0
186
+ itxt = str(self.lw_prof_defs.item(i).text())
187
+
188
+ if itxt not in self.lmod1.lith_list.keys():
189
+ return
190
+
191
+ lith = self.lmod1.lith_list[itxt]
192
+ self.mmc.curmodel = lith.lith_index
193
+
194
+ def change_model(self, slide=False):
195
+ """ Change Model """
196
+
197
+ bottom = self.lmod1.zrange[0]
198
+ top = self.lmod1.zrange[1]
199
+
200
+ data = self.lmod1.griddata['Calculated Gravity']
201
+ xxx, yyy, right = self.cp_init(data)
202
+
203
+ tmp = np.transpose([xxx, yyy]).astype(int)
204
+ self.mmc.crd = tmp
205
+
206
+ x = np.array(xxx).astype(int)
207
+ y = np.array(yyy).astype(int)
208
+
209
+ gtmp = []
210
+ for i in range(self.lmod1.numz):
211
+ gtmp.append(self.lmod1.lith_index[x, y, i])
212
+
213
+ gtmp = np.array(gtmp[::-1])
214
+ # First we plot the model stuff
215
+ left = 0
216
+
217
+ extent = (left, right, bottom, top)
218
+
219
+ ctxt = str(self.combo_profpic.currentText())
220
+ if len(self.lmod1.profpics) > 0 and ctxt != u'':
221
+ gtmpl = self.lmod1.profpics[ctxt]
222
+ opac = self.hs_ppic_opacity.value()/self.hs_ppic_opacity.maximum()
223
+ else:
224
+ gtmpl = None
225
+ opac = 1.0
226
+
227
+ if slide is True:
228
+ self.mmc.slide_grid(gtmp, gtmpl, opac)
229
+ else:
230
+ self.mmc.init_grid(gtmp, extent, gtmpl, opac)
231
+
232
+ # alt = self.lmod1.zrange[1]-self.lmod1.curlayer*self.lmod1.d_z
233
+
234
+ # self.mmc.update_line(self.lmod1.xrange, [alt, alt])
235
+
236
+ def cp_init(self, data):
237
+ """ Initializes stuff for custom profile """
238
+ x_0, x_1 = self.xnodes[self.curprof]
239
+ y_0, y_1 = self.ynodes[self.curprof]
240
+
241
+ bly = data.tly-data.ydim*data.rows
242
+ x_0 = (x_0-data.tlx)/data.xdim
243
+ x_1 = (x_1-data.tlx)/data.xdim
244
+ y_0 = (y_0-bly)/data.ydim
245
+ y_1 = (y_1-bly)/data.ydim
246
+ rcell = int(np.sqrt((x_1-x_0)**2+(y_1-y_0)**2))
247
+ rdist = np.sqrt((data.xdim*(x_1-x_0))**2+(data.ydim*(y_1-y_0))**2)
248
+
249
+ xxx = np.linspace(x_0, x_1, rcell, False)
250
+ yyy = np.linspace(y_0, y_1, rcell, False)
251
+
252
+ return xxx, yyy, rdist
253
+
254
+ def export_csv(self):
255
+ """ Export Profile to csv """
256
+ self.parent.pbars.resetall()
257
+ filename = QtGui.QFileDialog.getSaveFileName(
258
+ self.parent, 'Save File', '.', 'Comma separated values (*.csv)')
259
+ if filename == '':
260
+ return
261
+ os.chdir(filename.rpartition('/')[0])
262
+
263
+ maggrid = self.lmod1.griddata['Calculated Magnetics'].data
264
+ grvgrid = self.lmod1.griddata['Calculated Gravity'].data
265
+ curprof = self.curprof
266
+
267
+ cmag = maggrid[-curprof-1]
268
+ cgrv = grvgrid[-curprof-1]
269
+ xrng = (np.arange(cmag.shape[0])*self.lmod1.dxy +
270
+ self.lmod1.xrange[0]+self.lmod1.dxy/2.)
271
+ yrng = np.zeros_like(xrng)+self.lmod1.dxy/2.
272
+
273
+ newdata = np.transpose([xrng, yrng, cgrv, cmag])
274
+
275
+ fno = open(filename, 'wb')
276
+ fno.write(b'"x","y","Gravity","Magnetics"\n')
277
+ np.savetxt(fno, newdata, delimiter=',')
278
+ fno.close()
279
+ self.parent.pbars.incr()
280
+ self.showtext('Profile save complete')
281
+
282
+ def hprofnum(self):
283
+ """ Routine to change a profile from spinbox"""
284
+ self.sb_profnum2.setValue(self.hslider_profile2.sliderPosition())
285
+ self.profnum()
286
+
287
+ def profpic_hs(self):
288
+ """ Horizontal slider to change the profile """
289
+ self.update_model()
290
+ self.change_model(slide=True)
291
+ self.update_plot(slide=True)
292
+
293
+ def profnum(self):
294
+ """ Routine to change a profile from spinbox"""
295
+ self.update_model()
296
+
297
+ self.curprof = self.sb_profnum2.value()
298
+ self.change_model(slide=False)
299
+ self.update_plot(slide=False) # was True
300
+
301
+ def sprofnum(self):
302
+ """ Routine to change a profile from spinbox"""
303
+ self.hslider_profile2.setValue(self.sb_profnum2.value())
304
+ self.profnum()
305
+
306
+ def rb_plot_scale(self):
307
+ """ plot scale """
308
+ self.change_model()
309
+ self.update_plot()
310
+ self.mpl_toolbar.update()
311
+
312
+ def tab_activate(self):
313
+ """ Runs when the tab is activated """
314
+ self.lmod1 = self.parent.lmod1
315
+ self.mmc.lmod = self.lmod1
316
+
317
+ self.xnodes = self.lmod1.custprofx
318
+ self.ynodes = self.lmod1.custprofy
319
+ self.pcntmax = len(self.xnodes)-1
320
+
321
+ # self.xnodes[0] = self.lmod1.xrange
322
+ # self.ynodes[0] = [self.lmod1.yrange[0], self.lmod1.yrange[0]]
323
+
324
+ misc.update_lith_lw(self.lmod1, self.lw_prof_defs)
325
+
326
+ self.hslider_profile2.valueChanged.disconnect()
327
+ self.combo_profpic.currentIndexChanged.disconnect()
328
+ self.sb_profnum2.valueChanged.disconnect()
329
+
330
+ self.hslider_profile2.setMinimum(0)
331
+ self.hslider_profile2.setMaximum(self.pcntmax)
332
+ self.sb_profnum2.setMaximum(self.pcntmax)
333
+
334
+ if len(self.lmod1.profpics) > 0:
335
+ self.combo_profpic.clear()
336
+ self.combo_profpic.addItems(list(self.lmod1.profpics.keys()))
337
+ self.combo_profpic.setCurrentIndex(0)
338
+
339
+ self.change_model() # needs to happen before profnum set value
340
+ self.sb_profnum2.setValue(self.curprof)
341
+ self.update_plot()
342
+ self.sb_profnum2.valueChanged.connect(self.sprofnum)
343
+ self.hslider_profile2.valueChanged.connect(self.hprofnum)
344
+ self.combo_profpic.currentIndexChanged.connect(self.profpic_hs)
345
+
346
+ def update_model(self):
347
+ """ Update model itself """
348
+ # tmp = self.lmod1.lith_index[:, self.curprof, ::-1]
349
+ # if tmp.shape != self.mmc.mdata.T.shape:
350
+ # return
351
+ # self.lmod1.lith_index[:, self.curprof, ::-1] = (
352
+ # self.mmc.mdata.T.copy())
353
+
354
+ data = self.lmod1.griddata['Calculated Gravity']
355
+ xxx, yyy = self.cp_init(data)[:2]
356
+
357
+ gtmp = self.mmc.mdata[::-1].T.copy()
358
+ rows, cols = gtmp.shape
359
+
360
+ for j in range(cols):
361
+ for i in range(rows):
362
+ self.lmod1.lith_index[int(xxx[i]), int(yyy[i]), j] = gtmp[i, j]
363
+
364
+ def update_plot(self, slide=False):
365
+ """ Update the profile on the model view """
366
+
367
+ # Display the calculated profile
368
+ data = None
369
+
370
+ if self.viewmagnetics:
371
+ if 'Calculated Magnetics' in self.lmod1.griddata.keys():
372
+ data = self.lmod1.griddata['Calculated Magnetics']
373
+ self.mmc.ptitle = 'Magnetic Intensity: '
374
+ self.mmc.punit = 'nT'
375
+ regtmp = 0.0
376
+ else:
377
+ if 'Calculated Gravity' in self.lmod1.griddata.keys():
378
+ data = self.lmod1.griddata['Calculated Gravity']
379
+ self.mmc.ptitle = 'Gravity: '
380
+ self.mmc.punit = 'mGal'
381
+ regtmp = self.lmod1.gregional
382
+
383
+ x_0, x_1 = self.xnodes[self.curprof]
384
+ y_0, y_1 = self.ynodes[self.curprof]
385
+ self.mmc.ptitle += str((x_0, y_0)) + ' to ' + str((x_1, y_1))
386
+
387
+ if data is not None:
388
+ xxx, yyy, rdist = self.cp_init(data)
389
+
390
+ self.mmc.xlabel = "Eastings (m)"
391
+ tmprng = np.linspace(0, rdist, len(xxx), False)
392
+ tmpprof = ndimage.map_coordinates(data.data[::-1], [yyy, xxx],
393
+ order=1, cval=np.nan)
394
+ tmprng = tmprng[np.logical_not(np.isnan(tmpprof))]
395
+ tmpprof = tmpprof[np.logical_not(np.isnan(tmpprof))]+regtmp
396
+ extent = [0, rdist]
397
+
398
+ if self.rb_axis_calcmax.isChecked():
399
+ extent = list(extent)+[data.min()+regtmp, data.max()+regtmp]
400
+ else:
401
+ extent = list(extent)+[tmpprof.min(), tmpprof.max()]
402
+
403
+ # Load in observed data - if there is any
404
+ data2 = None
405
+ tmprng2 = None
406
+ tmpprof2 = None
407
+ if ('Magnetic Dataset' in self.lmod1.griddata.keys() and
408
+ self.viewmagnetics):
409
+ data2 = self.lmod1.griddata['Magnetic Dataset']
410
+ elif ('Gravity Dataset' in self.lmod1.griddata.keys() and
411
+ not self.viewmagnetics):
412
+ data2 = self.lmod1.griddata['Gravity Dataset']
413
+
414
+ if data2 is not None:
415
+ xxx, yyy, rdist = self.cp_init(data2)
416
+
417
+ tmprng2 = np.linspace(0, rdist, len(xxx), False)
418
+ tmpprof2 = ndimage.map_coordinates(data2.data[::-1], [yyy, xxx],
419
+ order=1, cval=np.nan)
420
+
421
+ tmprng2 = tmprng2[np.logical_not(np.isnan(tmpprof2))]
422
+ tmpprof2 = tmpprof2[np.logical_not(np.isnan(tmpprof2))]
423
+
424
+ if self.rb_axis_datamax.isChecked() or len(tmpprof2) == 0:
425
+ extent[2:] = [data2.data.min(), data2.data.max()]
426
+ elif self.rb_axis_profmax.isChecked():
427
+ extent[2:] = [tmpprof2.min(), tmpprof2.max()]
428
+
429
+ if slide is True:
430
+ self.mmc.slide_plot(tmprng, tmpprof, extent, tmprng2, tmpprof2)
431
+ else:
432
+ self.mmc.init_plot(tmprng, tmpprof, extent, tmprng2, tmpprof2)
433
+
434
+ def width(self, width):
435
+ """ Sets the width of the edits on the profile view """
436
+
437
+ self.mmc.width = width
438
+
439
+
440
+ class MyMplCanvas(FigureCanvas):
441
+ """This is a QWidget"""
442
+ def __init__(self, parent, lmod):
443
+ # fig = Figure()
444
+ fig = plt.figure()
445
+ FigureCanvas.__init__(self, fig)
446
+
447
+ self.parent = parent
448
+ self.lmod = lmod
449
+ self.cbar = plt.cm.jet
450
+ self.curmodel = 0
451
+ self.width = 1
452
+ self.xold = None
453
+ self.yold = None
454
+ self.press = False
455
+ self.newline = False
456
+ self.mdata = np.zeros([10, 100])
457
+ self.ptitle = ''
458
+ self.punit = ''
459
+ self.xlabel = 'Eastings (m)'
460
+ self.plotisinit = False
461
+ self.crd = None
462
+
463
+ # Events
464
+ self.figure.canvas.mpl_connect('motion_notify_event', self.move)
465
+ self.figure.canvas.mpl_connect('button_press_event', self.button_press)
466
+ self.figure.canvas.mpl_connect('button_release_event',
467
+ self.button_release)
468
+
469
+ # Initial Images
470
+ self.paxes = fig.add_subplot(211)
471
+ self.paxes.yaxis.set_label_text("mGal")
472
+ self.paxes.ticklabel_format(useOffset=False)
473
+
474
+ self.cal = self.paxes.plot([], [])
475
+ self.obs = plt.plot([], [], 'o')
476
+
477
+ self.axes = fig.add_subplot(212)
478
+ self.axes.xaxis.set_label_text(self.xlabel)
479
+ self.axes.yaxis.set_label_text("Altitude (m)")
480
+
481
+ tmp = self.cbar(self.mdata)
482
+ tmp[:, :, 3] = 0
483
+
484
+ self.ims2 = plt.imshow(tmp.copy(), interpolation='nearest',
485
+ aspect='auto')
486
+ self.ims = plt.imshow(tmp.copy(), interpolation='nearest',
487
+ aspect='auto')
488
+ self.figure.canvas.draw()
489
+
490
+ self.bbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
491
+ self.pbbox = self.figure.canvas.copy_from_bbox(self.paxes.bbox)
492
+ self.prf = self.axes.plot([0, 0])
493
+ self.figure.canvas.draw()
494
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
495
+
496
+ def button_press(self, event):
497
+ """ Button press """
498
+ nmode = self.axes.get_navigate_mode()
499
+ if event.button == 1 and nmode is None:
500
+ self.press = True
501
+ self.newline = True
502
+ self.move(event)
503
+
504
+ def button_release(self, event):
505
+ """ Button press """
506
+ nmode = self.axes.get_navigate_mode()
507
+ if event.button == 1:
508
+ self.press = False
509
+ if nmode == 'ZOOM':
510
+ extent = self.axes.get_xbound()
511
+ self.paxes.set_xbound(extent[0], extent[1])
512
+ self.figure.canvas.draw()
513
+ else:
514
+ self.parent.update_model()
515
+
516
+ def move(self, event):
517
+ """ Mouse is moving """
518
+ if self.figure.canvas.toolbar._active is None:
519
+ vlim = self.axes.viewLim
520
+ dlim = self.axes.dataLim
521
+ tmp0 = self.axes.transData.transform((vlim.x0, vlim.y0))
522
+ tmp1 = self.axes.transData.transform((vlim.x1, vlim.y1))
523
+ width, height = tmp1-tmp0
524
+ width /= self.mdata.shape[1]
525
+ height /= self.mdata.shape[0]
526
+ width *= dlim.width/vlim.width
527
+ height *= dlim.height/vlim.height
528
+ cwidth = (2*self.width-1)
529
+ cb = QtGui.QBitmap(cwidth*width, cwidth*height)
530
+ cb.fill(QtCore.Qt.color1)
531
+ self.setCursor(QtGui.QCursor(cb))
532
+
533
+ if event.inaxes == self.axes and self.press is True:
534
+ row = int((event.ydata - self.lmod.zrange[0])/self.lmod.d_z)+1
535
+ col = int((event.xdata)/self.lmod.dxy)
536
+
537
+ aaa = self.axes.get_xbound()[-1]
538
+ bbb = self.mdata.shape[1]
539
+ ccc = aaa/bbb
540
+ col = int((event.xdata)/ccc)
541
+
542
+ xdata = col
543
+ ydata = row
544
+
545
+ if self.newline is True:
546
+ self.newline = False
547
+ self.set_mdata(xdata, ydata)
548
+ elif xdata != self.xold:
549
+ mmm = float(ydata-self.yold)/(xdata-self.xold)
550
+ ccc = ydata - mmm * xdata
551
+ x_1 = min([self.xold, xdata])
552
+ x_2 = max([self.xold, xdata])
553
+ for i in range(x_1+1, x_2+1):
554
+ jold = int(mmm*(i-1)+ccc)
555
+ jnew = int(mmm*i+ccc)
556
+ if jold > jnew:
557
+ jold, jnew = jnew, jold
558
+ for j in range(jold, jnew+1):
559
+ self.set_mdata(i, j)
560
+
561
+ elif ydata != self.yold:
562
+ y_1 = min([self.yold, ydata])
563
+ y_2 = max([self.yold, ydata])
564
+ for j in range(y_1, y_2+1):
565
+ self.set_mdata(xdata, j)
566
+
567
+ self.xold = xdata
568
+ self.yold = ydata
569
+
570
+ self.slide_grid(self.mdata)
571
+
572
+ def set_mdata(self, xdata, ydata):
573
+ """ Routine to 'draw' the line on mdata """
574
+
575
+ gheight = self.mdata.shape[0]
576
+ gwidth = self.mdata.shape[1]
577
+
578
+ width = self.width-1 # 'pen' width
579
+ xstart = xdata-width-1
580
+ xend = xdata+width
581
+ ystart = ydata-width-1
582
+ yend = ydata+width
583
+ if xstart < 0:
584
+ xstart = 0
585
+ if xend > gwidth:
586
+ xend = gwidth
587
+ if ystart < 0:
588
+ ystart = 0
589
+ if yend > gheight:
590
+ yend = gheight
591
+
592
+ # for i in range(xstart, xend):
593
+ i = xstart
594
+ while i < xend:
595
+ tmp = (self.crd == self.crd[i])
596
+ tmp = np.logical_and(tmp[:, 0], tmp[:, 1])
597
+ tmp = tmp.nonzero()[0]
598
+ if tmp[-1] >= xend:
599
+ xend = tmp[-1]+1
600
+ i += 1
601
+
602
+ if xstart < xend and ystart < yend:
603
+ mtmp = self.mdata[ystart:yend, xstart:xend]
604
+ mtmp[mtmp != -1] = self.curmodel
605
+
606
+ def luttodat(self, dat):
607
+ """ lut to dat grid """
608
+ mlut = self.lmod.mlut
609
+ tmp = np.zeros([dat.shape[0], dat.shape[1], 4])
610
+
611
+ for i in np.unique(dat):
612
+ if i == -1:
613
+ ctmp = [0, 0, 0, 0]
614
+ else:
615
+ ctmp = np.array(mlut[i]+[255])/255.
616
+
617
+ tmp[dat[::-1] == i] = ctmp
618
+
619
+ return tmp
620
+
621
+ def init_grid(self, dat, extent, dat2, opac):
622
+ """ Updates the single color map """
623
+ # Note that because we clear the current axes, we must put the objects
624
+ # back into it are the graph will go blank on a draw(). This is the
625
+ # reason for the ims and prf commands below.
626
+
627
+ self.paxes.set_xbound(extent[0], extent[1])
628
+ self.ims.set_visible(False)
629
+ self.axes.set_xlim(extent[0], extent[1])
630
+ self.axes.set_ylim(extent[2], extent[3])
631
+
632
+ if dat2 is not None:
633
+ self.ims2.set_data(dat2.data)
634
+ self.ims2.set_extent(self.dat_extent(dat2))
635
+ self.ims2.set_clim(dat2.data.min(), dat2.data.max())
636
+
637
+ self.figure.canvas.draw()
638
+ QtGui.QApplication.processEvents()
639
+ self.bbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
640
+
641
+ self.ims.set_visible(True)
642
+ self.ims.set_extent(extent)
643
+ tmp = self.luttodat(dat)
644
+ self.ims.set_data(tmp)
645
+ self.ims.set_alpha(opac)
646
+
647
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
648
+ self.figure.canvas.draw()
649
+ QtGui.QApplication.processEvents()
650
+
651
+ self.mdata = dat
652
+
653
+ def slide_grid(self, dat, dat2=None, opac=1.0):
654
+ """ Slider """
655
+ self.mdata = dat
656
+ tmp = self.luttodat(dat)
657
+ self.ims.set_data(tmp)
658
+ self.ims.set_alpha(opac)
659
+
660
+ self.figure.canvas.restore_region(self.bbox)
661
+ self.axes.draw_artist(self.ims)
662
+ # self.figure.canvas.blit(self.axes.bbox)
663
+ self.figure.canvas.update()
664
+
665
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
666
+ self.axes.draw_artist(self.prf[0])
667
+ # self.figure.canvas.blit(self.axes.bbox)
668
+ self.figure.canvas.update()
669
+
670
+ def update_line(self, xrng, yrng):
671
+ """ Updates the line position """
672
+ self.prf[0].set_data([xrng, yrng])
673
+ self.figure.canvas.restore_region(self.lbbox)
674
+ self.axes.draw_artist(self.prf[0])
675
+ # self.figure.canvas.blit(self.axes.bbox)
676
+ self.figure.canvas.update()
677
+
678
+ def dat_extent(self, dat):
679
+ """ Gets the extend of the dat variable """
680
+ left = dat.tlx
681
+ top = dat.tly
682
+ right = left + dat.cols*dat.xdim
683
+ bottom = top - dat.rows*dat.ydim
684
+ return (left, right, bottom, top)
685
+
686
+ # This section is just for the profile line plot
687
+
688
+ def extentchk(self, extent):
689
+ """ Checks extent """
690
+ dmin = extent[2]
691
+ dmax = extent[3]
692
+ if dmin == dmax:
693
+ dmax = dmin+1
694
+ return dmin, dmax
695
+
696
+ def init_plot(self, xdat, dat, extent, xdat2, dat2):
697
+ """ Updates the single color map """
698
+ self.paxes.autoscale(False)
699
+ dmin, dmax = self.extentchk(extent)
700
+ self.paxes.cla()
701
+ self.paxes.ticklabel_format(useOffset=False)
702
+ self.paxes.set_title(self.ptitle)
703
+ self.axes.xaxis.set_label_text(self.xlabel)
704
+ self.paxes.yaxis.set_label_text(self.punit)
705
+ self.paxes.set_ylim(dmin, dmax)
706
+ self.paxes.set_xlim(extent[0], extent[1])
707
+ self.figure.canvas.draw()
708
+ QtGui.QApplication.processEvents()
709
+ self.pbbox = self.figure.canvas.copy_from_bbox(self.paxes.bbox)
710
+
711
+ self.paxes.set_autoscalex_on(False)
712
+ self.cal = self.paxes.plot(xdat, dat)
713
+ if xdat2 is not None:
714
+ self.obs = self.paxes.plot(xdat2, dat2, 'o')
715
+ else:
716
+ self.obs = self.paxes.plot([], [], 'o')
717
+ self.figure.canvas.draw()
718
+ QtGui.QApplication.processEvents()
719
+ self.plotisinit = True
720
+
721
+ def slide_plot(self, xdat, dat, extent, xdat2, dat2):
722
+ """ Slider """
723
+ dmin, dmax = self.extentchk(extent)
724
+
725
+ self.figure.canvas.restore_region(self.pbbox)
726
+ self.cal[0].set_data([xdat, dat])
727
+ if xdat2 is not None:
728
+ self.obs[0].set_data([xdat2, dat2])
729
+ else:
730
+ self.obs[0].set_data([[], []])
731
+ # self.paxes.set_ylim(dmin, dmax)
732
+ # self.paxes.set_xlim(extent[0], extent[1])
733
+
734
+ self.paxes.draw_artist(self.cal[0])
735
+ if xdat2 is not None:
736
+ self.paxes.draw_artist(self.obs[0])
737
+ # self.figure.canvas.blit(self.paxes.bbox)
738
+ self.figure.canvas.update()
739
+
740
+ QtGui.QApplication.processEvents()