wolfhece 2.0.16__py3-none-any.whl → 2.0.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.
Files changed (39) hide show
  1. wolfhece/CpGrid.py +10 -13
  2. wolfhece/PyCrosssections.py +18 -13
  3. wolfhece/PyHydrographs.py +2 -2
  4. wolfhece/PyParams.py +15 -27
  5. wolfhece/PyPictures.py +48 -45
  6. wolfhece/PyVertexvectors.py +14 -19
  7. wolfhece/apps/curvedigitizer.py +4 -1
  8. wolfhece/apps/wolfcompare2Darrays.py +11 -7
  9. wolfhece/clientserver/clientserver.py +62 -0
  10. wolfhece/friction_law.py +39 -34
  11. wolfhece/ftp/downloader.py +8 -7
  12. wolfhece/gpuview.py +14 -13
  13. wolfhece/hydrology/Catchment.py +2 -2
  14. wolfhece/hydrology/PyWatershed.py +2 -2
  15. wolfhece/hydrology/SubBasin.py +13 -11
  16. wolfhece/hydrometry/kiwis_gui.py +9 -9
  17. wolfhece/irm_qdf.py +12 -10
  18. wolfhece/mar/Interface_MAR_WOLF_objet.py +260 -161
  19. wolfhece/opengl/py3d.py +231 -16
  20. wolfhece/pyshields.py +4 -4
  21. wolfhece/pythonfortran/example_makendarray.py +46 -41
  22. wolfhece/pythonfortran/example_numpy_memory.py +87 -83
  23. wolfhece/pythonfortran/tools.py +1 -1
  24. wolfhece/scenario/imposebc_void.py +2 -3
  25. wolfhece/scenario/update_void.py +6 -6
  26. wolfhece/wolf_array.py +17 -16
  27. wolfhece/wolfresults_2D.py +2 -4
  28. {wolfhece-2.0.16.dist-info → wolfhece-2.0.18.dist-info}/METADATA +7 -1
  29. {wolfhece-2.0.16.dist-info → wolfhece-2.0.18.dist-info}/RECORD +33 -38
  30. wolfhece/apps/wolfBernoulli.py +0 -18
  31. wolfhece/bernoulli/ModelJockgrim.py +0 -226
  32. wolfhece/bernoulli/NetworkOpenGL.py +0 -6461
  33. wolfhece/bernoulli/ReadNeupotzData.py +0 -223
  34. wolfhece/bernoulli/opti_results_interactive_plot.py +0 -212
  35. wolfhece/debug.py +0 -8
  36. /wolfhece/{bernoulli → clientserver}/__init__.py +0 -0
  37. {wolfhece-2.0.16.dist-info → wolfhece-2.0.18.dist-info}/WHEEL +0 -0
  38. {wolfhece-2.0.16.dist-info → wolfhece-2.0.18.dist-info}/entry_points.txt +0 -0
  39. {wolfhece-2.0.16.dist-info → wolfhece-2.0.18.dist-info}/top_level.txt +0 -0
wolfhece/opengl/py3d.py CHANGED
@@ -10,6 +10,7 @@ from enum import Enum
10
10
  import numpy as np
11
11
  from glm import lookAt, perspective, mat4, vec3, vec4, rotate, cross, dot, ortho, mat4x4, transpose, inverse, normalize, translate
12
12
 
13
+ from ..PyTranslate import _
13
14
  from ..textpillow import Font_Priority, Text_Image, Text_Infos
14
15
  from ..wolf_texture import Text_Image_Texture
15
16
 
@@ -424,7 +425,7 @@ class WolfArray_plot3D():
424
425
  reference for texture 2D : https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
425
426
 
426
427
  OPENGL
427
- ------
428
+
428
429
  The first element corresponds to the lower left corner of the texture image.
429
430
  Subsequent elements progress left-to-right through the remaining texels in the lowest row of the texture image,
430
431
  and then in successively higher rows of the texture image.
@@ -441,7 +442,7 @@ class WolfArray_plot3D():
441
442
  const void * data);
442
443
 
443
444
  NUMPY
444
- -----
445
+
445
446
  shape[0] is the number of rows and shape[1] is the number of columns.
446
447
 
447
448
  The "data" buffer is row-major order or column-major order, depending on the value of the order parameter.
@@ -455,7 +456,7 @@ class WolfArray_plot3D():
455
456
  - OpenGL Texture width = shape[0]
456
457
  - OpenGL Texture height = shape[1]
457
458
 
458
- ** ++ IMPORTANT **
459
+ ++ IMPORTANT
459
460
 
460
461
  We assume that if data is row-major order, the indexing [i,j] is (y, x) and if data is column-major order, the indexing is (x, y)
461
462
 
@@ -468,7 +469,7 @@ class WolfArray_plot3D():
468
469
  - Transposition is done by changing the indexing convention.
469
470
  - "texture" calls in shaders is the same for both row-major and column-major order.
470
471
 
471
- ** -- IMPORTANT **
472
+ -- IMPORTANT
472
473
  """
473
474
 
474
475
  def __init__(self,
@@ -596,7 +597,7 @@ class WolfArray_plot3D():
596
597
  if self.cache is None:
597
598
  return None
598
599
 
599
- return self.cache._sunposition
600
+ return self.cache.sunposition
600
601
 
601
602
  @sunposition.setter
602
603
  def sunposition(self, sunposition:vec3):
@@ -604,21 +605,21 @@ class WolfArray_plot3D():
604
605
  if self.cache is None:
605
606
  return
606
607
 
607
- self.cache._sunposition = sunposition
608
+ self.cache.sunposition = sunposition
608
609
 
609
610
  @property
610
611
  def sunintensity(self):
611
612
  if self.cache is None:
612
613
  return None
613
614
 
614
- return self.cache._sunintensity
615
+ return self.cache.sunintensity
615
616
 
616
617
  @sunintensity.setter
617
618
  def sunintensity(self, sunintensity:float):
618
619
  if self.cache is None:
619
620
  return
620
621
 
621
- self.cache._sunintensity = sunintensity
622
+ self.cache.sunintensity = sunintensity
622
623
 
623
624
  def Draw(self):
624
625
 
@@ -665,7 +666,11 @@ class CanvasOGL(glcanvas.GLCanvas):
665
666
  self.far = 10000
666
667
 
667
668
  self._sunintensity = 1.
668
- self._sunposition = vec3(1000., 1000., 1000.)
669
+ self._sunaltitude = 10000.
670
+ self._sun_x = 10000.
671
+ self._sun_y = 10000.
672
+ self._sun_idx = 0
673
+ # self._sunposition = vec3(1000., 1000., self._sunaltitude)
669
674
 
670
675
  self.grid = False
671
676
  self.drawposition = False
@@ -831,13 +836,42 @@ class CanvasOGL(glcanvas.GLCanvas):
831
836
 
832
837
  @property
833
838
  def sunposition(self):
834
- return self._sunposition
839
+ return vec3(self._sun_x, self._sun_y, self._sunaltitude)
835
840
 
836
841
  @sunposition.setter
837
842
  def sunposition(self, sunposition:vec3):
838
- self._sunposition = sunposition
843
+
844
+ self._sun_x, self._sun_y, self._sunaltitude = sunposition.x, sunposition.y, sunposition.z
845
+
839
846
  for curarray in self.arrays.values():
840
- curarray.sunposition = sunposition
847
+ curarray.sunposition = sunposition #self.mvp_glm * sunposition
848
+
849
+ @property
850
+ def sunaltitude(self):
851
+ return self._sunaltitude
852
+
853
+ @sunaltitude.setter
854
+ def sunaltitude(self, sunaltitude:float):
855
+ self._sunaltitude = sunaltitude
856
+ self.sunposition = vec3(self._sun_x, self._sun_y, sunaltitude)
857
+
858
+ @property
859
+ def sunx(self):
860
+ return self._sun_x
861
+
862
+ @sunx.setter
863
+ def sunx(self, sunx:float):
864
+ self._sun_x = sunx
865
+ self.sunposition = vec3(sunx, self._sun_y, self._sunaltitude)
866
+
867
+ @property
868
+ def suny(self):
869
+ return self._sun_y
870
+
871
+ @suny.setter
872
+ def suny(self, suny:float):
873
+ self._sun_y = suny
874
+ self.sunposition = vec3(self._sun_x, suny, self._sunaltitude)
841
875
 
842
876
  @property
843
877
  def sunintensity(self):
@@ -1006,7 +1040,7 @@ class CanvasOGL(glcanvas.GLCanvas):
1006
1040
  self.height_view = self.width_view / self.ratio_woverh
1007
1041
 
1008
1042
  else:
1009
- self.eye = self.center - self._direction() * (1.-self.zoom_speed) * factor
1043
+ self.eye = self.center - self._direction() * (1.-self.zoom_speed * factor)
1010
1044
 
1011
1045
  self.update_view()
1012
1046
 
@@ -1018,7 +1052,7 @@ class CanvasOGL(glcanvas.GLCanvas):
1018
1052
  self.height_view = self.width_view / self.ratio_woverh
1019
1053
 
1020
1054
  else:
1021
- self.eye = self.center - self._direction() * (1.+self.zoom_speed) * factor
1055
+ self.eye = self.center - self._direction() * (1.+self.zoom_speed * factor)
1022
1056
 
1023
1057
  self.update_view()
1024
1058
 
@@ -1145,14 +1179,15 @@ class CanvasOGL(glcanvas.GLCanvas):
1145
1179
  self.deltaWheel = event.GetWheelDelta()
1146
1180
 
1147
1181
  ctrldown = event.ControlDown()
1182
+ shiftdown = event.ShiftDown()
1148
1183
 
1149
1184
  if self.mouseWheel > 0:
1150
- if ctrldown:
1185
+ if shiftdown:
1151
1186
  self.closer(self.deltaWheel / 120 * 5)
1152
1187
  else:
1153
1188
  self.closer(self.deltaWheel / 120)
1154
1189
  elif self.mouseWheel < 0:
1155
- if ctrldown:
1190
+ if shiftdown:
1156
1191
  self.further_away(self.deltaWheel / 120 * 5)
1157
1192
  else:
1158
1193
  self.further_away(self.deltaWheel / 120)
@@ -1288,6 +1323,98 @@ class CanvasOGL(glcanvas.GLCanvas):
1288
1323
 
1289
1324
  self.update_view()
1290
1325
 
1326
+ def copy_to_clipboard(self):
1327
+ """ Copy the image to the clipboard """
1328
+ self.SetCurrent(self.context)
1329
+ pixels = glReadPixels(0, 0, self.width, self.height, GL_RGB, GL_UNSIGNED_BYTE)
1330
+ image = wx.Image(self.width, self.height, pixels)
1331
+ with wx.TheClipboard as clipboard:
1332
+ clipboard.Open()
1333
+ clipboard.SetData(wx.BitmapDataObject(wx.Bitmap(image)))
1334
+ clipboard.Close()
1335
+
1336
+ def save_to_file(self):
1337
+ """ Save the image to a file """
1338
+ with wx.FileDialog(self, _("Save file"), wildcard="PNG files (*.png)|*.png",
1339
+ style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
1340
+ if fileDialog.ShowModal() == wx.ID_CANCEL:
1341
+ return
1342
+ pathname = fileDialog.GetPath()
1343
+ self.SetCurrent(self.context)
1344
+ pixels = glReadPixels(0, 0, self.width, self.height, GL_RGB, GL_UNSIGNED_BYTE)
1345
+ image = wx.Image(self.width, self.height, pixels)
1346
+ image.SaveFile(pathname, wx.BITMAP_TYPE_PNG)
1347
+
1348
+ def print_shortcuts(self) -> str:
1349
+ """ Print shortcuts """
1350
+
1351
+ shortcuts = _("Definitions:\n")
1352
+ shortcuts += "------------\n\n"
1353
+ shortcuts = _("Camera is the eye position\n")
1354
+ shortcuts += _("Center is the center of the view\n")
1355
+ shortcuts += _("Direction is the vector from the eye to the center\n")
1356
+ shortcuts += _("Up is the up vector, perpendicular to the direction\n")
1357
+ shortcuts += _("Right is the vector normal to the direction-up plan\n\n")
1358
+
1359
+ shortcuts += _("Clicks\n")
1360
+ shortcuts += "-------\n\n"
1361
+ shortcuts += _("Left click and drag: translate the view in the up-right plane\n")
1362
+ shortcuts += _("Right click: display the position of the mouse -- to improve\n")
1363
+ shortcuts += "\n\n"
1364
+ shortcuts += _("Zoom\n")
1365
+ shortcuts += "----\n"
1366
+ shortcuts += "\n\n"
1367
+ shortcuts += _("0 or Home: autoscale\n")
1368
+ shortcuts += _("Mouse wheel: zoom in/out (eye closer or further from the center)\n")
1369
+ shortcuts += _("Shift + mouse wheel: zoom in/out faster\n")
1370
+ shortcuts += _("+ or - or mouse wheel: zoom in/out\n")
1371
+ shortcuts += "\n\n"
1372
+ shortcuts += _("Translation\n")
1373
+ shortcuts += "-----------\n"
1374
+ shortcuts += "\n\n"
1375
+ shortcuts += _("Arrow keys: move the view\n")
1376
+ shortcuts += _("Shift + arrow keys: move the view 0\n")
1377
+ shortcuts += _("Page up/Page down: move the view along eye-center direction\n")
1378
+ shortcuts += "\n\n"
1379
+ shortcuts += _("Rotation\n")
1380
+ shortcuts += "-----------\n"
1381
+ shortcuts += "\n\n"
1382
+ shortcuts += _("Ctrl + arrow keys: rotate the view around eye\n")
1383
+ shortcuts += _("Alt + arrow keys: rotate the view around center\n")
1384
+ shortcuts += "\n\n"
1385
+ shortcuts += _("Projection/Orthographic\n")
1386
+ shortcuts += "-----------------------\n"
1387
+ shortcuts += "\n\n"
1388
+ shortcuts += _("Space: switch between perspective and orthographic view\n")
1389
+ shortcuts += "\n\n"
1390
+ shortcuts += _("Sun\n")
1391
+ shortcuts += "----\n"
1392
+ shortcuts += "\n\n"
1393
+ shortcuts += _("Ctrl+F1: sun position North-West\n")
1394
+ shortcuts += _("Ctrl+F2: sun position South-West\n")
1395
+ shortcuts += _("Ctrl+F3: sun position South-East\n")
1396
+ shortcuts += _("Ctrl+F4: sun position North-East\n")
1397
+ shortcuts += _("Ctrl+F5: decrease sun intensity\n")
1398
+ shortcuts += _("Ctrl+F6: increase sun intensity\n")
1399
+ shortcuts += _("Ctrl+F7: decrease sun altitude\n")
1400
+ shortcuts += _("Ctrl+F8: increase sun altitude\n")
1401
+ shortcuts += _("Ctrl+F9: iterate on precalculated sun positions (0->8)\n")
1402
+
1403
+ shortcuts += "\n\n"
1404
+ shortcuts += _("Miscellaneous (experimental)\n")
1405
+ shortcuts += "----------------------------\n"
1406
+ shortcuts += "\n\n"
1407
+ shortcuts += _("G: display/hide the grid\n")
1408
+ shortcuts += _("X: display/hide the x plane\n")
1409
+ shortcuts += _("Y: display/hide the y plane\n")
1410
+ shortcuts += _("Z: display/hide the z plane\n")
1411
+ shortcuts += _("C: display/hide the xy plane\n")
1412
+ shortcuts += _("V: display/hide the yz plane\n")
1413
+ shortcuts += _("B: display/hide the xz plane\n")
1414
+ shortcuts += _("H: display the shortcuts\n")
1415
+
1416
+ return shortcuts
1417
+
1291
1418
  def OnKeyDown(self, event):
1292
1419
  """ Called when a key is pressed."""
1293
1420
 
@@ -1310,6 +1437,86 @@ class CanvasOGL(glcanvas.GLCanvas):
1310
1437
  elif keycode == wx.WXK_DOWN:
1311
1438
  self.rotate_right_eye(-self.rotation_speed)
1312
1439
 
1440
+ elif keycode == ord('C'):
1441
+ # copy image to clipboard
1442
+ self.copy_to_clipboard()
1443
+
1444
+ elif keycode == ord('S'):
1445
+ # save image to file
1446
+ self.save_to_file()
1447
+
1448
+ elif keycode == wx.WXK_F9:
1449
+ # rotate sunposition
1450
+ if self._sun_idx == 0:
1451
+ self.sunposition = vec3(0., 0., self.sunaltitude) #+ self.center
1452
+ self._sun_idx +=1
1453
+ elif self._sun_idx == 1:
1454
+ self.sunposition = vec3(-10000., 0., self.sunaltitude)
1455
+ self._sun_idx +=1
1456
+ elif self._sun_idx == 2:
1457
+ self.sunposition = vec3(-10000., -10000, self.sunaltitude)
1458
+ self._sun_idx +=1
1459
+ elif self._sun_idx == 3:
1460
+ self.sunposition = vec3(0., -10000, self.sunaltitude)
1461
+ self._sun_idx +=1
1462
+ elif self._sun_idx == 4:
1463
+ self.sunposition = vec3(10000., -10000, self.sunaltitude)
1464
+ self._sun_idx +=1
1465
+ elif self._sun_idx == 5:
1466
+ self.sunposition = vec3(10000., 0., self.sunaltitude)
1467
+ self._sun_idx +=1
1468
+ elif self._sun_idx == 6:
1469
+ self.sunposition = vec3(10000., 10000, self.sunaltitude)
1470
+ self._sun_idx +=1
1471
+ elif self._sun_idx == 7:
1472
+ self.sunposition = vec3(0., 10000, self.sunaltitude)
1473
+ self._sun_idx +=1
1474
+ elif self._sun_idx == 8:
1475
+ self.sunposition = vec3(-10000., 10000, self.sunaltitude)
1476
+ self._sun_idx = 0
1477
+
1478
+ logging.info('sun position: {}'.format(self.sunposition))
1479
+
1480
+ elif keycode == wx.WXK_F1:
1481
+ # sun position North-West
1482
+ self.sunposition = vec3(-10000., 10000., self.sunaltitude)
1483
+ logging.info(_('sun position: North-West'))
1484
+
1485
+ elif keycode == wx.WXK_F2:
1486
+ # sun position South-West
1487
+ self.sunposition = vec3(-10000., -10000., self.sunaltitude)
1488
+ logging.info(_('sun position: South-West'))
1489
+
1490
+ elif keycode == wx.WXK_F3:
1491
+ # sun position South-East
1492
+ self.sunposition = vec3(10000., -10000., self.sunaltitude)
1493
+ logging.info(_('sun position: South-East'))
1494
+
1495
+ elif keycode == wx.WXK_F4:
1496
+ # sun position North-East
1497
+ self.sunposition = vec3(10000., 10000., self.sunaltitude)
1498
+ logging.info(_('sun position: North-East'))
1499
+
1500
+ elif keycode == wx.WXK_F5:
1501
+ # sun intensity increase
1502
+ self.sunintensity /= 1.1
1503
+ logging.info(_('sun intensity: {}'.format(self.sunintensity)))
1504
+
1505
+ elif keycode == wx.WXK_F6:
1506
+ # sun intensity decrease
1507
+ self.sunintensity *= 1.1
1508
+ logging.info(_('sun intensity: {}'.format(self.sunintensity)))
1509
+
1510
+ elif keycode == wx.WXK_F8:
1511
+ # sun altitude increase
1512
+ self.sunaltitude += 100.
1513
+ logging.info(_('sun altitude: {}'.format(self.sunaltitude)))
1514
+
1515
+ elif keycode == wx.WXK_F7:
1516
+ # sun altitude decrease
1517
+ self.sunaltitude -= 100.
1518
+ logging.info(_('sun altitude: {}'.format(self.sunaltitude)))
1519
+
1313
1520
  elif altdown:
1314
1521
  if keycode == wx.WXK_LEFT:
1315
1522
  self.rotate_z_center(-self.rotation_speed)
@@ -1429,6 +1636,14 @@ class CanvasOGL(glcanvas.GLCanvas):
1429
1636
  self.xy_plane = False
1430
1637
  self.yz_plane = False
1431
1638
 
1639
+ elif keycode == ord('H'):
1640
+ frmshortcuts = wx.Frame(self, -1, "Shortcuts", size=(400, 800))
1641
+ panel = wx.Panel(frmshortcuts, -1)
1642
+ st = wx.StaticText(panel, -1, self.print_shortcuts(), (10, 10))
1643
+ frmshortcuts.Show()
1644
+ logging.info(self.print_shortcuts())
1645
+
1646
+
1432
1647
  self.update_view()
1433
1648
 
1434
1649
  self.Refresh()
wolfhece/pyshields.py CHANGED
@@ -303,7 +303,7 @@ def _get_Rouse(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=R
303
303
  elif frac==100:
304
304
  return rouse-1.2
305
305
 
306
- def get_transport_mode(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER) -> BED_LOAD | SUSPENDED_LOAD_50 | SUSPENDED_LOAD_100 | WASH_LOAD:
306
+ def get_transport_mode(d:float, q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUREWATER): # -> BED_LOAD | SUSPENDED_LOAD_50 | SUSPENDED_LOAD_100 | WASH_LOAD:
307
307
  """
308
308
  Transport mode
309
309
 
@@ -350,7 +350,7 @@ def get_d_cr_susp(q:float, h:float, K:float, rhom:float=2650., rho:float=RHO_PUR
350
350
  except:
351
351
  return 0.
352
352
 
353
- def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> [plt.Figure,plt.Axes]:
353
+ def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> tuple[plt.Figure,plt.Axes]:
354
354
  """ Plot Shields diagram with sadim"""
355
355
 
356
356
  smax = 1000
@@ -406,7 +406,7 @@ def shieldsdia_sadim(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWAT
406
406
 
407
407
  return fig,ax
408
408
 
409
- def shieldsdia_dstar(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> [plt.Figure,plt.Axes]:
409
+ def shieldsdia_dstar(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWATER, figax=None) -> tuple[plt.Figure,plt.Axes]:
410
410
  """ Plot Shields diagram with dstar"""
411
411
 
412
412
  smax = 1000
@@ -465,7 +465,7 @@ def shieldsdia_dstar(s_psicr=None, dstar_psicr=None, rhom=2650., rho=RHO_PUREWAT
465
465
 
466
466
  return fig,ax
467
467
 
468
- def shieldsdia_dim(figax=None) -> [plt.Figure,plt.Axes]:
468
+ def shieldsdia_dim(figax=None) -> tuple[plt.Figure,plt.Axes]:
469
469
  """ Plot Shields diagram with dimensional values"""
470
470
 
471
471
  smax=1e6
@@ -2,60 +2,65 @@ import numpy as np
2
2
  import ctypes as ct
3
3
  from tools import make_nd_array
4
4
 
5
- """
6
- Création d'un matrice numpy depui un buffer/adresse mémoire
7
- """
8
5
 
9
- a = np.zeros((10,10))
6
+ def main():
7
+ """
8
+ Création d'un matrice numpy depui un buffer/adresse mémoire
9
+ """
10
10
 
11
- # a.ctypes.data => int, buffer's memory address
12
- # see : https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ctypes.html
13
- q = make_nd_array(a.ctypes.data, a.shape)
11
+ a = np.zeros((10,10))
14
12
 
15
- # récupération de la structure ct.pointer pointant vers l'espace de stockage de l'objet numpy "a"'
16
- p = a.ctypes.data_as(ct.POINTER(ct.c_double))
17
- # récupération de l'adresse mémoire dans la structure ctypes.pointer
18
- addr_p = list(p.contents._b_base_._objects.values())[0].value
19
- # mais il y a plus simple ...
20
- addr_p_2 = ct.addressof(p.contents)
13
+ # a.ctypes.data => int, buffer's memory address
14
+ # see : https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ctypes.html
15
+ q = make_nd_array(a.ctypes.data, a.shape)
21
16
 
22
- assert addr_p == addr_p_2
17
+ # récupération de la structure ct.pointer pointant vers l'espace de stockage de l'objet numpy "a"'
18
+ p = a.ctypes.data_as(ct.POINTER(ct.c_double))
19
+ # récupération de l'adresse mémoire dans la structure ctypes.pointer
20
+ addr_p = list(p.contents._b_base_._objects.values())[0].value
21
+ # mais il y a plus simple ...
22
+ addr_p_2 = ct.addressof(p.contents)
23
23
 
24
- # comparaison avec l'adresse mémoire du buffer de a
25
- print(addr_p, a.ctypes.data)
26
- assert a.ctypes.data == addr_p, 'Not the same address'
24
+ assert addr_p == addr_p_2
27
25
 
28
- c=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=False, readonly=False, order='F')
29
- d=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=False, order='F')
26
+ # comparaison avec l'adresse mémoire du buffer de a
27
+ print(addr_p, a.ctypes.data)
28
+ assert a.ctypes.data == addr_p, 'Not the same address'
30
29
 
31
- e=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=False, readonly=True, order='F')
32
- f=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=True, order='F')
33
- g=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=False, order='F')
30
+ c=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=False, readonly=False, order='F')
31
+ d=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=False, order='F')
34
32
 
35
- assert c.ctypes.data == a.ctypes.data, 'Not the same address'
36
- assert d.ctypes.data != a.ctypes.data, 'Same address'
33
+ e=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=False, readonly=True, order='F')
34
+ f=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=True, order='F')
35
+ g=make_nd_array(addr_p, [10,10], dtype=np.float64, own_data=True , readonly=False, order='F')
37
36
 
38
- assert e.flags.writeable == False, 'Array "e" is in read/write mode'
39
- assert f.flags.writeable == False, 'Array "f" is in read/write mode'
40
- assert g.flags.writeable == True, 'Array "g" is in read only mode'
37
+ assert c.ctypes.data == a.ctypes.data, 'Not the same address'
38
+ assert d.ctypes.data != a.ctypes.data, 'Same address'
41
39
 
40
+ assert e.flags.writeable == False, 'Array "e" is in read/write mode'
41
+ assert f.flags.writeable == False, 'Array "f" is in read/write mode'
42
+ assert g.flags.writeable == True, 'Array "g" is in read only mode'
42
43
 
43
- # Initialisation d'une Numpy array as 'C' order or 'F' order
44
- a = np.zeros((10,10), dtype=np.float64, order='C') # default order == 'C'
45
- a[:,1:]=3.
46
44
 
47
- h=make_nd_array(a.ctypes.data, [10,1], dtype=np.float64, own_data=True , readonly=False, order='F') # première ligne
48
- # h = [0,3,3,3,3,3,3,3,3,3,3]
45
+ # Initialisation d'une Numpy array as 'C' order or 'F' order
46
+ a = np.zeros((10,10), dtype=np.float64, order='C') # default order == 'C'
47
+ a[:,1:]=3.
49
48
 
50
- assert h.shape==(10,1)
51
- assert (h == np.asarray([[0.],[3.],[3.],[3.],[3.],[3.],[3.],[3.],[3.],[3.]])).all()
49
+ h=make_nd_array(a.ctypes.data, [10,1], dtype=np.float64, own_data=True , readonly=False, order='F') # première ligne
50
+ # h = [0,3,3,3,3,3,3,3,3,3,3]
52
51
 
53
- a = np.zeros((10,10), dtype=np.float64, order='F')
54
- a[:,1:]=3.
52
+ assert h.shape==(10,1)
53
+ assert (h == np.asarray([[0.],[3.],[3.],[3.],[3.],[3.],[3.],[3.],[3.],[3.]])).all()
55
54
 
56
- i=make_nd_array(a.ctypes.data, [10,1], dtype=np.float64, own_data=True , readonly=False, order='F') # première colonne
57
- # i = [0,0,0,0,0,0,0,0,0,0]
55
+ a = np.zeros((10,10), dtype=np.float64, order='F')
56
+ a[:,1:]=3.
58
57
 
59
- assert i.shape==(10,1)
60
- assert (i == np.asarray([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])).all()
61
- assert (i == np.asarray([[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.]])).all()
58
+ i=make_nd_array(a.ctypes.data, [10,1], dtype=np.float64, own_data=True , readonly=False, order='F') # première colonne
59
+ # i = [0,0,0,0,0,0,0,0,0,0]
60
+
61
+ assert i.shape==(10,1)
62
+ assert (i == np.asarray([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])).all()
63
+ assert (i == np.asarray([[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.],[0.]])).all()
64
+
65
+ if __name__ == '__main__':
66
+ main()