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