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.
- pygmi-2.2.7/LICENSE.txt +623 -0
- pygmi-2.2.7/MANIFEST.in +7 -0
- pygmi-2.2.7/PKG-INFO +47 -0
- pygmi-2.2.7/README.md +55 -0
- pygmi-2.2.7/README.rst +20 -0
- pygmi-2.2.7/log.txt +242 -0
- pygmi-2.2.7/pygmi/__init__.py +22 -0
- pygmi-2.2.7/pygmi/clust/__init__.py +4 -0
- pygmi-2.2.7/pygmi/clust/crisp_clust.py +708 -0
- pygmi-2.2.7/pygmi/clust/datatypes.py +65 -0
- pygmi-2.2.7/pygmi/clust/fuzzy_clust.py +906 -0
- pygmi-2.2.7/pygmi/clust/graphs.py +421 -0
- pygmi-2.2.7/pygmi/clust/graphtool.py +667 -0
- pygmi-2.2.7/pygmi/clust/menu.py +139 -0
- pygmi-2.2.7/pygmi/clust/var_ratio.py +92 -0
- pygmi-2.2.7/pygmi/clust/xie_beni.py +93 -0
- pygmi-2.2.7/pygmi/helpdocs/linepointer.png +0 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.main.html +31 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.ddisp.html +15 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.iodefs.exportkmz.html +13 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.iodefs.importpicture.html +16 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.layer.html +17 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.mext.html +44 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.misc.rangedcopy.html +16 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.param.html +37 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.prof.html +32 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.pfmod.pview.html +26 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.gradients.html +14 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.tilt.html +14 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.cooper.visibility.html +14 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datagrid.html +13 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datamerge.html +11 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.datareproj.html +11 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.dataprep.rtp.html +14 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.ginterp.html +31 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.igrf.html +20 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.normalisation.html +14 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.smooth.html +22 -0
- pygmi-2.2.7/pygmi/helpdocs/pygmi.raster.tiltdepth.html +20 -0
- pygmi-2.2.7/pygmi/images/Help.png +0 -0
- pygmi-2.2.7/pygmi/images/bringtofront.png +0 -0
- pygmi-2.2.7/pygmi/images/cgs2.emf +0 -0
- pygmi-2.2.7/pygmi/images/delete.png +0 -0
- pygmi-2.2.7/pygmi/images/linepointer.png +0 -0
- pygmi-2.2.7/pygmi/images/logo256.ico +0 -0
- pygmi-2.2.7/pygmi/images/logo256.png +0 -0
- pygmi-2.2.7/pygmi/images/pointer.png +0 -0
- pygmi-2.2.7/pygmi/images/pygmi.png +0 -0
- pygmi-2.2.7/pygmi/images/sendtoback.png +0 -0
- pygmi-2.2.7/pygmi/main.py +1037 -0
- pygmi-2.2.7/pygmi/menu_default.py +327 -0
- pygmi-2.2.7/pygmi/misc.py +147 -0
- pygmi-2.2.7/pygmi/pfmod/__init__.py +6 -0
- pygmi-2.2.7/pygmi/pfmod/cubes.py +1488 -0
- pygmi-2.2.7/pygmi/pfmod/datatypes.py +292 -0
- pygmi-2.2.7/pygmi/pfmod/grvmag3d.py +1265 -0
- pygmi-2.2.7/pygmi/pfmod/iodefs.py +1001 -0
- pygmi-2.2.7/pygmi/pfmod/menu.py +107 -0
- pygmi-2.2.7/pygmi/pfmod/misc.py +301 -0
- pygmi-2.2.7/pygmi/pfmod/pfmod.py +248 -0
- pygmi-2.2.7/pygmi/pfmod/tab_ddisp.py +425 -0
- pygmi-2.2.7/pygmi/pfmod/tab_layer.py +490 -0
- pygmi-2.2.7/pygmi/pfmod/tab_mext.py +544 -0
- pygmi-2.2.7/pygmi/pfmod/tab_param.py +548 -0
- pygmi-2.2.7/pygmi/pfmod/tab_prof.py +946 -0
- pygmi-2.2.7/pygmi/pfmod/tab_pview.py +740 -0
- pygmi-2.2.7/pygmi/raster/IGRF11.COF +1635 -0
- pygmi-2.2.7/pygmi/raster/__init__.py +14 -0
- pygmi-2.2.7/pygmi/raster/cooper.py +718 -0
- pygmi-2.2.7/pygmi/raster/dataprep.py +1640 -0
- pygmi-2.2.7/pygmi/raster/datatypes.py +123 -0
- pygmi-2.2.7/pygmi/raster/equation_editor.py +256 -0
- pygmi-2.2.7/pygmi/raster/ginterp.py +1901 -0
- pygmi-2.2.7/pygmi/raster/graphs.py +531 -0
- pygmi-2.2.7/pygmi/raster/igrf.py +860 -0
- pygmi-2.2.7/pygmi/raster/iodefs.py +813 -0
- pygmi-2.2.7/pygmi/raster/menu.py +307 -0
- pygmi-2.2.7/pygmi/raster/normalisation.py +187 -0
- pygmi-2.2.7/pygmi/raster/show_table.py +245 -0
- pygmi-2.2.7/pygmi/raster/smooth.py +406 -0
- pygmi-2.2.7/pygmi/raster/tiltdepth.py +590 -0
- pygmi-2.2.7/pygmi/seis/__init__.py +0 -0
- pygmi-2.2.7/pygmi/seis/beachball.py +751 -0
- pygmi-2.2.7/pygmi/seis/datatypes.py +605 -0
- pygmi-2.2.7/pygmi/seis/del_rec.py +410 -0
- pygmi-2.2.7/pygmi/seis/iodefs.py +1261 -0
- pygmi-2.2.7/pygmi/seis/menu.py +136 -0
- pygmi-2.2.7/pygmi/seis/scan_imp.py +795 -0
- pygmi-2.2.7/pygmi/test/__init__.py +6 -0
- pygmi-2.2.7/pygmi/test/pfmod.py +212 -0
- pygmi-2.2.7/pygmi/test/tests.py +39 -0
- pygmi-2.2.7/pygmi/vector/__init__.py +7 -0
- pygmi-2.2.7/pygmi/vector/datatypes.py +74 -0
- pygmi-2.2.7/pygmi/vector/graphs.py +443 -0
- pygmi-2.2.7/pygmi/vector/iodefs.py +345 -0
- pygmi-2.2.7/pygmi/vector/menu.py +127 -0
- pygmi-2.2.7/pygmi.egg-info/PKG-INFO +47 -0
- pygmi-2.2.7/pygmi.egg-info/SOURCES.txt +105 -0
- pygmi-2.2.7/pygmi.egg-info/dependency_links.txt +1 -0
- pygmi-2.2.7/pygmi.egg-info/entry_points.txt +3 -0
- pygmi-2.2.7/pygmi.egg-info/not-zip-safe +1 -0
- pygmi-2.2.7/pygmi.egg-info/requires.txt +7 -0
- pygmi-2.2.7/pygmi.egg-info/top_level.txt +1 -0
- pygmi-2.2.7/quickstart.py +35 -0
- pygmi-2.2.7/setup.cfg +8 -0
- pygmi-2.2.7/setup.py +80 -0
|
@@ -0,0 +1,1001 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Name: iodefs.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
|
+
""" Import Data """
|
|
26
|
+
|
|
27
|
+
from PyQt4 import QtGui, QtCore
|
|
28
|
+
from osgeo import osr, gdal
|
|
29
|
+
import os
|
|
30
|
+
import numpy as np
|
|
31
|
+
import sys
|
|
32
|
+
from .datatypes import Data, LithModel
|
|
33
|
+
import matplotlib.pyplot as plt
|
|
34
|
+
import zipfile
|
|
35
|
+
from . import grvmag3d
|
|
36
|
+
from . import cubes as mvis3d
|
|
37
|
+
import pygmi.menu_default as menu_default
|
|
38
|
+
import pygmi.raster.dataprep as dp
|
|
39
|
+
|
|
40
|
+
# This is necessary for loading npz files, since I moved the location of
|
|
41
|
+
# datatypes.
|
|
42
|
+
from . import datatypes
|
|
43
|
+
sys.modules['datatypes'] = datatypes
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ImportMod3D(object):
|
|
47
|
+
""" Import Data """
|
|
48
|
+
def __init__(self, parent):
|
|
49
|
+
self.parent = parent
|
|
50
|
+
self.lmod = LithModel()
|
|
51
|
+
|
|
52
|
+
self.ifile = ""
|
|
53
|
+
self.name = "Import 3D Model: "
|
|
54
|
+
self.ext = ""
|
|
55
|
+
self.pbar = None
|
|
56
|
+
self.indata = {}
|
|
57
|
+
self.outdata = {}
|
|
58
|
+
|
|
59
|
+
def settings(self):
|
|
60
|
+
""" Settings """
|
|
61
|
+
filename = QtGui.QFileDialog.getOpenFileName(
|
|
62
|
+
self.parent, 'Open File', '.',
|
|
63
|
+
'npz (*.npz);;csv (*.csv);; txt (*.txt)')
|
|
64
|
+
if filename == '':
|
|
65
|
+
return False
|
|
66
|
+
os.chdir(filename.rpartition('/')[0])
|
|
67
|
+
self.ifile = str(filename)
|
|
68
|
+
self.parent.modelfilename = filename.rpartition('.')[0]
|
|
69
|
+
|
|
70
|
+
# Reset Variables
|
|
71
|
+
self.lmod.griddata.clear()
|
|
72
|
+
self.lmod.lith_list.clear()
|
|
73
|
+
|
|
74
|
+
if filename.find('.csv') > -1:
|
|
75
|
+
self.import_ascii_xyz_model(filename)
|
|
76
|
+
elif filename.find('.txt') > -1:
|
|
77
|
+
self.import_ascii_xyz_model(filename)
|
|
78
|
+
else:
|
|
79
|
+
indict = np.load(filename)
|
|
80
|
+
self.dict2lmod(indict)
|
|
81
|
+
|
|
82
|
+
self.outdata['Model3D'] = [self.lmod]
|
|
83
|
+
self.lmod.name = filename.rpartition('/')[-1]
|
|
84
|
+
|
|
85
|
+
for i in self.lmod.griddata.keys():
|
|
86
|
+
if self.lmod.griddata[i].dataid == '':
|
|
87
|
+
self.lmod.griddata[i].dataid = i
|
|
88
|
+
# try:
|
|
89
|
+
# except AttributeError:
|
|
90
|
+
# if self.lmod.griddata[i].bandid == '':
|
|
91
|
+
# self.lmod.griddata[i].dataid = i
|
|
92
|
+
|
|
93
|
+
self.outdata['Raster'] = list(self.lmod.griddata.values())
|
|
94
|
+
|
|
95
|
+
return True
|
|
96
|
+
|
|
97
|
+
def import_ascii_xyz_model(self, filename):
|
|
98
|
+
""" Used to import ASCII XYZ Models of the form x,y,z,label"""
|
|
99
|
+
|
|
100
|
+
if filename.find('.csv') > -1:
|
|
101
|
+
tmp = np.genfromtxt(filename, delimiter=',', dtype=np.str)
|
|
102
|
+
else:
|
|
103
|
+
tmp = np.genfromtxt(filename, dtype=np.str)
|
|
104
|
+
|
|
105
|
+
x = tmp[:, 0].astype(np.float)
|
|
106
|
+
y = tmp[:, 1].astype(np.float)
|
|
107
|
+
z = tmp[:, 2].astype(np.float)
|
|
108
|
+
label = tmp[:, 3]
|
|
109
|
+
|
|
110
|
+
x_u = np.array(np.unique(x))
|
|
111
|
+
y_u = np.array(np.unique(y))
|
|
112
|
+
z_u = np.array(np.unique(z))
|
|
113
|
+
labelu = np.unique(label)
|
|
114
|
+
xcell = x.ptp()/float(x_u.shape[0]-1)
|
|
115
|
+
ycell = x.ptp()/float(y_u.shape[0]-1)
|
|
116
|
+
zcell = x.ptp()/float(z_u.shape[0]-1)
|
|
117
|
+
|
|
118
|
+
lmod = self.lmod
|
|
119
|
+
|
|
120
|
+
lmod.numx = x_u.shape[0]
|
|
121
|
+
lmod.numy = y_u.shape[0]
|
|
122
|
+
lmod.numz = z_u.shape[0]
|
|
123
|
+
lmod.dxy = max(xcell, ycell)
|
|
124
|
+
lmod.d_z = zcell
|
|
125
|
+
# lmod.lith_index = indict[pre+'lith_index']
|
|
126
|
+
lmod.curprof = 0
|
|
127
|
+
lmod.curlayer = 0
|
|
128
|
+
lmod.xrange = [x_u.min()-lmod.dxy/2., x_u.max()+lmod.dxy/2.]
|
|
129
|
+
lmod.yrange = [y_u.min()-lmod.dxy/2., y_u.max()+lmod.dxy/2.]
|
|
130
|
+
lmod.zrange = [z_u.min()-lmod.d_z/2., z_u.max()+lmod.d_z/2.]
|
|
131
|
+
|
|
132
|
+
# Section to load lithologies.
|
|
133
|
+
lmod.lith_list.pop('Generic 1')
|
|
134
|
+
|
|
135
|
+
lindx = 0
|
|
136
|
+
for itxt in labelu:
|
|
137
|
+
lindx += 1
|
|
138
|
+
lmod.mlut[lindx] = [np.random.randint(0, 255),
|
|
139
|
+
np.random.randint(0, 255),
|
|
140
|
+
np.random.randint(0, 255)]
|
|
141
|
+
lmod.lith_list[itxt] = grvmag3d.GeoData(
|
|
142
|
+
self.parent, ncols=lmod.numx, nrows=lmod.numy, numz=lmod.numz,
|
|
143
|
+
dxy=lmod.dxy, d_z=lmod.d_z)
|
|
144
|
+
|
|
145
|
+
lmod.lith_list[itxt].lith_index = lindx
|
|
146
|
+
lmod.lith_list[itxt].modified = True
|
|
147
|
+
lmod.lith_list[itxt].set_xyz12()
|
|
148
|
+
|
|
149
|
+
lmod.update(lmod.numx, lmod.numy, lmod.numz, lmod.xrange[0],
|
|
150
|
+
lmod.yrange[1], lmod.zrange[1], lmod.dxy, lmod.d_z)
|
|
151
|
+
lmod.update_lith_list_reverse()
|
|
152
|
+
|
|
153
|
+
for i in range(len(x)):
|
|
154
|
+
col = int((x[i]-lmod.xrange[0])/lmod.dxy)
|
|
155
|
+
row = int((lmod.yrange[1]-y[i])/lmod.dxy)
|
|
156
|
+
layer = int((lmod.zrange[1]-z[i])/lmod.d_z)
|
|
157
|
+
lmod.lith_index[col, row, layer] = \
|
|
158
|
+
lmod.lith_list[label[i]].lith_index
|
|
159
|
+
|
|
160
|
+
def dict2lmod(self, indict, pre=''):
|
|
161
|
+
""" routine to convert a dictionary to an lmod """
|
|
162
|
+
lithkeys = indict[pre+'lithkeys']
|
|
163
|
+
# self.pbars.resetall(maximum=lithkeys.size+1)
|
|
164
|
+
|
|
165
|
+
lmod = self.lmod
|
|
166
|
+
|
|
167
|
+
lmod.gregional = indict[pre+'gregional']
|
|
168
|
+
lmod.ght = indict[pre+'ght']
|
|
169
|
+
lmod.mht = indict[pre+'mht']
|
|
170
|
+
lmod.numx = indict[pre+'numx']
|
|
171
|
+
lmod.numy = indict[pre+'numy']
|
|
172
|
+
lmod.numz = indict[pre+'numz']
|
|
173
|
+
lmod.dxy = indict[pre+'dxy']
|
|
174
|
+
lmod.d_z = indict[pre+'d_z']
|
|
175
|
+
lmod.lith_index = indict[pre+'lith_index']
|
|
176
|
+
lmod.clith_index = np.zeros_like(lmod.lith_index)
|
|
177
|
+
lmod.curprof = 0
|
|
178
|
+
lmod.curlayer = 0
|
|
179
|
+
lmod.xrange = np.array(indict[pre+'xrange']).tolist()
|
|
180
|
+
lmod.yrange = np.array(indict[pre+'yrange']).tolist()
|
|
181
|
+
lmod.zrange = np.array(indict[pre+'zrange']).tolist()
|
|
182
|
+
if pre+'custprofx' in indict:
|
|
183
|
+
lmod.custprofx = np.asscalar(indict[pre+'custprofx'])
|
|
184
|
+
else:
|
|
185
|
+
lmod.custprofx = {0: (lmod.xrange[0], lmod.xrange[1])}
|
|
186
|
+
if pre+'custprofy' in indict:
|
|
187
|
+
lmod.custprofy = np.asscalar(indict[pre+'custprofy'])
|
|
188
|
+
else:
|
|
189
|
+
lmod.custprofy = {0: (lmod.yrange[0], lmod.yrange[0])}
|
|
190
|
+
|
|
191
|
+
lmod.mlut = np.asscalar(indict[pre+'mlut'])
|
|
192
|
+
lmod.init_calc_grids()
|
|
193
|
+
lmod.griddata = np.asscalar(indict[pre+'griddata'])
|
|
194
|
+
|
|
195
|
+
# This gets rid of a legacy variable name
|
|
196
|
+
for i in lmod.griddata.keys():
|
|
197
|
+
if not hasattr(lmod.griddata[i], 'dataid'):
|
|
198
|
+
lmod.griddata[i].dataid = ''
|
|
199
|
+
if hasattr(lmod.griddata[i], 'bandid'):
|
|
200
|
+
if lmod.griddata[i].dataid is '':
|
|
201
|
+
lmod.griddata[i].dataid = lmod.griddata[i].bandid
|
|
202
|
+
del lmod.griddata[i].bandid
|
|
203
|
+
|
|
204
|
+
wktfin = None
|
|
205
|
+
for i in lmod.griddata.keys():
|
|
206
|
+
wkt = lmod.griddata[i].wkt
|
|
207
|
+
if wkt != '' and wkt is not None:
|
|
208
|
+
wktfin = wkt
|
|
209
|
+
|
|
210
|
+
if wktfin is not None:
|
|
211
|
+
for i in lmod.griddata.keys():
|
|
212
|
+
wkt = lmod.griddata[i].wkt
|
|
213
|
+
if wkt == '' or wkt is None:
|
|
214
|
+
lmod.griddata[i].wkt = wktfin
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# self.pbars.incr()
|
|
218
|
+
|
|
219
|
+
# Section to load lithologies.
|
|
220
|
+
lmod.lith_list['Background'] = grvmag3d.GeoData(self.parent)
|
|
221
|
+
|
|
222
|
+
for itxt in lithkeys:
|
|
223
|
+
if itxt != 'Background':
|
|
224
|
+
lmod.lith_list[itxt] = grvmag3d.GeoData(self.parent)
|
|
225
|
+
|
|
226
|
+
lmod.lith_list[itxt].hintn = np.asscalar(indict[pre+itxt+'_hintn'])
|
|
227
|
+
lmod.lith_list[itxt].finc = np.asscalar(indict[pre+itxt+'_finc'])
|
|
228
|
+
lmod.lith_list[itxt].fdec = np.asscalar(indict[pre+itxt+'_fdec'])
|
|
229
|
+
lmod.lith_list[itxt].zobsm = np.asscalar(indict[pre+itxt+'_zobsm'])
|
|
230
|
+
lmod.lith_list[itxt].susc = np.asscalar(indict[pre+itxt+'_susc'])
|
|
231
|
+
lmod.lith_list[itxt].mstrength = np.asscalar(
|
|
232
|
+
indict[pre+itxt+'_mstrength'])
|
|
233
|
+
lmod.lith_list[itxt].qratio = np.asscalar(
|
|
234
|
+
indict[pre+itxt+'_qratio'])
|
|
235
|
+
lmod.lith_list[itxt].minc = np.asscalar(indict[pre+itxt+'_minc'])
|
|
236
|
+
lmod.lith_list[itxt].mdec = np.asscalar(indict[pre+itxt+'_mdec'])
|
|
237
|
+
lmod.lith_list[itxt].density = np.asscalar(
|
|
238
|
+
indict[pre+itxt+'_density'])
|
|
239
|
+
lmod.lith_list[itxt].bdensity = np.asscalar(
|
|
240
|
+
indict[pre+itxt+'_bdensity'])
|
|
241
|
+
lmod.lith_list[itxt].lith_index = np.asscalar(
|
|
242
|
+
indict[pre+itxt+'_lith_index'])
|
|
243
|
+
lmod.lith_list[itxt].g_cols = np.asscalar(indict[pre+itxt+'_numx'])
|
|
244
|
+
lmod.lith_list[itxt].g_rows = np.asscalar(indict[pre+itxt+'_numy'])
|
|
245
|
+
lmod.lith_list[itxt].numz = np.asscalar(indict[pre+itxt+'_numz'])
|
|
246
|
+
lmod.lith_list[itxt].g_dxy = np.asscalar(indict[pre+itxt+'_dxy'])
|
|
247
|
+
lmod.lith_list[itxt].dxy = np.asscalar(indict[pre+itxt+'_dxy'])
|
|
248
|
+
lmod.lith_list[itxt].d_z = np.asscalar(indict[pre+itxt+'_d_z'])
|
|
249
|
+
lmod.lith_list[itxt].zobsm = np.asscalar(indict[pre+itxt+'_zobsm'])
|
|
250
|
+
lmod.lith_list[itxt].zobsg = np.asscalar(indict[pre+itxt+'_zobsg'])
|
|
251
|
+
lmod.lith_list[itxt].modified = True
|
|
252
|
+
lmod.lith_list[itxt].set_xyz12()
|
|
253
|
+
# self.pbars.incr()
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class ExportMod3D(object):
|
|
257
|
+
""" Export Data """
|
|
258
|
+
def __init__(self, parent):
|
|
259
|
+
self.ifile = ""
|
|
260
|
+
self.name = "Import Data: "
|
|
261
|
+
self.ext = ""
|
|
262
|
+
self.pbar = None
|
|
263
|
+
self.parent = parent
|
|
264
|
+
self.indata = {}
|
|
265
|
+
self.outdata = {}
|
|
266
|
+
self.lmod = None
|
|
267
|
+
# self.dirname = ""
|
|
268
|
+
self.showtext = self.parent.showprocesslog
|
|
269
|
+
|
|
270
|
+
def run(self):
|
|
271
|
+
""" Show Info """
|
|
272
|
+
if 'Model3D' not in self.indata:
|
|
273
|
+
self.parent.showprocesslog(
|
|
274
|
+
'Error: You need to have a model first!')
|
|
275
|
+
return
|
|
276
|
+
|
|
277
|
+
for self.lmod in self.indata['Model3D']:
|
|
278
|
+
filename = QtGui.QFileDialog.getSaveFileName(
|
|
279
|
+
self.parent, 'Save File', '.',
|
|
280
|
+
'npz (*.npz);;kmz (*.kmz);;csv (*.csv)')
|
|
281
|
+
|
|
282
|
+
if filename == '':
|
|
283
|
+
return
|
|
284
|
+
|
|
285
|
+
os.chdir(filename.rpartition('/')[0])
|
|
286
|
+
self.ifile = str(filename)
|
|
287
|
+
self.ext = filename[-3:]
|
|
288
|
+
|
|
289
|
+
# Pop up save dialog box
|
|
290
|
+
if self.ext == 'npz':
|
|
291
|
+
self.savemodel()
|
|
292
|
+
if self.ext == 'kmz':
|
|
293
|
+
self.mod3dtokmz()
|
|
294
|
+
if self.ext == 'csv':
|
|
295
|
+
self.mod3dtocsv()
|
|
296
|
+
|
|
297
|
+
def savemodel(self):
|
|
298
|
+
""" Save model """
|
|
299
|
+
# Open file
|
|
300
|
+
# self.pbars.resetall(maximum = 2)
|
|
301
|
+
filename = self.ifile
|
|
302
|
+
|
|
303
|
+
# Construct output dictionary
|
|
304
|
+
outdict = {}
|
|
305
|
+
outdict = self.lmod2dict(outdict)
|
|
306
|
+
# self.pbars.incr()
|
|
307
|
+
|
|
308
|
+
# Save data
|
|
309
|
+
np.savez_compressed(filename, **outdict)
|
|
310
|
+
# self.pbars.incr()
|
|
311
|
+
self.showtext('Model save complete')
|
|
312
|
+
|
|
313
|
+
def lmod2dict(self, outdict, pre=''):
|
|
314
|
+
""" place lmod in dictionary """
|
|
315
|
+
|
|
316
|
+
outdict[pre+"gregional"] = self.lmod.gregional
|
|
317
|
+
outdict[pre+"ght"] = self.lmod.ght
|
|
318
|
+
outdict[pre+"mht"] = self.lmod.mht
|
|
319
|
+
outdict[pre+"numx"] = self.lmod.numx
|
|
320
|
+
outdict[pre+"numy"] = self.lmod.numy
|
|
321
|
+
outdict[pre+"numz"] = self.lmod.numz
|
|
322
|
+
outdict[pre+"dxy"] = self.lmod.dxy
|
|
323
|
+
outdict[pre+"d_z"] = self.lmod.d_z
|
|
324
|
+
outdict[pre+"lith_index"] = self.lmod.lith_index
|
|
325
|
+
outdict[pre+"xrange"] = self.lmod.xrange
|
|
326
|
+
outdict[pre+"yrange"] = self.lmod.yrange
|
|
327
|
+
outdict[pre+"zrange"] = self.lmod.zrange
|
|
328
|
+
outdict[pre+"mlut"] = self.lmod.mlut
|
|
329
|
+
outdict[pre+"griddata"] = self.lmod.griddata
|
|
330
|
+
outdict[pre+"custprofx"] = self.lmod.custprofx
|
|
331
|
+
outdict[pre+"custprofy"] = self.lmod.custprofy
|
|
332
|
+
|
|
333
|
+
# Section to save lithologies.
|
|
334
|
+
outdict[pre+"lithkeys"] = list(self.lmod.lith_list.keys())
|
|
335
|
+
|
|
336
|
+
for i in self.lmod.lith_list.items():
|
|
337
|
+
curkey = i[0]
|
|
338
|
+
outdict[pre+curkey+"_hintn"] = i[1].hintn
|
|
339
|
+
outdict[pre+curkey+"_finc"] = i[1].finc
|
|
340
|
+
outdict[pre+curkey+"_fdec"] = i[1].fdec
|
|
341
|
+
outdict[pre+curkey+"_zobsm"] = i[1].zobsm
|
|
342
|
+
outdict[pre+curkey+"_susc"] = i[1].susc
|
|
343
|
+
outdict[pre+curkey+"_mstrength"] = i[1].mstrength
|
|
344
|
+
outdict[pre+curkey+"_qratio"] = i[1].qratio
|
|
345
|
+
outdict[pre+curkey+"_minc"] = i[1].minc
|
|
346
|
+
outdict[pre+curkey+"_mdec"] = i[1].mdec
|
|
347
|
+
outdict[pre+curkey+"_density"] = i[1].density
|
|
348
|
+
outdict[pre+curkey+"_bdensity"] = i[1].bdensity
|
|
349
|
+
outdict[pre+curkey+"_lith_index"] = i[1].lith_index
|
|
350
|
+
outdict[pre+curkey+"_numx"] = i[1].g_cols
|
|
351
|
+
outdict[pre+curkey+"_numy"] = i[1].g_rows
|
|
352
|
+
outdict[pre+curkey+"_numz"] = i[1].numz
|
|
353
|
+
outdict[pre+curkey+"_dxy"] = i[1].g_dxy
|
|
354
|
+
outdict[pre+curkey+"_d_z"] = i[1].d_z
|
|
355
|
+
outdict[pre+curkey+"_zobsm"] = i[1].zobsm
|
|
356
|
+
outdict[pre+curkey+"_zobsg"] = i[1].zobsg
|
|
357
|
+
outdict[pre+curkey+"_x12"] = i[1].x12
|
|
358
|
+
outdict[pre+curkey+"_y12"] = i[1].y12
|
|
359
|
+
outdict[pre+curkey+"_z12"] = i[1].z12
|
|
360
|
+
|
|
361
|
+
return outdict
|
|
362
|
+
|
|
363
|
+
def mod3dtocsv(self):
|
|
364
|
+
""" Saves the 3D model in a csv file. """
|
|
365
|
+
# self.pbars.resetall(maximum = self.lmod1.numx, mmax = 2)
|
|
366
|
+
|
|
367
|
+
self.showtext('csv export starting...')
|
|
368
|
+
|
|
369
|
+
self.lmod.update_lith_list_reverse()
|
|
370
|
+
lithname = self.lmod.lith_list_reverse.copy()
|
|
371
|
+
lithlist = self.lmod.lith_list.copy()
|
|
372
|
+
|
|
373
|
+
tmp = []
|
|
374
|
+
ltmp = []
|
|
375
|
+
for i in range(self.lmod.numx):
|
|
376
|
+
# self.pbars.incr()
|
|
377
|
+
x = self.lmod.xrange[0]+i*self.lmod.dxy
|
|
378
|
+
for j in range(self.lmod.numy):
|
|
379
|
+
y = self.lmod.yrange[0]+j*self.lmod.dxy
|
|
380
|
+
for k in range(self.lmod.numz):
|
|
381
|
+
z = self.lmod.zrange[1]-k*self.lmod.d_z
|
|
382
|
+
lith = self.lmod.lith_index[i, j, k]
|
|
383
|
+
if lith > -1:
|
|
384
|
+
name = lithname[lith]
|
|
385
|
+
dens = lithlist[name].density
|
|
386
|
+
susc = lithlist[name].susc
|
|
387
|
+
tmp.append([x, y, z, dens, susc, lith])
|
|
388
|
+
ltmp.append(lithname[lith])
|
|
389
|
+
|
|
390
|
+
# self.pbars.resetsub(1)
|
|
391
|
+
tmp = np.array(tmp)
|
|
392
|
+
ltmp = np.array(ltmp)
|
|
393
|
+
stmp = np.zeros(len(tmp), dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4'),
|
|
394
|
+
('dens', 'f4'), ('susc', 'f4'),
|
|
395
|
+
('lith', 'i4'), ('lithname', 'a24')])
|
|
396
|
+
|
|
397
|
+
stmp['x'] = tmp[:, 0]
|
|
398
|
+
stmp['y'] = tmp[:, 1]
|
|
399
|
+
stmp['z'] = tmp[:, 2]
|
|
400
|
+
stmp['dens'] = tmp[:, 3]
|
|
401
|
+
stmp['susc'] = tmp[:, 4]
|
|
402
|
+
stmp['lith'] = tmp[:, 5]
|
|
403
|
+
stmp['lithname'] = ltmp
|
|
404
|
+
|
|
405
|
+
head = 'X, Y, Z, Density, Susceptibility, Lithology Code, Lithology'
|
|
406
|
+
np.savetxt(self.ifile, stmp, fmt="%f, %f, %f, %f, %f, %i, %s",
|
|
407
|
+
header=head)
|
|
408
|
+
# self.pbars.incr()
|
|
409
|
+
|
|
410
|
+
self.showtext('csv export complete...')
|
|
411
|
+
|
|
412
|
+
def mod3dtokmz(self):
|
|
413
|
+
""" Saves the 3D model and grids in a kmz file.
|
|
414
|
+
Note:
|
|
415
|
+
Only the boundary of the area is in degrees. The actual coordinates
|
|
416
|
+
are still in meters.
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
mvis_3d = mvis3d.Mod3dDisplay()
|
|
420
|
+
mvis_3d.lmod1 = self.lmod
|
|
421
|
+
# mvis_3d.checkbox_smooth.setChecked(True)
|
|
422
|
+
|
|
423
|
+
rev = 1 # should be 1 normally
|
|
424
|
+
|
|
425
|
+
xrng = np.array(self.lmod.xrange, dtype=float)
|
|
426
|
+
yrng = np.array(self.lmod.yrange, dtype=float)
|
|
427
|
+
zrng = np.array(self.lmod.zrange, dtype=float)
|
|
428
|
+
|
|
429
|
+
if 'Raster' in self.indata:
|
|
430
|
+
wkt = self.indata['Raster'][0].wkt
|
|
431
|
+
else:
|
|
432
|
+
wkt = ''
|
|
433
|
+
prjkmz = Exportkmz(wkt)
|
|
434
|
+
tmp = prjkmz.exec_()
|
|
435
|
+
|
|
436
|
+
if tmp == 0:
|
|
437
|
+
return
|
|
438
|
+
|
|
439
|
+
smooth = prjkmz.checkbox_smooth.isChecked()
|
|
440
|
+
|
|
441
|
+
orig_wkt = prjkmz.proj.wkt
|
|
442
|
+
orig = osr.SpatialReference()
|
|
443
|
+
orig.ImportFromWkt(orig_wkt)
|
|
444
|
+
|
|
445
|
+
targ = osr.SpatialReference()
|
|
446
|
+
targ.SetWellKnownGeogCS('WGS84')
|
|
447
|
+
prj = osr.CoordinateTransformation(orig, targ)
|
|
448
|
+
|
|
449
|
+
res = prj.TransformPoint(xrng[0], yrng[0])
|
|
450
|
+
lonwest, latsouth = res[0], res[1]
|
|
451
|
+
res = prj.TransformPoint(xrng[1], yrng[1])
|
|
452
|
+
loneast, latnorth = res[0], res[1]
|
|
453
|
+
|
|
454
|
+
# pdb.set_trace()
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
# Get Save Name
|
|
458
|
+
filename = self.ifile
|
|
459
|
+
|
|
460
|
+
self.showtext('kmz export starting...')
|
|
461
|
+
|
|
462
|
+
# Move to 3d model tab to update the model stuff
|
|
463
|
+
self.showtext('updating 3d model...')
|
|
464
|
+
|
|
465
|
+
mvis_3d.spacing = [self.lmod.dxy, self.lmod.dxy, self.lmod.d_z]
|
|
466
|
+
mvis_3d.origin = [xrng[0], yrng[0], zrng[0]]
|
|
467
|
+
mvis_3d.gdata = self.lmod.lith_index[::1, ::1, ::-1]
|
|
468
|
+
itmp = np.sort(np.unique(self.lmod.lith_index))
|
|
469
|
+
itmp = itmp[itmp > 0]
|
|
470
|
+
tmp = np.ones((255, 4))*255
|
|
471
|
+
for i in itmp:
|
|
472
|
+
tmp[i, :3] = self.lmod.mlut[i]
|
|
473
|
+
mvis_3d.lut = tmp
|
|
474
|
+
# mvis_3d.update_plot(fullcalc = True)
|
|
475
|
+
mvis_3d.update_model(smooth)
|
|
476
|
+
|
|
477
|
+
self.showtext('creating kmz file')
|
|
478
|
+
heading = str(0.)
|
|
479
|
+
tilt = str(45.) # angle from vertical
|
|
480
|
+
lat = str(np.mean([latsouth, latnorth])) # coord of object
|
|
481
|
+
lon = str(np.mean([lonwest, loneast])) # coord of object
|
|
482
|
+
rng = str(max(xrng.ptp(), yrng.ptp(), zrng.ptp())) # range to object
|
|
483
|
+
alt = str(0) # alt of object eye is looking at (meters)
|
|
484
|
+
lato = str(latsouth)
|
|
485
|
+
lono = str(lonwest)
|
|
486
|
+
|
|
487
|
+
# update colors
|
|
488
|
+
self.lmod.update_lith_list_reverse()
|
|
489
|
+
|
|
490
|
+
dockml = (
|
|
491
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\r\n'
|
|
492
|
+
'<kml xmlns="http://www.opengis.net/kml/2.2" '
|
|
493
|
+
'xmlns:gx="http://www.google.com/kml/ext/2.2">\r\n'
|
|
494
|
+
'\r\n'
|
|
495
|
+
' <Folder>\r\n'
|
|
496
|
+
' <name>Lithological Model</name>\r\n'
|
|
497
|
+
' <description>Created with PyGMI</description>\r\n'
|
|
498
|
+
' <visibility>1</visibility>\r\n'
|
|
499
|
+
' <LookAt>\r\n'
|
|
500
|
+
' <heading>' + heading + '</heading>\r\n'
|
|
501
|
+
' <tilt>' + tilt + '</tilt>\r\n'
|
|
502
|
+
' <latitude>' + lat + '</latitude>\r\n'
|
|
503
|
+
' <longitude>' + lon + '</longitude>\r\n'
|
|
504
|
+
' <range>' + rng + '</range>\r\n'
|
|
505
|
+
' <altitude>' + alt + '</altitude>\r\n'
|
|
506
|
+
' </LookAt>\r\n')
|
|
507
|
+
|
|
508
|
+
mvis_3d.update_for_kmz()
|
|
509
|
+
|
|
510
|
+
modeldae = []
|
|
511
|
+
# pmax = len(mvis_3d.gfaces)
|
|
512
|
+
# self.pbars.resetsub(maximum=pmax)
|
|
513
|
+
lkey = list(mvis_3d.faces.keys())
|
|
514
|
+
lkey.pop(lkey.index(0))
|
|
515
|
+
lithcnt = -1
|
|
516
|
+
|
|
517
|
+
alt = 0
|
|
518
|
+
for lith in lkey:
|
|
519
|
+
faces = np.array(mvis_3d.gfaces[lith])
|
|
520
|
+
# Google wants the model to have origin (0,0)
|
|
521
|
+
|
|
522
|
+
points = mvis_3d.gpoints[lith]
|
|
523
|
+
|
|
524
|
+
points -= mvis_3d.origin
|
|
525
|
+
|
|
526
|
+
x = points[:, 0]
|
|
527
|
+
y = points[:, 1]
|
|
528
|
+
earthrad = 6378137.
|
|
529
|
+
z = earthrad-np.sqrt(earthrad**2-(x**2+y**2))
|
|
530
|
+
points[:, 2] -= z
|
|
531
|
+
|
|
532
|
+
# pdb.set_trace()
|
|
533
|
+
|
|
534
|
+
if rev == -1:
|
|
535
|
+
points += [xrng.ptp(), yrng.ptp(), 0]
|
|
536
|
+
|
|
537
|
+
norm = np.abs(mvis_3d.gnorms[lith])
|
|
538
|
+
clrtmp = np.array(self.lmod.mlut[lith])/255.
|
|
539
|
+
curmod = self.lmod.lith_list_reverse[lith]
|
|
540
|
+
|
|
541
|
+
if len(points) > 60000:
|
|
542
|
+
self.showtext(curmod + ' has too many points (' +
|
|
543
|
+
str(len(points))+'). Not exported')
|
|
544
|
+
points = points[:60000]
|
|
545
|
+
norm = norm[:60000]
|
|
546
|
+
faces = faces[faces.max(1) < 60000]
|
|
547
|
+
# continue
|
|
548
|
+
|
|
549
|
+
lithcnt += 1
|
|
550
|
+
|
|
551
|
+
dockml += (
|
|
552
|
+
' <Placemark>\r\n'
|
|
553
|
+
' <name>' + curmod + '</name>\r\n'
|
|
554
|
+
' <description></description>\r\n'
|
|
555
|
+
' <Style id="default"/>\r\n'
|
|
556
|
+
' <Model>\r\n'
|
|
557
|
+
' <altitudeMode>absolute</altitudeMode>\r\n'
|
|
558
|
+
' <Location>\r\n'
|
|
559
|
+
' <latitude>' + lato + '</latitude>\r\n'
|
|
560
|
+
' <longitude>' + lono + '</longitude>\r\n'
|
|
561
|
+
' <altitude>' + str(alt) + '</altitude>\r\n'
|
|
562
|
+
' </Location>\r\n'
|
|
563
|
+
' <Orientation>\r\n'
|
|
564
|
+
' <heading>0</heading>\r\n'
|
|
565
|
+
' <tilt>0</tilt>\r\n'
|
|
566
|
+
' <roll>0</roll>\r\n'
|
|
567
|
+
' </Orientation>\r\n'
|
|
568
|
+
' <Scale>\r\n'
|
|
569
|
+
' <x>1</x>\r\n'
|
|
570
|
+
' <y>1</y>\r\n'
|
|
571
|
+
' <z>1</z>\r\n'
|
|
572
|
+
' </Scale>\r\n'
|
|
573
|
+
' <Link>\r\n'
|
|
574
|
+
' <href>models/mod3d' + str(lithcnt) +
|
|
575
|
+
'.dae</href>\r\n'
|
|
576
|
+
' </Link>\r\n'
|
|
577
|
+
' </Model>\r\n'
|
|
578
|
+
' </Placemark>\r\n')
|
|
579
|
+
|
|
580
|
+
position = str(points.flatten().tolist())
|
|
581
|
+
position = position.replace('[', '')
|
|
582
|
+
position = position.replace(']', '')
|
|
583
|
+
position = position.replace(',', '')
|
|
584
|
+
vertex = str(faces.flatten().tolist())
|
|
585
|
+
vertex = vertex.replace('[', '')
|
|
586
|
+
vertex = vertex.replace(']', '')
|
|
587
|
+
vertex = vertex.replace(',', '')
|
|
588
|
+
normal = str(norm.flatten().tolist())
|
|
589
|
+
normal = normal.replace('[', '')
|
|
590
|
+
normal = normal.replace(']', '')
|
|
591
|
+
normal = normal.replace(',', '')
|
|
592
|
+
color = str(clrtmp.flatten().tolist())
|
|
593
|
+
color = color.replace('[', '')
|
|
594
|
+
color = color.replace(']', '')
|
|
595
|
+
color = color.replace(',', '')
|
|
596
|
+
|
|
597
|
+
modeldae.append(
|
|
598
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\r\n'
|
|
599
|
+
'<COLLADA xmlns="http://www.collada.org/2005'
|
|
600
|
+
'/11/COLLADASchema" '
|
|
601
|
+
'version="1.4.1">\r\n'
|
|
602
|
+
' <asset>\r\n'
|
|
603
|
+
' <contributor>\r\n'
|
|
604
|
+
' <authoring_tool>PyGMI</authoring_tool>\r\n'
|
|
605
|
+
' </contributor>\r\n'
|
|
606
|
+
' <created>2012-03-01T10:36:38Z</created>\r\n'
|
|
607
|
+
' <modified>2012-03-01T10:36:38Z</modified>\r\n'
|
|
608
|
+
' <up_axis>Z_UP</up_axis>\r\n'
|
|
609
|
+
' </asset>\r\n'
|
|
610
|
+
' <library_visual_scenes>\r\n'
|
|
611
|
+
' <visual_scene id="ID1">\r\n'
|
|
612
|
+
' <node name="SketchUp">\r\n'
|
|
613
|
+
' <node id="ID2" name="instance_0">\r\n'
|
|
614
|
+
' <matrix> 1 0 0 0 \r\n'
|
|
615
|
+
' 0 1 0 0 \r\n'
|
|
616
|
+
' 0 0 1 0 \r\n'
|
|
617
|
+
' 0 0 0 1 \r\n'
|
|
618
|
+
' </matrix>\r\n'
|
|
619
|
+
' <instance_node url="#ID3" />\r\n'
|
|
620
|
+
' </node>\r\n'
|
|
621
|
+
' </node>\r\n'
|
|
622
|
+
' </visual_scene>\r\n'
|
|
623
|
+
' </library_visual_scenes>\r\n'
|
|
624
|
+
' <library_nodes>\r\n'
|
|
625
|
+
' <node id="ID3" name="skp489E">\r\n'
|
|
626
|
+
' <instance_geometry url="#ID4">\r\n'
|
|
627
|
+
' <bind_material>\r\n'
|
|
628
|
+
' <technique_common>\r\n'
|
|
629
|
+
' <instance_material symbol="Material2"'
|
|
630
|
+
' target="#ID5">\r\n'
|
|
631
|
+
' <bind_vertex_input semantic="UVSET0" '
|
|
632
|
+
'input_semantic="TEXCOORD" input_set="0" />\r\n'
|
|
633
|
+
' </instance_material>\r\n'
|
|
634
|
+
' </technique_common>\r\n'
|
|
635
|
+
' </bind_material>\r\n'
|
|
636
|
+
' </instance_geometry>\r\n'
|
|
637
|
+
' </node>\r\n'
|
|
638
|
+
' </library_nodes>\r\n'
|
|
639
|
+
' <library_geometries>\r\n'
|
|
640
|
+
' <geometry id="ID4">\r\n'
|
|
641
|
+
' <mesh>\r\n'
|
|
642
|
+
' <source id="ID7">\r\n'
|
|
643
|
+
' <float_array id="ID10" count="' +
|
|
644
|
+
str(points.size) + '">' + position +
|
|
645
|
+
' </float_array>\r\n'
|
|
646
|
+
' <technique_common>\r\n'
|
|
647
|
+
' <accessor count="' + str(points.shape[0]) +
|
|
648
|
+
'" source="#ID10" stride="3">\r\n'
|
|
649
|
+
' <param name="X" type="float" />\r\n'
|
|
650
|
+
' <param name="Y" type="float" />\r\n'
|
|
651
|
+
' <param name="Z" type="float" />\r\n'
|
|
652
|
+
' </accessor>\r\n'
|
|
653
|
+
' </technique_common>\r\n'
|
|
654
|
+
' </source>\r\n'
|
|
655
|
+
' <source id="ID8">\r\n'
|
|
656
|
+
' <float_array id="ID11" count="' + str(norm.size) +
|
|
657
|
+
'">' + normal +
|
|
658
|
+
' </float_array>\r\n'
|
|
659
|
+
' <technique_common>\r\n'
|
|
660
|
+
' <accessor count="' + str(norm.shape[0]) +
|
|
661
|
+
'" source="#ID11" stride="3">\r\n'
|
|
662
|
+
' <param name="X" type="float" />\r\n'
|
|
663
|
+
' <param name="Y" type="float" />\r\n'
|
|
664
|
+
' <param name="Z" type="float" />\r\n'
|
|
665
|
+
' </accessor>\r\n'
|
|
666
|
+
' </technique_common>\r\n'
|
|
667
|
+
' </source>\r\n'
|
|
668
|
+
' <vertices id="ID9">\r\n'
|
|
669
|
+
' <input semantic="POSITION" source="#ID7" />\r\n'
|
|
670
|
+
' <input semantic="NORMAL" source="#ID8" />\r\n'
|
|
671
|
+
' </vertices>\r\n'
|
|
672
|
+
' <triangles count="' + str(faces.shape[0]) +
|
|
673
|
+
'" material="Material2">\r\n'
|
|
674
|
+
' <input offset="0" semantic="VERTEX" '
|
|
675
|
+
'source="#ID9" />\r\n'
|
|
676
|
+
' <p>' + vertex + '</p>\r\n'
|
|
677
|
+
' </triangles>\r\n'
|
|
678
|
+
' </mesh>\r\n'
|
|
679
|
+
' </geometry>\r\n'
|
|
680
|
+
' </library_geometries>\r\n'
|
|
681
|
+
' <library_materials>\r\n'
|
|
682
|
+
' <material id="ID5" name="__auto_">\r\n'
|
|
683
|
+
' <instance_effect url="#ID6" />\r\n'
|
|
684
|
+
' </material>\r\n'
|
|
685
|
+
' </library_materials>\r\n'
|
|
686
|
+
' <library_effects>\r\n'
|
|
687
|
+
' <effect id="ID6">\r\n'
|
|
688
|
+
' <profile_COMMON>\r\n'
|
|
689
|
+
' <technique sid="COMMON">\r\n'
|
|
690
|
+
' <lambert>\r\n'
|
|
691
|
+
' <diffuse>\r\n'
|
|
692
|
+
' <color>' + color + '</color>\r\n'
|
|
693
|
+
' </diffuse>\r\n'
|
|
694
|
+
' </lambert>\r\n'
|
|
695
|
+
' </technique>\r\n'
|
|
696
|
+
' <extra> />\r\n'
|
|
697
|
+
' <technique profile="GOOGLEEARTH"> />\r\n'
|
|
698
|
+
' <double_sided>1</double_sided> />\r\n'
|
|
699
|
+
' </technique> />\r\n'
|
|
700
|
+
' </extra> />\r\n'
|
|
701
|
+
' </profile_COMMON>\r\n'
|
|
702
|
+
' </effect>\r\n'
|
|
703
|
+
' </library_effects>\r\n'
|
|
704
|
+
' <scene>\r\n'
|
|
705
|
+
' <instance_visual_scene url="#ID1" />\r\n'
|
|
706
|
+
' </scene>\r\n'
|
|
707
|
+
'</COLLADA>')
|
|
708
|
+
|
|
709
|
+
zfile = zipfile.ZipFile(filename, 'w')
|
|
710
|
+
for i in range(len(modeldae)):
|
|
711
|
+
zfile.writestr('models\\mod3d'+str(i)+'.dae', modeldae[i])
|
|
712
|
+
|
|
713
|
+
for i in self.lmod.griddata.keys():
|
|
714
|
+
x_1 = self.lmod.griddata[i].tlx
|
|
715
|
+
x_2 = x_1 + self.lmod.griddata[i].xdim*self.lmod.griddata[i].cols
|
|
716
|
+
y_2 = self.lmod.griddata[i].tly
|
|
717
|
+
y_1 = y_2 - self.lmod.griddata[i].ydim*self.lmod.griddata[i].rows
|
|
718
|
+
|
|
719
|
+
res = prj.TransformPoint(x_1, y_1)
|
|
720
|
+
lonwest, latsouth = res[0], res[1]
|
|
721
|
+
res = prj.TransformPoint(x_2, y_2)
|
|
722
|
+
loneast, latnorth = res[0], res[1]
|
|
723
|
+
|
|
724
|
+
dockml += (
|
|
725
|
+
' <GroundOverlay>\r\n'
|
|
726
|
+
' <name>' + i + '</name>\r\n'
|
|
727
|
+
' <description></description>\r\n'
|
|
728
|
+
' <Icon>\r\n'
|
|
729
|
+
' <href>models/' + i + '.png</href>\r\n'
|
|
730
|
+
' </Icon>\r\n'
|
|
731
|
+
' <LatLonBox>\r\n'
|
|
732
|
+
' <north>' + str(latnorth) + '</north>\r\n'
|
|
733
|
+
' <south>' + str(latsouth) + '</south>\r\n'
|
|
734
|
+
' <east>' + str(loneast) + '</east>\r\n'
|
|
735
|
+
' <west>' + str(lonwest) + '</west>\r\n'
|
|
736
|
+
' <rotation>0.0</rotation>\r\n'
|
|
737
|
+
' </LatLonBox>\r\n'
|
|
738
|
+
' </GroundOverlay>\r\n')
|
|
739
|
+
|
|
740
|
+
fig = plt.figure('tmp930', frameon=False)
|
|
741
|
+
ax1 = plt.Axes(fig, [0., 0., 1., 1.])
|
|
742
|
+
ax1.set_axis_off()
|
|
743
|
+
fig.add_axes(ax1)
|
|
744
|
+
|
|
745
|
+
plt.imshow(self.lmod.griddata[i].data,
|
|
746
|
+
extent=(lonwest, loneast, latsouth, latnorth),
|
|
747
|
+
aspect='auto',
|
|
748
|
+
interpolation='nearest')
|
|
749
|
+
plt.savefig('tmp930.png')
|
|
750
|
+
# plt.close('tmp930')
|
|
751
|
+
|
|
752
|
+
zfile.write('tmp930.png', 'models\\'+i+'.png')
|
|
753
|
+
os.remove('tmp930.png')
|
|
754
|
+
|
|
755
|
+
dockml += (
|
|
756
|
+
' </Folder>\r\n'
|
|
757
|
+
' \r\n'
|
|
758
|
+
' </kml>')
|
|
759
|
+
|
|
760
|
+
zfile.writestr('doc.kml', dockml)
|
|
761
|
+
|
|
762
|
+
zfile.close()
|
|
763
|
+
# self.pbars.resetsub(maximum=1)
|
|
764
|
+
# self.pbars.incr()
|
|
765
|
+
self.showtext('kmz export complete')
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
class Exportkmz(QtGui.QDialog):
|
|
769
|
+
""" Class to call up a dialog """
|
|
770
|
+
def __init__(self, wkt, parent=None):
|
|
771
|
+
QtGui.QDialog.__init__(self, parent)
|
|
772
|
+
|
|
773
|
+
self.checkbox_smooth = QtGui.QCheckBox()
|
|
774
|
+
self.proj = dp.GroupProj('Confirm Model Projection')
|
|
775
|
+
self.proj.set_current(wkt)
|
|
776
|
+
|
|
777
|
+
self.setupui()
|
|
778
|
+
|
|
779
|
+
def setupui(self):
|
|
780
|
+
""" Setup UI """
|
|
781
|
+
|
|
782
|
+
gridlayout = QtGui.QGridLayout(self)
|
|
783
|
+
buttonbox = QtGui.QDialogButtonBox()
|
|
784
|
+
helpdocs = menu_default.HelpButton('pygmi.pfmod.iodefs.exportkmz')
|
|
785
|
+
|
|
786
|
+
buttonbox.setOrientation(QtCore.Qt.Horizontal)
|
|
787
|
+
buttonbox.setStandardButtons(buttonbox.Cancel | buttonbox.Ok)
|
|
788
|
+
|
|
789
|
+
gridlayout.addWidget(self.proj, 0, 0, 1, 2)
|
|
790
|
+
gridlayout.addWidget(self.checkbox_smooth, 1, 0, 1, 2)
|
|
791
|
+
gridlayout.addWidget(helpdocs, 2, 0, 1, 1)
|
|
792
|
+
gridlayout.addWidget(buttonbox, 2, 1, 1, 1)
|
|
793
|
+
|
|
794
|
+
self.setWindowTitle("Google Earth kmz Export")
|
|
795
|
+
self.checkbox_smooth.setText("Smooth Model")
|
|
796
|
+
|
|
797
|
+
buttonbox.accepted.connect(self.accept)
|
|
798
|
+
buttonbox.rejected.connect(self.reject)
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
class ImportPicture(QtGui.QDialog):
|
|
802
|
+
""" Class to call up a dialog """
|
|
803
|
+
def __init__(self, parent=None):
|
|
804
|
+
QtGui.QDialog.__init__(self, parent)
|
|
805
|
+
|
|
806
|
+
self.parent = parent
|
|
807
|
+
self.lmod = LithModel()
|
|
808
|
+
|
|
809
|
+
self.ifile = ""
|
|
810
|
+
self.name = "Import 3D Model: "
|
|
811
|
+
self.ext = ""
|
|
812
|
+
self.pbar = None
|
|
813
|
+
self.indata = {}
|
|
814
|
+
self.outdata = {}
|
|
815
|
+
self.grid = None
|
|
816
|
+
|
|
817
|
+
self.dsb_picimp_west = QtGui.QDoubleSpinBox()
|
|
818
|
+
self.dsb_picimp_east = QtGui.QDoubleSpinBox()
|
|
819
|
+
self.dsb_picimp_depth = QtGui.QDoubleSpinBox()
|
|
820
|
+
self.rb_picimp_westeast = QtGui.QRadioButton()
|
|
821
|
+
self.rb_picimp_southnorth = QtGui.QRadioButton()
|
|
822
|
+
self.dsb_picimp_maxalt = QtGui.QDoubleSpinBox()
|
|
823
|
+
|
|
824
|
+
self.setupui()
|
|
825
|
+
|
|
826
|
+
self.min_coord = None
|
|
827
|
+
self.max_coord = None
|
|
828
|
+
self.max_alt = None
|
|
829
|
+
self.min_alt = None
|
|
830
|
+
self.is_eastwest = None
|
|
831
|
+
|
|
832
|
+
self.lmod2var()
|
|
833
|
+
|
|
834
|
+
def setupui(self):
|
|
835
|
+
""" Setup UI """
|
|
836
|
+
groupbox = QtGui.QGroupBox()
|
|
837
|
+
gridlayout_2 = QtGui.QGridLayout(self)
|
|
838
|
+
gridlayout_3 = QtGui.QGridLayout(groupbox)
|
|
839
|
+
buttonbox = QtGui.QDialogButtonBox()
|
|
840
|
+
helpdocs = menu_default.HelpButton('pygmi.pfmod.iodefs.importpicture')
|
|
841
|
+
|
|
842
|
+
label = QtGui.QLabel()
|
|
843
|
+
label_2 = QtGui.QLabel()
|
|
844
|
+
label_3 = QtGui.QLabel()
|
|
845
|
+
label_4 = QtGui.QLabel()
|
|
846
|
+
label_5 = QtGui.QLabel()
|
|
847
|
+
|
|
848
|
+
buttonbox.setOrientation(QtCore.Qt.Horizontal)
|
|
849
|
+
buttonbox.setStandardButtons(buttonbox.Cancel | buttonbox.Ok)
|
|
850
|
+
|
|
851
|
+
self.dsb_picimp_west.setDecimals(6)
|
|
852
|
+
self.dsb_picimp_west.setMinimum(-999999999.0)
|
|
853
|
+
self.dsb_picimp_west.setMaximum(999999999.0)
|
|
854
|
+
self.dsb_picimp_west.setProperty("value", 0.0)
|
|
855
|
+
self.dsb_picimp_east.setDecimals(6)
|
|
856
|
+
self.dsb_picimp_east.setMinimum(-999999999.0)
|
|
857
|
+
self.dsb_picimp_east.setMaximum(999999999.0)
|
|
858
|
+
self.dsb_picimp_east.setProperty("value", 1000.0)
|
|
859
|
+
self.dsb_picimp_depth.setDecimals(6)
|
|
860
|
+
self.dsb_picimp_depth.setMinimum(0.0)
|
|
861
|
+
self.dsb_picimp_depth.setMaximum(999999999.0)
|
|
862
|
+
self.dsb_picimp_depth.setProperty("value", 1000.0)
|
|
863
|
+
self.rb_picimp_westeast.setChecked(True)
|
|
864
|
+
self.dsb_picimp_maxalt.setDecimals(6)
|
|
865
|
+
self.dsb_picimp_maxalt.setMinimum(-999999999.0)
|
|
866
|
+
self.dsb_picimp_maxalt.setMaximum(999999999.0)
|
|
867
|
+
self.dsb_picimp_maxalt.setProperty("value", 1000.0)
|
|
868
|
+
|
|
869
|
+
self.setWindowTitle("Profile Picture Importer")
|
|
870
|
+
groupbox.setTitle("Profile Coordinates")
|
|
871
|
+
self.rb_picimp_westeast.setText("Profile is from West to East")
|
|
872
|
+
self.rb_picimp_southnorth.setText("Profile is from South to North")
|
|
873
|
+
label.setText("West/South Coordinate")
|
|
874
|
+
label_2.setText("East/North Coordinate")
|
|
875
|
+
label_3.setText("Depth")
|
|
876
|
+
label_4.setText("Maximum Altitude")
|
|
877
|
+
label_5.setText('Press Cancel if you wish to connect profile '
|
|
878
|
+
'information from a 3D model')
|
|
879
|
+
|
|
880
|
+
gridlayout_2.addWidget(groupbox, 0, 0, 1, 2)
|
|
881
|
+
gridlayout_2.addWidget(label_5, 1, 0, 1, 2)
|
|
882
|
+
gridlayout_2.addWidget(helpdocs, 2, 0, 1, 1)
|
|
883
|
+
gridlayout_2.addWidget(buttonbox, 2, 1, 1, 1)
|
|
884
|
+
|
|
885
|
+
gridlayout_3.addWidget(self.rb_picimp_westeast, 0, 0, 1, 1)
|
|
886
|
+
gridlayout_3.addWidget(self.rb_picimp_southnorth, 1, 0, 1, 1)
|
|
887
|
+
gridlayout_3.addWidget(label, 2, 0, 1, 1)
|
|
888
|
+
gridlayout_3.addWidget(self.dsb_picimp_west, 2, 1, 1, 1)
|
|
889
|
+
gridlayout_3.addWidget(label_2, 4, 0, 1, 1)
|
|
890
|
+
gridlayout_3.addWidget(self.dsb_picimp_east, 4, 1, 1, 1)
|
|
891
|
+
gridlayout_3.addWidget(label_4, 5, 0, 1, 1)
|
|
892
|
+
gridlayout_3.addWidget(self.dsb_picimp_maxalt, 5, 1, 1, 1)
|
|
893
|
+
gridlayout_3.addWidget(label_3, 6, 0, 1, 1)
|
|
894
|
+
gridlayout_3.addWidget(self.dsb_picimp_depth, 6, 1, 1, 1)
|
|
895
|
+
|
|
896
|
+
buttonbox.accepted.connect(self.accept)
|
|
897
|
+
buttonbox.rejected.connect(self.reject)
|
|
898
|
+
self.rb_picimp_westeast.clicked.connect(self.lmod2var)
|
|
899
|
+
self.rb_picimp_southnorth.clicked.connect(self.lmod2var)
|
|
900
|
+
|
|
901
|
+
def lmod2var(self):
|
|
902
|
+
""" lmod 2 var """
|
|
903
|
+
self.is_eastwest = self.rb_picimp_westeast.isChecked()
|
|
904
|
+
self.min_alt, self.max_alt = self.lmod.zrange
|
|
905
|
+
|
|
906
|
+
if self.is_eastwest:
|
|
907
|
+
self.min_coord, self.max_coord = self.lmod.xrange
|
|
908
|
+
else:
|
|
909
|
+
self.min_coord, self.max_coord = self.lmod.yrange
|
|
910
|
+
|
|
911
|
+
self.update_win()
|
|
912
|
+
|
|
913
|
+
def update_var(self):
|
|
914
|
+
""" Updates the values """
|
|
915
|
+
self.min_coord = self.dsb_picimp_west.value()
|
|
916
|
+
self.max_coord = self.dsb_picimp_east.value()
|
|
917
|
+
self.max_alt = self.dsb_picimp_maxalt.value()
|
|
918
|
+
self.min_alt = self.max_alt - self.dsb_picimp_depth.value()
|
|
919
|
+
self.is_eastwest = self.rb_picimp_westeast.isChecked()
|
|
920
|
+
|
|
921
|
+
if self.is_eastwest:
|
|
922
|
+
self.grid.dataid = r'West to East'
|
|
923
|
+
else:
|
|
924
|
+
self.grid.dataid = r'South to North'
|
|
925
|
+
|
|
926
|
+
self.grid.xdim = (self.max_coord-self.min_coord)/self.grid.cols
|
|
927
|
+
self.grid.ydim = (self.max_alt-self.min_alt)/self.grid.rows
|
|
928
|
+
self.grid.tlx = self.min_coord
|
|
929
|
+
self.grid.tly = self.max_alt
|
|
930
|
+
|
|
931
|
+
# filename = self.ifile
|
|
932
|
+
# if filename.rfind('/') != -1:
|
|
933
|
+
# datatext = filename.rpartition(r'/')[-1]
|
|
934
|
+
# else:
|
|
935
|
+
# datatext = filename
|
|
936
|
+
# self.lmod.profpics[datatext] = grid
|
|
937
|
+
|
|
938
|
+
def update_win(self):
|
|
939
|
+
""" Updates the window values """
|
|
940
|
+
self.dsb_picimp_west.setValue(self.min_coord)
|
|
941
|
+
self.dsb_picimp_east.setValue(self.max_coord)
|
|
942
|
+
self.dsb_picimp_maxalt.setValue(self.max_alt)
|
|
943
|
+
self.dsb_picimp_depth.setValue(self.max_alt-self.min_alt)
|
|
944
|
+
|
|
945
|
+
def settings(self):
|
|
946
|
+
""" Load GeoTiff """
|
|
947
|
+
if 'Model3D' in self.indata.keys():
|
|
948
|
+
self.lmod = self.indata['Model3D'][0]
|
|
949
|
+
self.lmod2var()
|
|
950
|
+
|
|
951
|
+
temp = self.exec_()
|
|
952
|
+
if temp == 0:
|
|
953
|
+
return False
|
|
954
|
+
|
|
955
|
+
filename = QtGui.QFileDialog.getOpenFileName(
|
|
956
|
+
self.parent, 'Open File', '.', '*.jpg *.tif *.bmp')
|
|
957
|
+
|
|
958
|
+
if filename == '':
|
|
959
|
+
return False
|
|
960
|
+
os.chdir(filename.rpartition('/')[0])
|
|
961
|
+
|
|
962
|
+
self.ifile = filename
|
|
963
|
+
|
|
964
|
+
data = gtiff(filename)
|
|
965
|
+
self.grid = data[0]
|
|
966
|
+
|
|
967
|
+
if (self.dsb_picimp_west.value() >=
|
|
968
|
+
self.dsb_picimp_east.value()):
|
|
969
|
+
return
|
|
970
|
+
if self.dsb_picimp_depth.value() == 0.0:
|
|
971
|
+
return
|
|
972
|
+
|
|
973
|
+
self.update_var()
|
|
974
|
+
self.outdata['ProfPic'] = [self.grid]
|
|
975
|
+
|
|
976
|
+
return True
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
def gtiff(filename):
|
|
980
|
+
""" Utility to import geotiffs """
|
|
981
|
+
|
|
982
|
+
dataset = gdal.Open(filename, gdal.GA_ReadOnly)
|
|
983
|
+
nred = dataset.GetRasterBand(1).ReadAsArray()
|
|
984
|
+
ngreen = dataset.GetRasterBand(2).ReadAsArray()
|
|
985
|
+
nblue = dataset.GetRasterBand(3).ReadAsArray()
|
|
986
|
+
itmp = np.uint32(nred*65536+ngreen*256+nblue+int('FF000000', 16))
|
|
987
|
+
|
|
988
|
+
gtr = dataset.GetGeoTransform()
|
|
989
|
+
dat = [Data()]
|
|
990
|
+
|
|
991
|
+
dat[0].tlx = gtr[0]
|
|
992
|
+
dat[0].tly = gtr[3]
|
|
993
|
+
dat[0].dataid = "Image"
|
|
994
|
+
dat[0].rows = dataset.RasterYSize
|
|
995
|
+
dat[0].cols = dataset.RasterXSize
|
|
996
|
+
dat[0].xdim = abs(gtr[1])
|
|
997
|
+
dat[0].ydim = abs(gtr[5])
|
|
998
|
+
dat[0].data = np.ma.array(itmp)
|
|
999
|
+
dat[0].nullvalue = np.nan # This was erread.nullvalue, is changed above
|
|
1000
|
+
|
|
1001
|
+
return dat
|