Salome HOME
cleaning of interpolZ. See EDF bugtracker #16280
[modules/hydro.git] / doc / salome / examples / h017_interpolationLineaire.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO")
5
6 import sys
7 import salome
8
9 salome.salome_init()
10 theStudy = salome.myStudy
11
12 ###
13 ### HYDRO component
14 ###
15
16 from HYDROPy import *
17 from PyQt5.QtCore import *
18 from PyQt5.QtGui import *
19
20 hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() )
21
22 hydro_doc.SetLocalCS( 430000.000, 6350000.000 )
23
24 Strickler_table_1 = hydro_doc.CreateObject( KIND_STRICKLER_TABLE )
25 Strickler_table_1.SetName( "Strickler table_1" )
26
27 Strickler_table_1.SetAttrName( "CODE_06" )
28
29 Strickler_table_1.Set( u"Pelouses et pâturages naturels", 1.0321 )
30 Strickler_table_1.SetAttrValue( u"Pelouses et pâturages naturels", "321" )
31 Strickler_table_1.SetColor( u"Pelouses et pâturages naturels", QColor( 204, 242, 77 ) )
32
33 Strickler_table_1.Set( u"Aéroports", 1.0124 )
34 Strickler_table_1.SetAttrValue( u"Aéroports", "124" )
35 Strickler_table_1.SetColor( u"Aéroports", QColor( 230, 204, 230 ) )
36
37 Strickler_table_1.Set( u"Systèmes culturaux et parcellaires complexes", 1.0242 )
38 Strickler_table_1.SetAttrValue( u"Systèmes culturaux et parcellaires complexes", "242" )
39 Strickler_table_1.SetColor( u"Systèmes culturaux et parcellaires complexes", QColor( 255, 230, 77 ) )
40
41 Strickler_table_1.Set( u"Cultures annuelles associées à des cultures permanentes", 1.0241 )
42 Strickler_table_1.SetAttrValue( u"Cultures annuelles associées à des cultures permanentes", "241" )
43 Strickler_table_1.SetColor( u"Cultures annuelles associées à des cultures permanentes", QColor( 255, 230, 166 ) )
44
45 Strickler_table_1.Set( u"Forêt et végétation arbustive en mutation", 1.0324 )
46 Strickler_table_1.SetAttrValue( u"Forêt et végétation arbustive en mutation", "324" )
47 Strickler_table_1.SetColor( u"Forêt et végétation arbustive en mutation", QColor( 166, 242, 0 ) )
48
49 Strickler_table_1.Set( u"Décharges", 1.0132 )
50 Strickler_table_1.SetAttrValue( u"Décharges", "132" )
51 Strickler_table_1.SetColor( u"Décharges", QColor( 166, 77, 0 ) )
52
53 Strickler_table_1.Set( u"Végétation clairsemée", 1.0333 )
54 Strickler_table_1.SetAttrValue( u"Végétation clairsemée", "333" )
55 Strickler_table_1.SetColor( u"Végétation clairsemée", QColor( 204, 255, 204 ) )
56
57 Strickler_table_1.Set( u"Prairies et autres surfaces toujours en herbe à usage agricole", 1.0231 )
58 Strickler_table_1.SetAttrValue( u"Prairies et autres surfaces toujours en herbe à usage agricole", "231" )
59 Strickler_table_1.SetColor( u"Prairies et autres surfaces toujours en herbe à usage agricole", QColor( 230, 230, 77 ) )
60
61 Strickler_table_1.Set( u"Périmètres irrigués en permanence", 1.0212 )
62 Strickler_table_1.SetAttrValue( u"Périmètres irrigués en permanence", "212" )
63 Strickler_table_1.SetColor( u"Périmètres irrigués en permanence", QColor( 255, 255, 0 ) )
64
65 Strickler_table_1.Set( u"Plans d'eau", 1.0512 )
66 Strickler_table_1.SetAttrValue( u"Plans d'eau", "512" )
67 Strickler_table_1.SetColor( u"Plans d'eau", QColor( 128, 242, 230 ) )
68
69 Strickler_table_1.Set( u"Territoires agroforestiers", 1.0244 )
70 Strickler_table_1.SetAttrValue( u"Territoires agroforestiers", "244" )
71 Strickler_table_1.SetColor( u"Territoires agroforestiers", QColor( 242, 204, 166 ) )
72
73 Strickler_table_1.Set( u"Forêts mélangées", 1.0313 )
74 Strickler_table_1.SetAttrValue( u"Forêts mélangées", "313" )
75 Strickler_table_1.SetColor( u"Forêts mélangées", QColor( 77, 255, 0 ) )
76
77 Strickler_table_1.Set( u"Glaciers et neiges éternelles", 1.0335 )
78 Strickler_table_1.SetAttrValue( u"Glaciers et neiges éternelles", "335" )
79 Strickler_table_1.SetColor( u"Glaciers et neiges éternelles", QColor( 166, 230, 204 ) )
80
81 Strickler_table_1.Set( u"Plages, dunes et sable", 1.0331 )
82 Strickler_table_1.SetAttrValue( u"Plages, dunes et sable", "331" )
83 Strickler_table_1.SetColor( u"Plages, dunes et sable", QColor( 230, 230, 230 ) )
84
85 Strickler_table_1.Set( u"Zones incendiées", 1.0334 )
86 Strickler_table_1.SetAttrValue( u"Zones incendiées", "334" )
87 Strickler_table_1.SetColor( u"Zones incendiées", QColor( 0, 0, 0 ) )
88
89 Strickler_table_1.Set( u"Tissu urbain continu", 1.0111 )
90 Strickler_table_1.SetAttrValue( u"Tissu urbain continu", "111" )
91 Strickler_table_1.SetColor( u"Tissu urbain continu", QColor( 230, 0, 77 ) )
92
93 Strickler_table_1.Set( u"Chantiers", 1.0133 )
94 Strickler_table_1.SetAttrValue( u"Chantiers", "133" )
95 Strickler_table_1.SetColor( u"Chantiers", QColor( 255, 77, 255 ) )
96
97 Strickler_table_1.Set( u"Estuaires", 1.0522 )
98 Strickler_table_1.SetAttrValue( u"Estuaires", "522" )
99 Strickler_table_1.SetColor( u"Estuaires", QColor( 166, 255, 230 ) )
100
101 Strickler_table_1.Set( u"Marais maritimes", 1.0421 )
102 Strickler_table_1.SetAttrValue( u"Marais maritimes", "421" )
103 Strickler_table_1.SetColor( u"Marais maritimes", QColor( 204, 204, 255 ) )
104
105 Strickler_table_1.Set( u"Forêts de conifères", 1.0312 )
106 Strickler_table_1.SetAttrValue( u"Forêts de conifères", "312" )
107 Strickler_table_1.SetColor( u"Forêts de conifères", QColor( 0, 166, 0 ) )
108
109 Strickler_table_1.Set( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", 1.0243 )
110 Strickler_table_1.SetAttrValue( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", "243" )
111 Strickler_table_1.SetColor( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", QColor( 230, 204, 77 ) )
112
113 Strickler_table_1.Set( u"Tourbières", 1.0412 )
114 Strickler_table_1.SetAttrValue( u"Tourbières", "412" )
115 Strickler_table_1.SetColor( u"Tourbières", QColor( 77, 77, 255 ) )
116
117 Strickler_table_1.Set( u"Extraction de matériaux", 1.0131 )
118 Strickler_table_1.SetAttrValue( u"Extraction de matériaux", "131" )
119 Strickler_table_1.SetColor( u"Extraction de matériaux", QColor( 166, 0, 204 ) )
120
121 Strickler_table_1.Set( u"Réseaux routier et ferroviaire et espaces associés", 1.0122 )
122 Strickler_table_1.SetAttrValue( u"Réseaux routier et ferroviaire et espaces associés", "122" )
123 Strickler_table_1.SetColor( u"Réseaux routier et ferroviaire et espaces associés", QColor( 204, 0, 0 ) )
124
125 Strickler_table_1.Set( u"Mers et océans", 1.0523 )
126 Strickler_table_1.SetAttrValue( u"Mers et océans", "523" )
127 Strickler_table_1.SetColor( u"Mers et océans", QColor( 230, 242, 255 ) )
128
129 Strickler_table_1.Set( u"Equipements sportifs et de loisirs", 1.0142 )
130 Strickler_table_1.SetAttrValue( u"Equipements sportifs et de loisirs", "142" )
131 Strickler_table_1.SetColor( u"Equipements sportifs et de loisirs", QColor( 255, 230, 255 ) )
132
133 Strickler_table_1.Set( u"Forêts de feuillus", 1.0311 )
134 Strickler_table_1.SetAttrValue( u"Forêts de feuillus", "311" )
135 Strickler_table_1.SetColor( u"Forêts de feuillus", QColor( 128, 255, 0 ) )
136
137 Strickler_table_1.Set( u"Vergers et petits fruits", 1.0222 )
138 Strickler_table_1.SetAttrValue( u"Vergers et petits fruits", "222" )
139 Strickler_table_1.SetColor( u"Vergers et petits fruits", QColor( 242, 166, 77 ) )
140
141 Strickler_table_1.Set( u"Végétation sclérophylle", 1.0323 )
142 Strickler_table_1.SetAttrValue( u"Végétation sclérophylle", "323" )
143 Strickler_table_1.SetColor( u"Végétation sclérophylle", QColor( 166, 230, 77 ) )
144
145 Strickler_table_1.Set( u"Landes et broussailles", 1.0322 )
146 Strickler_table_1.SetAttrValue( u"Landes et broussailles", "322" )
147 Strickler_table_1.SetColor( u"Landes et broussailles", QColor( 166, 255, 128 ) )
148
149 Strickler_table_1.Set( u"Tissu urbain discontinu", 1.0112 )
150 Strickler_table_1.SetAttrValue( u"Tissu urbain discontinu", "112" )
151 Strickler_table_1.SetColor( u"Tissu urbain discontinu", QColor( 255, 0, 0 ) )
152
153 Strickler_table_1.Set( u"Cours et voies d'eau", 1.0511 )
154 Strickler_table_1.SetAttrValue( u"Cours et voies d'eau", "511" )
155 Strickler_table_1.SetColor( u"Cours et voies d'eau", QColor( 0, 204, 242 ) )
156
157 Strickler_table_1.Set( u"Oliveraies", 1.0223 )
158 Strickler_table_1.SetAttrValue( u"Oliveraies", "223" )
159 Strickler_table_1.SetColor( u"Oliveraies", QColor( 230, 166, 0 ) )
160
161 Strickler_table_1.Set( u"Vignobles", 1.0221 )
162 Strickler_table_1.SetAttrValue( u"Vignobles", "221" )
163 Strickler_table_1.SetColor( u"Vignobles", QColor( 230, 128, 0 ) )
164
165 Strickler_table_1.Set( u"Rizières", 1.0213 )
166 Strickler_table_1.SetAttrValue( u"Rizières", "213" )
167 Strickler_table_1.SetColor( u"Rizières", QColor( 230, 230, 0 ) )
168
169 Strickler_table_1.Set( u"Zones portuaires", 1.0123 )
170 Strickler_table_1.SetAttrValue( u"Zones portuaires", "123" )
171 Strickler_table_1.SetColor( u"Zones portuaires", QColor( 230, 204, 204 ) )
172
173 Strickler_table_1.Set( u"Zones industrielles ou commerciales et installations publiques", 1.0121 )
174 Strickler_table_1.SetAttrValue( u"Zones industrielles ou commerciales et installations publiques", "121" )
175 Strickler_table_1.SetColor( u"Zones industrielles ou commerciales et installations publiques", QColor( 204, 77, 242 ) )
176
177 Strickler_table_1.Set( u"Marais salants", 1.0422 )
178 Strickler_table_1.SetAttrValue( u"Marais salants", "422" )
179 Strickler_table_1.SetColor( u"Marais salants", QColor( 230, 230, 255 ) )
180
181 Strickler_table_1.Set( u"Marais intérieurs", 1.0411 )
182 Strickler_table_1.SetAttrValue( u"Marais intérieurs", "411" )
183 Strickler_table_1.SetColor( u"Marais intérieurs", QColor( 166, 166, 255 ) )
184
185 Strickler_table_1.Set( u"Espaces verts urbains", 1.0141 )
186 Strickler_table_1.SetAttrValue( u"Espaces verts urbains", "141" )
187 Strickler_table_1.SetColor( u"Espaces verts urbains", QColor( 255, 166, 255 ) )
188
189 Strickler_table_1.Set( u"Lagunes littorales", 1.0521 )
190 Strickler_table_1.SetAttrValue( u"Lagunes littorales", "521" )
191 Strickler_table_1.SetColor( u"Lagunes littorales", QColor( 0, 255, 166 ) )
192
193 Strickler_table_1.Set( u"Roches nues", 1.0332 )
194 Strickler_table_1.SetAttrValue( u"Roches nues", "332" )
195 Strickler_table_1.SetColor( u"Roches nues", QColor( 204, 204, 204 ) )
196
197 Strickler_table_1.Set( u"Terres arables hors périmètres d'irrigation", 1.0211 )
198 Strickler_table_1.SetAttrValue( u"Terres arables hors périmètres d'irrigation", "211" )
199 Strickler_table_1.SetColor( u"Terres arables hors périmètres d'irrigation", QColor( 255, 255, 168 ) )
200
201 Strickler_table_1.Set( u"Zones intertidales", 1.0423 )
202 Strickler_table_1.SetAttrValue( u"Zones intertidales", "423" )
203 Strickler_table_1.SetColor( u"Zones intertidales", QColor( 166, 166, 230 ) )
204
205
206 Strickler_table_1.Update()
207
208 contour = hydro_doc.CreateObject( KIND_POLYLINEXY )
209 contour.SetName( "contour" )
210
211 contour.SetZLevel( 0 )
212
213 contour.AddSection( "Section_1", 0, 1 )
214 contour.AddPoint( 0, gp_XY( 56217.97, 14517.47 ) )
215 contour.AddPoint( 0, gp_XY( 58938.24, 14526.73 ) )
216 contour.AddPoint( 0, gp_XY( 58947.49, 13277.63 ) )
217 contour.AddPoint( 0, gp_XY( 56208.72, 13286.88 ) )
218
219 contour.Update()
220
221
222 Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY )
223 Cloud_02.SetName( "Cloud_02" )
224
225 Cloud_02.SetAltitudesInverted( 0 )
226 if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))):
227   raise ValueError('problem while loading bathymetry')
228
229 Cloud_02.Update()
230
231
232 domaine = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE )
233 domaine.SetName( "domaine" )
234
235 domaine.SetZLevel( 1 )
236
237 domaine.SetAltitudeObject( Cloud_02 )
238 domaine.SetPolyline( contour )
239
240 domaine.Update()
241
242
243 # Calculation case
244 etude = hydro_doc.CreateObject( KIND_CALCULATION )
245 etude.SetName( "etude" )
246
247 etude.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
248 etude.AddGeometryObject( domaine )
249
250 case_geom_group = domaine.GetGroup( 0 )
251 etude.AddGeometryGroup( case_geom_group )
252 etude.SetBoundaryPolyline( contour )
253
254 # Start the algorithm of the partition and assignment
255 etude.Update()
256 etude_Reg_1 = hydro_doc.FindObjectByName( "etude_Reg_1" )
257 etude_Zone_1 = hydro_doc.FindObjectByName( "etude_Zone_1" )
258 etude_Zone_1.SetColor( QColor( 124, 192, 64 ))
259 etude_Reg_1.AddZone( etude_Zone_1 )
260 etude_Reg_1.SetName( "etude_Reg_1" )
261
262 # Export of the calculation case
263 etude_entry = etude.Export( theStudy._get_StudyId() )
264
265 # Get geometry shape and print debug information
266 import GEOM
267 print "Entry:", etude_entry
268 HYDRO_etude_1 = salome.IDToObject( str( etude_entry ) )
269 print "Geom shape:", HYDRO_etude_1
270 print "Geom shape name:", HYDRO_etude_1.GetName()
271
272
273 ###
274 ### GEOM component
275 ###
276
277 import GEOM
278 from salome.geom import geomBuilder
279 import math
280 import SALOMEDS
281
282
283 geompy = geomBuilder.New(theStudy)
284
285 etude_domaine_Outer = geompy.CreateGroup(HYDRO_etude_1, geompy.ShapeType["EDGE"])
286 geompy.UnionIDs(etude_domaine_Outer, [3, 6, 8, 10])
287 domaine = geompy.CreateGroup(HYDRO_etude_1, geompy.ShapeType["FACE"])
288 geompy.UnionIDs(domaine, [1])
289 geompy.addToStudyInFather( HYDRO_etude_1, etude_domaine_Outer, 'etude_domaine_Outer' )
290 geompy.addToStudyInFather( HYDRO_etude_1, domaine, 'domaine' )
291
292 ###
293 ### SMESH component
294 ###
295
296 import  SMESH, SALOMEDS
297 from salome.smesh import smeshBuilder
298
299 smesh = smeshBuilder.New(theStudy)
300 relief = smesh.Mesh(HYDRO_etude_1)
301 NETGEN_2D = relief.Triangle(algo=smeshBuilder.NETGEN_1D2D)
302 NETGEN_2D_Parameters_1 = NETGEN_2D.Parameters()
303 NETGEN_2D_Parameters_1.SetMaxSize( 25 )
304 NETGEN_2D_Parameters_1.SetSecondOrder( 0 )
305 NETGEN_2D_Parameters_1.SetOptimize( 1 )
306 NETGEN_2D_Parameters_1.SetFineness( 3 )
307 NETGEN_2D_Parameters_1.SetMinSize( 10 )
308 NETGEN_2D_Parameters_1.SetUseSurfaceCurvature( 1 )
309 NETGEN_2D_Parameters_1.SetFuseEdges( 1 )
310 NETGEN_2D_Parameters_1.SetQuadAllowed( 0 )
311 isDone = relief.Compute()
312 domaine_1 = relief.GroupOnGeom(domaine,'domaine',SMESH.FACE)
313 domaine_2 = relief.GroupOnGeom(domaine,'domaine',SMESH.NODE)
314 smesh.SetName(relief, 'relief')
315
316 med_file = r'/tmp/relief.med'
317
318 try:
319   os.remove(med_file)
320 except OSError:
321   pass
322
323
324 try:
325   relief.ExportMED( med_file, 0, SMESH.MED_V2_2, 1, None ,1)
326 except:
327   print 'ExportToMEDX() failed. Invalid file name?'
328
329
330 ## Set names of Mesh objects
331 smesh.SetName(domaine_1, 'domaine')
332 smesh.SetName(NETGEN_2D.GetAlgorithm(), 'NETGEN_2D')
333 smesh.SetName(relief.GetMesh(), 'relief')
334 smesh.SetName(domaine_2, 'domaine')
335 smesh.SetName(NETGEN_2D_Parameters_1, 'NETGEN 2D Parameters_1')
336
337
338 if salome.sg.hasDesktop():
339   salome.sg.updateObjBrowser(1)
340
341 #----------------------
342 # --- Z interpolation with HYDRO
343 #----------------------
344
345 from salome.hydrotools.interpolZ import interpolZ
346 from salome.hydrotools.controls import controlStatZ
347
348 # --- nom du cas dans HYDRO
349 nomCas = 'etude'
350
351 # --- fichier med 2D(x,y) du cas, produit par SMESH
352 fichierMaillage = med_file
353
354 # --- dictionnaire: (clé = nom de groupe med, valeur= nom de région)
355 dicoGroupeRegion= dict(domaine  = 'etude_Reg_1',
356                       )
357
358 # --- value to use for Z when the node is not in a region (used to detect problems)
359 zUndef = 90
360 # --- interpolation Method: 0 = nearest point on bathymetry (default), 1 = linear interpolation
361 interpolMethod = 1
362 # --- produce a 3D mesh (Z set to its value instead of 0
363 m3d = True
364
365 # --- Z interpolation on the bathymety/altimetry on the mesh nodes
366 statz = interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef, interpolMethod, m3d)
367 #print statz
368 refstatz = {'domaine': (27.10, 168.28, 91.77, 46.047, 28.637, 161.17)}
369 controlStatZ(statz, refstatz)
370
371 # --- add a field on nodes of type double with z values, named "BOTTOM"
372 #createZfield2(fichierMaillage)