wolfhece 2.2.16__py3-none-any.whl → 2.2.17__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.
@@ -201,10 +201,10 @@ def u_splitting(q_left:float, q_right:float, h_left:float, h_right:float) -> flo
201
201
 
202
202
  def _process_danger_map_chunk(chunk):
203
203
  import pickle
204
- obj, start, end, every = chunk
204
+ obj, start, end, every, hmin = chunk
205
205
  # Create a new instance of the class for each chunk
206
206
  new:Wolfresults_2D = pickle.loads(pickle.dumps(obj))
207
- return new.danger_map(start, end, every)
207
+ return new.danger_map(start, end, every, None, hmin)
208
208
 
209
209
  class Props_Res_2D(wx.Frame):
210
210
  """
@@ -2314,153 +2314,187 @@ class Wolfresults_2D(Element_To_Draw):
2314
2314
  return
2315
2315
 
2316
2316
  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
2317
+ self._loader_CPU2D(fname)
2318
+ # # We are here for "classic" CPU results
2319
+ # parts=splitext(fname)
2320
+ # if len(parts)>1:
2321
+ # self.filename = parts[0]
2322
+ # else:
2323
+ # self.filename = fname
2324
+
2325
+ # self.filenamegen=self.filename
2326
+ # self._dll_tools = Tools2DFortran(self.filenamegen) # DLL de calculs de la classe Tools2DFortran
2327
+
2328
+ # if exists(self.filename + '.trl'):
2329
+ # with open(self.filename + '.trl') as f:
2330
+ # trl=f.read().splitlines()
2331
+ # self.translx=float(trl[1])
2332
+ # self.transly=float(trl[2])
2333
+
2334
+ # self.myblocks={}
2335
+ # self.read_param_simul()
2336
+
2337
+ # if exists(self.filename+'.head') or exists(join(dirname(self.filename),'bloc1.head')):
2338
+ # # wolfpy.r2d_init(self.filename.ljust(255).encode('ansi'))
2339
+ # # nb_blocks = wolfpy.r2d_nbblocks()
2340
+
2341
+ # nb_blocks = self._dll_tools.r2D_get_number_of_blocks()
2342
+ # for i in range(nb_blocks):
2343
+ # curblock = OneWolfResult(i, parent=self)
2344
+ # self.myblocks[getkeyblock(i)] = curblock
2345
+
2346
+ # # nbx,nby,dx,dy,ox,oy,tx,ty = wolfpy.r2d_hblock(i+1)
2347
+ # nbx, nby,dx,dy,ox,oy,tx,ty = self._dll_tools.r2D_get_header_one_block(i+1)
2348
+
2349
+ # curhead = self.head_blocks[getkeyblock(i)]=header_wolf()
2350
+ # curhead.nbx = nbx
2351
+ # curhead.nby = nby
2352
+ # curhead.origx = ox
2353
+ # curhead.origy = oy
2354
+ # curhead.dx = dx
2355
+ # curhead.dy = dy
2356
+ # curhead.translx = self.translx
2357
+ # curhead.transly = self.transly
2358
+
2359
+ # curblock.waterdepth.dx = dx
2360
+ # curblock.waterdepth.dy = dy
2361
+ # curblock.waterdepth.nbx = nbx
2362
+ # curblock.waterdepth.nby = nby
2363
+ # curblock.waterdepth.origx = ox
2364
+ # curblock.waterdepth.origy = oy
2365
+ # curblock.waterdepth.translx = self.translx
2366
+ # curblock.waterdepth.transly = self.transly
2367
+
2368
+ # curblock.top.dx = dx
2369
+ # curblock.top.dy = dy
2370
+ # curblock.top.nbx = nbx
2371
+ # curblock.top.nby = nby
2372
+ # curblock.top.origx = ox
2373
+ # curblock.top.origy = oy
2374
+ # curblock.top.translx = self.translx
2375
+ # curblock.top.transly = self.transly
2376
+
2377
+ # curblock.qx.dx = dx
2378
+ # curblock.qx.dy = dy
2379
+ # curblock.qx.nbx = nbx
2380
+ # curblock.qx.nby = nby
2381
+ # curblock.qx.origx = ox
2382
+ # curblock.qx.origy = oy
2383
+ # curblock.qx.translx = self.translx
2384
+ # curblock.qx.transly = self.transly
2385
+
2386
+ # curblock.qy.dx = dx
2387
+ # curblock.qy.dy = dy
2388
+ # curblock.qy.nbx = nbx
2389
+ # curblock.qy.nby = nby
2390
+ # curblock.qy.origx = ox
2391
+ # curblock.qy.origy = oy
2392
+ # curblock.qy.translx = self.translx
2393
+ # curblock.qy.transly = self.transly
2394
+
2395
+ # curblock.rough_n.dx = dx
2396
+ # curblock.rough_n.dy = dy
2397
+ # curblock.rough_n.nbx = nbx
2398
+ # curblock.rough_n.nby = nby
2399
+ # curblock.rough_n.origx = ox
2400
+ # curblock.rough_n.origy = oy
2401
+ # curblock.rough_n.translx = self.translx
2402
+ # curblock.rough_n.transly = self.transly
2403
+
2404
+ # curblock.eps.dx = dx
2405
+ # curblock.eps.dy = dy
2406
+ # curblock.eps.nbx = nbx
2407
+ # curblock.eps.nby = nby
2408
+ # curblock.eps.origx = ox
2409
+ # curblock.eps.origy = oy
2410
+ # curblock.eps.translx = self.translx
2411
+ # curblock.eps.transly = self.transly
2412
+
2413
+ # curblock.k.dx = dx
2414
+ # curblock.k.dy = dy
2415
+ # curblock.k.nbx = nbx
2416
+ # curblock.k.nby = nby
2417
+ # curblock.k.origx = ox
2418
+ # curblock.k.origy = oy
2419
+ # curblock.k.translx = self.translx
2420
+ # curblock.k.transly = self.transly
2421
+
2422
+ # curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2423
+ # curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2424
+ # curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2425
+
2426
+ # _param_turb = self.myparam.blocks[i].get_params_turbulence()
2427
+ # if 'cmu' in _param_turb:
2428
+ # curblock._cmu = _param_turb['cmu']
2429
+ # if 'cnu' in _param_turb:
2430
+ # curblock._cnu = _param_turb['cnu']
2431
+
2432
+ # else:
2433
+ # nb_blocks = self.myblocfile.nb_blocks
2434
+
2435
+ # for i in range(nb_blocks):
2436
+ # #print(f"Reading block {getkeyblock(i)}")
2437
+ # curblock = OneWolfResult(i, parent = self)
2438
+ # self.myblocks[getkeyblock(i)] = curblock
2439
+ # curblock.waterdepth.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2440
+ # curblock.top.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2441
+ # curblock.qx.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2442
+ # curblock.qy.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2443
+ # curblock.rough_n.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2444
+ # curblock.eps.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2445
+ # curblock.k.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2446
+
2447
+ # curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2448
+ # curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2449
+ # curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2450
+
2451
+ # _param_turb = self.myparam.blocks[i].get_params_turbulence()
2452
+ # if 'cmu' in _param_turb:
2453
+ # curblock._cmu = _param_turb['cmu']
2454
+ # if 'cnu' in _param_turb:
2455
+ # curblock._cnu = _param_turb['cnu']
2456
+
2457
+ # self.allocate_ressources()
2458
+ # self.read_topography()
2459
+ # self.read_ini_mb()
2460
+
2461
+ # self.loaded_rough = False
2461
2462
  else:
2462
2463
  self.myblocks={}
2463
2464
 
2465
+ self._post_loader()
2466
+ # self.nbx = 1
2467
+ # self.nby = 1
2468
+
2469
+ # ox=9999999.
2470
+ # oy=9999999.
2471
+ # ex=-9999999.
2472
+ # ey=-9999999.
2473
+ # for curblock in self.myblocks.values():
2474
+ # curhead=curblock.waterdepth.get_header(False)
2475
+ # ox=min(ox,curhead.origx)
2476
+ # oy=min(oy,curhead.origy)
2477
+ # ex=max(ex,curhead.origx+float(curhead.nbx)*curhead.dx)
2478
+ # ey=max(ey,curhead.origy+float(curhead.nby)*curhead.dy)
2479
+ # self.dx = ex-ox
2480
+ # self.dy = ey-oy
2481
+ # self.origx = ox
2482
+ # self.origy = oy
2483
+
2484
+ # self._nb_results = None
2485
+ # self.timesteps = []
2486
+ # self.times = []
2487
+
2488
+ # self.properties:Props_Res_2D = None
2489
+ # self.set_properties()
2490
+
2491
+ # self.mngselection = SelectionDataMB(self)
2492
+ # self.myops = None
2493
+ # self._active_blocks = 0
2494
+
2495
+ def _post_loader(self):
2496
+ """ Post loader for CPU/GPU results """
2497
+
2464
2498
  self.nbx = 1
2465
2499
  self.nby = 1
2466
2500
 
@@ -2490,6 +2524,188 @@ class Wolfresults_2D(Element_To_Draw):
2490
2524
  self.myops = None
2491
2525
  self._active_blocks = 0
2492
2526
 
2527
+ def _loader_CPU2D(self, fname:str) -> int:
2528
+ """ Loader for CPU results """
2529
+
2530
+ # We are here for "classic" CPU results
2531
+ parts=splitext(fname)
2532
+ if len(parts)>1:
2533
+ self.filename = parts[0]
2534
+ else:
2535
+ self.filename = fname
2536
+
2537
+ self.filenamegen=self.filename
2538
+ self._dll_tools = Tools2DFortran(self.filenamegen) # DLL de calculs de la classe Tools2DFortran
2539
+
2540
+ if exists(self.filename + '.trl'):
2541
+ with open(self.filename + '.trl') as f:
2542
+ trl=f.read().splitlines()
2543
+ self.translx=float(trl[1])
2544
+ self.transly=float(trl[2])
2545
+
2546
+ self.myblocks={}
2547
+ self.read_param_simul()
2548
+
2549
+ if exists(self.filename+'.head') or exists(join(dirname(self.filename),'bloc1.head')):
2550
+ # wolfpy.r2d_init(self.filename.ljust(255).encode('ansi'))
2551
+ # nb_blocks = wolfpy.r2d_nbblocks()
2552
+
2553
+ nb_blocks = self._dll_tools.r2D_get_number_of_blocks()
2554
+ for i in range(nb_blocks):
2555
+ curblock = OneWolfResult(i, parent=self)
2556
+ self.myblocks[getkeyblock(i)] = curblock
2557
+
2558
+ # nbx,nby,dx,dy,ox,oy,tx,ty = wolfpy.r2d_hblock(i+1)
2559
+ nbx, nby,dx,dy,ox,oy,tx,ty = self._dll_tools.r2D_get_header_one_block(i+1)
2560
+
2561
+ curhead = self.head_blocks[getkeyblock(i)]=header_wolf()
2562
+ curhead.nbx = nbx
2563
+ curhead.nby = nby
2564
+ curhead.origx = ox
2565
+ curhead.origy = oy
2566
+ curhead.dx = dx
2567
+ curhead.dy = dy
2568
+ curhead.translx = self.translx
2569
+ curhead.transly = self.transly
2570
+
2571
+ curblock.waterdepth.dx = dx
2572
+ curblock.waterdepth.dy = dy
2573
+ curblock.waterdepth.nbx = nbx
2574
+ curblock.waterdepth.nby = nby
2575
+ curblock.waterdepth.origx = ox
2576
+ curblock.waterdepth.origy = oy
2577
+ curblock.waterdepth.translx = self.translx
2578
+ curblock.waterdepth.transly = self.transly
2579
+
2580
+ curblock.top.dx = dx
2581
+ curblock.top.dy = dy
2582
+ curblock.top.nbx = nbx
2583
+ curblock.top.nby = nby
2584
+ curblock.top.origx = ox
2585
+ curblock.top.origy = oy
2586
+ curblock.top.translx = self.translx
2587
+ curblock.top.transly = self.transly
2588
+
2589
+ curblock.qx.dx = dx
2590
+ curblock.qx.dy = dy
2591
+ curblock.qx.nbx = nbx
2592
+ curblock.qx.nby = nby
2593
+ curblock.qx.origx = ox
2594
+ curblock.qx.origy = oy
2595
+ curblock.qx.translx = self.translx
2596
+ curblock.qx.transly = self.transly
2597
+
2598
+ curblock.qy.dx = dx
2599
+ curblock.qy.dy = dy
2600
+ curblock.qy.nbx = nbx
2601
+ curblock.qy.nby = nby
2602
+ curblock.qy.origx = ox
2603
+ curblock.qy.origy = oy
2604
+ curblock.qy.translx = self.translx
2605
+ curblock.qy.transly = self.transly
2606
+
2607
+ curblock.rough_n.dx = dx
2608
+ curblock.rough_n.dy = dy
2609
+ curblock.rough_n.nbx = nbx
2610
+ curblock.rough_n.nby = nby
2611
+ curblock.rough_n.origx = ox
2612
+ curblock.rough_n.origy = oy
2613
+ curblock.rough_n.translx = self.translx
2614
+ curblock.rough_n.transly = self.transly
2615
+
2616
+ curblock.eps.dx = dx
2617
+ curblock.eps.dy = dy
2618
+ curblock.eps.nbx = nbx
2619
+ curblock.eps.nby = nby
2620
+ curblock.eps.origx = ox
2621
+ curblock.eps.origy = oy
2622
+ curblock.eps.translx = self.translx
2623
+ curblock.eps.transly = self.transly
2624
+
2625
+ curblock.k.dx = dx
2626
+ curblock.k.dy = dy
2627
+ curblock.k.nbx = nbx
2628
+ curblock.k.nby = nby
2629
+ curblock.k.origx = ox
2630
+ curblock.k.origy = oy
2631
+ curblock.k.translx = self.translx
2632
+ curblock.k.transly = self.transly
2633
+
2634
+ curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2635
+ curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2636
+ curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2637
+
2638
+ _param_turb = self.myparam.blocks[i].get_params_turbulence()
2639
+ if 'cmu' in _param_turb:
2640
+ curblock._cmu = _param_turb['cmu']
2641
+ if 'cnu' in _param_turb:
2642
+ curblock._cnu = _param_turb['cnu']
2643
+
2644
+ else:
2645
+ nb_blocks = self.myblocfile.nb_blocks
2646
+
2647
+ for i in range(nb_blocks):
2648
+ #print(f"Reading block {getkeyblock(i)}")
2649
+ curblock = OneWolfResult(i, parent = self)
2650
+ self.myblocks[getkeyblock(i)] = curblock
2651
+ curblock.waterdepth.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2652
+ curblock.top.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2653
+ curblock.qx.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2654
+ curblock.qy.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2655
+ curblock.rough_n.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2656
+ curblock.eps.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2657
+ curblock.k.set_header(self.mymnap.head_blocks[getkeyblock(i)])
2658
+
2659
+ curblock._is_manning_strickler = self.myparam.blocks[i].is_Manning_surface_friction
2660
+ curblock._is_colebrook = self.myparam.blocks[i].is_Colebrook_surface_friction
2661
+ curblock._has_turbulence_model = self.myparam.blocks[i].has_turbulence
2662
+
2663
+ _param_turb = self.myparam.blocks[i].get_params_turbulence()
2664
+ if 'cmu' in _param_turb:
2665
+ curblock._cmu = _param_turb['cmu']
2666
+ if 'cnu' in _param_turb:
2667
+ curblock._cnu = _param_turb['cnu']
2668
+
2669
+ self.allocate_ressources()
2670
+ self.read_topography()
2671
+ self.read_ini_mb()
2672
+
2673
+ self.loaded_rough = False
2674
+
2675
+ def __getstate__(self):
2676
+ """Get the state of the object for pickling"""
2677
+ state = self.__dict__.copy()
2678
+ # Remove unpicklable attributes
2679
+
2680
+ topop = ['mapviewer',
2681
+ 'properties',
2682
+ 'mngselection',
2683
+ 'myops',
2684
+ '_dll_tools',
2685
+ 'myparam',
2686
+ 'myblocfile',
2687
+ 'mymnap']
2688
+
2689
+ for cur_pop in topop:
2690
+ if cur_pop in state:
2691
+ state.pop(cur_pop)
2692
+ return state
2693
+
2694
+ def __setstate__(self, state):
2695
+ """Set the state of the object after unpickling"""
2696
+ # Restore the state of the object
2697
+ self.__dict__.update(state)
2698
+ # Reinitialize any attributes that were removed during pickling
2699
+ self.mapviewer = None
2700
+ self.properties = None
2701
+ self.mngselection = None
2702
+ self.myops = None
2703
+
2704
+ if not 'isGPU' in list(state.keys()):
2705
+ self._loader_CPU2D(self.filenamegen)
2706
+ self._post_loader()
2707
+ self._dll_tools = Tools2DFortran(self.filenamegen)
2708
+
2493
2709
  @property
2494
2710
  def all_dt(self):
2495
2711
  #FIXME : defined in GPU version --> to be implemented for CPU version
@@ -5122,7 +5338,10 @@ class Wolfresults_2D(Element_To_Draw):
5122
5338
  self.get_working_array()
5123
5339
  self.updatepalette(whichpal)
5124
5340
 
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]]:
5341
+ def danger_map(self, start:int=0, end:int=-1,
5342
+ every:int=1, callback=None,
5343
+ hmin:float = None) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray, WolfArray, WolfArray],
5344
+ tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5126
5345
  """
5127
5346
  Create Danger Maps
5128
5347
 
@@ -5131,13 +5350,22 @@ class Wolfresults_2D(Element_To_Draw):
5131
5350
  :param every: step interval
5132
5351
  :param callback: optional callback to update progress
5133
5352
 
5134
- :return : tuple of WolfArray or WolfArrayMB - H, U_norm, Q_norm, Z, Head
5353
+ :return : tuple of WolfArray or WolfArrayMB - H, U_norm, Q_norm, Z, Head, Time_of_arrival, Time_of_maximum
5135
5354
  """
5136
5355
 
5356
+ DEFAULT_TOA = 0.
5357
+
5358
+ if hmin is None:
5359
+ hmin = self.epsilon
5360
+
5137
5361
  # Number of time steps
5138
5362
  number_of_time_steps = self.get_nbresults()
5139
5363
  if end ==-1:
5140
- end = number_of_time_steps
5364
+ end = number_of_time_steps - 1
5365
+
5366
+ if end > number_of_time_steps:
5367
+ logging.warning("End time step is greater than the number of time steps. Setting end to the last time step.")
5368
+ end = number_of_time_steps - 1
5141
5369
 
5142
5370
  # Init Danger Maps basde on results type
5143
5371
  # If only one block --> WolfArray
@@ -5148,7 +5376,16 @@ class Wolfresults_2D(Element_To_Draw):
5148
5376
  danger_map_matrix_z = self.as_WolfArray(copyarray=True)
5149
5377
  danger_map_matrix_head= self.as_WolfArray(copyarray=True)
5150
5378
 
5151
- danger = [danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head]
5379
+ danger_map_matrix_toa = self.as_WolfArray(copyarray=True)
5380
+ danger_map_matrix_tom = self.as_WolfArray(copyarray=True)
5381
+
5382
+ danger = [danger_map_matrix_h,
5383
+ danger_map_matrix_v,
5384
+ danger_map_matrix_mom,
5385
+ danger_map_matrix_z,
5386
+ danger_map_matrix_head,
5387
+ danger_map_matrix_toa,
5388
+ danger_map_matrix_tom]
5152
5389
 
5153
5390
  for curdanger in danger:
5154
5391
  curdanger.nullvalue = 0.
@@ -5159,12 +5396,15 @@ class Wolfresults_2D(Element_To_Draw):
5159
5396
  #add the end
5160
5397
  if end not in to_compute:
5161
5398
  to_compute = np.append(to_compute, end)
5399
+
5162
5400
  for time_step in tqdm(to_compute):
5163
5401
 
5164
5402
  if callback is not None:
5165
- callback(time_step, "Step {} / {}".format(time_step+1, end))
5403
+ callback(time_step, "Step {} / {}".format(int(time_step+1), int(end)))
5166
5404
 
5167
- self.read_oneresult(time_step+1)
5405
+ self.read_oneresult(time_step)
5406
+
5407
+ cur_time = self.times[time_step]
5168
5408
 
5169
5409
  if self.nb_blocks>1:
5170
5410
  for curblock in self.myblocks.keys():
@@ -5188,14 +5428,23 @@ class Wolfresults_2D(Element_To_Draw):
5188
5428
  z[ij] = wd.array[ij] + top.array[ij]
5189
5429
  head[ij]= z[ij] + v[ij]**2./2/9.81
5190
5430
 
5431
+ # Fill the time of arrival
5432
+ danger_map_matrix_toa[curblock].array[(danger_map_matrix_toa.array == DEFAULT_TOA) & (wd.array > hmin)] = cur_time
5433
+
5434
+ # Fill the time of maximum
5435
+ # Searching where wd > h_max
5436
+ ij_h = np.where((danger_map_matrix_h[curblock].array < wd.array) & (~wd.array.mask))
5437
+ danger_map_matrix_tom[curblock].array[ij_h] = cur_time
5438
+
5191
5439
  # Comparison
5192
5440
  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
5441
+ ij = np.where((curdanger[curblock].array < curcomp) & (~wd.array.mask))
5442
+ curdanger[curblock].array.data[ij] = curcomp[ij]
5443
+ curdanger[curblock].array.mask[ij] = False
5196
5444
 
5197
5445
  else:
5198
5446
  curblock = getkeyblock(0)
5447
+
5199
5448
  wd = self.get_h_for_block(curblock)
5200
5449
  qx = self.get_qx_for_block(curblock)
5201
5450
  qy = self.get_qy_for_block(curblock)
@@ -5214,8 +5463,16 @@ class Wolfresults_2D(Element_To_Draw):
5214
5463
  z[ij] = wd.array[ij] + top.array[ij]
5215
5464
  head[ij]= z[ij] + v[ij]**2./2/9.81
5216
5465
 
5466
+ # Fill the time of arrival
5467
+ danger_map_matrix_toa.array[(danger_map_matrix_toa.array == DEFAULT_TOA) & (wd.array > hmin)] = cur_time
5468
+
5469
+ # Fill the time of maximum
5470
+ # Searching where wd > h_max
5471
+ ij_h = np.where((danger_map_matrix_h.array < wd.array) & (~wd.array.mask))
5472
+ danger_map_matrix_tom.array[ij_h] = cur_time
5473
+
5217
5474
  # Comparison
5218
- for curdanger, curcomp in zip(danger, [wd.array, v, mom, z, head]):
5475
+ for curdanger, curcomp in zip(danger[:5], [wd.array, v, mom, z, head]):
5219
5476
  ij = np.where((curdanger.array < curcomp) & (~wd.array.mask))
5220
5477
  curdanger.array.data[ij] = curcomp[ij]
5221
5478
  curdanger.array.mask[ij] = False
@@ -5228,37 +5485,30 @@ class Wolfresults_2D(Element_To_Draw):
5228
5485
  danger_map_matrix_mom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5229
5486
  danger_map_matrix_z[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5230
5487
  danger_map_matrix_head[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5488
+ danger_map_matrix_toa[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5489
+ danger_map_matrix_tom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5231
5490
  else:
5232
5491
  danger_map_matrix_v.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5233
5492
  danger_map_matrix_mom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5234
5493
  danger_map_matrix_z.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5235
5494
  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]]:
5495
+ danger_map_matrix_toa.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5496
+ danger_map_matrix_tom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5497
+
5498
+ return (danger_map_matrix_h,
5499
+ danger_map_matrix_v,
5500
+ danger_map_matrix_mom,
5501
+ danger_map_matrix_z,
5502
+ danger_map_matrix_head,
5503
+ danger_map_matrix_toa,
5504
+ danger_map_matrix_tom)
5505
+
5506
+ def danger_map_multiprocess(self, start:int=0, end:int=-1,
5507
+ every:int=1,
5508
+ callback=None,
5509
+ hmin:float = None,
5510
+ nb_processors:int = -1) -> Union[tuple[WolfArray, WolfArray, WolfArray, WolfArray, WolfArray, WolfArray],
5511
+ tuple[WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB, WolfArrayMB]]:
5262
5512
  """
5263
5513
  Create Danger Maps using multiprocessing
5264
5514
 
@@ -5268,18 +5518,37 @@ class Wolfresults_2D(Element_To_Draw):
5268
5518
  :param callback: optional callback to update progress
5269
5519
  """
5270
5520
 
5521
+ DEFAULT_TOA = 0.
5522
+
5271
5523
  from multiprocessing import Pool, cpu_count
5272
5524
 
5525
+ if hmin is None:
5526
+ hmin = self.epsilon
5527
+
5273
5528
  if nb_processors == -1:
5274
5529
  nb_processors = cpu_count()
5530
+ elif nb_processors > cpu_count():
5531
+ nb_processors = cpu_count()
5532
+ elif nb_processors < 1:
5533
+ nb_processors = 1
5534
+
5535
+ if end == -1:
5536
+ end = self.get_nbresults() - 1
5537
+ if end > self.get_nbresults():
5538
+ logging.warning("End time step is greater than the number of time steps. Setting end to the last time step.")
5539
+ end = self.get_nbresults() - 1
5275
5540
 
5276
5541
  if nb_processors > self.get_nbresults():
5277
- nb_processors = self.get_nbresults()
5542
+ logging.warning('Number of processors is greater than the number of time steps.')
5543
+ nb_processors = int(self.get_nbresults() /4)
5544
+ elif nb_processors > end-start+1:
5545
+ logging.warning('Number of processors is greater than the number of time steps.')
5546
+ nb_processors = int((end-start)/4)
5278
5547
 
5279
- # Split the range of time steps into chunks for multiprocessing
5280
- if end == -1:
5281
- end = self.get_nbresults()
5548
+ if nb_processors < 1:
5549
+ nb_processors = 1
5282
5550
 
5551
+ # Create a list of chunks
5283
5552
  starts = [start + i * every for i in range(nb_processors)]
5284
5553
  ends = [end - i * every for i in range(nb_processors-1,-1,-1)]
5285
5554
 
@@ -5294,7 +5563,18 @@ class Wolfresults_2D(Element_To_Draw):
5294
5563
  if starts[i] >= ends[i]:
5295
5564
  ends[i] = starts[i] + every
5296
5565
 
5297
- chunks = [(self, start + i * every, end - (nb_processors - i) * every + 1, nb_processors) for i in range(min(nb_processors, len(starts)))]
5566
+ # clip ends to end
5567
+ for i in range(len(ends)):
5568
+ if ends[i] > end:
5569
+ ends[i] = end
5570
+
5571
+ everys = [min(nb_processors, (_end - _start)) for _start, _end in zip(starts, ends)]
5572
+
5573
+ chunks = [(self,
5574
+ starts[i],
5575
+ ends[i],
5576
+ everys[i],
5577
+ hmin) for i in range(min(nb_processors, len(starts)))]
5298
5578
 
5299
5579
  # Create a pool of workers
5300
5580
  with Pool(processes=nb_processors) as pool:
@@ -5306,7 +5586,16 @@ class Wolfresults_2D(Element_To_Draw):
5306
5586
  danger_map_matrix_z = self.as_WolfArray(copyarray=True)
5307
5587
  danger_map_matrix_head= self.as_WolfArray(copyarray=True)
5308
5588
 
5309
- danger = [danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head]
5589
+ danger_map_matrix_toa = self.as_WolfArray(copyarray=True)
5590
+ danger_map_matrix_tom = self.as_WolfArray(copyarray=True)
5591
+
5592
+ danger = [danger_map_matrix_h,
5593
+ danger_map_matrix_v,
5594
+ danger_map_matrix_mom,
5595
+ danger_map_matrix_z,
5596
+ danger_map_matrix_head,
5597
+ danger_map_matrix_toa,
5598
+ danger_map_matrix_tom]
5310
5599
 
5311
5600
  for curdanger in danger:
5312
5601
  curdanger.nullvalue = 0.
@@ -5315,16 +5604,89 @@ class Wolfresults_2D(Element_To_Draw):
5315
5604
 
5316
5605
  if self.nb_blocks>1:
5317
5606
  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)
5607
+
5608
+ for i in range(self.nb_blocks):
5609
+
5610
+ # time of arrival
5611
+ # Store if the value is DEFAULT_TOA and the new value is > 0
5612
+ # Other cases correspond to an lower TOA
5613
+
5614
+ danger_toa = danger_map_matrix_toa[i].array
5615
+ res_toa = result[5][i].array
5616
+
5617
+ ij = np.where((danger_toa.data == DEFAULT_TOA) & (res_toa.data > 0.))
5618
+ danger_toa.data[ij] = res_toa.data[ij]
5619
+ danger_toa.mask[ij] = False
5620
+
5621
+ # time of peak
5622
+ # Le temps de pic n'a pas encore été atteint et un valeur existe --> on prend
5623
+ danger_tom = danger_map_matrix_tom[i].array
5624
+ danger_h = danger_map_matrix_h[i].array
5625
+ res_tom = result[6][i].array
5626
+ res_h = result[0][i].array
5627
+
5628
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5629
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data == res_h.data) & (~res_tom.mask))
5630
+ danger_tom.data[ij] = np.minimum(res_tom.data[ij], danger_tom.data[ij])
5631
+ danger_tom.mask[ij] = False
5632
+
5633
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5634
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data < res_h.data) & (~res_tom.mask))
5635
+ danger_tom.data[ij] = res_tom.data[ij]
5636
+ danger_tom.mask[ij] = False
5637
+ danger_h.data[ij] = res_h.data[ij]
5638
+
5639
+ ij = np.where(((danger_tom.data == 0.) & (res_tom.data > 0.)))
5640
+ danger_tom.data[ij] = res_tom.data[ij]
5641
+ danger_h.data[ij] = res_h.data[ij]
5642
+ danger_tom.mask[ij] = False
5643
+
5644
+ # for i in range(self.nb_blocks):
5645
+ for idx, curdanger in enumerate(danger[:5]):
5646
+
5647
+ curdanger[i].array.data[:,:] = np.maximum(curdanger[i].array.data, result[idx][i].array.data)
5648
+ curdanger[i].array.mask[:,:] = np.logical_or(curdanger[i].array.mask, result[idx][i].array.mask)
5322
5649
  else:
5323
5650
  for result in results:
5324
- for idx, curdanger in enumerate(danger):
5651
+ # time of arrival
5652
+ # Store if the value is DEFAULT_TOA and the new value is > 0
5653
+ # Other cases correspond to an lower TOA
5654
+
5655
+ danger_toa = danger_map_matrix_toa.array
5656
+ res_toa = result[5].array
5657
+
5658
+ ij = np.where((danger_toa.data == DEFAULT_TOA) & (res_toa.data > 0.))
5659
+ danger_toa.data[ij] = res_toa.data[ij]
5660
+ danger_toa.mask[ij] = False
5661
+
5662
+ # time of peak
5663
+ # Le temps de pic n'a pas encore été atteint et un valeur existe --> on prend
5664
+ danger_tom = danger_map_matrix_tom.array
5665
+ danger_h = danger_map_matrix_h.array
5666
+ res_tom = result[6].array
5667
+ res_h = result[0].array
5668
+
5669
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5670
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data == res_h.data) & (~res_tom.mask))
5671
+ danger_tom.data[ij] = np.minimum(res_tom.data[ij], danger_tom.data[ij])
5672
+ danger_tom.mask[ij] = False
5673
+
5674
+ # Le temps de pic a été initialisé et une autre valeur existe --> on prend le temps où la hauteur est max
5675
+ ij = np.where((danger_tom.data > 0.) & (danger_h.data < res_h.data) & (~res_tom.mask))
5676
+ danger_tom.data[ij] = res_tom.data[ij]
5677
+ danger_tom.mask[ij] = False
5678
+ danger_h.data[ij] = res_h.data[ij]
5679
+
5680
+ ij = np.where(((danger_tom.data == 0.) & (res_tom.data > 0.)))
5681
+ danger_tom.data[ij] = res_tom.data[ij]
5682
+ danger_h.data[ij] = res_h.data[ij]
5683
+ danger_tom.mask[ij] = False
5684
+
5685
+ for idx, curdanger in enumerate(danger[:5]):
5325
5686
  curdanger.array.data[:,:] = np.maximum(curdanger.array.data, result[idx].array.data)
5326
5687
  curdanger.array.mask[:,:] = np.logical_or(curdanger.array.mask, result[idx].array.mask)
5327
5688
 
5689
+
5328
5690
  danger_map_matrix_h.mask_lower(self.epsilon)
5329
5691
 
5330
5692
  if self.nb_blocks>1:
@@ -5333,13 +5695,20 @@ class Wolfresults_2D(Element_To_Draw):
5333
5695
  danger_map_matrix_mom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5334
5696
  danger_map_matrix_z[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5335
5697
  danger_map_matrix_head[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5698
+ danger_map_matrix_toa[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5699
+ danger_map_matrix_tom[i].array.mask[:,:] = danger_map_matrix_h[i].array.mask[:,:]
5336
5700
  else:
5337
5701
  danger_map_matrix_v.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5338
5702
  danger_map_matrix_mom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5339
5703
  danger_map_matrix_z.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5340
5704
  danger_map_matrix_head.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5705
+ danger_map_matrix_toa.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5706
+ danger_map_matrix_tom.array.mask[:,:] = danger_map_matrix_h.array.mask[:,:]
5341
5707
 
5342
- return (danger_map_matrix_h, danger_map_matrix_v, danger_map_matrix_mom, danger_map_matrix_z, danger_map_matrix_head)
5708
+ return (danger_map_matrix_h, danger_map_matrix_v,
5709
+ danger_map_matrix_mom, danger_map_matrix_z,
5710
+ danger_map_matrix_head,
5711
+ danger_map_matrix_toa, danger_map_matrix_tom)
5343
5712
 
5344
5713
  def danger_map_only_h(self, start:int=0, end:int=-1, every:int=1) -> WolfArray:
5345
5714
  """