wolfhece 2.2.40__py3-none-any.whl → 2.2.42__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.
wolfhece/PyDraw.py CHANGED
@@ -1219,6 +1219,221 @@ class Sim_Explorer(wx.Frame):
1219
1219
  self._step_num.Set([str(i) for i in self._all_times_steps[1]])
1220
1220
 
1221
1221
 
1222
+ class Sim_VideoCreation(wx.Dialog):
1223
+
1224
+ def __init__(self, parent, title, mapviewer:"WolfMapViewer", sim:Wolfresults_2D):
1225
+ super(Sim_VideoCreation, self).__init__(parent, title=title, size=(350, 250), style = wx.DEFAULT_DIALOG_STYLE & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.CLOSE_BOX))
1226
+
1227
+ self.mapviewer = mapviewer
1228
+ self.active_res2d:Wolfresults_2D = sim
1229
+
1230
+ self._framerate = 25
1231
+ self._start_step = 1
1232
+ self._end_step = self.active_res2d.get_nbresults()
1233
+ self._interval = 1
1234
+ self._fn = str(Path(self.active_res2d.filename).parent / f'{Path(self.active_res2d.filename).stem}.avi')
1235
+
1236
+ self._fontsize = 16
1237
+ self._fontcolor = (255, 255, 255, 255)
1238
+ self._timeposition = 'top-left' # 'top-right', 'bottom-left', 'bottom-right', 'top-center', 'bottom-center'
1239
+
1240
+ panel = wx.Panel(self)
1241
+ vbox = wx.BoxSizer(wx.VERTICAL)
1242
+
1243
+ hbox1 = wx.BoxSizer(wx.HORIZONTAL)
1244
+ st1 = wx.StaticText(panel, -1, _('File name'))
1245
+ hbox1.Add(st1, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1246
+ tc1 = wx.TextCtrl(panel, -1, self._fn)
1247
+ hbox1.Add(tc1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1248
+ vbox.Add(hbox1,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1249
+ self.tc1 = tc1
1250
+
1251
+ # Add a button to choose the file name
1252
+ btn_browse = wx.Button(panel, -1, _('Browse'))
1253
+ hbox1.Add(btn_browse, 0, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1254
+ self.btn_browse = btn_browse
1255
+ self.btn_browse.Bind(wx.EVT_BUTTON, self.OnBrowse)
1256
+
1257
+ hbox2 = wx.BoxSizer(wx.HORIZONTAL)
1258
+ st2 = wx.StaticText(panel, -1, _('Frame rate [nb_images/second]'), style=wx.ALIGN_CENTER)
1259
+ hbox2.Add(st2, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1260
+ tc2 = wx.TextCtrl(panel, -1, str(self._framerate))
1261
+ hbox2.Add(tc2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1262
+ vbox.Add(hbox2,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1263
+ self.tc2 = tc2
1264
+
1265
+ hbox3 = wx.BoxSizer(wx.HORIZONTAL)
1266
+ st3 = wx.StaticText(panel, -1, _('First step'), style=wx.ALIGN_CENTER)
1267
+ hbox3.Add(st3, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1268
+ tc3 = wx.TextCtrl(panel, -1, str(self._start_step))
1269
+ hbox3.Add(tc3,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1270
+ vbox.Add(hbox3,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1271
+ self.tc3 = tc3
1272
+
1273
+ hbox4 = wx.BoxSizer(wx.HORIZONTAL)
1274
+ st4 = wx.StaticText(panel, -1, _('Final step'), style=wx.ALIGN_CENTER)
1275
+ hbox4.Add(st4, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1276
+ tc4 = wx.TextCtrl(panel, -1, str(self._end_step))
1277
+ hbox4.Add(tc4,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1278
+ vbox.Add(hbox4,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1279
+ self.tc4 = tc4
1280
+
1281
+ hbox5 = wx.BoxSizer(wx.HORIZONTAL)
1282
+ st5 = wx.StaticText(panel, -1, _('Interval'), style=wx.ALIGN_CENTER)
1283
+ hbox5.Add(st5, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1284
+ tc5 = wx.TextCtrl(panel, -1, str(self._interval))
1285
+ hbox5.Add(tc5,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1286
+ vbox.Add(hbox5,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1287
+ self.tc5 = tc5
1288
+
1289
+ hbox7 = wx.BoxSizer(wx.HORIZONTAL)
1290
+ st7 = wx.StaticText(panel, -1, _("Font size (for time stamp)"), style=wx.ALIGN_CENTER)
1291
+ hbox7.Add(st7, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1292
+ tc7 = wx.TextCtrl(panel, -1, str(self._fontsize))
1293
+ hbox7.Add(tc7,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1294
+ vbox.Add(hbox7,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1295
+ self.tc7 = tc7
1296
+
1297
+ hbox8 = wx.BoxSizer(wx.HORIZONTAL)
1298
+ st8 = wx.StaticText(panel, -1, _("Font color (R,G,B,A)"), style=wx.ALIGN_CENTER)
1299
+ hbox8.Add(st8, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1300
+ tc8 = wx.ColourPickerCtrl(panel, -1, wx.Colour(*self._fontcolor))
1301
+ hbox8.Add(tc8,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1302
+ vbox.Add(hbox8,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1303
+ self.tc8 = tc8
1304
+
1305
+ hbox9 = wx.BoxSizer(wx.HORIZONTAL)
1306
+ st9 = wx.StaticText(panel, -1, _("Time position"), style=wx.ALIGN_CENTER)
1307
+ hbox9.Add(st9, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1308
+ choices = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'top-center', 'bottom-center']
1309
+ tc9 = wx.Choice(panel, -1, choices=choices)
1310
+ hbox9.Add(tc9, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1311
+ vbox.Add(hbox9, 0, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL, 5)
1312
+ self.tc9 = tc9
1313
+
1314
+ hbox6 = wx.BoxSizer(wx.HORIZONTAL)
1315
+ btn1 = wx.Button(panel, -1, _('Ok'))
1316
+ hbox6.Add(btn1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1317
+ self.btn1 = btn1
1318
+
1319
+ btn2 = wx.Button(panel, -1, _('Cancel'))
1320
+ hbox6.Add(btn2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1321
+ self.btn2 = btn2
1322
+ vbox.Add(hbox6,0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
1323
+ panel.SetSizer(vbox)
1324
+ vbox.Fit(self)
1325
+
1326
+ self.btn1.Bind(wx.EVT_BUTTON, self.OnOk)
1327
+ self.btn2.Bind(wx.EVT_BUTTON, self.OnCancel)
1328
+
1329
+ # Add validation to the text controls
1330
+ self.tc2.Bind(wx.EVT_TEXT, self.OnValidate)
1331
+ self.tc3.Bind(wx.EVT_TEXT, self.OnValidate)
1332
+ self.tc4.Bind(wx.EVT_TEXT, self.OnValidate)
1333
+ self.tc5.Bind(wx.EVT_TEXT, self.OnValidate)
1334
+ self.tc7.Bind(wx.EVT_TEXT, self.OnValidate)
1335
+ self.tc8.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnValidate)
1336
+ self.tc9.SetSelection(0)
1337
+ self.tc9.Bind(wx.EVT_CHOICE, self.OnValidate)
1338
+
1339
+ icon = wx.Icon()
1340
+ icon_path = Path(__file__).parent / "apps/wolf_logo2.bmp"
1341
+ icon.CopyFromBitmap(wx.Bitmap(str(icon_path), wx.BITMAP_TYPE_ANY))
1342
+ self.SetIcon(icon)
1343
+ self.CenterOnScreen()
1344
+ self.Show()
1345
+
1346
+ def OnBrowse(self, event):
1347
+ """ Browse a file name to save the video """
1348
+ with wx.FileDialog(self, _("Save video file"), wildcard="MP4 files (*.mp4)|*.mp4|AVI files (*.avi)|*.avi|All files (*.*)|*.*",
1349
+ style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
1350
+ if fileDialog.ShowModal() == wx.ID_CANCEL:
1351
+ return # the user changed idea...
1352
+
1353
+ self._fn = fileDialog.GetPath()
1354
+ self.tc1.SetValue(self._fn)
1355
+
1356
+ def get_values(self):
1357
+ """ Return the values set in the dialog """
1358
+ return self._fn, self._framerate, self._start_step, self._end_step, self._interval, self._fontsize, self._fontcolor, self._timeposition
1359
+
1360
+ def OnValidate(self, event):
1361
+ """ Validate the text controls to be sure that the values are correct """
1362
+ try:
1363
+ framerate = int(self.tc2.GetValue())
1364
+ if framerate <= 0:
1365
+ framerate = 25
1366
+ self.tc2.SetValue(str(framerate))
1367
+ self._framerate = framerate
1368
+ except:
1369
+ self.tc2.SetValue(str(self._framerate))
1370
+ try:
1371
+ start_step = int(self.tc3.GetValue())
1372
+ if start_step < 1:
1373
+ start_step = 1
1374
+ self.tc3.SetValue(str(start_step))
1375
+ if start_step > self.active_res2d.get_nbresults():
1376
+ start_step = self.active_res2d.get_nbresults()
1377
+ self.tc3.SetValue(str(start_step))
1378
+ self._start_step = start_step
1379
+
1380
+ except:
1381
+ self.tc3.SetValue(str(self._start_step))
1382
+ try:
1383
+ end_step = int(self.tc4.GetValue())
1384
+ if end_step < 1:
1385
+ end_step = 1
1386
+ self.tc4.SetValue(str(end_step))
1387
+ if end_step > self.active_res2d.get_nbresults():
1388
+ end_step = self.active_res2d.get_nbresults()
1389
+ self.tc4.SetValue(str(end_step))
1390
+ self._end_step = end_step
1391
+ except:
1392
+ self.tc4.SetValue(str(self._end_step))
1393
+ try:
1394
+ interval = int(self.tc5.GetValue())
1395
+ if interval < 1:
1396
+ interval = 1
1397
+ self.tc5.SetValue(str(interval))
1398
+ self._interval = interval
1399
+ except:
1400
+ self.tc5.SetValue(str(self._interval))
1401
+
1402
+ try:
1403
+ fontsize = int(self.tc7.GetValue())
1404
+ if fontsize < 1:
1405
+ fontsize = 16
1406
+ self.tc7.SetValue(str(fontsize))
1407
+ self._fontsize = fontsize
1408
+ except:
1409
+ self.tc7.SetValue(str(self._fontsize))
1410
+
1411
+ try:
1412
+ color = self.tc8.GetColour()
1413
+ self._fontcolor = (color.Red(), color.Green(), color.Blue(), color.Alpha())
1414
+ except:
1415
+ self.tc8.SetColour(wx.Colour(*self._fontcolor))
1416
+
1417
+ try:
1418
+ pos_idx = self.tc9.GetSelection()
1419
+ choices = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'top-center', 'bottom-center']
1420
+ if pos_idx < 0 or pos_idx >= len(choices):
1421
+ pos_idx = 0
1422
+ self.tc9.SetSelection(pos_idx)
1423
+ self._timeposition = choices[pos_idx]
1424
+ except:
1425
+ self.tc9.SetSelection(0)
1426
+
1427
+ def OnOk(self, event):
1428
+ """ Create the video file """
1429
+ self.OnValidate(None)
1430
+ self.EndModal(wx.ID_OK)
1431
+
1432
+ def OnCancel(self, event):
1433
+ """ Cancel the video creation """
1434
+ self.EndModal(wx.ID_CANCEL)
1435
+
1436
+
1222
1437
  class Drowning_Explorer(wx.Frame):
1223
1438
 
1224
1439
  def __init__(self, parent, title, mapviewer:any, sim:Drowning_victim_Viewer):
@@ -2530,7 +2745,7 @@ class WolfMapViewer(wx.Frame):
2530
2745
  self.InitUI()
2531
2746
 
2532
2747
  self._tmp_vector_distance = None # distance computation the vector
2533
- self._distances = Zones(mapviewer=self, idx=_('Distances/Areas'))
2748
+ self._distances = Zones(mapviewer=self, idx=_('Distances/Areas'), parent = self)
2534
2749
  self._distances.add_zone(zone(name='memory distances', parent=self._distances)) # distances memory
2535
2750
 
2536
2751
  self.menu_alaro_forecasts()
@@ -3482,13 +3697,20 @@ class WolfMapViewer(wx.Frame):
3482
3697
  self._uts_menu = wx.Menu()
3483
3698
  self._ocs_menu = wx.Menu()
3484
3699
 
3485
- self._uts_crop = self._uts_menu.Append(wx.ID_ANY, _("Crop on active array"), _("Crop active array"))
3486
- self._uts_cropscreen = self._uts_menu.Append(wx.ID_ANY, _("Crop on screen"), _("Crop screen"))
3700
+ self._uts_crop = self._uts_menu.Append(wx.ID_ANY, _("Crop on active array"), _("Crop UTS data (vectorized - shp, gpkg) on the active array extent"))
3701
+ self._uts_cropscreen = self._uts_menu.Append(wx.ID_ANY, _("Crop on screen"), _("Crop UTS data (vectorized - shp, gpkg) on the current screen extent"))
3487
3702
  self._uts_map = self._uts_menu.Append(wx.ID_ANY, _("Map active array (WAL_UTS -> Manning)"), _("Map Walous UTS active array to Manning's n"))
3488
3703
  self._uts_legend = self._uts_menu.Append(wx.ID_ANY, _("Legend"), _("Legend"))
3489
3704
 
3490
- self._ocs_crop = self._ocs_menu.Append(wx.ID_ANY, _("Crop on active array"), _("Crop active array"))
3491
- self._ocs_cropscreen = self._ocs_menu.Append(wx.ID_ANY, _("Crop on screen"), _("Crop screen"))
3705
+ self._ocs_crop_10m_2023 = self._ocs_menu.Append(wx.ID_ANY, _("Crop on active array (prepared data 10 m - 2023)"), _("Crop OCS data (matrix - geotif) on the active array extent using prepared 10m data"))
3706
+ self._ocs_cropscreen_10m_2023 = self._ocs_menu.Append(wx.ID_ANY, _("Crop on screen (prepared data 10 m - 2023)"), _("Crop OCS data (matrix - geotif) on the current screen extent using prepared 10m data"))
3707
+ self._ocs_menu.AppendSeparator()
3708
+ self._ocs_crop_10m_2020 = self._ocs_menu.Append(wx.ID_ANY, _("Crop on active array (prepared data 10 m - 2020)"), _("Crop OCS data (matrix - geotif) on the active array extent using prepared 10m data"))
3709
+ self._ocs_cropscreen_10m_2020 = self._ocs_menu.Append(wx.ID_ANY, _("Crop on screen (prepared data 10 m - 2020)"), _("Crop OCS data (matrix - geotif) on the current screen extent using prepared 10m data"))
3710
+ self._ocs_menu.AppendSeparator()
3711
+ self._ocs_crop = self._ocs_menu.Append(wx.ID_ANY, _("Crop on active array"), _("Crop OCS data (matrix - geotif) on the active array extent"))
3712
+ self._ocs_cropscreen = self._ocs_menu.Append(wx.ID_ANY, _("Crop on screen"), _("Crop OCS data (matrix - geotif) on the current screen extent"))
3713
+ self._ocs_menu.AppendSeparator()
3492
3714
  self._ocs_map = self._ocs_menu.Append(wx.ID_ANY, _("Map active array (WAL_OCS -> Hydrology)"), _("Map Walous OCS active array to Hydrology's landuse classification"))
3493
3715
  self._ocs_map = self._ocs_menu.Append(wx.ID_ANY, _("Map active array (WAL_OCS -> Manning)"), _("Map Walous OCS active array to Manning's n"))
3494
3716
  self._ocs_legend = self._ocs_menu.Append(wx.ID_ANY, _("Legend"), _("Legend"))
@@ -3617,9 +3839,9 @@ class WolfMapViewer(wx.Frame):
3617
3839
 
3618
3840
  itemlabel = item.ItemLabel
3619
3841
 
3620
- if itemlabel in [_("Crop on active array"), _("Crop on screen")]:
3842
+ if _("Crop on active array") in itemlabel or _("Crop on screen") in itemlabel:
3621
3843
 
3622
- if itemlabel == _("Crop on screen"):
3844
+ if _("Crop on screen") in itemlabel:
3623
3845
 
3624
3846
  bounds = self.get_canvas_bounds(gridsize=1.)
3625
3847
 
@@ -3653,14 +3875,24 @@ class WolfMapViewer(wx.Frame):
3653
3875
  from .pywalous import update_palette_walous_ocs
3654
3876
 
3655
3877
  if self._walous_OCS_filepath is None:
3656
- dlg = wx.FileDialog(self, _("Choose the Walous OCS Tif file"), wildcard="Tif file (*.tif)|*.tif|all (*.*)|*.*", style=wx.FD_OPEN)
3657
- if dlg.ShowModal() == wx.ID_CANCEL:
3658
- dlg.Destroy()
3659
- return
3660
3878
 
3661
- self._walous_OCS_filepath = Path(dlg.GetPath())
3662
- dlg.Destroy()
3879
+ if itemlabel in [_("Crop on active array (prepared data 10 m - 2023)"), _("Crop on screen (prepared data 10 m - 2023)")]:
3880
+ self._walous_OCS_filepath = toys_dataset('Walous_OCS', 'WALOUS_2023_lbt72_10m.tif')
3881
+ elif itemlabel in [_("Crop on active array (prepared data 10 m - 2020)"), _("Crop on screen (prepared data 10 m - 2020)")]:
3882
+ self._walous_OCS_filepath = toys_dataset('Walous_OCS', 'WALOUS_2020_lbt72_10m.tif')
3663
3883
 
3884
+ else:
3885
+ dlg = wx.FileDialog(self, _("Choose the Walous OCS Tif file"), wildcard="Tif file (*.tif)|*.tif|all (*.*)|*.*", style=wx.FD_OPEN)
3886
+ if dlg.ShowModal() == wx.ID_CANCEL:
3887
+ dlg.Destroy()
3888
+ return
3889
+
3890
+ self._walous_OCS_filepath = Path(dlg.GetPath())
3891
+ dlg.Destroy()
3892
+
3893
+ if self._walous_OCS_filepath is None or not Path(self._walous_OCS_filepath).exists():
3894
+ logging.error(_('No Walous OCS file -- Please set it'))
3895
+ return
3664
3896
 
3665
3897
  dlg = wx.FileDialog(self, _("Choose the output file"), wildcard="Geotif (*.tif)|*.tif|all (*.*)|*.*", style=wx.FD_SAVE, defaultDir=str(def_outdrir))
3666
3898
  if dlg.ShowModal() == wx.ID_CANCEL:
@@ -3670,8 +3902,33 @@ class WolfMapViewer(wx.Frame):
3670
3902
  output = Path(dlg.GetPath())
3671
3903
  dlg.Destroy()
3672
3904
 
3905
+ header_OCS = header_wolf.read_header(self._walous_OCS_filepath)
3906
+ if header_OCS.dx != spatial_res:
3907
+ # Adapt bounds to ensure that the rebin will be correct.
3908
+ # If spatial_res is a multiple of header_OCS.dx, no need to change bounds.
3909
+ # If not, change the bounds to ensure that the crop will include data in all footprints.
3910
+
3911
+ # Convert bvounds to list to be able to modify it
3912
+ bounds = [list(bounds[0]), list(bounds[1])]
3913
+
3914
+ if (bounds[0][0] - header_OCS.origx) % header_OCS.dx != 0:
3915
+ bounds[0][0] = header_OCS.origx + ((bounds[0][0] - header_OCS.origx) // header_OCS.dx) * header_OCS.dx
3916
+ if (bounds[0][1] - bounds[0][0]) % header_OCS.dx != 0:
3917
+ bounds[0][1] = bounds[0][0] + ((bounds[0][1] - bounds[0][0]) // header_OCS.dx + 1) * header_OCS.dx
3918
+ if (bounds[1][0] - header_OCS.origy) % header_OCS.dy != 0:
3919
+ bounds[1][0] = header_OCS.origy + ((bounds[1][0] - header_OCS.origy) // header_OCS.dy) * header_OCS.dy
3920
+ if (bounds[1][1] - bounds[1][0]) % header_OCS.dy != 0:
3921
+ bounds[1][1] = bounds[1][0] + ((bounds[1][1] - bounds[1][0]) // header_OCS.dy + 1) * header_OCS.dy
3922
+
3673
3923
  locwalous = WolfArray(fname=self._walous_OCS_filepath,
3674
- crop = bounds)
3924
+ crop = [bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]])
3925
+
3926
+ if locwalous.dx != spatial_res:
3927
+ locwalous.rebin(spatial_res / locwalous.dx, operation='min')
3928
+ logging.info(_('Rebin to {} m because original data are {} m').format(spatial_res, locwalous.dx))
3929
+ locwalous = WolfArray(mold=locwalous, crop = self.active_array.get_bounds())
3930
+
3931
+ locwalous.write_all(output)
3675
3932
 
3676
3933
  if Path(output).exists():
3677
3934
  logging.info(_('File {} created').format(output))
@@ -3689,6 +3946,7 @@ class WolfMapViewer(wx.Frame):
3689
3946
  elif ret == wx.ID_YES:
3690
3947
  walousarray = WolfArray(fname=output)
3691
3948
  update_palette_walous_ocs(walousarray.mypal)
3949
+ walousarray.reset_plot()
3692
3950
  self.add_object('array', newobj=walousarray, id = 'walous_ocs_crop')
3693
3951
  dlg.Destroy()
3694
3952
 
@@ -3705,6 +3963,10 @@ class WolfMapViewer(wx.Frame):
3705
3963
  logging.warning(_('No active array -- Please activate data first'))
3706
3964
  return
3707
3965
 
3966
+ if self.active_array.wolftype != WOLF_ARRAY_FULL_SINGLE:
3967
+ logging.error(_('Active array is not a Float32 array -- Please change it to Float32 before mapping'))
3968
+ return
3969
+
3708
3970
  vals = self.active_array.get_unique_values()
3709
3971
 
3710
3972
  if self._walous_layer is None:
@@ -3740,6 +4002,10 @@ class WolfMapViewer(wx.Frame):
3740
4002
  logging.warning(_('No active array -- Please activate data first'))
3741
4003
  return
3742
4004
 
4005
+ if self.active_array.wolftype != WOLF_ARRAY_FULL_SINGLE:
4006
+ logging.error(_('Active array is not a Float32 array -- Please change it to Float32 before mapping'))
4007
+ return
4008
+
3743
4009
  vals = self.active_array.get_unique_values()
3744
4010
 
3745
4011
  if self._walous_layer is None:
@@ -3780,7 +4046,6 @@ class WolfMapViewer(wx.Frame):
3780
4046
 
3781
4047
  if itemlabel in [_("Crop on active array"), _("Crop on screen")]:
3782
4048
 
3783
-
3784
4049
  if itemlabel == _("Crop on screen"):
3785
4050
 
3786
4051
  bounds = self.get_canvas_bounds(gridsize=1.)
@@ -3812,10 +4077,10 @@ class WolfMapViewer(wx.Frame):
3812
4077
  def_outdrir = Path(self.active_array.filename).parent
3813
4078
  spatial_res = self.active_array.dx
3814
4079
 
3815
- from .pywalous import Walous_data, WALOUS2MANNING_MAJ_NIV1, WALOUS2MANNING_MAJ_NIV2, update_palette_walous_uts
4080
+ from .pywalous import Walous_data, WALOUS_UTS2MANNING_MAJ_NIV1, WALOUS_UTS2MANNING_MAJ_NIV2, update_palette_walous_uts
3816
4081
 
3817
4082
  if self._walous_UTS_filepath is None:
3818
- dlg = wx.FileDialog(self, _("Choose the Walous shape file"), wildcard="Shapefile (*.shp)|*.shp|all (*.*)|*.*", style=wx.FD_OPEN)
4083
+ dlg = wx.FileDialog(self, _("Choose the Walous shape file"), wildcard="Geopackage (*.gpkg)|*.gpkg|Shapefile (*.shp)|*.shp|all (*.*)|*.*", style=wx.FD_OPEN)
3819
4084
  if dlg.ShowModal() == wx.ID_CANCEL:
3820
4085
  dlg.Destroy()
3821
4086
  return
@@ -3839,7 +4104,7 @@ class WolfMapViewer(wx.Frame):
3839
4104
  dlg.Destroy()
3840
4105
  return
3841
4106
 
3842
- self._walous_layer = dlg.GetStringSelection()
4107
+ self._walous_layer = 'UTS_' + dlg.GetStringSelection()
3843
4108
 
3844
4109
  locwalous = Walous_data(self._walous_UTS_filepath.parent, self._walous_UTS_filepath.name)
3845
4110
  ret = locwalous.rasterize(bounds=bounds,
@@ -3885,14 +4150,18 @@ class WolfMapViewer(wx.Frame):
3885
4150
  logging.warning(_('No active array -- Please activate data first'))
3886
4151
  return
3887
4152
 
4153
+ if self.active_array.wolftype != WOLF_ARRAY_FULL_SINGLE:
4154
+ logging.error(_('Active array is not a Float32 array -- Please change it to Float32 before mapping'))
4155
+ return
4156
+
3888
4157
  vals = self.active_array.get_unique_values()
3889
4158
 
3890
4159
  if self._walous_layer is None:
3891
4160
 
3892
4161
  if vals[0] > 10:
3893
- self._walous_layer = 'MAJ_NIV2'
4162
+ self._walous_layer = 'UTS_MAJ_NIV2'
3894
4163
  else:
3895
- self._walous_layer = 'MAJ_NIV1'
4164
+ self._walous_layer = 'UTS_MAJ_NIV1'
3896
4165
 
3897
4166
  dlg = DlgMapWalous2Manning(self, which=self._walous_layer)
3898
4167
 
@@ -5370,112 +5639,98 @@ class WolfMapViewer(wx.Frame):
5370
5639
  logging.error(_('Please install opencv-python'))
5371
5640
  return
5372
5641
 
5373
- if fn=='':
5374
- dlg = wx.FileDialog(parent = None,
5375
- message = _('Choose file name'),
5376
- wildcard = 'AVI video file (*.avi)|*.avi',
5377
- style = wx.FD_SAVE)
5378
- ret = dlg.ShowModal()
5379
- if ret == wx.ID_CANCEL:
5380
- dlg.Destroy()
5381
- return
5382
- fn = dlg.GetPath()
5383
- dlg.Destroy()
5384
-
5385
- if not fn.endswith('.avi'):
5386
- fn+='.avi'
5387
-
5388
- if framerate<1:
5389
- dlg = wx.NumberEntryDialog(None, _("Frame rate [nb_images/second]"), _('Frame rate'), _('Frame rate'), 24, 1, 100)
5390
-
5391
- ret = dlg.ShowModal()
5392
-
5393
- if ret == wx.ID_CANCEL:
5394
- dlg.Destroy()
5395
- return
5642
+ dlg = Sim_VideoCreation(None, title = _('Video creation'), sim= self.active_res2d, mapviewer=self)
5396
5643
 
5397
- framerate = int(dlg.GetValue())
5644
+ ret = dlg.ShowModal()
5645
+ if ret == wx.ID_CANCEL:
5398
5646
  dlg.Destroy()
5647
+ return
5399
5648
 
5649
+ fn, framerate, start_step, end_step, interval, fontsize, fontcolor, timeposition = dlg.get_values()
5650
+ dlg.Destroy()
5400
5651
 
5401
5652
  times,steps = self.active_res2d.get_times_steps()
5402
5653
 
5403
- el_time = str(timedelta(seconds=int(times[self.active_res2d.current_result])))
5404
-
5405
- fig:Figure
5406
- fig, ax = self.get_mpl_plot([self.mousex, self.mousey],
5407
- self.width,
5408
- self.height,
5409
- title=_('Current time {:0>8} s'.format(el_time)),
5410
- toshow=False)
5411
-
5412
- video = cv2.VideoWriter(fn, cv2.VideoWriter_fourcc(*'XVID'), framerate, fig.canvas.get_width_height())
5413
-
5414
- nb = self.active_res2d.get_nbresults()
5415
- cid = max(self.active_res2d.current_result,1)
5416
-
5417
- self.active_res2d.mypal.automatic=False
5418
-
5419
- if start_step==0:
5420
- dlg = wx.NumberEntryDialog(None, _("First step"), _('From'), _('from'), cid, 1, nb)
5421
-
5422
- ret = dlg.ShowModal()
5654
+ framesize = (int(self.canvaswidth), int(self.canvasheight))
5655
+ video = cv2.VideoWriter(fn, cv2.VideoWriter_fourcc(*'XVID'), framerate, framesize)
5423
5656
 
5424
- if ret == wx.ID_CANCEL:
5425
- dlg.Destroy()
5426
- return
5427
-
5428
- start_step = int(dlg.GetValue())
5429
- dlg.Destroy()
5430
-
5431
- if end_step==0:
5432
- dlg = wx.NumberEntryDialog(None, _("Final step"), _('To'), _('To'), nb, 1, nb)
5433
-
5434
- ret = dlg.ShowModal()
5435
-
5436
- if ret == wx.ID_CANCEL:
5437
- dlg.Destroy()
5438
- return
5439
-
5440
- end_step = int(dlg.GetValue())
5441
- dlg.Destroy()
5442
-
5443
- if every==0:
5444
- dlg = wx.NumberEntryDialog(None, _("Interval"), _('Interval'), _('Interval'), 1, 1, end_step-start_step)
5445
-
5446
- ret = dlg.ShowModal()
5447
-
5448
- if ret == wx.ID_CANCEL:
5449
- dlg.Destroy()
5450
- return
5657
+ el_time = str(timedelta(seconds=int(times[self.active_res2d.current_result])))
5451
5658
 
5452
- interval = int(dlg.GetValue())
5453
- dlg.Destroy()
5659
+ zones_time = Zones(mapviewer=self)
5660
+ self.add_object('vector', newobj=zones_time, ToCheck=True, id='__VideoTime__')
5661
+ zone_time = zone(name='Time')
5662
+ vec_time = vector(name='Time')
5663
+
5664
+ zones_time.add_zone(zone_time, forceparent=True)
5665
+ zone_time.add_vector(vec_time, forceparent=True)
5666
+
5667
+ if timeposition == 'top-center':
5668
+ x = (self.xmax+self.xmin)/2.
5669
+ y = self.ymax - 0.05*(self.ymax-self.ymin)
5670
+ elif timeposition == 'bottom-center':
5671
+ x = (self.xmax+self.xmin)/2.
5672
+ y = self.ymin + 0.05*(self.ymax-self.ymin)
5673
+ elif timeposition == 'top-left':
5674
+ x = self.xmin + 0.15*(self.xmax-self.xmin)
5675
+ y = self.ymax - 0.05*(self.ymax-self.ymin)
5676
+ elif timeposition == 'bottom-left':
5677
+ x = self.xmin + 0.15*(self.xmax-self.xmin)
5678
+ y = self.ymin + 0.05*(self.ymax-self.ymin)
5679
+ elif timeposition == 'top-right':
5680
+ x = self.xmax - 0.15*(self.xmax-self.xmin)
5681
+ y = self.ymax - 0.05*(self.ymax-self.ymin)
5682
+ elif timeposition == 'bottom-right':
5683
+ x = self.xmax - 0.15*(self.xmax-self.xmin)
5684
+ y = self.ymin + 0.05*(self.ymax-self.ymin)
5685
+ else:
5686
+ x = (self.xmax+self.xmin)/2.
5687
+ y = self.ymax - 0.05*(self.ymax-self.ymin)
5454
5688
 
5455
- self.read_one_result(start_step)
5689
+ vec_time.add_vertex(wolfvertex(x,y))
5690
+ vec_time.set_legend_position(x,y)
5691
+ vec_time.set_legend_text('Time {:0>8} s'.format(el_time))
5692
+ vec_time.set_legend_visible(True)
5693
+ vec_time.myprop.legendfontsize = fontsize
5694
+ vec_time.myprop.legendcolor = getIfromRGB(fontcolor)
5456
5695
 
5457
5696
  for curmodel in self.iterator_over_objects(draw_type.RES2D):
5458
5697
  curmodel: Wolfresults_2D
5459
5698
  curmodel.step_interval_results = interval
5460
5699
 
5461
- for idx in tqdm(range(start_step, end_step, interval)):
5700
+ all_steps = range(0, int((end_step-start_step) // interval) + 1)
5701
+
5702
+ pgbar = wx.ProgressDialog(_('Video creation'),
5703
+ _('Creating video...'),
5704
+ maximum = len(all_steps),
5705
+ parent = None,
5706
+ style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME)
5707
+ pgbar.Show()
5462
5708
 
5463
- image = Image.frombytes('RGB', fig.canvas.get_width_height(),fig.canvas.tostring_rgb())
5709
+ self.read_one_result(start_step-1)
5710
+ for idx in tqdm(all_steps, desc=_('Creating video')):
5711
+
5712
+ image = self.get_canvas_as_image()
5464
5713
 
5465
5714
  video.write(cv2.cvtColor(np.asarray(image),cv2.COLOR_RGB2BGR))
5466
5715
 
5467
5716
  self.simul_next_step()
5468
5717
 
5469
5718
  el_time = str(timedelta(seconds=int(times[self.active_res2d.current_result])))
5719
+ vec_time.set_legend_text('Time {:0>8} s'.format(el_time))
5720
+
5721
+ if not pgbar.WasCancelled():
5722
+ pgbar.Update(idx)
5723
+ else:
5724
+ break
5470
5725
 
5471
- self.display_canvasogl(fig=fig,
5472
- ax=ax[0],
5473
- title=_('Current time {:0>8} s'.format(el_time)))
5726
+ pgbar.Destroy()
5727
+ video.release()
5474
5728
 
5475
5729
  for curmodel in self.iterator_over_objects(draw_type.RES2D):
5476
5730
  curmodel: Wolfresults_2D
5477
5731
  curmodel.step_interval_results = 1
5478
5732
 
5733
+ self.removeobj_from_id('__VideoTime__')
5479
5734
 
5480
5735
  def get_canvas_as_image(self) -> Image.Image:
5481
5736
  """
@@ -5493,7 +5748,11 @@ class WolfMapViewer(wx.Frame):
5493
5748
 
5494
5749
  return myimage
5495
5750
 
5496
- def copy_canvasogl(self, mpl:bool= True, ds:float= 0., figsizes= [10.,10.], palette:wolfpalette = None):
5751
+ def copy_canvasogl(self,
5752
+ mpl:bool= True,
5753
+ ds:float= 0.,
5754
+ figsizes= [10.,10.],
5755
+ palette:wolfpalette = None):
5497
5756
  """
5498
5757
  Generate image based on UI context and copy to the Clipboard
5499
5758
 
@@ -5811,7 +6070,7 @@ class WolfMapViewer(wx.Frame):
5811
6070
  'Opengl setcurrent -- maybe a conflict with an existing opengl32.dll file - please rename the opengl32.dll in the libs directory and retry')
5812
6071
 
5813
6072
  def reporting(self, dir=''):
5814
- """ Firsdt attempr to create a reporting.
6073
+ """ First attempt to create a reporting.
5815
6074
  !! Must be improved !!
5816
6075
  """
5817
6076
  if dir == '':
@@ -6940,6 +7199,14 @@ class WolfMapViewer(wx.Frame):
6940
7199
 
6941
7200
  """
6942
7201
 
7202
+ msg = _('This function will force a null border of 1 cell on each array to avoid issues with the contouring algorithm')
7203
+ dlg = wx.MessageDialog(None, msg, _('Warning'), wx.OK | wx.CANCEL | wx.ICON_WARNING)
7204
+ result = dlg.ShowModal()
7205
+ dlg.Destroy()
7206
+ if result != wx.ID_OK:
7207
+ logging.info(_('Operation cancelled by user'))
7208
+ return None
7209
+
6943
7210
  # création de l'instance de Zones
6944
7211
  new_zones = Zones(idx = 'contour' if id is None else id.lower(), mapviewer=self)
6945
7212
 
@@ -6948,6 +7215,7 @@ class WolfMapViewer(wx.Frame):
6948
7215
  if isinstance(curarray, WolfArray):
6949
7216
 
6950
7217
  curarray.nullify_border(1)
7218
+ curarray.reset_plot()
6951
7219
 
6952
7220
  new_zone = zone(name = curarray.idx)
6953
7221
  new_zones.add_zone(new_zone, forceparent=True)
@@ -8295,6 +8563,9 @@ class WolfMapViewer(wx.Frame):
8295
8563
  def read_one_result(self, which:int):
8296
8564
  """
8297
8565
  Lecture d'un résultat spécific pour les modèles ajoutés et plottés
8566
+
8567
+ :param which: result index (0-based) -- -1 for last result
8568
+ 0 = first result
8298
8569
  """
8299
8570
  self.currently_readresults = True
8300
8571
 
@@ -9597,7 +9868,7 @@ class WolfMapViewer(wx.Frame):
9597
9868
  elif itemlabel == _("Add distances to viewer..."):
9598
9869
 
9599
9870
  if self._distances is not None:
9600
- self.add_object('vector', newobj=self._distances, ToCheck=True, id='Distances')
9871
+ self.add_object('vector', newobj=self._distances, ToCheck=True, id='Distances',)
9601
9872
 
9602
9873
  elif itemlabel == _("Create bridge and export gltf..."):
9603
9874
 
wolfhece/apps/version.py CHANGED
@@ -5,7 +5,7 @@ class WolfVersion():
5
5
 
6
6
  self.major = 2
7
7
  self.minor = 2
8
- self.patch = 40
8
+ self.patch = 42
9
9
 
10
10
  def __str__(self):
11
11