Interaction WolfArray/vectors - Transfer Z data
It is easy to transfer Z data from a WolfArray to a vector.
‘z’ is a property of the vector, so it can be set directly.
The setter vector.z = wolfarray_instance
will transfer the Z data from the WolfArray to the vector. Thre vector will convert its vertices coordinates to the WolfArray’s coordinate system and extract the corresponding values.
[1]:
# import _add_path # for debugging purposes only - can be removed in production
from wolfhece import is_enough, __version__
assert is_enough("2.2.7"), "Please update wolfhece to 2.2.7 or later - you have " + __version__
from wolfhece.wolf_array import WolfArray, header_wolf
from wolfhece.PyVertexvectors import Zones, zone, vector
import numpy as np
from packaging import version
Creation of an array
Create a header
Set shape and resolution
Create an array from the header
[2]:
h = header_wolf()
h.shape = (100, 100)
h.set_resolution(1., 1.)
a = WolfArray(srcheader=h)
a.array = np.random.rand(h.shape[0], h.shape[1]) * 10.0 # Random values between 0 and 10
Creation of a vector
Create a vector and add vertices from Numpy array
Split the vector with a given distance (1 meter) and replace it
[3]:
v = vector(fromnumpy= np.asarray([[5.,5.],
[10.,5.],
[10.,20.],
[15.,30.],
[5., 45.]]))
v.split(1., new = False) # Split the vector into segments of 1 unit length
Copy the values from the array to the vector
See vector “z.setter” for more information.
[4]:
v.z = a # Transfer the Z values from the array to the vector -- The vector will retrieve the values from the array based on the vertices' coordinates
[5]:
print(v.z) # This will print the Z values of the vector, which are now linked to the array values
[6.17796835 3.78758632 1.54473996 1.54473996 2.24521166 5.31537719
5.31537719 7.26549213 7.26549213 3.30763981 3.08678037 3.08678037
4.82598289 4.82598289 3.90230366 3.90230366 8.76591086 8.57796737
4.24841736 4.24841736 2.65791145 2.65791145 0.2473708 3.67111596
9.73361847 4.08649935 2.01570756 1.57680202 4.57863609 7.79916745
7.79916745 4.01318474 3.98424547 7.98752954 3.23897928 6.01450406
2.21527156 0.27510984 3.34785821 2.83141191 9.95544353 8.46809499
5.79207877 1.48870911 1.48870911 8.44722858 5.26646236 9.541056
1.72990087 3.68136678 4.97815591 8.97383011]
Other vector’s properties
Other properties of the vector exist, such as :
vector.x
: the X coordinates of the verticesvector.y
: the Y coordinates of the verticesvector.z
: the Z coordinates of the verticesvector.xy
: the XY coordinates of the verticesvector.xyz
: the XYZ coordinates of the verticesvector.s_curvi
: the curvilinear abscissa of the verticesvector.sz_curvi
: the curvilinear abscissa of the vertices associated with the Z valuesvector.xyi
: the XY coordinates of the vertices asscociated with an integer indicating if the segment is used (1) or not (0)
[ ]:
print('X-coordinates : ', v.x) # X coordinates
print('Y-coordinates : ', v.y) # Y coordinates
print('XY-coordinates : ', v.xy) # XY coordinates
print('XZ-coordinates : ', v.xz) # XZ coordinates
print('XYZ-coordinates : ', v.xyz) # XYZ coordinates
print('SZ-coordinates : ', v.sz_curvi) # Curvilinear coordinates with Z values
print('S-coordinates : ', v.s_curvi) # Curvilinear coordinates
print('XY-coordinates and 1 if visible (0 otherwise) :', v.xyi) # XY coordinates and segment's visibility indicator
print('XYZ-coordinates and 1 if visible (0 otherwise) :', v.xyzi) # XYZ coordinates and segment's visibility indicator
print('1 if visible (0 otherwise) for each segment :', v.i) # segment's visibility indicator
X-coordinates : [ 5. 6. 7. 8. 9. 10.
10. 10. 10. 10. 10. 10.
10. 10. 10. 10. 10. 10.
10. 10. 10. 10.4472136 10.89442719 11.34164079
11.78885438 12.23606798 12.68328157 13.13049517 13.57770876 14.02492236
14.47213595 14.91934955 15. 14.54533437 13.99063418 13.43593398
12.88123379 12.32653359 11.77183339 11.2171332 10.662433 10.1077328
9.55303261 8.99833241 8.44363222 7.88893202 7.33423182 6.77953163
6.22483143 5.67013124 5.11543104 5. ]
Y-coordinates : [ 5. 5. 5. 5. 5. 5.
6. 7. 8. 9. 10. 11.
12. 13. 14. 15. 16. 17.
18. 19. 20. 20.89442719 21.78885438 22.68328157
23.57770876 24.47213595 25.36656315 26.26099034 27.15541753 28.04984472
28.94427191 29.8386991 30. 30.68199844 31.51404873 32.34609903
33.17814932 34.01019962 34.84224991 35.6743002 36.5063505 37.33840079
38.17045109 39.00250138 39.83455168 40.66660197 41.49865226 42.33070256
43.16275285 43.99480315 44.82685344 45. ]
XY-coordinates : [[ 5. 5. ]
[ 6. 5. ]
[ 7. 5. ]
[ 8. 5. ]
[ 9. 5. ]
[10. 5. ]
[10. 6. ]
[10. 7. ]
[10. 8. ]
[10. 9. ]
[10. 10. ]
[10. 11. ]
[10. 12. ]
[10. 13. ]
[10. 14. ]
[10. 15. ]
[10. 16. ]
[10. 17. ]
[10. 18. ]
[10. 19. ]
[10. 20. ]
[10.4472136 20.89442719]
[10.89442719 21.78885438]
[11.34164079 22.68328157]
[11.78885438 23.57770876]
[12.23606798 24.47213595]
[12.68328157 25.36656315]
[13.13049517 26.26099034]
[13.57770876 27.15541753]
[14.02492236 28.04984472]
[14.47213595 28.94427191]
[14.91934955 29.8386991 ]
[15. 30. ]
[14.54533437 30.68199844]
[13.99063418 31.51404873]
[13.43593398 32.34609903]
[12.88123379 33.17814932]
[12.32653359 34.01019962]
[11.77183339 34.84224991]
[11.2171332 35.6743002 ]
[10.662433 36.5063505 ]
[10.1077328 37.33840079]
[ 9.55303261 38.17045109]
[ 8.99833241 39.00250138]
[ 8.44363222 39.83455168]
[ 7.88893202 40.66660197]
[ 7.33423182 41.49865226]
[ 6.77953163 42.33070256]
[ 6.22483143 43.16275285]
[ 5.67013124 43.99480315]
[ 5.11543104 44.82685344]
[ 5. 45. ]]
XYZ-coordinates : [[ 5. 5. 6.17796835]
[ 6. 5. 3.78758632]
[ 7. 5. 1.54473996]
[ 8. 5. 1.54473996]
[ 9. 5. 2.24521166]
[10. 5. 5.31537719]
[10. 6. 5.31537719]
[10. 7. 7.26549213]
[10. 8. 7.26549213]
[10. 9. 3.30763981]
[10. 10. 3.08678037]
[10. 11. 3.08678037]
[10. 12. 4.82598289]
[10. 13. 4.82598289]
[10. 14. 3.90230366]
[10. 15. 3.90230366]
[10. 16. 8.76591086]
[10. 17. 8.57796737]
[10. 18. 4.24841736]
[10. 19. 4.24841736]
[10. 20. 2.65791145]
[10.4472136 20.89442719 2.65791145]
[10.89442719 21.78885438 0.2473708 ]
[11.34164079 22.68328157 3.67111596]
[11.78885438 23.57770876 9.73361847]
[12.23606798 24.47213595 4.08649935]
[12.68328157 25.36656315 2.01570756]
[13.13049517 26.26099034 1.57680202]
[13.57770876 27.15541753 4.57863609]
[14.02492236 28.04984472 7.79916745]
[14.47213595 28.94427191 7.79916745]
[14.91934955 29.8386991 4.01318474]
[15. 30. 3.98424547]
[14.54533437 30.68199844 7.98752954]
[13.99063418 31.51404873 3.23897928]
[13.43593398 32.34609903 6.01450406]
[12.88123379 33.17814932 2.21527156]
[12.32653359 34.01019962 0.27510984]
[11.77183339 34.84224991 3.34785821]
[11.2171332 35.6743002 2.83141191]
[10.662433 36.5063505 9.95544353]
[10.1077328 37.33840079 8.46809499]
[ 9.55303261 38.17045109 5.79207877]
[ 8.99833241 39.00250138 1.48870911]
[ 8.44363222 39.83455168 1.48870911]
[ 7.88893202 40.66660197 8.44722858]
[ 7.33423182 41.49865226 5.26646236]
[ 6.77953163 42.33070256 9.541056 ]
[ 6.22483143 43.16275285 1.72990087]
[ 5.67013124 43.99480315 3.68136678]
[ 5.11543104 44.82685344 4.97815591]
[ 5. 45. 8.97383011]]
SZ-coordinates : (array([ 0. , 1. , 2. , 3. , 4. ,
5. , 6. , 7. , 8. , 9. ,
10. , 11. , 12. , 13. , 14. ,
15. , 16. , 17. , 18. , 19. ,
20. , 21. , 22. , 23. , 24. ,
25. , 26. , 27. , 28. , 29. ,
30. , 31. , 31.18033989, 32. , 33. ,
34. , 35. , 36. , 37. , 38. ,
39. , 40. , 41. , 42. , 43. ,
44. , 45. , 46. , 47. , 48. ,
49. , 49.20809626]), array([6.17796835, 3.78758632, 1.54473996, 1.54473996, 2.24521166,
5.31537719, 5.31537719, 7.26549213, 7.26549213, 3.30763981,
3.08678037, 3.08678037, 4.82598289, 4.82598289, 3.90230366,
3.90230366, 8.76591086, 8.57796737, 4.24841736, 4.24841736,
2.65791145, 2.65791145, 0.2473708 , 3.67111596, 9.73361847,
4.08649935, 2.01570756, 1.57680202, 4.57863609, 7.79916745,
7.79916745, 4.01318474, 3.98424547, 7.98752954, 3.23897928,
6.01450406, 2.21527156, 0.27510984, 3.34785821, 2.83141191,
9.95544353, 8.46809499, 5.79207877, 1.48870911, 1.48870911,
8.44722858, 5.26646236, 9.541056 , 1.72990087, 3.68136678,
4.97815591, 8.97383011]))
S-coordinates : [ 0. 1. 2. 3. 4. 5.
6. 7. 8. 9. 10. 11.
12. 13. 14. 15. 16. 17.
18. 19. 20. 21. 22. 23.
24. 25. 26. 27. 28. 29.
30. 31. 31.18033989 32. 33. 34.
35. 36. 37. 38. 39. 40.
41. 42. 43. 44. 45. 46.
47. 48. 49. 49.20809626]
XY-coordinates and 1 if visible (0 otherwise) : [[ 5. 5. 1. ]
[ 6. 5. 1. ]
[ 7. 5. 1. ]
[ 8. 5. 1. ]
[ 9. 5. 1. ]
[10. 5. 1. ]
[10. 6. 1. ]
[10. 7. 1. ]
[10. 8. 1. ]
[10. 9. 1. ]
[10. 10. 1. ]
[10. 11. 1. ]
[10. 12. 1. ]
[10. 13. 1. ]
[10. 14. 1. ]
[10. 15. 1. ]
[10. 16. 1. ]
[10. 17. 1. ]
[10. 18. 1. ]
[10. 19. 1. ]
[10. 20. 1. ]
[10.4472136 20.89442719 1. ]
[10.89442719 21.78885438 1. ]
[11.34164079 22.68328157 1. ]
[11.78885438 23.57770876 1. ]
[12.23606798 24.47213595 1. ]
[12.68328157 25.36656315 1. ]
[13.13049517 26.26099034 1. ]
[13.57770876 27.15541753 1. ]
[14.02492236 28.04984472 1. ]
[14.47213595 28.94427191 1. ]
[14.91934955 29.8386991 1. ]
[15. 30. 1. ]
[14.54533437 30.68199844 1. ]
[13.99063418 31.51404873 1. ]
[13.43593398 32.34609903 1. ]
[12.88123379 33.17814932 1. ]
[12.32653359 34.01019962 1. ]
[11.77183339 34.84224991 1. ]
[11.2171332 35.6743002 1. ]
[10.662433 36.5063505 1. ]
[10.1077328 37.33840079 1. ]
[ 9.55303261 38.17045109 1. ]
[ 8.99833241 39.00250138 1. ]
[ 8.44363222 39.83455168 1. ]
[ 7.88893202 40.66660197 1. ]
[ 7.33423182 41.49865226 1. ]
[ 6.77953163 42.33070256 1. ]
[ 6.22483143 43.16275285 1. ]
[ 5.67013124 43.99480315 1. ]
[ 5.11543104 44.82685344 1. ]
[ 5. 45. 1. ]]
[ ]:
# Pour savoir si un setter est défini pour une propriété d'un objet Python,
# on peut utiliser la fonction built-in `getattr` et vérifier l'attribut `fset` de la propriété.
def has_setter(obj, prop_name):
cls = obj.__class__
prop = getattr(cls, prop_name, None)
return isinstance(prop, property) and prop.fset is not None
# Exemple d'utilisation :
print(has_setter(v, 'z')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'x')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'y')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'xy')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'xz')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'xyz')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 's_curvi')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
print(has_setter(v, 'sz_curvi')) # Affiche True si un setter est défini pour la propriété 'z' de l'objet v
True
True
True
True
True
False
True