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,490 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Name: tab_layer.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
+ """ Layer Display Tab Routines """
26
+
27
+ from PyQt4 import QtGui, QtCore
28
+ import numpy as np
29
+ import pygmi.pfmod.misc as misc
30
+ import matplotlib.pyplot as plt
31
+ from matplotlib.backends.backend_qt4agg import FigureCanvas
32
+ from matplotlib.backends.backend_qt4agg import \
33
+ NavigationToolbar2QT as NavigationToolbar
34
+
35
+
36
+ class LayerDisplay(object):
37
+ """ Widget class to call the main interface """
38
+ def __init__(self, parent):
39
+ self.parent = parent
40
+ self.lmod = parent.lmod1
41
+ self.grid_stretch = 'linear'
42
+ self.grid3txt = 'Calculated Magnetics'
43
+
44
+ self.grid3 = self.lmod.griddata['Calculated Magnetics']
45
+
46
+ self.userint = QtGui.QWidget()
47
+
48
+ self.mmc = MyMplCanvas(self, self.lmod)
49
+ self.mpl_toolbar = NavigationToolbar(self.mmc, self.userint)
50
+
51
+ self.label_altitude = QtGui.QLabel()
52
+ self.sb_model_layer = QtGui.QSpinBox()
53
+ self.hslider_layer = QtGui.QSlider()
54
+ self.combo_grid3 = QtGui.QComboBox()
55
+ self.hs_model_opacity = QtGui.QSlider()
56
+ self.sb_layer_linethick = QtGui.QSpinBox()
57
+ self.lw_editor_defs = QtGui.QListWidget()
58
+ self.pb_layer_rcopy = QtGui.QPushButton()
59
+
60
+ self.setupui()
61
+
62
+ def setupui(self):
63
+ """ Setup UI """
64
+ gridlayout = QtGui.QGridLayout(self.userint)
65
+
66
+ gtmp = ['Calculated Magnetics', 'Calculated Gravity']
67
+
68
+ self.lw_editor_defs.setFixedWidth(220)
69
+ self.sb_model_layer.setWrapping(True)
70
+ self.sb_model_layer.setMinimum(0)
71
+ self.sb_model_layer.setMaximum(1000)
72
+ self.sb_model_layer.setProperty("value", 0)
73
+
74
+ sizepolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
75
+ QtGui.QSizePolicy.Fixed)
76
+
77
+ self.hslider_layer.setSizePolicy(sizepolicy)
78
+ self.hslider_layer.setOrientation(QtCore.Qt.Horizontal)
79
+ self.hs_model_opacity.setSizePolicy(sizepolicy)
80
+ self.hs_model_opacity.setMaximum(100)
81
+ self.hs_model_opacity.setProperty("value", 100)
82
+ self.hs_model_opacity.setOrientation(QtCore.Qt.Horizontal)
83
+ self.hs_model_opacity.setTickPosition(QtGui.QSlider.TicksAbove)
84
+ self.sb_layer_linethick.setMinimum(1)
85
+ self.sb_layer_linethick.setMaximum(1000)
86
+ self.sb_model_layer.setMaximum(self.lmod.numz-1)
87
+ self.combo_grid3.addItems(gtmp)
88
+ self.combo_grid3.setCurrentIndex(0)
89
+
90
+ self.label_altitude.setText("Altitude: 0")
91
+ self.sb_model_layer.setPrefix("Model Layer: ")
92
+ self.hslider_layer.setToolTip("Model Layer")
93
+ self.hs_model_opacity.setToolTip("Model Opacity")
94
+ self.sb_layer_linethick.setPrefix("Line Thickness: ")
95
+ self.pb_layer_rcopy.setText("Ranged Copy")
96
+
97
+ gridlayout.addWidget(self.mpl_toolbar, 0, 0, 1, 1)
98
+ gridlayout.addWidget(self.mmc, 1, 0, 8, 1)
99
+ gridlayout.addWidget(self.label_altitude, 0, 1, 1, 1)
100
+ gridlayout.addWidget(self.sb_model_layer, 1, 1, 1, 1)
101
+ gridlayout.addWidget(self.hslider_layer, 2, 1, 1, 1)
102
+ gridlayout.addWidget(self.combo_grid3, 3, 1, 1, 1)
103
+ gridlayout.addWidget(self.hs_model_opacity, 4, 1, 1, 1)
104
+ gridlayout.addWidget(self.lw_editor_defs, 5, 1, 1, 1)
105
+ gridlayout.addWidget(self.sb_layer_linethick, 6, 1, 1, 1)
106
+ gridlayout.addWidget(self.pb_layer_rcopy, 7, 1, 1, 1)
107
+
108
+ self.sb_model_layer.valueChanged.connect(self.sb_laynum)
109
+ self.combo_grid3.currentIndexChanged.connect(self.combo)
110
+ self.lw_editor_defs.currentItemChanged.connect(self.change_defs)
111
+ self.hslider_layer.valueChanged.connect(self.layer_hs)
112
+ self.pb_layer_rcopy.clicked.connect(self.rcopy)
113
+ self.sb_layer_linethick.valueChanged.connect(self.width)
114
+ self.hs_model_opacity.valueChanged.connect(self.sb_laynum)
115
+
116
+ def change_defs(self):
117
+ """ List box in layer tab for definitions """
118
+ i = self.lw_editor_defs.currentRow()
119
+ if i == -1:
120
+ misc.update_lith_lw(self.lmod, self.lw_editor_defs)
121
+ i = 0
122
+ itxt = str(self.lw_editor_defs.item(i).text())
123
+ if itxt not in self.lmod.lith_list.keys():
124
+ return
125
+
126
+ lith = self.lmod.lith_list[itxt]
127
+ self.mmc.curmodel = lith.lith_index
128
+
129
+ def combo(self):
130
+ """ Combo box to choose grid 3 """
131
+ ctxt = str(self.combo_grid3.currentText())
132
+ if ctxt == '':
133
+ return
134
+ self.grid3txt = ctxt
135
+ self.grid3 = self.lmod.griddata[ctxt]
136
+ self.update_model_plot()
137
+
138
+ def layer_hs(self, hval):
139
+ """ Horizontal slider to change the layer """
140
+ perc = hval / float(self.hslider_layer.maximum())
141
+ self.sb_model_layer.setValue(int((self.lmod.numz-1)*perc))
142
+ self.sb_laynum()
143
+
144
+ def rcopy(self):
145
+ """ Do a ranged copy on a layer """
146
+ self.update_model()
147
+ misc.rcopy_dialog(self.lmod, islayer=True, is_ew=self.lmod.is_ew)
148
+
149
+ def sb_laynum(self):
150
+ """ This increases or decreases the model layer """
151
+ self.update_model()
152
+ self.lmod.curlayer = self.sb_model_layer.value()
153
+ alt = self.lmod.zrange[1]-self.lmod.curlayer*self.lmod.d_z
154
+ self.label_altitude.setText('Altitude: '+str(alt))
155
+
156
+ gtmp = self.lmod.lith_index[:, :, self.lmod.curlayer].T.copy()
157
+ opac = self.hs_model_opacity.value()/100.
158
+ self.mmc.opac = opac
159
+ self.mmc.slide_grid(gtmp, self.grid3)
160
+
161
+ def update_combos(self):
162
+ """ This updates combos """
163
+ tmp = list(self.lmod.griddata.keys())
164
+ self.combo_grid3.blockSignals(True)
165
+
166
+ self.combo_grid3.clear()
167
+ self.combo_grid3.addItems(tmp)
168
+ self.combo_grid3.setCurrentIndex(tmp.index(self.grid3txt))
169
+
170
+ self.combo_grid3.blockSignals(False)
171
+
172
+ def update_model_plot(self):
173
+ """ This updates some of the plotting stuff """
174
+ self.lmod.curlayer = self.sb_model_layer.value()
175
+ alt = self.lmod.zrange[1]-self.lmod.curlayer*self.lmod.d_z
176
+ self.label_altitude.setText('Altitude: '+str(alt))
177
+
178
+ gtmp = self.lmod.lith_index[:, :, self.lmod.curlayer].T.copy()
179
+
180
+ left = self.lmod.xrange[0]
181
+ right = self.lmod.xrange[1]
182
+ bottom = self.lmod.yrange[0]
183
+ top = self.lmod.yrange[1]
184
+ extent = (left, right, bottom, top)
185
+ opac = self.hs_model_opacity.value()/100.
186
+
187
+ self.mmc.init_grid(gtmp, self.grid3, extent, opac)
188
+
189
+ if self.lmod.is_ew:
190
+ xys = self.lmod.yrange[0]+self.lmod.curprof*self.lmod.dxy
191
+ self.mmc.init_line(self.lmod.xrange, [xys, xys])
192
+ else:
193
+ xys = self.lmod.xrange[0]+self.lmod.curprof*self.lmod.dxy
194
+ self.mmc.init_line([xys, xys], self.lmod.yrange)
195
+
196
+ def update_model(self):
197
+ """ Updates the model from the graph """
198
+ self.lmod.lith_index[:, :, self.lmod.curlayer] = \
199
+ self.mmc.mdata.T.copy()
200
+
201
+ def width(self, width):
202
+ """ Sets the width of the edits on the layer view """
203
+ self.mmc.width = width
204
+
205
+ def tab_activate(self):
206
+ """ Runs when the tab is activated """
207
+ self.lmod = self.parent.lmod1
208
+ self.mmc.set_limits(self.lmod)
209
+ self.mmc.lmod = self.lmod
210
+ self.update_combos()
211
+ misc.update_lith_lw(self.lmod, self.lw_editor_defs)
212
+ self.sb_model_layer.setMaximum(self.lmod.numz-1)
213
+ self.combo()
214
+
215
+
216
+ class MyMplCanvas(FigureCanvas):
217
+ """
218
+ Canvas for the actual plot
219
+
220
+ Attributes
221
+ ----------
222
+ """
223
+ def __init__(self, parent, lmod):
224
+ # fig = Figure()
225
+ fig = plt.figure()
226
+ FigureCanvas.__init__(self, fig)
227
+
228
+ self.parent = parent
229
+ self.lmod = lmod
230
+ self.cbar = plt.cm.jet
231
+ self.curmodel = 0
232
+ self.width = 1
233
+ self.xold = None
234
+ self.yold = None
235
+ self.press = False
236
+ self.newline = False
237
+ self.mdata = np.zeros([100, 100])
238
+ self.opac = 1.0
239
+ self.xlims = None
240
+ self.ylims = None
241
+
242
+ # Events
243
+ self.figure.canvas.mpl_connect('motion_notify_event', self.move)
244
+ self.figure.canvas.mpl_connect('button_press_event', self.button_press)
245
+ self.figure.canvas.mpl_connect('button_release_event',
246
+ self.button_release)
247
+
248
+ # Initial Images
249
+ self.axes = fig.add_subplot(111)
250
+ self.axes.xaxis.set_label_text("Eastings (m)")
251
+ self.axes.yaxis.set_label_text("Northings (m)")
252
+ self.ims2 = plt.imshow(self.mdata, cmap=self.cbar,
253
+ interpolation='nearest')
254
+ self.ims = plt.imshow(self.cbar(self.mdata), interpolation='nearest')
255
+ self.figure.canvas.draw()
256
+
257
+ self.bbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
258
+
259
+ self.prf = self.axes.plot([0, 1], [0, 1])
260
+ self.figure.canvas.draw()
261
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
262
+
263
+ def button_press(self, event):
264
+ """ Button press """
265
+ nmode = self.axes.get_navigate_mode()
266
+ if event.button == 1 and nmode is None:
267
+ self.press = True
268
+ self.newline = True
269
+ self.move(event)
270
+
271
+ def button_release(self, event):
272
+ """ Button press """
273
+ if event.button == 1:
274
+ self.press = False
275
+ self.parent.update_model()
276
+
277
+ def move(self, event):
278
+ """ Mouse is moving """
279
+ if self.figure.canvas.toolbar._active is None:
280
+ vlim = self.axes.viewLim
281
+ xptp = self.lmod.xrange[1]-self.lmod.xrange[0]
282
+ yptp = self.lmod.yrange[1]-self.lmod.yrange[0]
283
+ if xptp > 10000 or yptp > 10000:
284
+ xptp /= 1000
285
+ yptp /= 1000
286
+ tmp0 = self.axes.transData.transform((vlim.x0, vlim.y0))
287
+ tmp1 = self.axes.transData.transform((vlim.x1, vlim.y1))
288
+ width, height = tmp1-tmp0
289
+ width /= self.mdata.shape[1]
290
+ height /= self.mdata.shape[0]
291
+
292
+ width *= xptp/vlim.width
293
+ height *= yptp/vlim.height
294
+
295
+ cwidth = (2*self.width-1)
296
+ cb = QtGui.QBitmap(cwidth*width, cwidth*height)
297
+ cb.fill(QtCore.Qt.color1)
298
+ self.setCursor(QtGui.QCursor(cb))
299
+
300
+ if self.axes.xaxis.get_label_text().find('km') > -1:
301
+ cdiv = 1000.
302
+ else:
303
+ cdiv = 1.
304
+
305
+ dxy = self.lmod.dxy/cdiv
306
+ xmin = self.lmod.xrange[0]/cdiv
307
+ ymin = self.lmod.yrange[0]/cdiv
308
+
309
+ if event.inaxes == self.axes and self.press is True:
310
+ col = int((event.xdata - xmin)/dxy)+1
311
+ row = int((event.ydata - ymin)/dxy)+1
312
+
313
+ xdata = col
314
+ ydata = row
315
+
316
+ if self.newline is True:
317
+ self.newline = False
318
+ self.set_mdata(xdata, ydata)
319
+ elif xdata != self.xold:
320
+ mmm = float(ydata-self.yold)/(xdata-self.xold)
321
+ ccc = ydata - mmm * xdata
322
+ x_1 = min([self.xold, xdata])
323
+ x_2 = max([self.xold, xdata])
324
+ for i in range(x_1+1, x_2+1):
325
+ jold = int(mmm*(i-1)+ccc)
326
+ jnew = int(mmm*i+ccc)
327
+ if jold > jnew:
328
+ jold, jnew = jnew, jold
329
+ for j in range(jold, jnew+1):
330
+ self.set_mdata(i, j)
331
+
332
+ elif ydata != self.yold:
333
+ y_1 = min([self.yold, ydata])
334
+ y_2 = max([self.yold, ydata])
335
+ for j in range(y_1, y_2+1):
336
+ self.set_mdata(xdata, j)
337
+
338
+ self.xold = xdata
339
+ self.yold = ydata
340
+
341
+ self.slide_grid(self.mdata)
342
+
343
+ def set_mdata(self, xdata, ydata):
344
+ """ Routine to 'draw' the line on mdata """
345
+ gheight = self.mdata.shape[0]
346
+ gwidth = self.mdata.shape[1]
347
+
348
+ width = self.width-1 # 'pen' width
349
+ xstart = xdata-width-1
350
+ xend = xdata+width
351
+ ystart = ydata-width-1
352
+ yend = ydata+width
353
+ if xstart < 0:
354
+ xstart = 0
355
+ if xend > gwidth:
356
+ xend = gwidth
357
+ if ystart < 0:
358
+ ystart = 0
359
+ if yend > gheight:
360
+ yend = gheight
361
+
362
+ if xstart < xend and ystart < yend:
363
+ mtmp = self.mdata[ystart:yend, xstart:xend]
364
+ mtmp[mtmp != -1] = self.curmodel
365
+
366
+ def luttodat(self, dat):
367
+ """ lut to dat grid """
368
+ mlut = self.lmod.mlut
369
+ tmp = np.zeros([dat.shape[0], dat.shape[1], 4])
370
+
371
+ for i in np.unique(dat):
372
+ if i == -1:
373
+ ctmp = [0, 0, 0, 0]
374
+ else:
375
+ ctmp = np.array(mlut[i]+[255])/255.
376
+
377
+ tmp[dat[::-1] == i] = ctmp
378
+ # tmp[dat == i] = ctmp
379
+
380
+ return tmp
381
+
382
+ def init_grid(self, dat, dat2, extent, opac):
383
+ """ Updates the single color map """
384
+ left, right, bottom, top = extent
385
+
386
+ if (right-left) > 10000 or (top-bottom) > 10000:
387
+ self.axes.xaxis.set_label_text("Eastings (km)")
388
+ self.axes.yaxis.set_label_text("Northings (km)")
389
+ left /= 1000.
390
+ right /= 1000.
391
+ top /= 1000.
392
+ bottom /= 1000.
393
+ extent = (left, right, bottom, top)
394
+ else:
395
+ self.axes.xaxis.set_label_text("Eastings (m)")
396
+ self.axes.yaxis.set_label_text("Northings (m)")
397
+
398
+ self.mdata = dat
399
+ tmp = self.luttodat(dat)
400
+
401
+ self.ims.set_visible(False)
402
+ self.ims.set_data(tmp)
403
+ self.ims.set_extent(extent)
404
+ self.ims.set_alpha(opac)
405
+
406
+ # self.ims2.set_data(dat2.data[::-1])
407
+ self.ims2.set_data(dat2.data)
408
+ self.ims2.set_extent(self.dat_extent(dat2))
409
+ if self.xlims is not None:
410
+ self.axes.set_xlim(self.xlims)
411
+ self.axes.set_ylim(self.ylims)
412
+ self.ims2.set_clim(dat2.data.min(), dat2.data.max())
413
+
414
+ self.figure.canvas.draw()
415
+ QtGui.QApplication.processEvents()
416
+ self.bbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
417
+
418
+ self.ims.set_visible(True)
419
+ self.figure.canvas.draw()
420
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
421
+ self.slide_grid(dat, dat2) # used to get rid of extra line
422
+
423
+ def slide_grid(self, dat, dat2=None):
424
+ """ Slider """
425
+ opac = self.opac
426
+
427
+ tmp = self.luttodat(dat)
428
+ self.ims.set_data(tmp)
429
+ self.ims.set_alpha(opac)
430
+ if dat2 is not None:
431
+ self.ims2.set_data(dat2.data)
432
+ # self.ims2.set_data(dat2.data[::-1])
433
+
434
+ self.figure.canvas.restore_region(self.bbox)
435
+ self.axes.draw_artist(self.ims2)
436
+ self.axes.draw_artist(self.ims)
437
+ # self.figure.canvas.blit(self.axes.bbox)
438
+ self.figure.canvas.update()
439
+ self.mdata = dat
440
+ self.lbbox = self.figure.canvas.copy_from_bbox(self.axes.bbox)
441
+ self.axes.draw_artist(self.prf[0])
442
+ # self.figure.canvas.blit(self.axes.bbox)
443
+ self.figure.canvas.update()
444
+
445
+ def init_line(self, xrng, yrng):
446
+ """ Updates the line position """
447
+ if self.axes.xaxis.get_label_text().find('km') > -1:
448
+ xrng = [xrng[0]/1000., xrng[1]/1000.]
449
+ yrng = [yrng[0]/1000., yrng[1]/1000.]
450
+
451
+ self.prf[0].set_data([xrng, yrng])
452
+ self.figure.canvas.restore_region(self.lbbox)
453
+ self.axes.draw_artist(self.prf[0])
454
+ # self.figure.canvas.blit(self.axes.bbox)
455
+ self.figure.canvas.update()
456
+
457
+ def dat_extent(self, dat):
458
+ """ Gets the extend of the dat variable """
459
+ left = dat.tlx
460
+ top = dat.tly
461
+ right = left + dat.cols*dat.xdim
462
+ bottom = top - dat.rows*dat.ydim
463
+
464
+ if (right-left) > 10000 or (top-bottom) > 10000:
465
+ self.axes.xaxis.set_label_text("Eastings (km)")
466
+ self.axes.yaxis.set_label_text("Northings (km)")
467
+ left /= 1000.
468
+ right /= 1000.
469
+ top /= 1000.
470
+ bottom /= 1000.
471
+ else:
472
+ self.axes.xaxis.set_label_text("Eastings (m)")
473
+ self.axes.yaxis.set_label_text("Northings (m)")
474
+
475
+ return (left, right, bottom, top)
476
+
477
+ def set_limits(self, lmod):
478
+ """ Sets limits for the axes """
479
+ left, right = lmod.xrange
480
+ bottom, top = lmod.yrange
481
+ if (right-left) > 10000 or (top-bottom) > 10000:
482
+ left /= 1000.
483
+ right /= 1000.
484
+ top /= 1000.
485
+ bottom /= 1000.
486
+
487
+ self.xlims = (left, right)
488
+ self.ylims = (bottom, top)
489
+ self.axes.set_xlim(self.xlims)
490
+ self.axes.set_ylim(self.ylims)