wolfhece.PyVertex

Author: HECE - University of Liege, Pierre Archambeau Date: 2024

Copyright (c) 2024 University of Liege. All rights reserved.

This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.

Module Contents

wolfhece.PyVertex.msg[source]
wolfhece.PyVertex.getRGBfromI(rgbint: int)[source]

Convert integer to RGB

wolfhece.PyVertex.getIfromRGB(rgb: list | tuple)[source]

Convert RGB to integer

wolfhece.PyVertex.circle(x: float, y: float, r: float, numseg: int = 20)[source]
wolfhece.PyVertex.cross(x: float, y: float, r: float)[source]
wolfhece.PyVertex.quad(x: float, y: float, r: float)[source]
class wolfhece.PyVertex.Cloud_Styles(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.PyVertex.Cloud_Styles

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

POINT = 0[source]
CIRCLE = 1[source]
CROSS = 2[source]
QUAD = 3[source]
class wolfhece.PyVertex.wolfvertex(x: float, y: float, z: float = -99999.0)[source]

Vertex WOLF - 3 coordonnées + valeurs associées dans un dictionnaire

x: float[source]
y: float[source]
z: float[source]
values: dict = None[source]
in_use = True[source]
rotate(angle: float, center: tuple)[source]

Rotate the vertex

Parameters:
  • angle – angle in radians (positive for counterclockwise)

  • center – center of the rotation (x, y)

as_shapelypoint()[source]

Return a shapely Point

copy()[source]

Return a copy of the vertex

getcoords()[source]

Return the coordinates as a numpy array

dist3D(v: wolfvertex) float[source]

Return the 3D distance to another vertex

Parameters:

v – vertex to compare

dist2D(v: wolfvertex) float[source]

Return the 2D distance to another vertex

Parameters:

v – vertex to compare

addvalue(id, value)[source]

Add a value to the vertex

Parameters:
  • id – key of the value

  • value – value to add

add_value(id, value)[source]

Add a set of values to the vertex

Parameters:
  • id – key of the value

  • value – value to add

add_values(values: dict)[source]

Add a set of values to the vertex

Parameters:

values – dictionary of values to add

getvalue(id)[source]

Return a value from the vertex

Parameters:

id – key of the value

get_value(id)[source]

Return a set of values from the vertex

Parameters:

id – key of the value

get_values(ids: list) dict[source]

Return a set of values from the vertex

limit2bounds(bounds=None)[source]

Limit the vertex to a set of bounds

Parameters:

bounds – [[xmin, xmax], [ymin, ymax]] – floats

is_like(v: wolfvertex, tol: float = 1e-06)[source]

Return True if the vertex is close to another one

Parameters:
  • v – vertex to compare

  • tol – tolerance

class wolfhece.PyVertex.cloudproperties(lines=[], parent: cloud_vertices = None)[source]

Properties of a cloud of vertices

used: bool[source]
color: int[source]
width: int[source]
style: int[source]
alpha: int[source]
filled: bool[source]
legendvisible: bool[source]
transparent: bool[source]
flash: bool[source]
legendtext: str[source]
legendrelpos: int[source]
legendx: float[source]
legendy: float[source]
legendbold: bool[source]
legenditalic: bool[source]
legendunderlined: bool[source]
legendfontname[source]
legendfontsize: int[source]
legendcolor: int[source]
legendpriority: int[source]
legendorientation: int[source]
legendwidth: int[source]
legendheight: int[source]
extrude: bool = False[source]
myprops: wolfhece.PyParams.Wolf_Param = None[source]
parent = None[source]
fill_property()[source]
defaultprop()[source]

Default properties

destroyprop()[source]
show()[source]
class wolfhece.PyVertex.cloud_vertices(fname: str | pathlib.Path = '', fromxls: str = '', header: bool = False, toload=True, idx: str = '', plotted: bool = True, mapviewer=None, need_for_wx: bool = False, bbox: shapely.geometry.Polygon = None, dxf_imported_elts=['MTEXT', 'INSERT'])[source]

Bases: wolfhece.drawing_obj.Element_To_Draw

Inheritance diagram of wolfhece.PyVertex.cloud_vertices

Scatter points with associated values

Accepted formats : dxf, ascii

Ascii separator : tabulation ‘ ‘, semicolon ‘;’

‘dxf’ type is automatically finded based on file extension otherwise, ascii file is supposed.

If header exists in the first line of the file, you have to mention it by header=True in initialization.

Total number of columns (nb) is important :
  • if nb >3 : the file must contain a header

  • if header[2].lower() == ‘z’, the file contains XYZ coordinates, otherwise all columns >1 are interpreted as values associated to XY

Number os values = nb - (2 or 3) depending if Z coordinate exists

Data are stored in Python dictionnary :
  • ‘vertex’ : XY or XYZ

Each value is accessible through its headname as key :
  • ‘headname1’ : value with headname1

  • ‘headname2’ : value with headname2

  • ‘headnamen’ : value with headnamen

For more information, see ‘readfile’ or ‘import_from_dxf’

filename: str[source]
myvertices: dict[int, dict['vertex':wolfvertex, str:float]][source]
xbounds: tuple[source]
ybounds: tuple[source]
zbounds: tuple[source]
myprop: cloudproperties[source]
mytree: scipy.spatial.KDTree[source]
loaded = False[source]
_header = False[source]
gllist = 0[source]
forceupdategl = False[source]
ongoing = False[source]
create_kdtree()[source]

Set a Scipy KDTree structure based on a copy of the vertices

find_nearest(xyz: numpy.ndarray | list, nb: int = 1)[source]

Find nearest neighbors from Scipy KDTree structure based on a copy of the vertices.

See : https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.KDTree.query.html

Parameters:
  • xyz – coordinates to find nearest neighbors – shape (n, m) - where m is the number of coordinates (2 or 3)

  • nb – number of nearest neighbors to find

Returns:

list of distances, list of “Wolfvertex”, list of elements stored in self.myvertices - or list of lists if xyz is a list of coordinates

init_from_nparray(array: numpy.ndarray)[source]

Fill-in from nparray – shape (n,3)

check_plot()[source]

The cloud is plotted – useful for mapviewer

uncheck_plot(unload=True)[source]

The cloud is not plotted – useful for mapviewer

readfile(fname: str = '', header: bool = False)[source]

Reading an ascii file with or without header

Parameters:
  • fname – (str) file name

  • header – (bool) header in file (first line with column names)

The separator is automatically detected among : tabulation, semicolon, space, comma.

The file must contain at least 2 columns (X, Y) and may contain a third one (Z) and more (values). If values are present, they are stored in the dictionnary with their header name as key.

import_from_dxf(fn: str = '', imported_elts=['MTEXT', 'INSERT'])[source]

Importing DXF file using ezdxf library

Parameters:

fn – file name (*.dxf)

import_from_shapefile(fn: str = '', targetcolumn: str = 'X1_Y1_Z1', bbox: shapely.geometry.Polygon = None)[source]

Importing Shapefile using geopandas library

Parameters:
  • fn – file name

  • targetcolumn – column name to be used for XYZ coordinates – ‘X1_Y1_Z1’ is used by SPW-ARNE-DCENN

add_vertex(vertextoadd: wolfvertex = None, id=None, cloud: dict = None)[source]

Add a vertex to the cloud

Parameters:
  • vertextoadd – vertex to add

  • id – id of the vertex – if None, the id is the length of the cloud

  • cloud – cloud of vertices to add – wolfvertex instances are pointed not copied

add_vertices(vertices: list[wolfvertex])[source]

Add a list of vertices to the cloud

get_vertices()[source]

Return the vertices as a list

plot_legend(sx=None, sy=None, xmin=None, ymin=None, xmax=None, ymax=None, size=None)[source]

Plot OpenGL

Legend is an image texture

FIXME : to be improved

plot(update: bool = False, *args, **kwargs)[source]

OpenGL plot of the cloud of vertices

FIXME : to be improved

show_properties()[source]

Show properties of the cloud

_updatebounds(newvert: wolfvertex = None, newcloud: dict = None)[source]

Update the bounds of the cloud

:param newvert : (optional) vertex added to the cloud :param newcloud: (optional) cloud added to the cloud

‘newvert’ or ‘newcloud’ can be passed as argument during add_vertex operation. In this way, the bounds are updated without going through all the vertices -> expected more rapid.

find_minmax(force=False)[source]

Find the bounds of the cloud

Parameters:

force – force the computation of the bounds

get_xyz(key='vertex') numpy.ndarray[source]

Return the vertices as numpy array

Parameters:

key – key to be used for the third column (Z) – ‘vertex’ or any key in the dictionnary – if ‘vertex’’, [[X,Y,Z]] are returned

property has_values: bool[source]

Check if the cloud has values (other than X,Y,Z)

property header: list[str][source]

Return the headers of the cloud

add_values_by_id_list(id: str, values: list[float])[source]

Add values to the cloud

Parameters:
  • id – use as key for the values

  • values – list of values to be added - must be the same length as number of vertices

property xyz: numpy.ndarray[source]

Alias for get_xyz method

property nbvertices: int[source]

Number of vertices in the cloud

interp_on_array(myarray, key: str = 'vertex', method: Literal['linear', 'nearest', 'cubic'] = 'linear')[source]

Interpolation of the cloud on a 2D array

Parameters:
  • myarray – WolfArray instance

  • key – key to be used for the third column (Z) – ‘vertex’ or any key in the dictionnary

  • method – interpolation method – ‘linear’, ‘nearest’, ‘cubic’

see interpolate_on_cloud method of WolfArray for more information

iter_on_vertices()[source]

Iteration on vertices

get_multipoint()[source]

Return the cloud as a Shapely MultiPoint

projectontrace(trace, return_cloud: bool = True, proximity: float = 99999.0)[source]

Project the cloud onto a trace (type ‘vector’)

Parameters:
  • trace – vector class

  • return_cloud – return a cloud or the lists [s],[z]

  • proximity – search distance for projection

Returns:

New cloud containing the position information on the trace and altitude (s,z) else:

s,z: 2 lists of floats

Return type:

if return_cloud

plot_matplotlib(ax=None, **kwargs)[source]

Plot the cloud using matplotlib

Parameters:
  • ax – axis to plot on – if None, a new figure is created

  • kwargs – additional arguments for matplotlib