wolfhece 2.2.16__py3-none-any.whl → 2.2.18__py3-none-any.whl

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.
@@ -45,8 +45,14 @@ from .mesh2d.wolf2dprev import prev_parameters_simul, blocks_file
45
45
  from .GraphNotebook import PlotPanel
46
46
  from .CpGrid import CpGrid
47
47
  from .matplotlib_fig import Matplotlib_Figure
48
- from .tools2d_dll import Tools2DFortran
49
48
 
49
+ try:
50
+ from .tools2d_dll import Tools2DFortran
51
+ except ImportError as ex:
52
+ msg = _("Error importing Fortran library for 2D tools")
53
+ msg += _(" Python version : " + sys.version)
54
+ msg += _(" The actual error was: {}").format(str(ex))
55
+ logging.error(msg)
50
56
 
51
57
  # try:
52
58
  # from .libs import wolfpy
@@ -201,10 +207,10 @@ def u_splitting(q_left:float, q_right:float, h_left:float, h_right:float) -> flo
201
207
 
202
208
  def _process_danger_map_chunk(chunk):
203
209
  import pickle
204
- obj, start, end, every = chunk
210
+ obj, start, end, every, hmin = chunk
205
211
  # Create a new instance of the class for each chunk
206
212
  new:Wolfresults_2D = pickle.loads(pickle.dumps(obj))
207
- return new.danger_map(start, end, every)
213
+ return new.danger_map(start, end, every, None, hmin)
208
214
 
209
215
  class Props_Res_2D(wx.Frame):
210
216
  """
@@ -2314,153 +2320,187 @@ class Wolfresults_2D(Element_To_Draw):
2314
2320
  return
2315
2321
 
2316
2322
  else:
2317
- # We are here for "classic" CPU results
2318
- parts=splitext(fname)
2319
- if len(parts)>1:
2320
- self.filename = parts[0]
2321
- else:
2322
- self.filename = fname
2323
-
2324
- self.filenamegen=self.filename
2325
- self._dll_tools = Tools2DFortran(self.filenamegen) # DLL de calculs de la classe Tools2DFortran
2326
-
2327
- if exists(self.filename + '.trl'):
2328
- with open(self.filename + '.trl') as f:
2329
- trl=f.read().splitlines()
2330
- self.translx=float(trl[1])
2331
- self.transly=float(trl[2])
2332
-
2333
- self.myblocks={}
2334
- self.read_param_simul()
2335
-
2336
- if exists(self.filename+'.head') or exists(join(dirname(self.filename),'bloc1.head')):
2337
- # wolfpy.r2d_init(self.filename.ljust(255).encode('ansi'))
2338
- # nb_blocks = wolfpy.r2d_nbblocks()
2339
-
2340
- nb_blocks = self._dll_tools.r2D_get_number_of_blocks()
2341
- for i in range(nb_blocks):
2342
- curblock = OneWolfResult(i, parent=self)
2343
- self.myblocks[getkeyblock(i)] = curblock
2344
-
2345
- # nbx,nby,dx,dy,ox,oy,tx,ty = wolfpy.r2d_hblock(i+1)
2346
- nbx, nby,dx,dy,ox,oy,tx,ty = self._dll_tools.r2D_get_header_one_block(i+1)
2347
-
2348
- curhead = self.head_blocks[getkeyblock(i)]=header_wolf()
2349
- curhead.nbx = nbx
2350
- curhead.nby = nby
2351
- curhead.origx = ox
2352
- curhead.origy = oy
2353
- curhead.dx = dx
2354
- curhead.dy = dy
2355
- curhead.translx = self.translx
2356
- curhead.transly = self.transly
2357
-
2358
- curblock.waterdepth.dx = dx
2359
- curblock.waterdepth.dy = dy
2360
- curblock.waterdepth.nbx = nbx
2361
- curblock.waterdepth.nby = nby
2362
- curblock.waterdepth.origx = ox
2363
- curblock.waterdepth.origy = oy
2364
- curblock.waterdepth.translx = self.translx
2365
- curblock.waterdepth.transly = self.transly
2366
-
2367
- curblock.top.dx = dx
2368
- curblock.top.dy = dy
2369
- curblock.top.nbx = nbx
2370
- curblock.top.nby = nby
2371
- curblock.top.origx = ox
2372
- curblock.top.origy = oy
2373
- curblock.top.translx = self.translx
2374
- curblock.top.transly = self.transly
2375
-
2376
- curblock.qx.dx = dx
2377
- curblock.qx.dy = dy
2378
- curblock.qx.nbx = nbx
2379
- curblock.qx.nby = nby
2380
- curblock.qx.origx = ox
2381
- curblock.qx.origy = oy
2382
- curblock.qx.translx = self.translx
2383
- curblock.qx.transly = self.transly
2384
-
2385
- curblock.qy.dx = dx
2386
- curblock.qy.dy = dy
2387
- curblock.qy.nbx = nbx
2388
- curblock.qy.nby = nby
2389
- curblock.qy.origx = ox
2390
- curblock.qy.origy = oy
2391
- curblock.qy.translx = self.translx
2392
- curblock.qy.transly = self.transly
2393
-
2394
- curblock.rough_n.dx = dx
2395
- curblock.rough_n.dy = dy
2396
- curblock.rough_n.nbx = nbx
2397
- curblock.rough_n.nby = nby
2398
- curblock.rough_n.origx = ox
2399
- curblock.rough_n.origy = oy
2400
- curblock.rough_n.translx = self.translx
2401
- curblock.rough_n.transly = self.transly
2402
-
2403
- curblock.eps.dx = dx
2404
- curblock.eps.dy = dy
2405
- curblock.eps.nbx = nbx
2406
- curblock.eps.nby = nby
2407
- curblock.eps.origx = ox
2408
- curblock.eps.origy = oy
2409
- curblock.eps.translx = self.translx
2410
- curblock.eps.transly = self.transly
2411
-
2412
- curblock.k.dx = dx
2413
- curblock.k.dy = dy
2414
- curblock.k.nbx = nbx
2415
- curblock.k.nby = nby
2416
- curblock.k.origx = ox
2417
- curblock.k.origy = oy
2418
- curblock.k.translx = self.translx
2419
- curblock.k.transly = self.transly
2420
-
2421
- curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2422
- curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2423
- curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2424
-
2425
- _param_turb = self.myparam.blocks[i].get_params_turbulence()
2426
- if 'cmu' in _param_turb:
2427
- curblock._cmu = _param_turb['cmu']
2428
- if 'cnu' in _param_turb:
2429
- curblock._cnu = _param_turb['cnu']
2430
-
2431
- else:
2432
- nb_blocks = self.myblocfile.nb_blocks
2433
-
2434
- for i in range(nb_blocks):
2435
- #print(f"Reading block {getkeyblock(i)}")
2436
- curblock = OneWolfResult(i, parent = self)
2437
- self.myblocks[getkeyblock(i)] = curblock
2438
- curblock.waterdepth.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2439
- curblock.top.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2440
- curblock.qx.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2441
- curblock.qy.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2442
- curblock.rough_n.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2443
- curblock.eps.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2444
- curblock.k.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2445
-
2446
- curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2447
- curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2448
- curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2449
-
2450
- _param_turb = self.myparam.blocks[i].get_params_turbulence()
2451
- if 'cmu' in _param_turb:
2452
- curblock._cmu = _param_turb['cmu']
2453
- if 'cnu' in _param_turb:
2454
- curblock._cnu = _param_turb['cnu']
2455
-
2456
- self.allocate_ressources()
2457
- self.read_topography()
2458
- self.read_ini_mb()
2459
-
2460
- self.loaded_rough = False
2323
+ self._loader_CPU2D(fname)
2324
+ # # We are here for "classic" CPU results
2325
+ # parts=splitext(fname)
2326
+ # if len(parts)>1:
2327
+ # self.filename = parts[0]
2328
+ # else:
2329
+ # self.filename = fname
2330
+
2331
+ # self.filenamegen=self.filename
2332
+ # self._dll_tools = Tools2DFortran(self.filenamegen) # DLL de calculs de la classe Tools2DFortran
2333
+
2334
+ # if exists(self.filename + '.trl'):
2335
+ # with open(self.filename + '.trl') as f:
2336
+ # trl=f.read().splitlines()
2337
+ # self.translx=float(trl[1])
2338
+ # self.transly=float(trl[2])
2339
+
2340
+ # self.myblocks={}
2341
+ # self.read_param_simul()
2342
+
2343
+ # if exists(self.filename+'.head') or exists(join(dirname(self.filename),'bloc1.head')):
2344
+ # # wolfpy.r2d_init(self.filename.ljust(255).encode('ansi'))
2345
+ # # nb_blocks = wolfpy.r2d_nbblocks()
2346
+
2347
+ # nb_blocks = self._dll_tools.r2D_get_number_of_blocks()
2348
+ # for i in range(nb_blocks):
2349
+ # curblock = OneWolfResult(i, parent=self)
2350
+ # self.myblocks[getkeyblock(i)] = curblock
2351
+
2352
+ # # nbx,nby,dx,dy,ox,oy,tx,ty = wolfpy.r2d_hblock(i+1)
2353
+ # nbx, nby,dx,dy,ox,oy,tx,ty = self._dll_tools.r2D_get_header_one_block(i+1)
2354
+
2355
+ # curhead = self.head_blocks[getkeyblock(i)]=header_wolf()
2356
+ # curhead.nbx = nbx
2357
+ # curhead.nby = nby
2358
+ # curhead.origx = ox
2359
+ # curhead.origy = oy
2360
+ # curhead.dx = dx
2361
+ # curhead.dy = dy
2362
+ # curhead.translx = self.translx
2363
+ # curhead.transly = self.transly
2364
+
2365
+ # curblock.waterdepth.dx = dx
2366
+ # curblock.waterdepth.dy = dy
2367
+ # curblock.waterdepth.nbx = nbx
2368
+ # curblock.waterdepth.nby = nby
2369
+ # curblock.waterdepth.origx = ox
2370
+ # curblock.waterdepth.origy = oy
2371
+ # curblock.waterdepth.translx = self.translx
2372
+ # curblock.waterdepth.transly = self.transly
2373
+
2374
+ # curblock.top.dx = dx
2375
+ # curblock.top.dy = dy
2376
+ # curblock.top.nbx = nbx
2377
+ # curblock.top.nby = nby
2378
+ # curblock.top.origx = ox
2379
+ # curblock.top.origy = oy
2380
+ # curblock.top.translx = self.translx
2381
+ # curblock.top.transly = self.transly
2382
+
2383
+ # curblock.qx.dx = dx
2384
+ # curblock.qx.dy = dy
2385
+ # curblock.qx.nbx = nbx
2386
+ # curblock.qx.nby = nby
2387
+ # curblock.qx.origx = ox
2388
+ # curblock.qx.origy = oy
2389
+ # curblock.qx.translx = self.translx
2390
+ # curblock.qx.transly = self.transly
2391
+
2392
+ # curblock.qy.dx = dx
2393
+ # curblock.qy.dy = dy
2394
+ # curblock.qy.nbx = nbx
2395
+ # curblock.qy.nby = nby
2396
+ # curblock.qy.origx = ox
2397
+ # curblock.qy.origy = oy
2398
+ # curblock.qy.translx = self.translx
2399
+ # curblock.qy.transly = self.transly
2400
+
2401
+ # curblock.rough_n.dx = dx
2402
+ # curblock.rough_n.dy = dy
2403
+ # curblock.rough_n.nbx = nbx
2404
+ # curblock.rough_n.nby = nby
2405
+ # curblock.rough_n.origx = ox
2406
+ # curblock.rough_n.origy = oy
2407
+ # curblock.rough_n.translx = self.translx
2408
+ # curblock.rough_n.transly = self.transly
2409
+
2410
+ # curblock.eps.dx = dx
2411
+ # curblock.eps.dy = dy
2412
+ # curblock.eps.nbx = nbx
2413
+ # curblock.eps.nby = nby
2414
+ # curblock.eps.origx = ox
2415
+ # curblock.eps.origy = oy
2416
+ # curblock.eps.translx = self.translx
2417
+ # curblock.eps.transly = self.transly
2418
+
2419
+ # curblock.k.dx = dx
2420
+ # curblock.k.dy = dy
2421
+ # curblock.k.nbx = nbx
2422
+ # curblock.k.nby = nby
2423
+ # curblock.k.origx = ox
2424
+ # curblock.k.origy = oy
2425
+ # curblock.k.translx = self.translx
2426
+ # curblock.k.transly = self.transly
2427
+
2428
+ # curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2429
+ # curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2430
+ # curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2431
+
2432
+ # _param_turb = self.myparam.blocks[i].get_params_turbulence()
2433
+ # if 'cmu' in _param_turb:
2434
+ # curblock._cmu = _param_turb['cmu']
2435
+ # if 'cnu' in _param_turb:
2436
+ # curblock._cnu = _param_turb['cnu']
2437
+
2438
+ # else:
2439
+ # nb_blocks = self.myblocfile.nb_blocks
2440
+
2441
+ # for i in range(nb_blocks):
2442
+ # #print(f"Reading block {getkeyblock(i)}")
2443
+ # curblock = OneWolfResult(i, parent = self)
2444
+ # self.myblocks[getkeyblock(i)] = curblock
2445
+ # curblock.waterdepth.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2446
+ # curblock.top.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2447
+ # curblock.qx.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2448
+ # curblock.qy.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2449
+ # curblock.rough_n.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2450
+ # curblock.eps.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2451
+ # curblock.k.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2452
+
2453
+ # curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2454
+ # curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2455
+ # curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2456
+
2457
+ # _param_turb = self.myparam.blocks[i].get_params_turbulence()
2458
+ # if 'cmu' in _param_turb:
2459
+ # curblock._cmu = _param_turb['cmu']
2460
+ # if 'cnu' in _param_turb:
2461
+ # curblock._cnu = _param_turb['cnu']
2462
+
2463
+ # self.allocate_ressources()
2464
+ # self.read_topography()
2465
+ # self.read_ini_mb()
2466
+
2467
+ # self.loaded_rough = False
2461
2468
  else:
2462
2469
  self.myblocks={}
2463
2470
 
2471
+ self._post_loader()
2472
+ # self.nbx = 1
2473
+ # self.nby = 1
2474
+
2475
+ # ox=9999999.
2476
+ # oy=9999999.
2477
+ # ex=-9999999.
2478
+ # ey=-9999999.
2479
+ # for curblock in self.myblocks.values():
2480
+ # curhead=curblock.waterdepth.get_header(False)
2481
+ # ox=min(ox,curhead.origx)
2482
+ # oy=min(oy,curhead.origy)
2483
+ # ex=max(ex,curhead.origx+float(curhead.nbx)*curhead.dx)
2484
+ # ey=max(ey,curhead.origy+float(curhead.nby)*curhead.dy)
2485
+ # self.dx = ex-ox
2486
+ # self.dy = ey-oy
2487
+ # self.origx = ox
2488
+ # self.origy = oy
2489
+
2490
+ # self._nb_results = None
2491
+ # self.timesteps = []
2492
+ # self.times = []
2493
+
2494
+ # self.properties:Props_Res_2D = None
2495
+ # self.set_properties()
2496
+
2497
+ # self.mngselection = SelectionDataMB(self)
2498
+ # self.myops = None
2499
+ # self._active_blocks = 0
2500
+
2501
+ def _post_loader(self):
2502
+ """ Post loader for CPU/GPU results """
2503
+
2464
2504
  self.nbx = 1
2465
2505
  self.nby = 1
2466
2506
 
@@ -2490,6 +2530,188 @@ class Wolfresults_2D(Element_To_Draw):
2490
2530
  self.myops = None
2491
2531
  self._active_blocks = 0
2492
2532
 
2533
+ def _loader_CPU2D(self, fname:str) -> int:
2534
+ """ Loader for CPU results """
2535
+
2536
+ # We are here for "classic" CPU results
2537
+ parts=splitext(fname)
2538
+ if len(parts)>1:
2539
+ self.filename = parts[0]
2540
+ else:
2541
+ self.filename = fname
2542
+
2543
+ self.filenamegen=self.filename
2544
+ self._dll_tools = Tools2DFortran(self.filenamegen) # DLL de calculs de la classe Tools2DFortran
2545
+
2546
+ if exists(self.filename + '.trl'):
2547
+ with open(self.filename + '.trl') as f:
2548
+ trl=f.read().splitlines()
2549
+ self.translx=float(trl[1])
2550
+ self.transly=float(trl[2])
2551
+
2552
+ self.myblocks={}
2553
+ self.read_param_simul()
2554
+
2555
+ if exists(self.filename+'.head') or exists(join(dirname(self.filename),'bloc1.head')):
2556
+ # wolfpy.r2d_init(self.filename.ljust(255).encode('ansi'))
2557
+ # nb_blocks = wolfpy.r2d_nbblocks()
2558
+
2559
+ nb_blocks = self._dll_tools.r2D_get_number_of_blocks()
2560
+ for i in range(nb_blocks):
2561
+ curblock = OneWolfResult(i, parent=self)
2562
+ self.myblocks[getkeyblock(i)] = curblock
2563
+
2564
+ # nbx,nby,dx,dy,ox,oy,tx,ty = wolfpy.r2d_hblock(i+1)
2565
+ nbx, nby,dx,dy,ox,oy,tx,ty = self._dll_tools.r2D_get_header_one_block(i+1)
2566
+
2567
+ curhead = self.head_blocks[getkeyblock(i)]=header_wolf()
2568
+ curhead.nbx = nbx
2569
+ curhead.nby = nby
2570
+ curhead.origx = ox
2571
+ curhead.origy = oy
2572
+ curhead.dx = dx
2573
+ curhead.dy = dy
2574
+ curhead.translx = self.translx
2575
+ curhead.transly = self.transly
2576
+
2577
+ curblock.waterdepth.dx = dx
2578
+ curblock.waterdepth.dy = dy
2579
+ curblock.waterdepth.nbx = nbx
2580
+ curblock.waterdepth.nby = nby
2581
+ curblock.waterdepth.origx = ox
2582
+ curblock.waterdepth.origy = oy
2583
+ curblock.waterdepth.translx = self.translx
2584
+ curblock.waterdepth.transly = self.transly
2585
+
2586
+ curblock.top.dx = dx
2587
+ curblock.top.dy = dy
2588
+ curblock.top.nbx = nbx
2589
+ curblock.top.nby = nby
2590
+ curblock.top.origx = ox
2591
+ curblock.top.origy = oy
2592
+ curblock.top.translx = self.translx
2593
+ curblock.top.transly = self.transly
2594
+
2595
+ curblock.qx.dx = dx
2596
+ curblock.qx.dy = dy
2597
+ curblock.qx.nbx = nbx
2598
+ curblock.qx.nby = nby
2599
+ curblock.qx.origx = ox
2600
+ curblock.qx.origy = oy
2601
+ curblock.qx.translx = self.translx
2602
+ curblock.qx.transly = self.transly
2603
+
2604
+ curblock.qy.dx = dx
2605
+ curblock.qy.dy = dy
2606
+ curblock.qy.nbx = nbx
2607
+ curblock.qy.nby = nby
2608
+ curblock.qy.origx = ox
2609
+ curblock.qy.origy = oy
2610
+ curblock.qy.translx = self.translx
2611
+ curblock.qy.transly = self.transly
2612
+
2613
+ curblock.rough_n.dx = dx
2614
+ curblock.rough_n.dy = dy
2615
+ curblock.rough_n.nbx = nbx
2616
+ curblock.rough_n.nby = nby
2617
+ curblock.rough_n.origx = ox
2618
+ curblock.rough_n.origy = oy
2619
+ curblock.rough_n.translx = self.translx
2620
+ curblock.rough_n.transly = self.transly
2621
+
2622
+ curblock.eps.dx = dx
2623
+ curblock.eps.dy = dy
2624
+ curblock.eps.nbx = nbx
2625
+ curblock.eps.nby = nby
2626
+ curblock.eps.origx = ox
2627
+ curblock.eps.origy = oy
2628
+ curblock.eps.translx = self.translx
2629
+ curblock.eps.transly = self.transly
2630
+
2631
+ curblock.k.dx = dx
2632
+ curblock.k.dy = dy
2633
+ curblock.k.nbx = nbx
2634
+ curblock.k.nby = nby
2635
+ curblock.k.origx = ox
2636
+ curblock.k.origy = oy
2637
+ curblock.k.translx = self.translx
2638
+ curblock.k.transly = self.transly
2639
+
2640
+ curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2641
+ curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2642
+ curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2643
+
2644
+ _param_turb = self.myparam.blocks[i].get_params_turbulence()
2645
+ if 'cmu' in _param_turb:
2646
+ curblock._cmu = _param_turb['cmu']
2647
+ if 'cnu' in _param_turb:
2648
+ curblock._cnu = _param_turb['cnu']
2649
+
2650
+ else:
2651
+ nb_blocks = self.myblocfile.nb_blocks
2652
+
2653
+ for i in range(nb_blocks):
2654
+ #print(f"Reading block {getkeyblock(i)}")
2655
+ curblock = OneWolfResult(i, parent = self)
2656
+ self.myblocks[getkeyblock(i)] = curblock
2657
+ curblock.waterdepth.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2658
+ curblock.top.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2659
+ curblock.qx.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2660
+ curblock.qy.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2661
+ curblock.rough_n.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2662
+ curblock.eps.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2663
+ curblock.k.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2664
+
2665
+ curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2666
+ curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2667
+ curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2668
+
2669
+ _param_turb = self.myparam.blocks[i].get_params_turbulence()
2670
+ if 'cmu' in _param_turb:
2671
+ curblock._cmu = _param_turb['cmu']
2672
+ if 'cnu' in _param_turb:
2673
+ curblock._cnu = _param_turb['cnu']
2674
+
2675
+ self.allocate_ressources()
2676
+ self.read_topography()
2677
+ self.read_ini_mb()
2678
+
2679
+ self.loaded_rough = False
2680
+
2681
+ def __getstate__(self):
2682
+ """Get the state of the object for pickling"""
2683
+ state = self.__dict__.copy()
2684
+ # Remove unpicklable attributes
2685
+
2686
+ topop = ['mapviewer',
2687
+ 'properties',
2688
+ 'mngselection',
2689
+ 'myops',
2690
+ '_dll_tools',
2691
+ 'myparam',
2692
+ 'myblocfile',
2693
+ 'mymnap']
2694
+
2695
+ for cur_pop in topop:
2696
+ if cur_pop in state:
2697
+ state.pop(cur_pop)
2698
+ return state
2699
+
2700
+ def __setstate__(self, state):
2701
+ """Set the state of the object after unpickling"""
2702
+ # Restore the state of the object
2703
+ self.__dict__.update(state)
2704
+ # Reinitialize any attributes that were removed during pickling
2705
+ self.mapviewer = None
2706
+ self.properties = None
2707
+ self.mngselection = None
2708
+ self.myops = None
2709
+
2710
+ if not 'isGPU' in list(state.keys()):
2711
+ self._loader_CPU2D(self.filenamegen)
2712
+ self._post_loader()
2713
+ self._dll_tools = Tools2DFortran(self.filenamegen)
2714
+
2493
2715
  @property
2494
2716
  def all_dt(self):
2495
2717
  #FIXME : defined in GPU version --> to be implemented for CPU version
@@ -2936,6 +3158,10 @@ class Wolfresults_2D(Element_To_Draw):
2936
3158
  maxq_rel = np.max(np.asarray([cur[1] for cur in nmax]))
2937
3159
  size_min_rel= np.min(np.asarray([cur[0] for cur in nmax]))
2938
3160
 
3161
+ if maxq == 0.:
3162
+ logging.warning(_('No flow in the blocks'))
3163
+ maxq = 1.
3164
+
2939
3165
  dmin = self.get_dxdy_min()
2940
3166
 
2941
3167
  for idx, curblock in enumerate(self.myblocks.values()):
@@ -3327,6 +3553,10 @@ class Wolfresults_2D(Element_To_Draw):
3327
3553
  """ Sanitize result step index -- 0-based """
3328
3554
 
3329
3555
  nb = self.get_nbresults()
3556
+ if nb is None:
3557
+ logging.error(_('No results available'))
3558
+ return None
3559
+
3330
3560
  while which_step<0:
3331
3561
  which_step += nb
3332
3562
  which_step = min(nb-1, which_step)
@@ -5122,7 +5352,10 @@ class Wolfresults_2D(Element_To_Draw):
5122
5352
  self.get_working_array()
5123
5353
  self.updatepalette(whichpal)
5124
5354
 
5125
- def danger_map(self, start:int=0, end:int=-1, every:int=1, callback=None) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray], tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5355
+ def danger_map(self, start:int=0, end:int=-1,
5356
+ every:int=1, callback=None,
5357
+ hmin:float = None) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray, WolfArray, WolfArray],
5358
+ tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5126
5359
  """
5127
5360
  Create Danger Maps
5128
5361
 
@@ -5131,13 +5364,22 @@ class Wolfresults_2D(Element_To_Draw):
5131
5364
  :param every: step interval
5132
5365
  :param callback: optional callback to update progress
5133
5366
 
5134
- :return : tuple of WolfArray or WolfArrayMB - H, U_norm, Q_norm, Z, Head
5367
+ :return : tuple of WolfArray or WolfArrayMB - H, U_norm, Q_norm, Z, Head, Time_of_arrival, Time_of_maximum
5135
5368
  """
5136
5369
 
5370
+ DEFAULT_TOA = 0.
5371
+
5372
+ if hmin is None:
5373
+ hmin = self.epsilon
5374
+
5137
5375
  # Number of time steps
5138
5376
  number_of_time_steps = self.get_nbresults()
5139
5377
  if end ==-1:
5140
- end = number_of_time_steps
5378
+ end = number_of_time_steps - 1
5379
+
5380
+ if end > number_of_time_steps:
5381
+ logging.warning("End time step is greater than the number of time steps. Setting end to the last time step.")
5382
+ end = number_of_time_steps - 1
5141
5383
 
5142
5384
  # Init Danger Maps basde on results type
5143
5385
  # If only one block --> WolfArray
@@ -5148,7 +5390,16 @@ class Wolfresults_2D(Element_To_Draw):
5148
5390
  danger_map_matrix_z = self.as_WolfArray(copyarray=True)
5149
5391
  danger_map_matrix_head= self.as_WolfArray(copyarray=True)
5150
5392
 
5151
- danger = [danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head]
5393
+ danger_map_matrix_toa = self.as_WolfArray(copyarray=True)
5394
+ danger_map_matrix_tom = self.as_WolfArray(copyarray=True)
5395
+
5396
+ danger = [danger_map_matrix_h,
5397
+ danger_map_matrix_v,
5398
+ danger_map_matrix_mom,
5399
+ danger_map_matrix_z,
5400
+ danger_map_matrix_head,
5401
+ danger_map_matrix_toa,
5402
+ danger_map_matrix_tom]
5152
5403
 
5153
5404
  for curdanger in danger:
5154
5405
  curdanger.nullvalue = 0.
@@ -5159,12 +5410,15 @@ class Wolfresults_2D(Element_To_Draw):
5159
5410
  #add the end
5160
5411
  if end not in to_compute:
5161
5412
  to_compute = np.append(to_compute, end)
5413
+
5162
5414
  for time_step in tqdm(to_compute):
5163
5415
 
5164
5416
  if callback is not None:
5165
- callback(time_step, "Step {} / {}".format(time_step+1, end))
5417
+ callback(time_step, "Step {} / {}".format(int(time_step+1), int(end)))
5166
5418
 
5167
- self.read_oneresult(time_step+1)
5419
+ self.read_oneresult(time_step)
5420
+
5421
+ cur_time = self.times[time_step]
5168
5422
 
5169
5423
  if self.nb_blocks>1:
5170
5424
  for curblock in self.myblocks.keys():
@@ -5188,14 +5442,23 @@ class Wolfresults_2D(Element_To_Draw):
5188
5442
  z[ij] = wd.array[ij] + top.array[ij]
5189
5443
  head[ij]= z[ij] + v[ij]**2./2/9.81
5190
5444
 
5445
+ # Fill the time of arrival
5446
+ danger_map_matrix_toa[curblock].array[(danger_map_matrix_toa.array == DEFAULT_TOA) & (wd.array > hmin)] = cur_time
5447
+
5448
+ # Fill the time of maximum
5449
+ # Searching where wd > h_max
5450
+ ij_h = np.where((danger_map_matrix_h[curblock].array < wd.array) & (~wd.array.mask))
5451
+ danger_map_matrix_tom[curblock].array[ij_h] = cur_time
5452
+
5191
5453
  # Comparison
5192
5454
  for curdanger, curcomp in zip(danger, [wd.array, v, mom, z, head]):
5193
- ij = np.where((curdanger.array < curcomp) & (~wd.array.mask))
5194
- curdanger.array.data[ij] = curcomp[ij]
5195
- curdanger.array.mask[ij] = False
5455
+ ij = np.where((curdanger[curblock].array < curcomp) & (~wd.array.mask))
5456
+ curdanger[curblock].array.data[ij] = curcomp[ij]
5457
+ curdanger[curblock].array.mask[ij] = False
5196
5458
 
5197
5459
  else:
5198
5460
  curblock = getkeyblock(0)
5461
+
5199
5462
  wd = self.get_h_for_block(curblock)
5200
5463
  qx = self.get_qx_for_block(curblock)
5201
5464
  qy = self.get_qy_for_block(curblock)
@@ -5214,8 +5477,16 @@ class Wolfresults_2D(Element_To_Draw):
5214
5477
  z[ij] = wd.array[ij] + top.array[ij]
5215
5478
  head[ij]= z[ij] + v[ij]**2./2/9.81
5216
5479
 
5480
+ # Fill the time of arrival
5481
+ danger_map_matrix_toa.array[(danger_map_matrix_toa.array == DEFAULT_TOA) & (wd.array > hmin)] = cur_time
5482
+
5483
+ # Fill the time of maximum
5484
+ # Searching where wd > h_max
5485
+ ij_h = np.where((danger_map_matrix_h.array < wd.array) & (~wd.array.mask))
5486
+ danger_map_matrix_tom.array[ij_h] = cur_time
5487
+
5217
5488
  # Comparison
5218
- for curdanger, curcomp in zip(danger, [wd.array, v, mom, z, head]):
5489
+ for curdanger, curcomp in zip(danger[:5], [wd.array, v, mom, z, head]):
5219
5490
  ij = np.where((curdanger.array < curcomp) & (~wd.array.mask))
5220
5491
  curdanger.array.data[ij] = curcomp[ij]
5221
5492
  curdanger.array.mask[ij] = False
@@ -5228,37 +5499,30 @@ class Wolfresults_2D(Element_To_Draw):
5228
5499
  danger_map_matrix_mom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5229
5500
  danger_map_matrix_z[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5230
5501
  danger_map_matrix_head[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5502
+ danger_map_matrix_toa[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5503
+ danger_map_matrix_tom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5231
5504
  else:
5232
5505
  danger_map_matrix_v.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5233
5506
  danger_map_matrix_mom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5234
5507
  danger_map_matrix_z.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5235
5508
  danger_map_matrix_head.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5236
-
5237
- return (danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head)
5238
-
5239
- def __getstate__(self):
5240
- """Get the state of the object for pickling"""
5241
- state = self.__dict__.copy()
5242
- # Remove unpicklable attributes
5243
-
5244
- topop = ['mapviewer', 'properties', 'mngselection', 'myops']
5245
-
5246
- for cur_pop in topop:
5247
- if cur_pop in state:
5248
- state.pop(cur_pop)
5249
- return state
5250
-
5251
- def __setstate__(self, state):
5252
- """Set the state of the object after unpickling"""
5253
- # Restore the state of the object
5254
- self.__dict__.update(state)
5255
- # Reinitialize any attributes that were removed during pickling
5256
- self.mapviewer = None
5257
- self.properties = None
5258
- self.mngselection = None
5259
- self.myops = None
5260
-
5261
- def danger_map_multiprocess(self, start:int=0, end:int=-1, every:int=1, callback=None, nb_processors:int = -1) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray], tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5509
+ danger_map_matrix_toa.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5510
+ danger_map_matrix_tom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5511
+
5512
+ return (danger_map_matrix_h,
5513
+ danger_map_matrix_v,
5514
+ danger_map_matrix_mom,
5515
+ danger_map_matrix_z,
5516
+ danger_map_matrix_head,
5517
+ danger_map_matrix_toa,
5518
+ danger_map_matrix_tom)
5519
+
5520
+ def danger_map_multiprocess(self, start:int=0, end:int=-1,
5521
+ every:int=1,
5522
+ callback=None,
5523
+ hmin:float = None,
5524
+ nb_processors:int = -1) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray, WolfArray, WolfArray],
5525
+ tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5262
5526
  """
5263
5527
  Create Danger Maps using multiprocessing
5264
5528
 
@@ -5268,18 +5532,37 @@ class Wolfresults_2D(Element_To_Draw):
5268
5532
  :param callback: optional callback to update progress
5269
5533
  """
5270
5534
 
5535
+ DEFAULT_TOA = 0.
5536
+
5271
5537
  from multiprocessing import Pool, cpu_count
5272
5538
 
5539
+ if hmin is None:
5540
+ hmin = self.epsilon
5541
+
5273
5542
  if nb_processors == -1:
5274
5543
  nb_processors = cpu_count()
5544
+ elif nb_processors > cpu_count():
5545
+ nb_processors = cpu_count()
5546
+ elif nb_processors < 1:
5547
+ nb_processors = 1
5548
+
5549
+ if end == -1:
5550
+ end = self.get_nbresults() - 1
5551
+ if end > self.get_nbresults():
5552
+ logging.warning("End time step is greater than the number of time steps. Setting end to the last time step.")
5553
+ end = self.get_nbresults() - 1
5275
5554
 
5276
5555
  if nb_processors > self.get_nbresults():
5277
- nb_processors = self.get_nbresults()
5556
+ logging.warning('Number of processors is greater than the number of time steps.')
5557
+ nb_processors = int(self.get_nbresults() /4)
5558
+ elif nb_processors > end-start+1:
5559
+ logging.warning('Number of processors is greater than the number of time steps.')
5560
+ nb_processors = int((end-start)/4)
5278
5561
 
5279
- # Split the range of time steps into chunks for multiprocessing
5280
- if end == -1:
5281
- end = self.get_nbresults()
5562
+ if nb_processors < 1:
5563
+ nb_processors = 1
5282
5564
 
5565
+ # Create a list of chunks
5283
5566
  starts = [start + i * every for i in range(nb_processors)]
5284
5567
  ends = [end - i * every for i in range(nb_processors-1,-1,-1)]
5285
5568
 
@@ -5294,7 +5577,18 @@ class Wolfresults_2D(Element_To_Draw):
5294
5577
  if starts[i] >= ends[i]:
5295
5578
  ends[i] = starts[i] + every
5296
5579
 
5297
- chunks = [(self, start + i * every, end - (nb_processors - i) * every + 1, nb_processors) for i in range(min(nb_processors, len(starts)))]
5580
+ # clip ends to end
5581
+ for i in range(len(ends)):
5582
+ if ends[i] > end:
5583
+ ends[i] = end
5584
+
5585
+ everys = [min(nb_processors, (_end - _start)) for _start, _end in zip(starts, ends)]
5586
+
5587
+ chunks = [(self,
5588
+ starts[i],
5589
+ ends[i],
5590
+ everys[i],
5591
+ hmin) for i in range(min(nb_processors, len(starts)))]
5298
5592
 
5299
5593
  # Create a pool of workers
5300
5594
  with Pool(processes=nb_processors) as pool:
@@ -5306,7 +5600,16 @@ class Wolfresults_2D(Element_To_Draw):
5306
5600
  danger_map_matrix_z = self.as_WolfArray(copyarray=True)
5307
5601
  danger_map_matrix_head= self.as_WolfArray(copyarray=True)
5308
5602
 
5309
- danger = [danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head]
5603
+ danger_map_matrix_toa = self.as_WolfArray(copyarray=True)
5604
+ danger_map_matrix_tom = self.as_WolfArray(copyarray=True)
5605
+
5606
+ danger = [danger_map_matrix_h,
5607
+ danger_map_matrix_v,
5608
+ danger_map_matrix_mom,
5609
+ danger_map_matrix_z,
5610
+ danger_map_matrix_head,
5611
+ danger_map_matrix_toa,
5612
+ danger_map_matrix_tom]
5310
5613
 
5311
5614
  for curdanger in danger:
5312
5615
  curdanger.nullvalue = 0.
@@ -5315,16 +5618,89 @@ class Wolfresults_2D(Element_To_Draw):
5315
5618
 
5316
5619
  if self.nb_blocks>1:
5317
5620
  for result in results:
5318
- for idx, curdanger in enumerate(danger):
5319
- for i in range(self.nb_blocks):
5320
- curdanger[i].array.data = np.maximum(curdanger[i].array.data, result[idx][i].array.data)
5321
- curdanger[i].array.mask = np.logical_or(curdanger[i].array.mask, result[idx][i].array.mask)
5621
+
5622
+ for i in range(self.nb_blocks):
5623
+
5624
+ # time of arrival
5625
+ # Store if the value is DEFAULT_TOA and the new value is > 0
5626
+ # Other cases correspond to an lower TOA
5627
+
5628
+ danger_toa = danger_map_matrix_toa[i].array
5629
+ res_toa = result[5][i].array
5630
+
5631
+ ij = np.where((danger_toa.data == DEFAULT_TOA) & (res_toa.data > 0.))
5632
+ danger_toa.data[ij] = res_toa.data[ij]
5633
+ danger_toa.mask[ij] = False
5634
+
5635
+ # time of peak
5636
+ # Le temps de pic n'a pas encore été atteint et un valeur existe --> on prend
5637
+ danger_tom = danger_map_matrix_tom[i].array
5638
+ danger_h = danger_map_matrix_h[i].array
5639
+ res_tom = result[6][i].array
5640
+ res_h = result[0][i].array
5641
+
5642
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5643
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data == res_h.data) & (~res_tom.mask))
5644
+ danger_tom.data[ij] = np.minimum(res_tom.data[ij], danger_tom.data[ij])
5645
+ danger_tom.mask[ij] = False
5646
+
5647
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5648
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data < res_h.data) & (~res_tom.mask))
5649
+ danger_tom.data[ij] = res_tom.data[ij]
5650
+ danger_tom.mask[ij] = False
5651
+ danger_h.data[ij] = res_h.data[ij]
5652
+
5653
+ ij = np.where(((danger_tom.data == 0.) & (res_tom.data > 0.)))
5654
+ danger_tom.data[ij] = res_tom.data[ij]
5655
+ danger_h.data[ij] = res_h.data[ij]
5656
+ danger_tom.mask[ij] = False
5657
+
5658
+ # for i in range(self.nb_blocks):
5659
+ for idx, curdanger in enumerate(danger[:5]):
5660
+
5661
+ curdanger[i].array.data[:,:] = np.maximum(curdanger[i].array.data, result[idx][i].array.data)
5662
+ curdanger[i].array.mask[:,:] = np.logical_or(curdanger[i].array.mask, result[idx][i].array.mask)
5322
5663
  else:
5323
5664
  for result in results:
5324
- for idx, curdanger in enumerate(danger):
5665
+ # time of arrival
5666
+ # Store if the value is DEFAULT_TOA and the new value is > 0
5667
+ # Other cases correspond to an lower TOA
5668
+
5669
+ danger_toa = danger_map_matrix_toa.array
5670
+ res_toa = result[5].array
5671
+
5672
+ ij = np.where((danger_toa.data == DEFAULT_TOA) & (res_toa.data > 0.))
5673
+ danger_toa.data[ij] = res_toa.data[ij]
5674
+ danger_toa.mask[ij] = False
5675
+
5676
+ # time of peak
5677
+ # Le temps de pic n'a pas encore été atteint et un valeur existe --> on prend
5678
+ danger_tom = danger_map_matrix_tom.array
5679
+ danger_h = danger_map_matrix_h.array
5680
+ res_tom = result[6].array
5681
+ res_h = result[0].array
5682
+
5683
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5684
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data == res_h.data) & (~res_tom.mask))
5685
+ danger_tom.data[ij] = np.minimum(res_tom.data[ij], danger_tom.data[ij])
5686
+ danger_tom.mask[ij] = False
5687
+
5688
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5689
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data < res_h.data) & (~res_tom.mask))
5690
+ danger_tom.data[ij] = res_tom.data[ij]
5691
+ danger_tom.mask[ij] = False
5692
+ danger_h.data[ij] = res_h.data[ij]
5693
+
5694
+ ij = np.where(((danger_tom.data == 0.) & (res_tom.data > 0.)))
5695
+ danger_tom.data[ij] = res_tom.data[ij]
5696
+ danger_h.data[ij] = res_h.data[ij]
5697
+ danger_tom.mask[ij] = False
5698
+
5699
+ for idx, curdanger in enumerate(danger[:5]):
5325
5700
  curdanger.array.data[:,:] = np.maximum(curdanger.array.data, result[idx].array.data)
5326
5701
  curdanger.array.mask[:,:] = np.logical_or(curdanger.array.mask, result[idx].array.mask)
5327
5702
 
5703
+
5328
5704
  danger_map_matrix_h.mask_lower(self.epsilon)
5329
5705
 
5330
5706
  if self.nb_blocks>1:
@@ -5333,13 +5709,20 @@ class Wolfresults_2D(Element_To_Draw):
5333
5709
  danger_map_matrix_mom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5334
5710
  danger_map_matrix_z[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5335
5711
  danger_map_matrix_head[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5712
+ danger_map_matrix_toa[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5713
+ danger_map_matrix_tom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5336
5714
  else:
5337
5715
  danger_map_matrix_v.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5338
5716
  danger_map_matrix_mom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5339
5717
  danger_map_matrix_z.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5340
5718
  danger_map_matrix_head.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5719
+ danger_map_matrix_toa.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5720
+ danger_map_matrix_tom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5341
5721
 
5342
- return (danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head)
5722
+ return (danger_map_matrix_h, danger_map_matrix_v,
5723
+ danger_map_matrix_mom, danger_map_matrix_z,
5724
+ danger_map_matrix_head,
5725
+ danger_map_matrix_toa, danger_map_matrix_tom)
5343
5726
 
5344
5727
  def danger_map_only_h(self, start:int=0, end:int=-1, every:int=1) -> WolfArray:
5345
5728
  """